@luma.gl/engine 9.4.0-alpha.3 → 9.4.0-beta.1

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.
Files changed (255) hide show
  1. package/LICENSE +5 -1
  2. package/dist/animation/animation-clip.d.ts +18 -0
  3. package/dist/animation/animation-clip.d.ts.map +1 -0
  4. package/dist/animation/animation-clip.js +15 -0
  5. package/dist/animation/animation-clip.js.map +1 -0
  6. package/dist/animation/animation-interpolation.d.ts +18 -0
  7. package/dist/animation/animation-interpolation.d.ts.map +1 -0
  8. package/dist/animation/animation-interpolation.js +101 -0
  9. package/dist/animation/animation-interpolation.js.map +1 -0
  10. package/dist/animation/animation-mixer.d.ts +88 -0
  11. package/dist/animation/animation-mixer.d.ts.map +1 -0
  12. package/dist/animation/animation-mixer.js +287 -0
  13. package/dist/animation/animation-mixer.js.map +1 -0
  14. package/dist/animation/animation-track.d.ts +42 -0
  15. package/dist/animation/animation-track.d.ts.map +1 -0
  16. package/dist/animation/animation-track.js +34 -0
  17. package/dist/animation/animation-track.js.map +1 -0
  18. package/dist/animation/animator.js +1 -1
  19. package/dist/animation/animator.js.map +1 -1
  20. package/dist/animation/key-frames.js +1 -1
  21. package/dist/animation/key-frames.js.map +1 -1
  22. package/dist/animation/morph-targets.d.ts +15 -0
  23. package/dist/animation/morph-targets.d.ts.map +1 -0
  24. package/dist/animation/morph-targets.js +151 -0
  25. package/dist/animation/morph-targets.js.map +1 -0
  26. package/dist/animation/skin.d.ts +18 -0
  27. package/dist/animation/skin.d.ts.map +1 -0
  28. package/dist/animation/skin.js +30 -0
  29. package/dist/animation/skin.js.map +1 -0
  30. package/dist/animation/timeline.js +1 -1
  31. package/dist/animation/timeline.js.map +1 -1
  32. package/dist/animation-loop/animation-loop-template.js +1 -1
  33. package/dist/animation-loop/animation-loop-template.js.map +1 -1
  34. package/dist/animation-loop/animation-loop.d.ts +5 -4
  35. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  36. package/dist/animation-loop/animation-loop.js +3 -3
  37. package/dist/animation-loop/animation-loop.js.map +1 -1
  38. package/dist/animation-loop/animation-props.d.ts +1 -1
  39. package/dist/animation-loop/animation-props.js +1 -1
  40. package/dist/animation-loop/animation-props.js.map +1 -1
  41. package/dist/animation-loop/make-animation-loop.d.ts +9 -1
  42. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  43. package/dist/animation-loop/make-animation-loop.js +24 -5
  44. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  45. package/dist/animation-loop/request-animation-frame.js +1 -1
  46. package/dist/animation-loop/request-animation-frame.js.map +1 -1
  47. package/dist/application-utils/load-file.js +1 -1
  48. package/dist/application-utils/load-file.js.map +1 -1
  49. package/dist/application-utils/random.js +1 -1
  50. package/dist/application-utils/random.js.map +1 -1
  51. package/dist/compute/buffer-transform.d.ts +1 -1
  52. package/dist/compute/buffer-transform.d.ts.map +1 -1
  53. package/dist/compute/buffer-transform.js +1 -1
  54. package/dist/compute/buffer-transform.js.map +1 -1
  55. package/dist/compute/computation.d.ts +4 -1
  56. package/dist/compute/computation.d.ts.map +1 -1
  57. package/dist/compute/computation.js +34 -15
  58. package/dist/compute/computation.js.map +1 -1
  59. package/dist/compute/swap.js +1 -1
  60. package/dist/compute/swap.js.map +1 -1
  61. package/dist/compute/texture-transform.js +1 -1
  62. package/dist/compute/texture-transform.js.map +1 -1
  63. package/dist/controls/orbit-controls.d.ts +61 -0
  64. package/dist/controls/orbit-controls.d.ts.map +1 -0
  65. package/dist/controls/orbit-controls.js +179 -0
  66. package/dist/controls/orbit-controls.js.map +1 -0
  67. package/dist/debug/copy-texture-to-image.js +1 -1
  68. package/dist/debug/copy-texture-to-image.js.map +1 -1
  69. package/dist/debug/debug-framebuffer.js +1 -1
  70. package/dist/debug/debug-framebuffer.js.map +1 -1
  71. package/dist/debug/debug-shader-layout.js +1 -1
  72. package/dist/debug/debug-shader-layout.js.map +1 -1
  73. package/dist/debug/pixel-data-utils.js +1 -1
  74. package/dist/debug/pixel-data-utils.js.map +1 -1
  75. package/dist/dist.dev.js +7605 -6249
  76. package/dist/dist.min.js +31 -31
  77. package/dist/dynamic-buffer/dynamic-buffer.js +1 -1
  78. package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -1
  79. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  80. package/dist/dynamic-texture/dynamic-texture.js +3 -2
  81. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  82. package/dist/dynamic-texture/texture-binding-source.js +1 -1
  83. package/dist/dynamic-texture/texture-binding-source.js.map +1 -1
  84. package/dist/dynamic-texture/texture-data.js +1 -1
  85. package/dist/dynamic-texture/texture-data.js.map +1 -1
  86. package/dist/dynamic-texture/video-texture.js +1 -1
  87. package/dist/dynamic-texture/video-texture.js.map +1 -1
  88. package/dist/geometries/cone-geometry.js +1 -1
  89. package/dist/geometries/cone-geometry.js.map +1 -1
  90. package/dist/geometries/cube-geometry.js +1 -1
  91. package/dist/geometries/cube-geometry.js.map +1 -1
  92. package/dist/geometries/cylinder-geometry.js +1 -1
  93. package/dist/geometries/cylinder-geometry.js.map +1 -1
  94. package/dist/geometries/ico-sphere-geometry.js +1 -1
  95. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  96. package/dist/geometry/geometry-table.js +1 -1
  97. package/dist/geometry/geometry-table.js.map +1 -1
  98. package/dist/geometry/geometry-utils.js +1 -1
  99. package/dist/geometry/geometry-utils.js.map +1 -1
  100. package/dist/geometry/geometry.js +1 -1
  101. package/dist/geometry/geometry.js.map +1 -1
  102. package/dist/geometry/gpu-geometry.js +1 -1
  103. package/dist/geometry/gpu-geometry.js.map +1 -1
  104. package/dist/geometry/mesh-simplification.d.ts +29 -0
  105. package/dist/geometry/mesh-simplification.d.ts.map +1 -0
  106. package/dist/geometry/mesh-simplification.js +402 -0
  107. package/dist/geometry/mesh-simplification.js.map +1 -0
  108. package/dist/index.cjs +9874 -1407
  109. package/dist/index.cjs.map +3 -4
  110. package/dist/index.d.ts +17 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +9 -1
  113. package/dist/index.js.map +1 -1
  114. package/dist/material/material-factory.js +1 -1
  115. package/dist/material/material-factory.js.map +1 -1
  116. package/dist/material/material.js +1 -1
  117. package/dist/material/material.js.map +1 -1
  118. package/dist/model/model.d.ts +1 -1
  119. package/dist/model/model.d.ts.map +1 -1
  120. package/dist/model/model.js +35 -10
  121. package/dist/model/model.js.map +1 -1
  122. package/dist/model/split-uniforms-and-bindings.js +1 -1
  123. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  124. package/dist/models/billboard-texture-model.js +1 -1
  125. package/dist/models/billboard-texture-model.js.map +1 -1
  126. package/dist/models/billboard-texture-module.js +1 -1
  127. package/dist/models/billboard-texture-module.js.map +1 -1
  128. package/dist/models/clip-space.js +1 -1
  129. package/dist/models/clip-space.js.map +1 -1
  130. package/dist/models/directional-light-model.js +1 -1
  131. package/dist/models/directional-light-model.js.map +1 -1
  132. package/dist/models/light-model-utils.js +1 -1
  133. package/dist/models/light-model-utils.js.map +1 -1
  134. package/dist/models/point-light-model.js +1 -1
  135. package/dist/models/point-light-model.js.map +1 -1
  136. package/dist/models/spot-light-model.js +1 -1
  137. package/dist/models/spot-light-model.js.map +1 -1
  138. package/dist/modules/picking/color-picking.js +1 -1
  139. package/dist/modules/picking/color-picking.js.map +1 -1
  140. package/dist/modules/picking/index-color-picking.js +1 -1
  141. package/dist/modules/picking/index-color-picking.js.map +1 -1
  142. package/dist/modules/picking/index-picking.js +1 -1
  143. package/dist/modules/picking/index-picking.js.map +1 -1
  144. package/dist/modules/picking/legacy-color-picking.js +1 -1
  145. package/dist/modules/picking/legacy-color-picking.js.map +1 -1
  146. package/dist/modules/picking/legacy-picking-manager.js +1 -1
  147. package/dist/modules/picking/legacy-picking-manager.js.map +1 -1
  148. package/dist/modules/picking/picking-manager.js +1 -1
  149. package/dist/modules/picking/picking-manager.js.map +1 -1
  150. package/dist/modules/picking/picking-uniforms.js +1 -1
  151. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  152. package/dist/modules/picking/picking.js +1 -1
  153. package/dist/modules/picking/picking.js.map +1 -1
  154. package/dist/passes/get-fragment-shader.js +1 -1
  155. package/dist/passes/get-fragment-shader.js.map +1 -1
  156. package/dist/passes/shader-pass-renderer.d.ts +19 -1
  157. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  158. package/dist/passes/shader-pass-renderer.js +180 -11
  159. package/dist/passes/shader-pass-renderer.js.map +1 -1
  160. package/dist/passes/texture-transform-module.js +1 -1
  161. package/dist/passes/texture-transform-module.js.map +1 -1
  162. package/dist/scenegraph/group-node.d.ts.map +1 -1
  163. package/dist/scenegraph/group-node.js +7 -1
  164. package/dist/scenegraph/group-node.js.map +1 -1
  165. package/dist/scenegraph/model-node.js +1 -1
  166. package/dist/scenegraph/model-node.js.map +1 -1
  167. package/dist/scenegraph/scenegraph-bounds.js +1 -1
  168. package/dist/scenegraph/scenegraph-bounds.js.map +1 -1
  169. package/dist/scenegraph/scenegraph-node.js +4 -4
  170. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  171. package/dist/shader-inputs.js +1 -1
  172. package/dist/shader-inputs.js.map +1 -1
  173. package/dist/utils/buffer-layout-helper.js +1 -1
  174. package/dist/utils/buffer-layout-helper.js.map +1 -1
  175. package/dist/utils/buffer-layout-order.js +1 -1
  176. package/dist/utils/buffer-layout-order.js.map +1 -1
  177. package/dist/utils/deep-equal.js +1 -1
  178. package/dist/utils/deep-equal.js.map +1 -1
  179. package/dist/utils/shader-module-utils.js +1 -1
  180. package/dist/utils/shader-module-utils.js.map +1 -1
  181. package/dist/utils/uid.js +1 -1
  182. package/dist/utils/uid.js.map +1 -1
  183. package/package.json +2 -2
  184. package/src/animation/animation-clip.ts +28 -0
  185. package/src/animation/animation-interpolation.ts +175 -0
  186. package/src/animation/animation-mixer.ts +370 -0
  187. package/src/animation/animation-track.ts +70 -0
  188. package/src/animation/animator.ts +1 -1
  189. package/src/animation/key-frames.ts +1 -1
  190. package/src/animation/morph-targets.ts +191 -0
  191. package/src/animation/skin.ts +50 -0
  192. package/src/animation/timeline.ts +1 -1
  193. package/src/animation-loop/animation-loop-template.ts +1 -1
  194. package/src/animation-loop/animation-loop.ts +8 -7
  195. package/src/animation-loop/animation-props.ts +2 -2
  196. package/src/animation-loop/make-animation-loop.ts +36 -6
  197. package/src/animation-loop/request-animation-frame.ts +1 -1
  198. package/src/application-utils/load-file.ts +1 -1
  199. package/src/application-utils/random.ts +1 -1
  200. package/src/compute/buffer-transform.ts +2 -2
  201. package/src/compute/computation.ts +47 -20
  202. package/src/compute/swap.ts +1 -1
  203. package/src/compute/texture-transform.ts +1 -1
  204. package/src/controls/orbit-controls.ts +248 -0
  205. package/src/debug/copy-texture-to-image.ts +1 -1
  206. package/src/debug/debug-framebuffer.ts +1 -1
  207. package/src/debug/debug-shader-layout.ts +1 -1
  208. package/src/debug/pixel-data-utils.ts +1 -1
  209. package/src/dynamic-buffer/dynamic-buffer.ts +1 -1
  210. package/src/dynamic-texture/dynamic-texture.ts +3 -2
  211. package/src/dynamic-texture/texture-binding-source.ts +1 -1
  212. package/src/dynamic-texture/texture-data.ts +1 -1
  213. package/src/dynamic-texture/video-texture.ts +1 -1
  214. package/src/geometries/cone-geometry.ts +1 -1
  215. package/src/geometries/cube-geometry.ts +1 -1
  216. package/src/geometries/cylinder-geometry.ts +1 -1
  217. package/src/geometries/ico-sphere-geometry.ts +1 -1
  218. package/src/geometry/geometry-table.ts +1 -1
  219. package/src/geometry/geometry-utils.ts +1 -1
  220. package/src/geometry/geometry.ts +1 -1
  221. package/src/geometry/gpu-geometry.ts +1 -1
  222. package/src/geometry/mesh-simplification.ts +554 -0
  223. package/src/index.ts +32 -1
  224. package/src/material/material-factory.ts +1 -1
  225. package/src/material/material.ts +1 -1
  226. package/src/model/model.ts +67 -12
  227. package/src/model/split-uniforms-and-bindings.ts +1 -1
  228. package/src/models/billboard-texture-model.ts +1 -1
  229. package/src/models/billboard-texture-module.ts +1 -1
  230. package/src/models/clip-space.ts +1 -1
  231. package/src/models/directional-light-model.ts +1 -1
  232. package/src/models/light-model-utils.ts +1 -1
  233. package/src/models/point-light-model.ts +1 -1
  234. package/src/models/spot-light-model.ts +1 -1
  235. package/src/modules/picking/color-picking.ts +1 -1
  236. package/src/modules/picking/index-color-picking.ts +1 -1
  237. package/src/modules/picking/index-picking.ts +1 -1
  238. package/src/modules/picking/legacy-color-picking.ts +1 -1
  239. package/src/modules/picking/legacy-picking-manager.ts +1 -1
  240. package/src/modules/picking/picking-manager.ts +1 -1
  241. package/src/modules/picking/picking-uniforms.ts +1 -1
  242. package/src/modules/picking/picking.ts +1 -1
  243. package/src/passes/get-fragment-shader.ts +1 -1
  244. package/src/passes/shader-pass-renderer.ts +246 -14
  245. package/src/passes/texture-transform-module.ts +1 -1
  246. package/src/scenegraph/group-node.ts +8 -1
  247. package/src/scenegraph/model-node.ts +1 -1
  248. package/src/scenegraph/scenegraph-bounds.ts +1 -1
  249. package/src/scenegraph/scenegraph-node.ts +4 -4
  250. package/src/shader-inputs.ts +1 -1
  251. package/src/utils/buffer-layout-helper.ts +1 -1
  252. package/src/utils/buffer-layout-order.ts +1 -1
  253. package/src/utils/deep-equal.ts +1 -1
  254. package/src/utils/shader-module-utils.ts +1 -1
  255. package/src/utils/uid.ts +1 -1
