From 3443c1c65e9f1753e1e656b35d08416c1fa298f2 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 00:14:38 +0200 Subject: worldmap-viewer: initial public history --- viewer/js/lines.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 viewer/js/lines.js (limited to 'viewer/js/lines.js') diff --git a/viewer/js/lines.js b/viewer/js/lines.js new file mode 100644 index 0000000..f29fe1f --- /dev/null +++ b/viewer/js/lines.js @@ -0,0 +1,45 @@ +// lines.js — named groups of 1-px line segments in a three.js scene +import * as THREE from 'three'; + +export class LineSet { + constructor(scene) { + this.scene = scene; + this.objects = new Map(); + } + + set(id, positions, color, origin = null) { // origin: positions are relative to it (float precision near the ground) + this.remove(id); + if (!positions.length) return; + const geom = new THREE.BufferGeometry(); + geom.setAttribute('position', new THREE.BufferAttribute(positions, 3)); + const obj = new THREE.LineSegments(geom, new THREE.LineBasicMaterial({ color, transparent: true, opacity: 0.85, + depthTest: this.depthTest ?? true, clippingPlanes: this.clip ?? null })); + obj.scale.setScalar(this.scale ?? 1); + if (origin) obj.position.set(origin[0], origin[1], origin[2]); + this.objects.set(id, obj); + this.scene.add(obj); + } + + setClip(planes) { // shared THREE.Plane objects: callers move them, every line follows + this.clip = planes; + for (const o of this.objects.values()) o.material.clippingPlanes = planes; + } + + setTransform(scale, depthTest) { // globe: hug the ground when zoomed in and draw on top of tiles + this.scale = scale; + this.depthTest = depthTest; + for (const o of this.objects.values()) { + o.scale.setScalar(scale); + o.material.depthTest = depthTest; + } + } + + remove(id) { + const obj = this.objects.get(id); + if (!obj) return; + this.scene.remove(obj); + obj.geometry.dispose(); + obj.material.dispose(); + this.objects.delete(id); + } +} -- cgit