@myned-ai/gsplat-flame-avatar-renderer 1.0.2 → 1.0.5

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 +6 -36
  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 +6 -11
  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,41 @@
1
+ /**
2
+ * SplatBufferGenerator
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
+ * Import paths adjusted for gsplat-flame-avatar package structure.
9
+ */
10
+
11
+ import { Vector3 } from 'three';
12
+ import { SplatBuffer } from './SplatBuffer.js';
13
+ import { SplatPartitioner } from './SplatPartitioner.js';
14
+
15
+ export class SplatBufferGenerator {
16
+
17
+ constructor(splatPartitioner, alphaRemovalThreshold, compressionLevel, sectionSize, sceneCenter, blockSize, bucketSize) {
18
+ this.splatPartitioner = splatPartitioner;
19
+ this.alphaRemovalThreshold = alphaRemovalThreshold;
20
+ this.compressionLevel = compressionLevel;
21
+ this.sectionSize = sectionSize;
22
+ this.sceneCenter = sceneCenter ? new Vector3().copy(sceneCenter) : undefined;
23
+ this.blockSize = blockSize;
24
+ this.bucketSize = bucketSize;
25
+ }
26
+
27
+ generateFromUncompressedSplatArray(splatArray) {
28
+ const partitionResults = this.splatPartitioner.partitionUncompressedSplatArray(splatArray);
29
+ return SplatBuffer.generateFromUncompressedSplatArrays(partitionResults.splatArrays,
30
+ this.alphaRemovalThreshold, this.compressionLevel,
31
+ this.sceneCenter, this.blockSize, this.bucketSize,
32
+ partitionResults.parameters);
33
+ }
34
+
35
+ static getStandardGenerator(alphaRemovalThreshold = 1, compressionLevel = 1, sectionSize = 0, sceneCenter = new Vector3(),
36
+ blockSize = SplatBuffer.BucketBlockSize, bucketSize = SplatBuffer.BucketSize) {
37
+ const splatPartitioner = SplatPartitioner.getStandardPartitioner(sectionSize, sceneCenter, blockSize, bucketSize);
38
+ return new SplatBufferGenerator(splatPartitioner, alphaRemovalThreshold, compressionLevel,
39
+ sectionSize, sceneCenter, blockSize, bucketSize);
40
+ }
41
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * SplatPartitioner
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
+ * Import paths adjusted for gsplat-flame-avatar package structure.
9
+ */
10
+
11
+ import { Vector3 } from 'three';
12
+ import { SplatBuffer } from './SplatBuffer.js';
13
+ import { UncompressedSplatArray } from './UncompressedSplatArray.js';
14
+
15
+ export class SplatPartitioner {
16
+
17
+ constructor(sectionCount, sectionFilters, groupingParameters, partitionGenerator) {
18
+ this.sectionCount = sectionCount;
19
+ this.sectionFilters = sectionFilters;
20
+ this.groupingParameters = groupingParameters;
21
+ this.partitionGenerator = partitionGenerator;
22
+ }
23
+
24
+ partitionUncompressedSplatArray(splatArray) {
25
+ let groupingParameters;
26
+ let sectionCount;
27
+ let sectionFilters;
28
+ if (this.partitionGenerator) {
29
+ const results = this.partitionGenerator(splatArray);
30
+ groupingParameters = results.groupingParameters;
31
+ sectionCount = results.sectionCount;
32
+ sectionFilters = results.sectionFilters;
33
+ } else {
34
+ groupingParameters = this.groupingParameters;
35
+ sectionCount = this.sectionCount;
36
+ sectionFilters = this.sectionFilters;
37
+ }
38
+
39
+ const newArrays = [];
40
+ for (let s = 0; s < sectionCount; s++) {
41
+ const sectionSplats = new UncompressedSplatArray(splatArray.sphericalHarmonicsDegree);
42
+ const sectionFilter = sectionFilters[s];
43
+ for (let i = 0; i < splatArray.splatCount; i++) {
44
+ if (sectionFilter(i)) {
45
+ sectionSplats.addSplat(splatArray.splats[i]);
46
+ }
47
+ }
48
+ newArrays.push(sectionSplats);
49
+ }
50
+ return {
51
+ splatArrays: newArrays,
52
+ parameters: groupingParameters
53
+ };
54
+ }
55
+
56
+ static getStandardPartitioner(partitionSize = 0, sceneCenter = new Vector3(),
57
+ blockSize = SplatBuffer.BucketBlockSize, bucketSize = SplatBuffer.BucketSize) {
58
+
59
+ const partitionGenerator = (splatArray) => {
60
+
61
+ const OFFSET_X = UncompressedSplatArray.OFFSET.X;
62
+ const OFFSET_Y = UncompressedSplatArray.OFFSET.Y;
63
+ const OFFSET_Z = UncompressedSplatArray.OFFSET.Z;
64
+
65
+ if (partitionSize <= 0) partitionSize = splatArray.splatCount;
66
+
67
+ const center = new Vector3();
68
+ const clampDistance = 0.5;
69
+ const clampPoint = (point) => {
70
+ point.x = Math.floor(point.x / clampDistance) * clampDistance;
71
+ point.y = Math.floor(point.y / clampDistance) * clampDistance;
72
+ point.z = Math.floor(point.z / clampDistance) * clampDistance;
73
+ };
74
+ splatArray.splats.forEach((splat) => {
75
+ center.set(splat[OFFSET_X], splat[OFFSET_Y], splat[OFFSET_Z]).sub(sceneCenter);
76
+ clampPoint(center);
77
+ splat.centerDist = center.lengthSq();
78
+ });
79
+ splatArray.splats.sort((a, b) => {
80
+ let centerADist = a.centerDist;
81
+ let centerBDist = b.centerDist;
82
+ if (centerADist > centerBDist) return 1;
83
+ else return -1;
84
+ });
85
+
86
+ const sectionFilters = [];
87
+ const groupingParameters = [];
88
+ partitionSize = Math.min(splatArray.splatCount, partitionSize);
89
+ const patitionCount = Math.ceil(splatArray.splatCount / partitionSize);
90
+ let currentStartSplat = 0;
91
+ for (let i = 0; i < patitionCount; i ++) {
92
+ let startSplat = currentStartSplat;
93
+ sectionFilters.push((splatIndex) => {
94
+ return splatIndex >= startSplat && splatIndex < startSplat + partitionSize;
95
+ });
96
+ groupingParameters.push({
97
+ 'blocksSize': blockSize,
98
+ 'bucketSize': bucketSize,
99
+ });
100
+ currentStartSplat += partitionSize;
101
+ }
102
+ return {
103
+ 'sectionCount': sectionFilters.length,
104
+ sectionFilters,
105
+ groupingParameters
106
+ };
107
+ };
108
+ return new SplatPartitioner(undefined, undefined, undefined, partitionGenerator);
109
+ }
110
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * UncompressedSplatArray
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
+ * Import paths adjusted for gsplat-flame-avatar package structure.
9
+ */
10
+
11
+ import { getSphericalHarmonicsComponentCountForDegree } from '../utils/Util.js';
12
+
13
+ const BASE_COMPONENT_COUNT = 14;
14
+
15
+ export class UncompressedSplatArray {
16
+
17
+ static OFFSET = {
18
+ X: 0,
19
+ Y: 1,
20
+ Z: 2,
21
+ SCALE0: 3,
22
+ SCALE1: 4,
23
+ SCALE2: 5,
24
+ ROTATION0: 6,
25
+ ROTATION1: 7,
26
+ ROTATION2: 8,
27
+ ROTATION3: 9,
28
+ FDC0: 10,
29
+ FDC1: 11,
30
+ FDC2: 12,
31
+ OPACITY: 13,
32
+ FRC0: 14,
33
+ FRC1: 15,
34
+ FRC2: 16,
35
+ FRC3: 17,
36
+ FRC4: 18,
37
+ FRC5: 19,
38
+ FRC6: 20,
39
+ FRC7: 21,
40
+ FRC8: 22,
41
+ FRC9: 23,
42
+ FRC10: 24,
43
+ FRC11: 25,
44
+ FRC12: 26,
45
+ FRC13: 27,
46
+ FRC14: 28,
47
+ FRC15: 29,
48
+ FRC16: 30,
49
+ FRC17: 31,
50
+ FRC18: 32,
51
+ FRC19: 33,
52
+ FRC20: 34,
53
+ FRC21: 35,
54
+ FRC22: 36,
55
+ FRC23: 37
56
+ };
57
+
58
+ constructor(sphericalHarmonicsDegree = 0) {
59
+ this.sphericalHarmonicsDegree = sphericalHarmonicsDegree;
60
+ this.sphericalHarmonicsCount = getSphericalHarmonicsComponentCountForDegree(this.sphericalHarmonicsDegree);
61
+ this.componentCount = this.sphericalHarmonicsCount + BASE_COMPONENT_COUNT;
62
+ this.defaultSphericalHarmonics = new Array(this.sphericalHarmonicsCount).fill(0);
63
+ this.splats = [];
64
+ this.splatCount = 0;
65
+ }
66
+
67
+ static createSplat(sphericalHarmonicsDegree = 0) {
68
+ const baseSplat = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
69
+ let shEntries = getSphericalHarmonicsComponentCountForDegree(sphericalHarmonicsDegree);
70
+ for (let i = 0; i < shEntries; i++) baseSplat.push(0);
71
+ return baseSplat;
72
+ }
73
+
74
+ addSplat(splat) {
75
+ this.splats.push(splat);
76
+ this.splatCount++;
77
+ }
78
+
79
+ getSplat(index) {
80
+ return this.splats[index];
81
+ }
82
+
83
+ addDefaultSplat() {
84
+ const newSplat = UncompressedSplatArray.createSplat(this.sphericalHarmonicsDegree);
85
+ this.addSplat(newSplat);
86
+ return newSplat;
87
+ }
88
+
89
+ addSplatFromComonents(x, y, z, scale0, scale1, scale2, rot0, rot1, rot2, rot3, r, g, b, opacity, ...rest) {
90
+ const newSplat = [x, y, z, scale0, scale1, scale2, rot0, rot1, rot2, rot3, r, g, b, opacity, ...this.defaultSphericalHarmonics];
91
+ for (let i = 0; i < rest.length && i < this.sphericalHarmonicsCount; i++) {
92
+ newSplat[i] = rest[i];
93
+ }
94
+ this.addSplat(newSplat);
95
+ return newSplat;
96
+ }
97
+
98
+ addSplatFromArray(src, srcIndex) {
99
+ const srcSplat = src.splats[srcIndex];
100
+ const newSplat = UncompressedSplatArray.createSplat(this.sphericalHarmonicsDegree);
101
+ for (let i = 0; i < this.componentCount && i < srcSplat.length; i++) {
102
+ newSplat[i] = srcSplat[i];
103
+ }
104
+ this.addSplat(newSplat);
105
+ }
106
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * gsplat-flame-avatar - Buffers Module
3
+ * GPU buffer management for Gaussian Splat data.
4
+ *
5
+ * Derived from @mkkellogg/gaussian-splats-3d (MIT License)
6
+ */
7
+
8
+ export { SplatBuffer } from './SplatBuffer.js';
9
+ export { SplatBufferGenerator } from './SplatBufferGenerator.js';
10
+ export { SplatPartitioner } from './SplatPartitioner.js';
11
+ export { UncompressedSplatArray } from './UncompressedSplatArray.js';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * SplatGeometry
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 { BufferAttribute, BufferGeometry, DynamicDrawUsage, InstancedBufferAttribute, InstancedBufferGeometry } from 'three';
11
+
12
+ export class SplatGeometry {
13
+
14
+ /**
15
+ * Build the Three.js geometry that will be used to render the splats. The geometry is instanced and is made up of
16
+ * vertices for a single quad as well as an attribute buffer for the splat indexes.
17
+ * @param {number} maxSplatCount The maximum number of splats that the geometry will need to accomodate
18
+ * @return {THREE.InstancedBufferGeometry}
19
+ */
20
+ static build(maxSplatCount) {
21
+
22
+ const baseGeometry = new BufferGeometry();
23
+ baseGeometry.setIndex([0, 1, 2, 0, 2, 3]);
24
+
25
+ // Vertices for the instanced quad
26
+ const positionsArray = new Float32Array(4 * 3);
27
+ const positions = new BufferAttribute(positionsArray, 3);
28
+ baseGeometry.setAttribute('position', positions);
29
+ positions.setXYZ(0, -1.0, -1.0, 0.0);
30
+ positions.setXYZ(1, -1.0, 1.0, 0.0);
31
+ positions.setXYZ(2, 1.0, 1.0, 0.0);
32
+ positions.setXYZ(3, 1.0, -1.0, 0.0);
33
+ positions.needsUpdate = true;
34
+
35
+ const geometry = new InstancedBufferGeometry().copy(baseGeometry);
36
+
37
+ // Splat index buffer
38
+ const splatIndexArray = new Uint32Array(maxSplatCount);
39
+
40
+ const splatIndexes = new InstancedBufferAttribute(splatIndexArray, 1, false);
41
+ splatIndexes.setUsage(DynamicDrawUsage);
42
+ geometry.setAttribute('splatIndex', splatIndexes);
43
+
44
+ geometry.instanceCount = 0;
45
+
46
+ return geometry;
47
+ }
48
+ }