@@ -0,0 +1,554 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {assert} from '@luma.gl/core';
6
+
7
+ /** Per-vertex data used to preserve appearance and deformation during simplification. */
8
+ export type MeshSimplificationAttribute = {
9
+ values: ArrayLike<number>;
10
+ size: number;
11
+ weight?: number;
12
+ };
13
+
14
+ /** Describes one indexed triangle mesh without transferring ownership of its vertex data. */
15
+ export type MeshSimplificationOptions = {
16
+ positions: ArrayLike<number>;
17
+ indices: Uint8Array | Uint16Array | Uint32Array;
18
+ targetRatio?: number;
19
+ targetIndexCount?: number;
20
+ attributes?: readonly MeshSimplificationAttribute[];
21
+ preserveBoundary?: boolean;
22
+ };
23
+
24
+ /** Simplified indices still reference the immutable source vertex and attribute arrays. */
25
+ export type MeshSimplificationResult = {
26
+ indices: Uint8Array | Uint16Array | Uint32Array;
27
+ geometricError: number;
28
+ };
29
+
30
+ type SimplificationVertex = {
31
+ quadric: Float64Array;
32
+ neighbors: Set<number>;
33
+ boundaryNeighbors: Set<number>;
34
+ triangles: Set<number>;
35
+ active: boolean;
36
+ version: number;
37
+ };
38
+
39
+ type SimplificationTriangle = {
40
+ vertices: [number, number, number];
41
+ active: boolean;
42
+ };
43
+
44
+ type EdgeCollapse = {
45
+ retainedVertex: number;
46
+ removedVertex: number;
47
+ retainedVersion: number;
48
+ removedVersion: number;
49
+ geometricCost: number;
50
+ cost: number;
51
+ };
52
+
53
+ const QUADRIC_COMPONENTS = 10;
54
+ const BOUNDARY_COLLINEAR_TOLERANCE = 1e-10;
55
+
56
+ /**
57
+ * Simplifies an indexed triangle mesh through deterministic endpoint-only quadric edge collapses.
58
+ *
59
+ * The returned indices always reference existing source vertices. Positions, UV coordinates,
60
+ * normals, joint indices, joint weights, morph deltas, and other original attributes therefore
61
+ * remain shared and unchanged across every generated detail level.
62
+ */
63
+ export function simplifyMesh(options: MeshSimplificationOptions): MeshSimplificationResult {
64
+ const {positions, indices, attributes = [], preserveBoundary = true} = options;
65
+
66
+ // Triangle indices and XYZ positions must describe complete source elements.
67
+ assert(indices.length % 3 === 0 && positions.length % 3 === 0);
68
+
69
+ const targetIndexCount = Math.max(
70
+ 0,
71
+ Math.min(
72
+ indices.length,
73
+ Math.floor((options.targetIndexCount ?? indices.length * (options.targetRatio ?? 0.5)) / 3) *
74
+ 3
75
+ )
76
+ );
77
+ if (indices.length === 0 || targetIndexCount >= indices.length) {
78
+ return {indices: indices.slice(), geometricError: 0};
79
+ }
80
+
81
+ const vertexCount = positions.length / 3;
82
+ const vertices: SimplificationVertex[] = Array.from({length: vertexCount}, () => ({
83
+ quadric: new Float64Array(QUADRIC_COMPONENTS),
84
+ neighbors: new Set<number>(),
85
+ boundaryNeighbors: new Set<number>(),
86
+ triangles: new Set<number>(),
87
+ active: false,
88
+ version: 0
89
+ }));
90
+ const triangles: SimplificationTriangle[] = [];
91
+ const edgeCounts = new Map<number, number>();
92
+ const triangleKeys = new Map<string, number>();
93
+ const queue = new EdgeCollapseQueue();
94
+ let activeTriangleCount = 0;
95
+ let geometricErrorSquared = 0;
96
+
97
+ const updateEdge = (firstVertex: number, secondVertex: number, change: number): void => {
98
+ const minimumVertex = Math.min(firstVertex, secondVertex);
99
+ const maximumVertex = Math.max(firstVertex, secondVertex);
100
+ const edgeKey = minimumVertex * vertexCount + maximumVertex;
101
+ const previousCount = edgeCounts.get(edgeKey) || 0;
102
+ const nextCount = previousCount + change;
103
+
104
+ if (nextCount <= 0) {
105
+ edgeCounts.delete(edgeKey);
106
+ vertices[firstVertex].neighbors.delete(secondVertex);
107
+ vertices[secondVertex].neighbors.delete(firstVertex);
108
+ } else {
109
+ edgeCounts.set(edgeKey, nextCount);
110
+ vertices[firstVertex].neighbors.add(secondVertex);
111
+ vertices[secondVertex].neighbors.add(firstVertex);
112
+ }
113
+
114
+ if (nextCount === 1) {
115
+ vertices[firstVertex].boundaryNeighbors.add(secondVertex);
116
+ vertices[secondVertex].boundaryNeighbors.add(firstVertex);
117
+ } else {
118
+ vertices[firstVertex].boundaryNeighbors.delete(secondVertex);
119
+ vertices[secondVertex].boundaryNeighbors.delete(firstVertex);
120
+ }
121
+ };
122
+
123
+ const removeTriangle = (triangleIndex: number): void => {
124
+ const triangle = triangles[triangleIndex];
125
+ if (!triangle.active) {
126
+ return;
127
+ }
128
+ const [firstVertex, secondVertex, thirdVertex] = triangle.vertices;
129
+ triangleKeys.delete(getTriangleKey(firstVertex, secondVertex, thirdVertex));
130
+ updateEdge(firstVertex, secondVertex, -1);
131
+ updateEdge(secondVertex, thirdVertex, -1);
132
+ updateEdge(thirdVertex, firstVertex, -1);
133
+ vertices[firstVertex].triangles.delete(triangleIndex);
134
+ vertices[secondVertex].triangles.delete(triangleIndex);
135
+ vertices[thirdVertex].triangles.delete(triangleIndex);
136
+ triangle.active = false;
137
+ activeTriangleCount--;
138
+ };
139
+
140
+ const addTriangle = (triangleIndex: number): boolean => {
141
+ const triangle = triangles[triangleIndex];
142
+ const [firstVertex, secondVertex, thirdVertex] = triangle.vertices;
143
+ if (
144
+ firstVertex === secondVertex ||
145
+ secondVertex === thirdVertex ||
146
+ thirdVertex === firstVertex
147
+ ) {
148
+ return false;
149
+ }
150
+
151
+ const triangleKey = getTriangleKey(firstVertex, secondVertex, thirdVertex);
152
+ if (triangleKeys.has(triangleKey)) {
153
+ return false;
154
+ }
155
+
156
+ triangleKeys.set(triangleKey, triangleIndex);
157
+ updateEdge(firstVertex, secondVertex, 1);
158
+ updateEdge(secondVertex, thirdVertex, 1);
159
+ updateEdge(thirdVertex, firstVertex, 1);
160
+ vertices[firstVertex].triangles.add(triangleIndex);
161
+ vertices[secondVertex].triangles.add(triangleIndex);
162
+ vertices[thirdVertex].triangles.add(triangleIndex);
163
+ vertices[firstVertex].active = true;
164
+ vertices[secondVertex].active = true;
165
+ vertices[thirdVertex].active = true;
166
+ triangle.active = true;
167
+ activeTriangleCount++;
168
+ return true;
169
+ };
170
+
171
+ for (let indexOffset = 0; indexOffset < indices.length; indexOffset += 3) {
172
+ const firstVertex = indices[indexOffset];
173
+ const secondVertex = indices[indexOffset + 1];
174
+ const thirdVertex = indices[indexOffset + 2];
175
+ // Index-only simplification cannot represent references outside the source vertex array.
176
+ assert(firstVertex < vertexCount && secondVertex < vertexCount && thirdVertex < vertexCount);
177
+
178
+ const triangle: SimplificationTriangle = {
179
+ vertices: [firstVertex, secondVertex, thirdVertex],
180
+ active: false
181
+ };
182
+ const triangleIndex = triangles.push(triangle) - 1;
183
+ if (addTriangle(triangleIndex)) {
184
+ addTriangleQuadric(vertices, positions, firstVertex, secondVertex, thirdVertex);
185
+ }
186
+ }
187
+
188
+ const enqueueEdge = (firstVertex: number, secondVertex: number): void => {
189
+ if (!vertices[firstVertex].active || !vertices[secondVertex].active) {
190
+ return;
191
+ }
192
+
193
+ const attributeCost = getAttributeCost(attributes, firstVertex, secondVertex);
194
+ if (!Number.isFinite(attributeCost)) {
195
+ return;
196
+ }
197
+
198
+ for (const [retainedVertex, removedVertex] of [
199
+ [firstVertex, secondVertex],
200
+ [secondVertex, firstVertex]
201
+ ]) {
202
+ if (
203
+ preserveBoundary &&
204
+ !canCollapseBoundary(vertices, positions, retainedVertex, removedVertex)
205
+ ) {
206
+ continue;
207
+ }
208
+ const geometricCost = Math.max(
209
+ 0,
210
+ evaluateCombinedQuadric(vertices, positions, firstVertex, secondVertex, retainedVertex)
211
+ );
212
+ queue.add({
213
+ retainedVertex,
214
+ removedVertex,
215
+ retainedVersion: vertices[retainedVertex].version,
216
+ removedVersion: vertices[removedVertex].version,
217
+ geometricCost,
218
+ cost: geometricCost + attributeCost
219
+ });
220
+ }
221
+ };
222
+
223
+ for (let vertexIndex = 0; vertexIndex < vertices.length; vertexIndex++) {
224
+ for (const neighbor of vertices[vertexIndex].neighbors) {
225
+ if (vertexIndex < neighbor) {
226
+ enqueueEdge(vertexIndex, neighbor);
227
+ }
228
+ }
229
+ }
230
+
231
+ while (activeTriangleCount * 3 > targetIndexCount) {
232
+ const candidate = queue.remove();
233
+ if (!candidate) {
234
+ break;
235
+ }
236
+ const {retainedVertex, removedVertex} = candidate;
237
+ const retained = vertices[retainedVertex];
238
+ const removed = vertices[removedVertex];
239
+ if (
240
+ !retained.active ||
241
+ !removed.active ||
242
+ retained.version !== candidate.retainedVersion ||
243
+ removed.version !== candidate.removedVersion ||
244
+ !retained.neighbors.has(removedVertex) ||
245
+ (preserveBoundary &&
246
+ !canCollapseBoundary(vertices, positions, retainedVertex, removedVertex)) ||
247
+ !preservesTriangleOrientation(triangles, vertices, positions, retainedVertex, removedVertex)
248
+ ) {
249
+ continue;
250
+ }
251
+
252
+ const affectedVertices = new Set<number>([
253
+ retainedVertex,
254
+ removedVertex,
255
+ ...retained.neighbors,
256
+ ...removed.neighbors
257
+ ]);
258
+ const affectedTriangles = [...removed.triangles];
259
+ for (const triangleIndex of affectedTriangles) {
260
+ removeTriangle(triangleIndex);
261
+ }
262
+ for (const triangleIndex of affectedTriangles) {
263
+ const triangle = triangles[triangleIndex];
264
+ for (let cornerIndex = 0; cornerIndex < 3; cornerIndex++) {
265
+ if (triangle.vertices[cornerIndex] === removedVertex) {
266
+ triangle.vertices[cornerIndex] = retainedVertex;
267
+ }
268
+ }
269
+ addTriangle(triangleIndex);
270
+ }
271
+
272
+ for (let quadricIndex = 0; quadricIndex < QUADRIC_COMPONENTS; quadricIndex++) {
273
+ retained.quadric[quadricIndex] += removed.quadric[quadricIndex];
274
+ }
275
+ removed.active = false;
276
+ geometricErrorSquared = Math.max(geometricErrorSquared, candidate.geometricCost);
277
+
278
+ for (const affectedVertex of affectedVertices) {
279
+ vertices[affectedVertex].version++;
280
+ }
281
+ for (const affectedVertex of affectedVertices) {
282
+ if (!vertices[affectedVertex].active) {
283
+ continue;
284
+ }
285
+ for (const neighbor of vertices[affectedVertex].neighbors) {
286
+ enqueueEdge(affectedVertex, neighbor);
287
+ }
288
+ }
289
+ }
290
+
291
+ const IndexArray = indices.constructor as
292
+ | Uint8ArrayConstructor
293
+ | Uint16ArrayConstructor
294
+ | Uint32ArrayConstructor;
295
+ const simplifiedIndices = new IndexArray(activeTriangleCount * 3);
296
+ let indexOffset = 0;
297
+ for (const triangle of triangles) {
298
+ if (triangle.active) {
299
+ simplifiedIndices[indexOffset++] = triangle.vertices[0];
300
+ simplifiedIndices[indexOffset++] = triangle.vertices[1];
301
+ simplifiedIndices[indexOffset++] = triangle.vertices[2];
302
+ }
303
+ }
304
+ return {indices: simplifiedIndices, geometricError: Math.sqrt(geometricErrorSquared)};
305
+ }
306
+
307
+ function addTriangleQuadric(
308
+ vertices: SimplificationVertex[],
309
+ positions: ArrayLike<number>,
310
+ firstVertex: number,
311
+ secondVertex: number,
312
+ thirdVertex: number
313
+ ): void {
314
+ const normal = getTriangleNormal(positions, firstVertex, secondVertex, thirdVertex);
315
+ const length = Math.hypot(normal[0], normal[1], normal[2]);
316
+ if (length === 0) {
317
+ return;
318
+ }
319
+ const planeX = normal[0] / length;
320
+ const planeY = normal[1] / length;
321
+ const planeZ = normal[2] / length;
322
+ const planeOffset = -(
323
+ planeX * positions[firstVertex * 3] +
324
+ planeY * positions[firstVertex * 3 + 1] +
325
+ planeZ * positions[firstVertex * 3 + 2]
326
+ );
327
+ const plane = [planeX, planeY, planeZ, planeOffset];
328
+
329
+ for (const vertexIndex of [firstVertex, secondVertex, thirdVertex]) {
330
+ let quadricIndex = 0;
331
+ for (let rowIndex = 0; rowIndex < 4; rowIndex++) {
332
+ for (let columnIndex = rowIndex; columnIndex < 4; columnIndex++) {
333
+ vertices[vertexIndex].quadric[quadricIndex++] += plane[rowIndex] * plane[columnIndex];
334
+ }
335
+ }
336
+ }
337
+ }
338
+
339
+ function evaluateCombinedQuadric(
340
+ vertices: SimplificationVertex[],
341
+ positions: ArrayLike<number>,
342
+ firstVertex: number,
343
+ secondVertex: number,
344
+ targetVertex: number
345
+ ): number {
346
+ const point = [
347
+ positions[targetVertex * 3],
348
+ positions[targetVertex * 3 + 1],
349
+ positions[targetVertex * 3 + 2],
350
+ 1
351
+ ];
352
+ let quadricIndex = 0;
353
+ let error = 0;
354
+ for (let rowIndex = 0; rowIndex < 4; rowIndex++) {
355
+ for (let columnIndex = rowIndex; columnIndex < 4; columnIndex++) {
356
+ const quadric =
357
+ vertices[firstVertex].quadric[quadricIndex] + vertices[secondVertex].quadric[quadricIndex];
358
+ error += quadric * point[rowIndex] * point[columnIndex] * (rowIndex === columnIndex ? 1 : 2);
359
+ quadricIndex++;
360
+ }
361
+ }
362
+ return error;
363
+ }
364
+
365
+ function getAttributeCost(
366
+ attributes: readonly MeshSimplificationAttribute[],
367
+ firstVertex: number,
368
+ secondVertex: number
369
+ ): number {
370
+ let error = 0;
371
+ for (const attribute of attributes) {
372
+ const weight = attribute.weight ?? 1;
373
+ if (weight === 0) {
374
+ continue;
375
+ }
376
+ const discrete =
377
+ attribute.values instanceof Uint8Array ||
378
+ attribute.values instanceof Uint16Array ||
379
+ attribute.values instanceof Uint32Array;
380
+ for (let componentIndex = 0; componentIndex < attribute.size; componentIndex++) {
381
+ const difference =
382
+ attribute.values[firstVertex * attribute.size + componentIndex] -
383
+ attribute.values[secondVertex * attribute.size + componentIndex];
384
+ if (discrete && difference !== 0) {
385
+ return Infinity;
386
+ }
387
+ error += difference * difference * weight;
388
+ }
389
+ }
390
+ return error;
391
+ }
392
+
393
+ function canCollapseBoundary(
394
+ vertices: SimplificationVertex[],
395
+ positions: ArrayLike<number>,
396
+ retainedVertex: number,
397
+ removedVertex: number
398
+ ): boolean {
399
+ const retainedBoundary = vertices[retainedVertex].boundaryNeighbors.size > 0;
400
+ const removedBoundary = vertices[removedVertex].boundaryNeighbors.size > 0;
401
+ if (retainedBoundary !== removedBoundary) {
402
+ return false;
403
+ }
404
+ if (!removedBoundary) {
405
+ return true;
406
+ }
407
+
408
+ const boundaryNeighbors = vertices[removedVertex].boundaryNeighbors;
409
+ if (boundaryNeighbors.size !== 2 || !boundaryNeighbors.has(retainedVertex)) {
410
+ return false;
411
+ }
412
+ const otherNeighbor = [...boundaryNeighbors].find(neighbor => neighbor !== retainedVertex);
413
+ if (otherNeighbor === undefined) {
414
+ return false;
415
+ }
416
+
417
+ const retainedOffset = getPositionDifference(positions, retainedVertex, removedVertex);
418
+ const otherOffset = getPositionDifference(positions, otherNeighbor, removedVertex);
419
+ const retainedLengthSquared = squaredLength(retainedOffset);
420
+ const otherLengthSquared = squaredLength(otherOffset);
421
+ const cross = [
422
+ retainedOffset[1] * otherOffset[2] - retainedOffset[2] * otherOffset[1],
423
+ retainedOffset[2] * otherOffset[0] - retainedOffset[0] * otherOffset[2],
424
+ retainedOffset[0] * otherOffset[1] - retainedOffset[1] * otherOffset[0]
425
+ ] as const;
426
+ const dot =
427
+ retainedOffset[0] * otherOffset[0] +
428
+ retainedOffset[1] * otherOffset[1] +
429
+ retainedOffset[2] * otherOffset[2];
430
+
431
+ return (
432
+ dot <= 0 &&
433
+ squaredLength(cross) <=
434
+ BOUNDARY_COLLINEAR_TOLERANCE * retainedLengthSquared * otherLengthSquared
435
+ );
436
+ }
437
+
438
+ function preservesTriangleOrientation(
439
+ triangles: SimplificationTriangle[],
440
+ vertices: SimplificationVertex[],
441
+ positions: ArrayLike<number>,
442
+ retainedVertex: number,
443
+ removedVertex: number
444
+ ): boolean {
445
+ for (const triangleIndex of vertices[removedVertex].triangles) {
446
+ const triangle = triangles[triangleIndex];
447
+ if (triangle.vertices.includes(retainedVertex)) {
448
+ continue;
449
+ }
450
+ const originalNormal = getTriangleNormal(positions, ...triangle.vertices);
451
+ const replacement = triangle.vertices.map(vertex =>
452
+ vertex === removedVertex ? retainedVertex : vertex
453
+ ) as [number, number, number];
454
+ const replacementNormal = getTriangleNormal(positions, ...replacement);
455
+ const normalAlignment =
456
+ originalNormal[0] * replacementNormal[0] +
457
+ originalNormal[1] * replacementNormal[1] +
458
+ originalNormal[2] * replacementNormal[2];
459
+ if (normalAlignment <= 0) {
460
+ return false;
461
+ }
462
+ }
463
+ return true;
464
+ }
465
+
466
+ function getTriangleNormal(
467
+ positions: ArrayLike<number>,
468
+ firstVertex: number,
469
+ secondVertex: number,
470
+ thirdVertex: number
471
+ ): readonly [number, number, number] {
472
+ const firstEdge = getPositionDifference(positions, secondVertex, firstVertex);
473
+ const secondEdge = getPositionDifference(positions, thirdVertex, firstVertex);
474
+ return [
475
+ firstEdge[1] * secondEdge[2] - firstEdge[2] * secondEdge[1],
476
+ firstEdge[2] * secondEdge[0] - firstEdge[0] * secondEdge[2],
477
+ firstEdge[0] * secondEdge[1] - firstEdge[1] * secondEdge[0]
478
+ ];
479
+ }
480
+
481
+ function getPositionDifference(
482
+ positions: ArrayLike<number>,
483
+ firstVertex: number,
484
+ secondVertex: number
485
+ ): readonly [number, number, number] {
486
+ return [
487
+ positions[firstVertex * 3] - positions[secondVertex * 3],
488
+ positions[firstVertex * 3 + 1] - positions[secondVertex * 3 + 1],
489
+ positions[firstVertex * 3 + 2] - positions[secondVertex * 3 + 2]
490
+ ];
491
+ }
492
+
493
+ function squaredLength(vector: readonly [number, number, number]): number {
494
+ return vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2];
495
+ }
496
+
497
+ function getTriangleKey(firstVertex: number, secondVertex: number, thirdVertex: number): string {
498
+ return [firstVertex, secondVertex, thirdVertex].sort((first, second) => first - second).join(':');
499
+ }
500
+
501
+ /** Binary min-heap keeps repeated edge collapses practical for real production meshes. */
502
+ class EdgeCollapseQueue {
503
+ private readonly entries: EdgeCollapse[] = [];
504
+
505
+ add(candidate: EdgeCollapse): void {
506
+ this.entries.push(candidate);
507
+ let index = this.entries.length - 1;
508
+ while (index > 0) {
509
+ const parentIndex = (index - 1) >> 1;
510
+ if (compareCollapses(this.entries[parentIndex], candidate) <= 0) {
511
+ break;
512
+ }
513
+ this.entries[index] = this.entries[parentIndex];
514
+ this.entries[parentIndex] = candidate;
515
+ index = parentIndex;
516
+ }
517
+ }
518
+
519
+ remove(): EdgeCollapse | undefined {
520
+ const first = this.entries[0];
521
+ const last = this.entries.pop();
522
+ if (!first || !last || this.entries.length === 0) {
523
+ return first;
524
+ }
525
+ this.entries[0] = last;
526
+ let index = 0;
527
+ while (true) {
528
+ const firstChild = index * 2 + 1;
529
+ if (firstChild >= this.entries.length) {
530
+ break;
531
+ }
532
+ const secondChild = firstChild + 1;
533
+ const child =
534
+ secondChild < this.entries.length &&
535
+ compareCollapses(this.entries[secondChild], this.entries[firstChild]) < 0
536
+ ? secondChild
537
+ : firstChild;
538
+ if (compareCollapses(this.entries[index], this.entries[child]) <= 0) {
539
+ break;
540
+ }
541
+ [this.entries[index], this.entries[child]] = [this.entries[child], this.entries[index]];
542
+ index = child;
543
+ }
544
+ return first;
545
+ }
546
+ }
547
+
548
+ function compareCollapses(first: EdgeCollapse, second: EdgeCollapse): number {
549
+ return (
550
+ first.cost - second.cost ||
551
+ first.retainedVertex - second.retainedVertex ||
552
+ first.removedVertex - second.removedVertex
553
+ );
554
+ }
package/src/index.ts CHANGED
@@ -1,12 +1,32 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  // luma.gl Engine API
6
6
 
