@woosh/meep-engine 2.160.0 → 2.162.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
7
7
  "type": "module",
8
8
  "author": "Alexander Goldring",
9
- "version": "2.160.0",
9
+ "version": "2.162.0",
10
10
  "main": "build/meep.module.js",
11
11
  "module": "build/meep.module.js",
12
12
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"make_cap.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/ecs/path/tube/build/make_cap.js"],"names":[],"mappings":"AAgNA;;;;;;;;;;;;;;GAcG;AACH,4DAbW,MAAM,gBACN,YAAY,GAAC,MAAM,EAAE,cACrB,OAAO,EAAE,gBACT,OAAO,EAAE,eAET,OAAO,EAAE,SACT,MAAM,EAAE,gBACR,MAAM,EAAE,GAAC,YAAY,gBACrB,MAAM,mBACN,MAAM,EAAE,GAAC,YAAY,aACrB,MAAM,QACN,OAAO,QA6BjB;AAED;;;;;;GAMG;AACH,wDALW,MAAM,OACN;IAAC,aAAa,EAAC,MAAM,CAAC;IAAC,YAAY,EAAC,MAAM,CAAA;CAAC,mBAC3C,MAAM,QACN,OAAO,QAiBjB;wBAlRuB,OAAO;wBAMP,eAAe"}
1
+ {"version":3,"file":"make_cap.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/ecs/path/tube/build/make_cap.js"],"names":[],"mappings":"AA+PA;;;;;;;;;;;;;;GAcG;AACH,4DAbW,MAAM,gBACN,YAAY,GAAC,MAAM,EAAE,cACrB,OAAO,EAAE,gBACT,OAAO,EAAE,eAET,OAAO,EAAE,SACT,MAAM,EAAE,gBACR,MAAM,EAAE,GAAC,YAAY,gBACrB,MAAM,mBACN,MAAM,EAAE,GAAC,YAAY,aACrB,MAAM,QACN,OAAO,QA6BjB;AAED;;;;;;GAMG;AACH,wDALW,MAAM,OACN;IAAC,aAAa,EAAC,MAAM,CAAC;IAAC,YAAY,EAAC,MAAM,CAAA;CAAC,mBAC3C,MAAM,QACN,OAAO,QAiBjB;wBAjUuB,OAAO;wBAMP,eAAe"}
@@ -79,10 +79,32 @@ function make_cap_round(
79
79
  const B = in_binormals[index];
80
80
  const T = in_tangents[index];
81
81
 
82
- const tangent = new Vector3();
83
- tangent.crossVectors(N, B);
84
- tangent.normalize();
85
- tangent.multiplyScalar(-direction);
82
+ // Outward cap axis. Derive it from the PATH itself (the segment between the
83
+ // cap and its neighbour sample) rather than from N x B: the Frenet frame's
84
+ // tangent can flip sign at curvature features, and an N x B-derived axis
85
+ // would then make the cap bulge inward for a frame ("cap twists off-axis").
86
+ // The path direction is always well-defined and outward. Fall back to the
87
+ // frame only if the neighbour sample is coincident (degenerate segment).
88
+ const point_count = in_positions.length / 3;
89
+ const neighbour = direction > 0
90
+ ? Math.min(index + 1, point_count - 1)
91
+ : Math.max(index - 1, 0);
92
+ const n3 = neighbour * 3;
93
+
94
+ const tangent = new Vector3(
95
+ Px - in_positions[n3],
96
+ Py - in_positions[n3 + 1],
97
+ Pz - in_positions[n3 + 2]
98
+ );
99
+
100
+ if (tangent.lengthSq() > 1e-12) {
101
+ tangent.normalize();
102
+ } else {
103
+ // degenerate: neighbour coincides with the cap point, use the frame
104
+ tangent.crossVectors(N, B);
105
+ tangent.normalize();
106
+ tangent.multiplyScalar(-direction);
107
+ }
86
108
 
87
109
  const normal = direction > 0 ? N : N.clone().negate();
88
110
  const binormal = direction > 0 ? B : B.clone().negate();
@@ -138,6 +160,31 @@ function make_cap_round(
138
160
  }
139
161
 
140
162
  make_ring_faces(out, index_offset, cap_segment_count, shape_length);
163
+
164
+ // Correct the cap vertex normals. make_ring_vertices wrote the tube WALL
165
+ // normal (purely radial) for each cap ring, which shades the dome like a
166
+ // flat cylinder end. Every cap vertex lies on the sphere of radius `radius`
167
+ // centred at the cap base (Px, Py, Pz), so the true outward normal is just
168
+ // the direction from that centre to the vertex. This bends the normals from
169
+ // radial (at the base ring) to axial (at the pole), independent of the
170
+ // path frame's roll.
171
+ const cap_normals = out.normals;
172
+ const cap_positions = out.positions;
173
+ for (let v = index_offset; v < out.cursor_vertices; v++) {
174
+ const v3 = v * 3;
175
+
176
+ const nx = cap_positions[v3] - Px;
177
+ const ny = cap_positions[v3 + 1] - Py;
178
+ const nz = cap_positions[v3 + 2] - Pz;
179
+
180
+ const length = Math.sqrt(nx * nx + ny * ny + nz * nz);
181
+ if (length > 1e-8) {
182
+ const inv = 1 / length;
183
+ cap_normals[v3] = nx * inv;
184
+ cap_normals[v3 + 1] = ny * inv;
185
+ cap_normals[v3 + 2] = nz * inv;
186
+ }
187
+ }
141
188
  }
142
189
 
143
190
  const m3_zero = new Float32Array(9);