Late binding of geometry to mesh
The current Mesh constructor computes the bounding sphere of the input geometry and initializes its own bounding/morph target dictionary.
Does it make sense to have it support late binding? e.g.
// construct a hierarchy top-down
var rootObject = new THREE.Object3D();
scene.addChild(rootObject);
var mesh = new THREE.Mesh();
rootObject.addChild(mesh);
var geometry = new THREE.Geometry();
// fully constructing geometry
mesh.setGeometry(geometry); // TADA!!
I like it! Will add :)
Is the setGeometry method implemented?
Not yet...
What's the suggested workaround for now if I want to change the geometry of a Mesh after it has been added to scene.
My use case is like this: two wheels are connected to an axle. Users should be able to drag them around as a whole, so I merged them (1 axle + 2 wheels) into one geometry and make a Mesh out of it. On the other hand, users should be able to change the length of the axle but the wheel geometries should keep the same. What I am currently doing is to create another axle according to the new length, and attache the wheels onto it. But how to update the Mesh object to use this new geometry? Or any better way of doing this?
Does the new axle have the same number of vertices/faces as the old one?
Yes. The axle is actually a cylinder. The only variable is its length.
So what about doing...
var compose = new THREE.Object3D();
compose.add( wheel1 );
compose.add( axle );
compose.add( wheel2 );
scene.add( compose );
// say that the axle is 100 of length
axle.scale.x = scale;
wheel1.position.x = - 50 * scale;
wheel2.position.y = 50 * scale;
This works for the change-the-length requirement, but doesn't work for the dragging part. In order for users to drag the whole wheel pair (1 axle + 2 wheels), I used ray.intersectObject() to detect which object is clicked. If the 2 wheels and 1 axle are not merged into one Mesh object, they could not be selected and dragged together.
What do you think linzhp, Don't merge the objects, you have a Group mapping, let say {Group1 : [Axle1, Wheel1, Wheel2]}
function pickObjects() {
picked = ray.intersectObject();
if (picked inside Group1) {
picked = Group1
}
}
then move the three things together
Exactly. wheel1.parent is what you need.
Well, that may work. In fact, I can check if the picked object is one of scene.children, if not, then recursively check the children of scene.children until it is found and go back to pick the child of scene that own the object. However, I wonder if there is any more elegant way of doing this
Elegant how? This is already much better than creating a new cylinder every time ;)
Yeah, there is a trade-off. Alright, I will take this approach. Thanks @mrdoob and @et-nowis
This doesn't seem to be implemented. Is there any chance it could be? It's exactly what I need. :D
I have created two nodes as mesh object and a link between them as cylinder or line. when I am dragging the node then link is also dragging fine respect to node. But for this when dragging the node every time, I am crating new link and removing old link. This is not optimal solution. Any idea for optimal solution. (i.e. without creating new link or removing old link we can dragged node with link) Thanks @mrdoob and @linzhp
@navneetk-egnaroinc As stated in the guidelines, help requests should be directed to stackoverflow. This board is for bugs and feature requests.