7
7
  // Animation
8
8
  export type {AnimationClipControllerProps} from './animation/animator';
9
9
  export {AnimationClipController, Animator} from './animation/animator';
10
+ export type {
11
+ AnimationInterpolation,
12
+ AnimationSampler,
13
+ AnimationValueType
14
+ } from './animation/animation-interpolation';
15
+ export {evaluateAnimationSampler} from './animation/animation-interpolation';
16
+ export type {AnimationBinding, AnimationTrackProps} from './animation/animation-track';
17
+ export {AnimationTrack} from './animation/animation-track';
18
+ export type {AnimationClipProps} from './animation/animation-clip';
19
+ export {AnimationClip} from './animation/animation-clip';
20
+ export type {AnimationActionProps, AnimationLoopMode} from './animation/animation-mixer';
21
+ export {AnimationAction, AnimationMixer} from './animation/animation-mixer';
22
+ export type {MorphTargetAttributes} from './animation/morph-targets';
23
+ export {
24
+ applyMorphTargets,
25
+ decodeMorphTargetAttribute,
26
+ updateMorphTargetBuffers
27
+ } from './animation/morph-targets';
28
+ export type {SkinJointMatricesProps} from './animation/skin';
29
+ export {updateSkinJointMatrices} from './animation/skin';
10
30
  export {Timeline} from './animation/timeline';
