MCPcopy Create free account
hub / github.com/CNCKitchen/stlTexturizer / buildAxesIndicator

Function buildAxesIndicator

js/viewer.js:32–82  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

30let _hoverMaterial = null;
31let _needsRender = true;
32let _diagEdges = null; // LineSegments2 for open/non-manifold edges
33let _diagFaces = []; // Array of THREE.Mesh overlays for face highlights
34
35// Turntable pitch clamp: keep the view direction at least this far (radians)
36// away from ±world Z. At the pole itself the up direction is ambiguous and
37// lookAt() flips, which is what used to make the view jump — stopping just
38// short of it makes the pole unreachable, so no flip can ever occur.
39const _POLAR_EPS = 0.01;
40
41// Build a labelled coordinate axes indicator scaled to `size`.
42// X = red, Y = green, Z = blue (up).
43function buildAxesIndicator(size) {
44 const group = new THREE.Group();
45
46 const addAxis = (dir, hex, label) => {
47 const r = size;
48 // Shaft
49 const pts = [new THREE.Vector3(0, 0, 0), dir.clone().multiplyScalar(r * 0.78)];
50 const line = new THREE.Line(
51 new THREE.BufferGeometry().setFromPoints(pts),
52 new THREE.LineBasicMaterial({ color: hex, transparent: true, opacity: 0.9 }),
53 );
54 group.add(line);
55
56 // Cone arrowhead
57 const cone = new THREE.Mesh(
58 new THREE.ConeGeometry(r * 0.07, r * 0.22, 8),
59 new THREE.MeshBasicMaterial({ color: hex }),
60 );
61 cone.position.copy(dir.clone().multiplyScalar(r * 0.89));
62 cone.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), dir);
63 group.add(cone);
64
65 // Text sprite label
66 const c = document.createElement('canvas');
67 c.width = c.height = 64;
68 const ctx = c.getContext('2d');
69 ctx.fillStyle = `#${hex.toString(16).padStart(6, '0')}`;
70 ctx.font = 'bold 48px Arial';
71 ctx.textAlign = 'center';
72 ctx.textBaseline = 'middle';
73 ctx.fillText(label, 32, 32);
74 // depthWrite OFF + renderOrder above the wireframe overlay (3): label
75 // quads must not stamp their rectangle into the depth buffer, or they
76 // punch line-free holes into the wireframe drawn after them. Rendered
77 // last, the transparent label background lets the wireframe shine
78 // through while the glyph stays readable on top.
79 const sprite = new THREE.Sprite(
80 new THREE.SpriteMaterial({ map: new THREE.CanvasTexture(c), transparent: true, depthWrite: false }),
81 );
82 sprite.renderOrder = 4;
83 sprite.position.copy(dir.clone().multiplyScalar(r * 1.18));
84 sprite.scale.set(r * 0.32, r * 0.32, 1);
85 group.add(sprite);

Callers 1

loadGeometryFunction · 0.85

Calls 1

addAxisFunction · 0.85

Tested by

no test coverage detected