vasturiano / aframe-globe-component

3D Globe data visualization component for A-Frame
https://vasturiano.github.io/aframe-globe-component/
MIT License
33 stars 11 forks source link

Is there a way to rotate objects? #15

Closed edhyah closed 2 years ago

edhyah commented 2 years ago

Hello,

In the 3D objects layer, after adding an object to the globe, is it possible to rotate the object to a desired orientation? Specifically, I'm trying to add a plane icon to your airline routes demo that points the plane in the direction of the route. I looked through your other demos like the satellite demo but none of them actually change the orientation of the added objects.

Thanks!

vasturiano commented 2 years ago

@edhyah thanks for reaching out.

Since you are building the ThreeJS objects yourself, you should be able to apply the desired rotation operations to the objects. See: https://threejs.org/docs/#api/en/core/Object3D.rotation

edhyah commented 2 years ago

How can I access the objects themselves? object-three-object or objectsData doesn't seem to give me pointers to the generated threejs objects.

edhyah commented 2 years ago

Specifically, I have a globe entity (globeEl), and I do the following: globeEl.setAttribute('globe', { objectThreeObject: () => new THREE.Mesh(geometry, material) });

objectThreeObject is a function, and I don't have access (ie. don't have access to the pointer) to the three object that is created after calling this function. Is there an API function that allows me to get pointers to the generated threejs objects?

vasturiano commented 2 years ago

@edhyah you do have access to the Three object itself, at generation time, since you're actually implementing that function.

Perhaps it's clearer if you re-write that function as:

objectThreeObject: objectData => {
  const myObj = new THREE.Mesh(geometry, material);

  myObj.rotation = /* your code, possibly depending on objectData */

  return myObj;
}
edhyah commented 2 years ago

Do you not have access to the object at runtime after generation? I want to be able to set the rotation after the object has been generated, based on some real-time data. If that's not possible, does that mean I have to generate all of the objects each time I want to change the rotation?

Thanks again though, this is super helpful!

vasturiano commented 2 years ago

You can also find the ThreeJS object attached to each the items in your data array that you have passed using objectsData.

Each of these items have an attribute called __threeObj that references the ThreeJS object itself. So at any point you can iterate through your data and apply rotation to each of the objects.

edhyah commented 2 years ago

That worked! Thank you!