11
31
  export {KeyFrames} from './animation/key-frames';
12
32
  export type {AnimationProps} from './animation-loop/animation-props';
@@ -21,8 +41,13 @@ export type {
21
41
  export {AnimationLoop} from './animation-loop/animation-loop';
22
42
 
23
43
  export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
44
+ export type {TemplateAnimationLoop} from './animation-loop/make-animation-loop';
24
45
  export {makeAnimationLoop} from './animation-loop/make-animation-loop';
25
46
 
47
+ // Camera controls
48
+ export type {OrbitControlsProps, OrbitPosition} from './controls/orbit-controls';
49
+ export {OrbitControls} from './controls/orbit-controls';
50
+
26
51
  export type {ModelProps} from './model/model';
27
52
  export {Model} from './model/model';
28
53
  export type {MaterialProps} from './material/material';
@@ -68,6 +93,12 @@ export type {GeometryProps, GeometryAttribute, GeometryAttributeInput} from './g
68
93
  export {Geometry} from './geometry/geometry';
69
94
  export type {MakeInterleavedGeometryOptions} from './geometry/geometry-utils';
70
95
  export {makeInterleavedGeometry} from './geometry/geometry-utils';
96
+ export type {
97
+ MeshSimplificationAttribute,
98
+ MeshSimplificationOptions,
99
+ MeshSimplificationResult
100
+ } from './geometry/mesh-simplification';
101
+ export {simplifyMesh} from './geometry/mesh-simplification';
71
102
  export type {GPUGeometryProps} from './geometry/gpu-geometry';
72
103
  export {GPUGeometry} from './geometry/gpu-geometry';
73
104
 
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Binding, BindingsByGroup, Device} from '@luma.gl/core';
6
6
  import type {ShaderModule} from '@luma.gl/shadertools';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {
6
6
  Binding,