@myned-ai/gsplat-flame-avatar-renderer 1.0.6 → 1.0.7
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/README.md +30 -0
- package/dist/gsplat-flame-avatar-renderer.cjs.js +38 -33
- package/dist/gsplat-flame-avatar-renderer.cjs.min.js +1 -1
- package/dist/gsplat-flame-avatar-renderer.cjs.min.js.map +1 -1
- package/dist/gsplat-flame-avatar-renderer.esm.js +38 -33
- package/dist/gsplat-flame-avatar-renderer.esm.min.js +1 -1
- package/dist/gsplat-flame-avatar-renderer.esm.min.js.map +1 -1
- package/package.json +5 -2
- package/src/api/index.js +0 -7
- package/src/buffers/SplatBuffer.js +0 -1394
- package/src/buffers/SplatBufferGenerator.js +0 -41
- package/src/buffers/SplatPartitioner.js +0 -110
- package/src/buffers/UncompressedSplatArray.js +0 -106
- package/src/buffers/index.js +0 -11
- package/src/core/SplatGeometry.js +0 -48
- package/src/core/SplatMesh.js +0 -2627
- package/src/core/SplatScene.js +0 -43
- package/src/core/SplatTree.js +0 -200
- package/src/core/Viewer.js +0 -2746
- package/src/core/index.js +0 -13
- package/src/enums/EngineConstants.js +0 -58
- package/src/enums/LogLevel.js +0 -13
- package/src/enums/RenderMode.js +0 -11
- package/src/enums/SceneFormat.js +0 -21
- package/src/enums/SceneRevealMode.js +0 -11
- package/src/enums/SplatRenderMode.js +0 -10
- package/src/enums/index.js +0 -13
- package/src/errors/ApplicationError.js +0 -185
- package/src/errors/index.js +0 -17
- package/src/flame/FlameAnimator.js +0 -496
- package/src/flame/FlameConstants.js +0 -21
- package/src/flame/FlameTextureManager.js +0 -293
- package/src/flame/index.js +0 -22
- package/src/flame/utils.js +0 -50
- package/src/index.js +0 -39
- package/src/loaders/DirectLoadError.js +0 -14
- package/src/loaders/INRIAV1PlyParser.js +0 -223
- package/src/loaders/PlyLoader.js +0 -519
- package/src/loaders/PlyParser.js +0 -19
- package/src/loaders/PlyParserUtils.js +0 -311
- package/src/loaders/index.js +0 -13
- package/src/materials/SplatMaterial.js +0 -1068
- package/src/materials/SplatMaterial2D.js +0 -358
- package/src/materials/SplatMaterial3D.js +0 -323
- package/src/materials/index.js +0 -11
- package/src/raycaster/Hit.js +0 -37
- package/src/raycaster/Ray.js +0 -123
- package/src/raycaster/Raycaster.js +0 -175
- package/src/raycaster/index.js +0 -10
- package/src/renderer/AnimationManager.js +0 -577
- package/src/renderer/AppConstants.js +0 -101
- package/src/renderer/GaussianSplatRenderer.js +0 -1146
- package/src/renderer/index.js +0 -24
- package/src/utils/BlobUrlManager.js +0 -294
- package/src/utils/EventEmitter.js +0 -349
- package/src/utils/LoaderUtils.js +0 -66
- package/src/utils/Logger.js +0 -171
- package/src/utils/ObjectPool.js +0 -248
- package/src/utils/RenderLoop.js +0 -306
- package/src/utils/Util.js +0 -416
- package/src/utils/ValidationUtils.js +0 -331
- package/src/utils/index.js +0 -18
- package/src/worker/SortWorker.js +0 -284
- package/src/worker/index.js +0 -8
package/src/raycaster/Hit.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hit
|
|
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 * as THREE from 'three';
|
|
11
|
-
|
|
12
|
-
export class Hit {
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
this.origin = new THREE.Vector3();
|
|
16
|
-
this.normal = new THREE.Vector3();
|
|
17
|
-
this.distance = 0;
|
|
18
|
-
this.splatIndex = 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
set(origin, normal, distance, splatIndex) {
|
|
22
|
-
this.origin.copy(origin);
|
|
23
|
-
this.normal.copy(normal);
|
|
24
|
-
this.distance = distance;
|
|
25
|
-
this.splatIndex = splatIndex;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
clone() {
|
|
29
|
-
const hitClone = new Hit();
|
|
30
|
-
hitClone.origin.copy(this.origin);
|
|
31
|
-
hitClone.normal.copy(this.normal);
|
|
32
|
-
hitClone.distance = this.distance;
|
|
33
|
-
hitClone.splatIndex = this.splatIndex;
|
|
34
|
-
return hitClone;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
package/src/raycaster/Ray.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ray
|
|
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 * as THREE from 'three';
|
|
11
|
-
|
|
12
|
-
const VectorRight = new THREE.Vector3(1, 0, 0);
|
|
13
|
-
const VectorUp = new THREE.Vector3(0, 1, 0);
|
|
14
|
-
const VectorBackward = new THREE.Vector3(0, 0, 1);
|
|
15
|
-
|
|
16
|
-
export class Ray {
|
|
17
|
-
|
|
18
|
-
constructor(origin = new THREE.Vector3(), direction = new THREE.Vector3()) {
|
|
19
|
-
this.origin = new THREE.Vector3();
|
|
20
|
-
this.direction = new THREE.Vector3();
|
|
21
|
-
this.setParameters(origin, direction);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
setParameters(origin, direction) {
|
|
25
|
-
this.origin.copy(origin);
|
|
26
|
-
this.direction.copy(direction).normalize();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
boxContainsPoint(box, point, epsilon) {
|
|
30
|
-
return point.x < box.min.x - epsilon || point.x > box.max.x + epsilon ||
|
|
31
|
-
point.y < box.min.y - epsilon || point.y > box.max.y + epsilon ||
|
|
32
|
-
point.z < box.min.z - epsilon || point.z > box.max.z + epsilon ? false : true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
intersectBox = function() {
|
|
36
|
-
|
|
37
|
-
const planeIntersectionPoint = new THREE.Vector3();
|
|
38
|
-
const planeIntersectionPointArray = [];
|
|
39
|
-
const originArray = [];
|
|
40
|
-
const directionArray = [];
|
|
41
|
-
|
|
42
|
-
return function(box, outHit) {
|
|
43
|
-
|
|
44
|
-
originArray[0] = this.origin.x;
|
|
45
|
-
originArray[1] = this.origin.y;
|
|
46
|
-
originArray[2] = this.origin.z;
|
|
47
|
-
directionArray[0] = this.direction.x;
|
|
48
|
-
directionArray[1] = this.direction.y;
|
|
49
|
-
directionArray[2] = this.direction.z;
|
|
50
|
-
|
|
51
|
-
if (this.boxContainsPoint(box, this.origin, 0.0001)) {
|
|
52
|
-
if (outHit) {
|
|
53
|
-
outHit.origin.copy(this.origin);
|
|
54
|
-
outHit.normal.set(0, 0, 0);
|
|
55
|
-
outHit.distance = -1;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (let i = 0; i < 3; i++) {
|
|
61
|
-
if (directionArray[i] == 0.0) continue;
|
|
62
|
-
|
|
63
|
-
const hitNormal = i == 0 ? VectorRight : i == 1 ? VectorUp : VectorBackward;
|
|
64
|
-
const extremeVec = directionArray[i] < 0 ? box.max : box.min;
|
|
65
|
-
let multiplier = -Math.sign(directionArray[i]);
|
|
66
|
-
planeIntersectionPointArray[0] = i == 0 ? extremeVec.x : i == 1 ? extremeVec.y : extremeVec.z;
|
|
67
|
-
let toSide = planeIntersectionPointArray[0] - originArray[i];
|
|
68
|
-
|
|
69
|
-
if (toSide * multiplier < 0) {
|
|
70
|
-
const idx1 = (i + 1) % 3;
|
|
71
|
-
const idx2 = (i + 2) % 3;
|
|
72
|
-
planeIntersectionPointArray[2] = directionArray[idx1] / directionArray[i] * toSide + originArray[idx1];
|
|
73
|
-
planeIntersectionPointArray[1] = directionArray[idx2] / directionArray[i] * toSide + originArray[idx2];
|
|
74
|
-
planeIntersectionPoint.set(planeIntersectionPointArray[i],
|
|
75
|
-
planeIntersectionPointArray[idx2],
|
|
76
|
-
planeIntersectionPointArray[idx1]);
|
|
77
|
-
if (this.boxContainsPoint(box, planeIntersectionPoint, 0.0001)) {
|
|
78
|
-
if (outHit) {
|
|
79
|
-
outHit.origin.copy(planeIntersectionPoint);
|
|
80
|
-
outHit.normal.copy(hitNormal).multiplyScalar(multiplier);
|
|
81
|
-
outHit.distance = planeIntersectionPoint.sub(this.origin).length();
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return false;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
}();
|
|
92
|
-
|
|
93
|
-
intersectSphere = function() {
|
|
94
|
-
|
|
95
|
-
const toSphereCenterVec = new THREE.Vector3();
|
|
96
|
-
|
|
97
|
-
return function(center, radius, outHit) {
|
|
98
|
-
toSphereCenterVec.copy(center).sub(this.origin);
|
|
99
|
-
const toClosestApproach = toSphereCenterVec.dot(this.direction);
|
|
100
|
-
const toClosestApproachSq = toClosestApproach * toClosestApproach;
|
|
101
|
-
const toSphereCenterSq = toSphereCenterVec.dot(toSphereCenterVec);
|
|
102
|
-
const diffSq = toSphereCenterSq - toClosestApproachSq;
|
|
103
|
-
const radiusSq = radius * radius;
|
|
104
|
-
|
|
105
|
-
if (diffSq > radiusSq) return false;
|
|
106
|
-
|
|
107
|
-
const thc = Math.sqrt(radiusSq - diffSq);
|
|
108
|
-
const t0 = toClosestApproach - thc;
|
|
109
|
-
const t1 = toClosestApproach + thc;
|
|
110
|
-
|
|
111
|
-
if (t1 < 0) return false;
|
|
112
|
-
let t = t0 < 0 ? t1 : t0;
|
|
113
|
-
|
|
114
|
-
if (outHit) {
|
|
115
|
-
outHit.origin.copy(this.origin).addScaledVector(this.direction, t);
|
|
116
|
-
outHit.normal.copy(outHit.origin).sub(center).normalize();
|
|
117
|
-
outHit.distance = t;
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
}();
|
|
123
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Raycaster
|
|
3
|
-
*
|
|
4
|
-
* Derived from @mkkellogg/gaussian-splats-3d (MIT License)
|
|
5
|
-
* https://github.com/mkkellogg/GaussianSplats3D
|
|
6
|
-
*
|
|
7
|
-
* Import paths adjusted for gsplat-flame-avatar package structure.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as THREE from 'three';
|
|
11
|
-
import { Ray } from './Ray.js';
|
|
12
|
-
import { Hit } from './Hit.js';
|
|
13
|
-
import { SplatRenderMode } from '../enums/index.js';
|
|
14
|
-
|
|
15
|
-
export class Raycaster {
|
|
16
|
-
|
|
17
|
-
constructor(origin, direction, raycastAgainstTrueSplatEllipsoid = false) {
|
|
18
|
-
this.ray = new Ray(origin, direction);
|
|
19
|
-
this.raycastAgainstTrueSplatEllipsoid = raycastAgainstTrueSplatEllipsoid;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
setFromCameraAndScreenPosition = function() {
|
|
23
|
-
|
|
24
|
-
const ndcCoords = new THREE.Vector2();
|
|
25
|
-
|
|
26
|
-
return function(camera, screenPosition, screenDimensions) {
|
|
27
|
-
ndcCoords.x = screenPosition.x / screenDimensions.x * 2.0 - 1.0;
|
|
28
|
-
ndcCoords.y = (screenDimensions.y - screenPosition.y) / screenDimensions.y * 2.0 - 1.0;
|
|
29
|
-
if (camera.isPerspectiveCamera) {
|
|
30
|
-
this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
|
|
31
|
-
this.ray.direction.set(ndcCoords.x, ndcCoords.y, 0.5 ).unproject(camera).sub(this.ray.origin).normalize();
|
|
32
|
-
this.camera = camera;
|
|
33
|
-
} else if (camera.isOrthographicCamera) {
|
|
34
|
-
this.ray.origin.set(ndcCoords.x, ndcCoords.y,
|
|
35
|
-
(camera.near + camera.far) / (camera.near - camera.far)).unproject(camera);
|
|
36
|
-
this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
|
|
37
|
-
this.camera = camera;
|
|
38
|
-
} else {
|
|
39
|
-
throw new Error('Raycaster::setFromCameraAndScreenPosition() -> Unsupported camera type');
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
}();
|
|
44
|
-
|
|
45
|
-
intersectSplatMesh = function() {
|
|
46
|
-
|
|
47
|
-
const toLocal = new THREE.Matrix4();
|
|
48
|
-
const fromLocal = new THREE.Matrix4();
|
|
49
|
-
const sceneTransform = new THREE.Matrix4();
|
|
50
|
-
const localRay = new Ray();
|
|
51
|
-
const tempPoint = new THREE.Vector3();
|
|
52
|
-
|
|
53
|
-
return function(splatMesh, outHits = []) {
|
|
54
|
-
const splatTree = splatMesh.getSplatTree();
|
|
55
|
-
|
|
56
|
-
if (!splatTree) return;
|
|
57
|
-
|
|
58
|
-
for (let s = 0; s < splatTree.subTrees.length; s++) {
|
|
59
|
-
const subTree = splatTree.subTrees[s];
|
|
60
|
-
|
|
61
|
-
fromLocal.copy(splatMesh.matrixWorld);
|
|
62
|
-
if (splatMesh.dynamicMode) {
|
|
63
|
-
splatMesh.getSceneTransform(s, sceneTransform);
|
|
64
|
-
fromLocal.multiply(sceneTransform);
|
|
65
|
-
}
|
|
66
|
-
toLocal.copy(fromLocal).invert();
|
|
67
|
-
|
|
68
|
-
localRay.origin.copy(this.ray.origin).applyMatrix4(toLocal);
|
|
69
|
-
localRay.direction.copy(this.ray.origin).add(this.ray.direction);
|
|
70
|
-
localRay.direction.applyMatrix4(toLocal).sub(localRay.origin).normalize();
|
|
71
|
-
|
|
72
|
-
const outHitsForSubTree = [];
|
|
73
|
-
if (subTree.rootNode) {
|
|
74
|
-
this.castRayAtSplatTreeNode(localRay, splatTree, subTree.rootNode, outHitsForSubTree);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
outHitsForSubTree.forEach((hit) => {
|
|
78
|
-
hit.origin.applyMatrix4(fromLocal);
|
|
79
|
-
hit.normal.applyMatrix4(fromLocal).normalize();
|
|
80
|
-
hit.distance = tempPoint.copy(hit.origin).sub(this.ray.origin).length();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
outHits.push(...outHitsForSubTree);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
outHits.sort((a, b) => {
|
|
87
|
-
if (a.distance > b.distance) return 1;
|
|
88
|
-
else return -1;
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
return outHits;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
}();
|
|
95
|
-
|
|
96
|
-
castRayAtSplatTreeNode = function() {
|
|
97
|
-
|
|
98
|
-
const tempColor = new THREE.Vector4();
|
|
99
|
-
const tempCenter = new THREE.Vector3();
|
|
100
|
-
const tempScale = new THREE.Vector3();
|
|
101
|
-
const tempRotation = new THREE.Quaternion();
|
|
102
|
-
const tempHit = new Hit();
|
|
103
|
-
const scaleEpsilon = 0.0000001;
|
|
104
|
-
|
|
105
|
-
const origin = new THREE.Vector3(0, 0, 0);
|
|
106
|
-
const uniformScaleMatrix = new THREE.Matrix4();
|
|
107
|
-
const scaleMatrix = new THREE.Matrix4();
|
|
108
|
-
const rotationMatrix = new THREE.Matrix4();
|
|
109
|
-
const toSphereSpace = new THREE.Matrix4();
|
|
110
|
-
const fromSphereSpace = new THREE.Matrix4();
|
|
111
|
-
const tempRay = new Ray();
|
|
112
|
-
|
|
113
|
-
return function(ray, splatTree, node, outHits = []) {
|
|
114
|
-
if (!ray.intersectBox(node.boundingBox)) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (node.data && node.data.indexes && node.data.indexes.length > 0) {
|
|
118
|
-
for (let i = 0; i < node.data.indexes.length; i++) {
|
|
119
|
-
|
|
120
|
-
const splatGlobalIndex = node.data.indexes[i];
|
|
121
|
-
const splatSceneIndex = splatTree.splatMesh.getSceneIndexForSplat(splatGlobalIndex);
|
|
122
|
-
const splatScene = splatTree.splatMesh.getScene(splatSceneIndex);
|
|
123
|
-
if (!splatScene.visible) continue;
|
|
124
|
-
|
|
125
|
-
splatTree.splatMesh.getSplatColor(splatGlobalIndex, tempColor);
|
|
126
|
-
splatTree.splatMesh.getSplatCenter(splatGlobalIndex, tempCenter);
|
|
127
|
-
splatTree.splatMesh.getSplatScaleAndRotation(splatGlobalIndex, tempScale, tempRotation);
|
|
128
|
-
|
|
129
|
-
if (tempScale.x <= scaleEpsilon || tempScale.y <= scaleEpsilon ||
|
|
130
|
-
splatTree.splatMesh.splatRenderMode === SplatRenderMode.ThreeD && tempScale.z <= scaleEpsilon) {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!this.raycastAgainstTrueSplatEllipsoid) {
|
|
135
|
-
let radius = (tempScale.x + tempScale.y);
|
|
136
|
-
let componentCount = 2;
|
|
137
|
-
if (splatTree.splatMesh.splatRenderMode === SplatRenderMode.ThreeD) {
|
|
138
|
-
radius += tempScale.z;
|
|
139
|
-
componentCount = 3;
|
|
140
|
-
}
|
|
141
|
-
radius = radius / componentCount;
|
|
142
|
-
if (ray.intersectSphere(tempCenter, radius, tempHit)) {
|
|
143
|
-
const hitClone = tempHit.clone();
|
|
144
|
-
hitClone.splatIndex = splatGlobalIndex;
|
|
145
|
-
outHits.push(hitClone);
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
scaleMatrix.makeScale(tempScale.x, tempScale.y, tempScale.z);
|
|
149
|
-
rotationMatrix.makeRotationFromQuaternion(tempRotation);
|
|
150
|
-
const uniformScale = Math.log10(tempColor.w) * 2.0;
|
|
151
|
-
uniformScaleMatrix.makeScale(uniformScale, uniformScale, uniformScale);
|
|
152
|
-
fromSphereSpace.copy(uniformScaleMatrix).multiply(rotationMatrix).multiply(scaleMatrix);
|
|
153
|
-
toSphereSpace.copy(fromSphereSpace).invert();
|
|
154
|
-
tempRay.origin.copy(ray.origin).sub(tempCenter).applyMatrix4(toSphereSpace);
|
|
155
|
-
tempRay.direction.copy(ray.origin).add(ray.direction).sub(tempCenter);
|
|
156
|
-
tempRay.direction.applyMatrix4(toSphereSpace).sub(tempRay.origin).normalize();
|
|
157
|
-
if (tempRay.intersectSphere(origin, 1.0, tempHit)) {
|
|
158
|
-
const hitClone = tempHit.clone();
|
|
159
|
-
hitClone.splatIndex = splatGlobalIndex;
|
|
160
|
-
hitClone.origin.applyMatrix4(fromSphereSpace).add(tempCenter);
|
|
161
|
-
outHits.push(hitClone);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (node.children && node.children.length > 0) {
|
|
167
|
-
for (let child of node.children) {
|
|
168
|
-
this.castRayAtSplatTreeNode(ray, splatTree, child, outHits);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return outHits;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
}();
|
|
175
|
-
}
|
package/src/raycaster/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* gsplat-flame-avatar - Raycaster Module
|
|
3
|
-
* Intersection testing for splat picking/selection.
|
|
4
|
-
*
|
|
5
|
-
* Derived from @mkkellogg/gaussian-splats-3d (MIT License)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { Ray } from './Ray.js';
|
|
9
|
-
export { Hit } from './Hit.js';
|
|
10
|
-
export { Raycaster } from './Raycaster.js';
|