@myned-ai/gsplat-flame-avatar-renderer 1.0.1 → 1.0.4

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 (66) hide show
  1. package/README.md +4 -29
  2. package/dist/gsplat-flame-avatar-renderer.cjs.js +12875 -0
  3. package/dist/{gsplat-flame-avatar-renderer.umd.js.map → gsplat-flame-avatar-renderer.cjs.js.map} +1 -1
  4. package/dist/gsplat-flame-avatar-renderer.esm.js +1 -1
  5. package/package.json +5 -3
  6. package/src/api/index.js +7 -0
  7. package/src/buffers/SplatBuffer.js +1394 -0
  8. package/src/buffers/SplatBufferGenerator.js +41 -0
  9. package/src/buffers/SplatPartitioner.js +110 -0
  10. package/src/buffers/UncompressedSplatArray.js +106 -0
  11. package/src/buffers/index.js +11 -0
  12. package/src/core/SplatGeometry.js +48 -0
  13. package/src/core/SplatMesh.js +2620 -0
  14. package/src/core/SplatScene.js +43 -0
  15. package/src/core/SplatTree.js +200 -0
  16. package/src/core/Viewer.js +2895 -0
  17. package/src/core/index.js +13 -0
  18. package/src/enums/EngineConstants.js +58 -0
  19. package/src/enums/LogLevel.js +13 -0
  20. package/src/enums/RenderMode.js +11 -0
  21. package/src/enums/SceneFormat.js +21 -0
  22. package/src/enums/SceneRevealMode.js +11 -0
  23. package/src/enums/SplatRenderMode.js +10 -0
  24. package/src/enums/index.js +13 -0
  25. package/src/flame/FlameAnimator.js +271 -0
  26. package/src/flame/FlameConstants.js +21 -0
  27. package/src/flame/FlameTextureManager.js +293 -0
  28. package/src/flame/index.js +22 -0
  29. package/src/flame/utils.js +50 -0
  30. package/src/index.js +39 -0
  31. package/src/loaders/DirectLoadError.js +14 -0
  32. package/src/loaders/INRIAV1PlyParser.js +223 -0
  33. package/src/loaders/PlyLoader.js +261 -0
  34. package/src/loaders/PlyParser.js +19 -0
  35. package/src/loaders/PlyParserUtils.js +311 -0
  36. package/src/loaders/index.js +13 -0
  37. package/src/materials/SplatMaterial.js +1065 -0
  38. package/src/materials/SplatMaterial2D.js +358 -0
  39. package/src/materials/SplatMaterial3D.js +278 -0
  40. package/src/materials/index.js +11 -0
  41. package/src/raycaster/Hit.js +37 -0
  42. package/src/raycaster/Ray.js +123 -0
  43. package/src/raycaster/Raycaster.js +175 -0
  44. package/src/raycaster/index.js +10 -0
  45. package/src/renderer/AnimationManager.js +574 -0
  46. package/src/renderer/AppConstants.js +101 -0
  47. package/src/renderer/GaussianSplatRenderer.js +695 -0
  48. package/src/renderer/index.js +24 -0
  49. package/src/utils/LoaderUtils.js +65 -0
  50. package/src/utils/Util.js +375 -0
  51. package/src/utils/index.js +9 -0
  52. package/src/worker/SortWorker.js +284 -0
  53. package/src/worker/index.js +8 -0
  54. package/dist/gsplat-flame-avatar-renderer.esm.min.js +0 -2
  55. package/dist/gsplat-flame-avatar-renderer.esm.min.js.map +0 -1
  56. package/dist/gsplat-flame-avatar-renderer.umd.js +0 -12876
  57. package/dist/gsplat-flame-avatar-renderer.umd.min.js +0 -2
  58. package/dist/gsplat-flame-avatar-renderer.umd.min.js.map +0 -1
  59. package/dist/gsplat-flame-avatar.esm.js +0 -12755
  60. package/dist/gsplat-flame-avatar.esm.js.map +0 -1
  61. package/dist/gsplat-flame-avatar.esm.min.js +0 -2
  62. package/dist/gsplat-flame-avatar.esm.min.js.map +0 -1
  63. package/dist/gsplat-flame-avatar.umd.js +0 -12876
  64. package/dist/gsplat-flame-avatar.umd.js.map +0 -1
  65. package/dist/gsplat-flame-avatar.umd.min.js +0 -2
  66. package/dist/gsplat-flame-avatar.umd.min.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ /**
2
+ * SplatScene
3
+ *
4
+ * Derived from @mkkellogg/gaussian-splats-3d (MIT License)
5
+ * https://github.com/mkkellogg/GaussianSplats3D
6
+ *
7
+ * This file is functionally identical to the original.
8
+ */
9
+
10
+ import { Matrix4, Object3D, Quaternion, Vector3 } from 'three';
11
+
12
+ export class SplatScene extends Object3D {
13
+
14
+ constructor(splatBuffer, position = new Vector3(), quaternion = new Quaternion(),
15
+ scale = new Vector3(1, 1, 1), minimumAlpha = 1, opacity = 1.0, visible = true) {
16
+ super();
17
+ this.splatBuffer = splatBuffer;
18
+ this.position.copy(position);
19
+ this.quaternion.copy(quaternion);
20
+ this.scale.copy(scale);
21
+ this.transform = new Matrix4();
22
+ this.minimumAlpha = minimumAlpha;
23
+ this.opacity = opacity;
24
+ this.visible = visible;
25
+ }
26
+
27
+ copyTransformData(otherScene) {
28
+ this.position.copy(otherScene.position);
29
+ this.quaternion.copy(otherScene.quaternion);
30
+ this.scale.copy(otherScene.scale);
31
+ this.transform.copy(otherScene.transform);
32
+ }
33
+
34
+ updateTransform(dynamicMode) {
35
+ if (dynamicMode) {
36
+ if (this.matrixWorldAutoUpdate) this.updateWorldMatrix(true, false);
37
+ this.transform.copy(this.matrixWorld);
38
+ } else {
39
+ if (this.matrixAutoUpdate) this.updateMatrix();
40
+ this.transform.copy(this.matrix);
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,200 @@
1
+ /**
2
+ * SplatTree
3
+ *
4
+ * Derived from @mkkellogg/gaussian-splats-3d (MIT License)
5
+ * https://github.com/mkkellogg/GaussianSplats3D
6
+ *
7
+ * This file is functionally identical to the original.
8
+ */
9
+
10
+ import { Vector3 } from 'three';
11
+ import { delayedExecute } from '../utils/Util.js';
12
+
13
+ // Worker-related functions (simplified stubs - the actual worker is handled differently)
14
+ const checkAndCreateWorker = () => {
15
+ // Worker creation is handled by the build system
16
+ return null;
17
+ };
18
+
19
+ const workerProcessCenters = (worker, centers, buffers, maxDepth, maxCentersPerNode) => {
20
+ // Worker message passing
21
+ if (worker) {
22
+ worker.postMessage({
23
+ 'process': {
24
+ 'centers': centers,
25
+ 'maxDepth': maxDepth,
26
+ 'maxCentersPerNode': maxCentersPerNode
27
+ }
28
+ }, buffers);
29
+ }
30
+ };
31
+
32
+ // SplatSubTree helper class
33
+ class SplatSubTree {
34
+ constructor() {
35
+ this.rootNode = null;
36
+ this.splatMesh = null;
37
+ }
38
+
39
+ static convertWorkerSubTree(workerSubTree, splatMesh) {
40
+ const subTree = new SplatSubTree();
41
+ subTree.rootNode = workerSubTree.rootNode;
42
+ subTree.splatMesh = splatMesh;
43
+ return subTree;
44
+ }
45
+ }
46
+
47
+ export class SplatTree {
48
+
49
+ constructor(maxDepth, maxCentersPerNode) {
50
+ this.maxDepth = maxDepth;
51
+ this.maxCentersPerNode = maxCentersPerNode;
52
+ this.subTrees = [];
53
+ this.splatMesh = null;
54
+ }
55
+
56
+
57
+ dispose() {
58
+ this.diposeSplatTreeWorker();
59
+ this.disposed = true;
60
+ }
61
+
62
+ diposeSplatTreeWorker() {
63
+ if (this.splatTreeWorker) this.splatTreeWorker.terminate();
64
+ this.splatTreeWorker = null;
65
+ };
66
+
67
+ /**
68
+ * Construct this instance of SplatTree from an instance of SplatMesh.
69
+ *
70
+ * @param {SplatMesh} splatMesh The instance of SplatMesh from which to construct this splat tree.
71
+ * @param {function} filterFunc Optional function to filter out unwanted splats.
72
+ * @param {function} onIndexesUpload Function to be called when the upload of splat centers to the splat tree
73
+ * builder worker starts and finishes.
74
+ * @param {function} onSplatTreeConstruction Function to be called when the conversion of the local splat tree from
75
+ * the format produced by the splat tree builder worker starts and ends.
76
+ * @return {undefined}
77
+ */
78
+ processSplatMesh = (splatMesh, filterFunc = () => true, onIndexesUpload, onSplatTreeConstruction) => {
79
+ if (!this.splatTreeWorker) this.splatTreeWorker = checkAndCreateWorker();
80
+
81
+ this.splatMesh = splatMesh;
82
+ this.subTrees = [];
83
+ const center = new Vector3();
84
+
85
+ const addCentersForScene = (splatOffset, splatCount) => {
86
+ const sceneCenters = new Float32Array(splatCount * 4);
87
+ let addedCount = 0;
88
+ for (let i = 0; i < splatCount; i++) {
89
+ const globalSplatIndex = i + splatOffset;
90
+ if (filterFunc(globalSplatIndex)) {
91
+ splatMesh.getSplatCenter(globalSplatIndex, center);
92
+ const addBase = addedCount * 4;
93
+ sceneCenters[addBase] = center.x;
94
+ sceneCenters[addBase + 1] = center.y;
95
+ sceneCenters[addBase + 2] = center.z;
96
+ sceneCenters[addBase + 3] = globalSplatIndex;
97
+ addedCount++;
98
+ }
99
+ }
100
+ return sceneCenters;
101
+ };
102
+
103
+ return new Promise((resolve) => {
104
+
105
+ const checkForEarlyExit = () => {
106
+ if (this.disposed) {
107
+ this.diposeSplatTreeWorker();
108
+ resolve();
109
+ return true;
110
+ }
111
+ return false;
112
+ };
113
+
114
+ if (onIndexesUpload) onIndexesUpload(false);
115
+
116
+ delayedExecute(() => {
117
+
118
+ if (checkForEarlyExit()) return;
119
+
120
+ const allCenters = [];
121
+ if (splatMesh.dynamicMode) {
122
+ let splatOffset = 0;
123
+ for (let s = 0; s < splatMesh.scenes.length; s++) {
124
+ const scene = splatMesh.getScene(s);
125
+ const splatCount = scene.splatBuffer.getSplatCount();
126
+ const sceneCenters = addCentersForScene(splatOffset, splatCount);
127
+ allCenters.push(sceneCenters);
128
+ splatOffset += splatCount;
129
+ }
130
+ } else {
131
+ const sceneCenters = addCentersForScene(0, splatMesh.getSplatCount());
132
+ allCenters.push(sceneCenters);
133
+ }
134
+
135
+ this.splatTreeWorker.onmessage = (e) => {
136
+
137
+ if (checkForEarlyExit()) return;
138
+
139
+ if (e.data.subTrees) {
140
+
141
+ if (onSplatTreeConstruction) onSplatTreeConstruction(false);
142
+
143
+ delayedExecute(() => {
144
+
145
+ if (checkForEarlyExit()) return;
146
+
147
+ for (let workerSubTree of e.data.subTrees) {
148
+ const convertedSubTree = SplatSubTree.convertWorkerSubTree(workerSubTree, splatMesh);
149
+ this.subTrees.push(convertedSubTree);
150
+ }
151
+ this.diposeSplatTreeWorker();
152
+
153
+ if (onSplatTreeConstruction) onSplatTreeConstruction(true);
154
+
155
+ delayedExecute(() => {
156
+ resolve();
157
+ });
158
+
159
+ });
160
+ }
161
+ };
162
+
163
+ delayedExecute(() => {
164
+ if (checkForEarlyExit()) return;
165
+ if (onIndexesUpload) onIndexesUpload(true);
166
+ const transferBuffers = allCenters.map((array) => array.buffer);
167
+ workerProcessCenters(this.splatTreeWorker, allCenters, transferBuffers, this.maxDepth, this.maxCentersPerNode);
168
+ });
169
+
170
+ });
171
+
172
+ });
173
+
174
+ };
175
+
176
+ countLeaves() {
177
+
178
+ let leafCount = 0;
179
+ this.visitLeaves(() => {
180
+ leafCount++;
181
+ });
182
+
183
+ return leafCount;
184
+ }
185
+
186
+ visitLeaves(visitFunc) {
187
+
188
+ const visitLeavesFromNode = (node, visitFunc) => {
189
+ if (node.children.length === 0) visitFunc(node);
190
+ for (let child of node.children) {
191
+ visitLeavesFromNode(child, visitFunc);
192
+ }
193
+ };
194
+
195
+ for (let subTree of this.subTrees) {
196
+ visitLeavesFromNode(subTree.rootNode, visitFunc);
197
+ }
198
+ }
199
+
200
+ }