Skip to content

Commit f291f4d

Browse files
authored
Merge pull request #7 from martinRenou/add_pointcloud_support
Add support for PointCloud
2 parents 836a26a + 91f0a65 commit f291f4d

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/MeshBlock.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,45 @@ class TetraMesh extends PolyMesh {
9191
tetrahedronIndices: Uint32Array;
9292

9393
}
94+
95+
96+
/**
97+
* PointCloud class
98+
*/
99+
export
100+
class PointCloud extends Block {
101+
102+
constructor (vertices: Float32Array, data: Data[], options?: BlockOptions) {
103+
super(vertices, data, options);
104+
105+
this.geometry = new THREE.BufferGeometry();
106+
107+
const vertexBuffer = new THREE.BufferAttribute(vertices, 3);
108+
109+
this.geometry.setAttribute('position', vertexBuffer);
110+
111+
this.mesh = new NodeMesh(THREE.Points, this.geometry, this.data);
112+
this.meshes.push(this.mesh);
113+
114+
this.buildMaterial();
115+
}
116+
117+
/**
118+
* Update vertices buffers
119+
*/
120+
handleVerticesChange () {
121+
super.handleVerticesChange();
122+
123+
this.mesh.vertices = this.vertices;
124+
}
125+
126+
get boundingSphere () : THREE.Sphere {
127+
this.geometry.computeBoundingSphere();
128+
return this.geometry.boundingSphere;
129+
}
130+
131+
geometry: THREE.BufferGeometry;
132+
133+
mesh: NodeMesh;
134+
135+
}

src/NodeMesh.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum NodeOperation {
1616
}
1717

1818
export
19-
type MeshConstructor = new (geometry: THREE.BufferGeometry, material: Nodes.StandardNodeMaterial) => THREE.Mesh;
19+
type MeshConstructor = new (geometry: THREE.BufferGeometry, material: Nodes.StandardNodeMaterial) => THREE.Object3D;
2020

2121
export
2222
type NodeOperationResult<T extends Nodes.Node> = T | Nodes.OperatorNode;
@@ -145,6 +145,12 @@ class NodeMesh {
145145
// @ts-ignore
146146
this.material.color = color;
147147

148+
// Workaround for https://github.com/mrdoob/three.js/issues/18152
149+
if (this.mesh.type == 'Points') {
150+
// @ts-ignore
151+
this.material.normal = new Nodes.Vector3Node(1, 1, 1);
152+
}
153+
148154
this.material.alphaTest = 0.1;
149155

150156
this.material.build();
@@ -285,8 +291,8 @@ class NodeMesh {
285291
}
286292

287293
geometry: THREE.BufferGeometry;
288-
material: Nodes.StandardNodeMaterial;
289-
mesh: THREE.Mesh;
294+
material: Nodes.NodeMaterial;
295+
mesh: THREE.Object3D;
290296
readonly data: Data[];
291297

292298
private meshCtor: MeshConstructor;

0 commit comments

Comments
 (0)