vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
2.03k stars 301 forks source link

Points as customLayerData #46

Open JuliensLab opened 3 years ago

JuliensLab commented 3 years ago

Hi there,

Fantastic library! Thank you for this detailed work and documentation.

I'm trying to use Points instead of Spheres in your Custom Layer API (found here: https://github.com/vasturiano/globe.gl/blob/master/example/custom-layer/index.html).

I am replacing the original code (pasted here for convenience):

  .customLayerData(gData)
  .customThreeObject(d => new THREE.Mesh(
    new THREE.SphereBufferGeometry(d.radius),
    new THREE.MeshLambertMaterial({ color: d.color })
  ))
  .customThreeObjectUpdate((obj, d) => {
    Object.assign(obj.position, world.getCoords(d.lat, d.lng, d.alt));
  });

(function moveSpheres() {
  gData.forEach(d => d.lat += 0.2);
  world.customLayerData(world.customLayerData());
  requestAnimationFrame(moveSpheres);
})();

by my modified code:

  .customLayerData(gData)
  .customThreeObject(d => new THREE.Points(
    new THREE.BufferGeometry(),
    new THREE.PointsMaterial({ color: d.color, size: 100 })
  ))
  .customThreeObjectUpdate((obj, d) => {
    Object.assign(obj.position, world.getCoords(d.lat, d.lng, d.alt));
  });

(function moveSpheres() {
  gData.forEach(d => d.lat += 0.2);
  world.customLayerData(world.customLayerData());
  requestAnimationFrame(moveSpheres);
})();

The original code works perfect: the spheres are visible where expected. My modified code doesn't yield points. Nothing appears. I tried to change the size of the point. I checked as reference:

So far, no success. I am wondering if you know why this is.

Thank you!

vasturiano commented 3 years ago

@JuliensLab thanks for reaching out.

It appears you're not assigning any vertices to your points geometry. That may be the reason why nothing is showing.

See this ThreeJs example: https://threejs.org/docs/#api/en/materials/PointsMaterial

Specifically this line:

geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );