Forge Community Blog

Using PointCloud in the Forge Viewer

Using PointCloud in the Forge Viewer is possible, however not all approaches will work. After a bit of fiddling around, I could get a combination that works fine: The Three.js entity to insert in the scene is named THREE.PointCloud, which has been renamed to THREE.Points in the latest releases, however the Forge Viewer is using an older version (r71). You can use a THREE.PointCloudMaterial for that entity, unfortunately the Viewer renderer will not like it, so I had to use a THREE.ShaderMaterial and implement a custom shader. Also the renderer will not accept THREE.BufferGeometry, which is accepted only for THREE.Mesh instances. So use a plain THREE.Geometry object.

A PointCloud instance will allow you to display a large number of points and potentially animate them independently while keeping a decent frame rate comparing to displaying the points using separate meshes because only a single instance is being rendered.

To make the demo more exciting I used one of my previous sample involving a custom particle system and used the PointCloud entity to render and animate all particles at once. You can see in the video below that even when increasing the number of particles to 1Million, you can maintain a relatively hight FPS hence keeping the simulation smooth. I wanted to give each particle a potentially different random colour, so I could achieve that by using the shader attributes. Attributes have a one-to-one mapping to the entity vertices.

Here is how the method that generates the PointCloud with my custom shader looks like:

The complete demo can be found at Viewing.Extension.Particle, here is a link to the live demo and a recording the demo in action when running at full capacity with a million points in the system. You need to select the particle emitter in order to display its properties in the panel and increase the values. Hope you like it!