-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathgaussianSplattingPartProxyMesh.ts
More file actions
201 lines (178 loc) · 7.64 KB
/
gaussianSplattingPartProxyMesh.ts
File metadata and controls
201 lines (178 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import type { Nullable } from "core/types";
import type { Scene } from "core/scene";
import { Mesh } from "../mesh";
import { BoundingInfo } from "../../Culling/boundingInfo";
import type { GaussianSplattingMesh } from "./gaussianSplattingMesh";
import type { Ray } from "../../Culling/ray.core";
import { PickingInfo } from "../../Collisions/pickingInfo";
import { Vector3 } from "../../Maths/math.vector";
/**
* This is a dummy interface for holding BoundingInfo for serialization,
* it keeps the exact same getBoundingInfo() like Mesh to not break code
*/
interface IBoundingInfoProvider {
/**
* Get underlying BoundingInfo
*/
getBoundingInfo(): BoundingInfo;
}
/**
* Class used as a proxy mesh for a part of a compound Gaussian Splatting mesh
*/
export class GaussianSplattingPartProxyMesh extends Mesh {
/**
* The Gaussian Splatting mesh that this proxy represents a part of
*/
public readonly proxiedMesh: GaussianSplattingMesh | IBoundingInfoProvider;
/**
* The index of the part in the compound mesh (internal storage)
*/
private _partIndex: number;
/**
* Gets the index of the part in the compound mesh
*/
public get partIndex(): number {
return this._partIndex;
}
/**
* The original Gaussian Splatting mesh that was merged into the compound
*/
public readonly compoundSplatMesh: GaussianSplattingMesh;
/**
* Creates a new Gaussian Splatting part proxy mesh
* @param name The name of the proxy mesh
* @param scene The scene the proxy mesh belongs to
* @param compoundSplatMesh The original Gaussian Splatting mesh that was merged into the compound
* @param proxiedMesh The Gaussian Splatting mesh that this proxy represents a part of
* @param partIndex The index of the part in the compound mesh
*/
constructor(name: string, scene: Nullable<Scene>, compoundSplatMesh: GaussianSplattingMesh, proxiedMesh: GaussianSplattingMesh | IBoundingInfoProvider, partIndex: number) {
super(name, scene);
this.proxiedMesh = proxiedMesh;
this._partIndex = partIndex;
this.compoundSplatMesh = compoundSplatMesh;
// Set bounding info based on the source mesh's bounds
this.updateBoundingInfoFromProxiedMesh();
this.compoundSplatMesh.setWorldMatrixForPart(this.partIndex, this.getWorldMatrix());
// Update the proxied mesh's part matrix when this proxy's world matrix changes
this.onAfterWorldMatrixUpdateObservable.add(() => {
this.compoundSplatMesh.setWorldMatrixForPart(this.partIndex, this.getWorldMatrix());
this.updateBoundingInfoFromProxiedMesh();
});
}
/**
* Updates the bounding info of this proxy mesh from the proxied mesh
*/
public updateBoundingInfoFromProxiedMesh(): void {
const boundingInfo = this.proxiedMesh.getBoundingInfo();
this.setBoundingInfo(new BoundingInfo(boundingInfo.minimum.clone(), boundingInfo.maximum.clone()));
}
/**
* Returns the class name
* @returns "GaussianSplattingPartProxyMesh"
*/
public override getClassName(): string {
return "GaussianSplattingPartProxyMesh";
}
/**
* Updates the part index for this proxy mesh.
* This should only be called internally when parts are removed from the compound mesh.
* @param newPartIndex the new part index
* @internal
*/
public updatePartIndex(newPartIndex: number): void {
this._partIndex = newPartIndex;
}
/**
* Gets whether the part is visible
*/
public override get isVisible(): boolean {
return this.compoundSplatMesh.getPartVisibility(this.partIndex) > 0;
}
/**
* Sets whether the part is visible
*/
public override set isVisible(value: boolean) {
this.compoundSplatMesh.setPartVisibility(this.partIndex, value ? 1.0 : 0.0);
}
/**
* Gets the visibility of the part (0.0 to 1.0)
*/
public override get visibility(): number {
return this.compoundSplatMesh.getPartVisibility(this.partIndex);
}
/**
* Sets the visibility of the part (0.0 to 1.0)
*/
public override set visibility(value: number) {
this.compoundSplatMesh.setPartVisibility(this.partIndex, value);
}
/**
* Checks if a ray intersects with this proxy mesh using only bounding info
* @param ray defines the ray to test
* @returns the picking info with this mesh set as pickedMesh if hit
*/
public override intersects(ray: Ray): PickingInfo {
const pickingInfo = new PickingInfo();
const boundingInfo = this.getBoundingInfo();
if (!boundingInfo) {
return pickingInfo;
}
// Always check against bounding info for proxy meshes
if (!ray.intersectsSphere(boundingInfo.boundingSphere) || !ray.intersectsBox(boundingInfo.boundingBox)) {
return pickingInfo;
}
// If we hit the bounding volume, report this mesh as picked
pickingInfo.hit = true;
pickingInfo.pickedMesh = this;
pickingInfo.distance = Vector3.Distance(ray.origin, boundingInfo.boundingSphere.center);
pickingInfo.subMeshId = 0;
return pickingInfo;
}
/**
* Serialize current GaussianSplattingPartProxyMesh
* @param serializationObject defines the object which will receive the serialization data
* @returns the serialized object
*/
override serialize(serializationObject: any = {}): any {
serializationObject = super.serialize(serializationObject);
// GaussianSplattingPartProxyMesh needs no SubMesh, Geometry, or Material
serializationObject.subMeshes = [];
serializationObject.geometryUniqueId = undefined;
serializationObject.geometryId = undefined;
serializationObject.materialUniqueId = undefined;
serializationObject.materialId = undefined;
serializationObject.instances = [];
serializationObject.actions = undefined;
serializationObject.type = this.getClassName();
// partIndex is needed in constructor
serializationObject.partIndex = this._partIndex;
const boundingInfo = this.getBoundingInfo();
// boundingInfo is needed in constructor
serializationObject.boundingInfo = {
minimum: boundingInfo.minimum.asArray(),
maximum: boundingInfo.maximum.asArray(),
};
return serializationObject;
}
/**
* Parses a serialized GaussianSplattingPartProxyMesh
* @param parsedMesh the serialized mesh
* @param scene the scene to create the GaussianSplattingPartProxyMesh in
* @returns the created GaussianSplattingPartProxyMesh
*/
public static override Parse(parsedMesh: any, scene: Scene): GaussianSplattingPartProxyMesh {
const partIndex = parsedMesh.partIndex;
const compoundSplatMesh = parsedMesh.compoundSplatMesh as GaussianSplattingMesh;
const minimum = Vector3.FromArray(parsedMesh.boundingInfo.minimum);
const maximum = Vector3.FromArray(parsedMesh.boundingInfo.maximum);
const boundingInfo = new BoundingInfo(minimum, maximum);
const proxiedMesh: IBoundingInfoProvider = {
getBoundingInfo() {
return boundingInfo;
},
};
return new GaussianSplattingPartProxyMesh(parsedMesh.name, scene, compoundSplatMesh, proxiedMesh, partIndex);
}
}
Mesh._GaussianSplattingPartProxyMeshParser = GaussianSplattingPartProxyMesh.Parse;