This repository was archived by the owner on Aug 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathMeshDescriptor.js
More file actions
65 lines (51 loc) · 1.68 KB
/
Copy pathMeshDescriptor.js
File metadata and controls
65 lines (51 loc) · 1.68 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
import * as THREE from 'three';
import invariant from 'fbjs/lib/invariant';
import ResourceReference from '../../Resources/ResourceReference';
import Object3DDescriptor from './Object3DDescriptor';
class MeshDescriptor extends Object3DDescriptor {
construct(props) {
const geometry = props.hasOwnProperty('geometry') ? props.geometry : undefined;
const material = props.hasOwnProperty('material') ? props.material : undefined;
const mesh = new THREE.Mesh(geometry, material);
if (!geometry) {
mesh.geometry.dispose();
mesh.geometry = undefined;
}
if (!material) {
mesh.material.dispose();
mesh.material = undefined;
}
return mesh;
}
_invalidChild = (child) => {
const invalid = !(
child instanceof THREE.Material ||
child instanceof ResourceReference ||
child instanceof THREE.Geometry ||
child instanceof THREE.BufferGeometry
);
return invalid;
};
addChildren(threeObject, children) {
if (process.env.NODE_ENV !== 'production') {
invariant(children.filter(this._invalidChild).length === 0,
'Mesh children can only be materials or geometries!');
} else {
invariant(children.filter(this._invalidChild).length === 0, false);
}
}
addChild(threeObject, child) {
this.addChildren(threeObject, [child]);
}
moveChild() {
// doesn't matter
}
getBoundingBoxes(threeObject) {
// recompute bounding box for highlighting from a fresh update
if (threeObject.geometry && threeObject.geometry.computeBoundingBox) {
threeObject.geometry.computeBoundingBox();
}
return super.getBoundingBoxes(threeObject);
}
}
module.exports = MeshDescriptor;