i 'm a newbie and i 'm trying to place randomly a box on a sphere (directly on the surface). i see a lot of complicated method…(quaternion,etc…)
is there a easy way to achieve that ?

Thanks, effectively this soluce works. BUT… in my case i’m searching to create trees with trunc and foliage. The problem is that the trunc is not set relatively to the center of the sphere.
I put a jsfiddle to explain that : (trunc is white and foliage is red) https://jsfiddle.net/ebhja9wm/

When i change the rotation of the mesh, that don’t works because in certain area the degree is not correct.

in fact i’m searching to move my tree in same time than my heart(sphere). https://jsfiddle.net/espace3d/67o8y1ct/
and it doesn’t works because my tree rotate around his center and not the center of the hearth.
i see that a pivot point can do that or a group. But my attempts don’t works…thanks if you could show me the solution.

You have set sphere.rotation.z to zero which was responsible for the restart. I’ve fixed this by resetting the previous rotation.

I’ve noticed that you create unnecessarily many objects in your collide() function via Object3D.clone(). It’s more memory friendly to define helper objects just once outside of the function and reuse them.

In one of your statements you have used directionVector.length(). This code does not make sense since directionVector is already normalized so length() returns always 1. I’ve rewritten the code a bit so you are using the real length of the vector defined by the difference between a vertex and the box’s position.

Hi and thanks for your jsfiddle!
I’m a little bit loss with this.
I took your snippet and in the same time the doc to understand but i 'm still again loss :frowning
could you explain to me in more detail each line, i’m starting with 3d…before i works with Phaser, only 2d…

The following line transforms a vertex of the geometry from its local space to world space. That’s necessary since your ray is defined in world space. However, you can also do it the other way around. Transform the ray into the local space of the mesh which is in most cases more performant for raycasting (since you transform the ray just once for all vertices of the geometry).

vertex.applyMatrix4( staticCube.matrixWorld );

The following lines calculates the direction vector via vector subtraction. This vectors needs to be normalized. You can do it via direction.normalize() but since you need the length of the vector a bit later in your code, it is calculated and then used for normalization. Normalizing a vector is nothing else than dividing it through its length.