Lets say I want to puzzle together various 3d model. The models can be of various shape and sizes. They can only connect at specific places.

I try to create an editor where I can puzzle together various road elements in order to create a track.

What I have done so far is to create a road element with texture and stuff. Then, on the side where I want to be able to connect the next model, I have cut out a plane, detached it from the model, gave it a name, then I linked the plane as a child to the model.

Now I can render the model, and move it around, and the child element on the extension points will follow since it is a child. I can now easily get the plane in space where I want to connect next piece.

How can I take a new road element, which has its own named child plane that identify its connection point, and move the parent element(the road) into position so that the planes from both models end up sharing the same vertice points? The end result have then the 2 road elements lined up nicely.

I am a bit puzzled on how to achieve this, and not sure what to look for.

The child plane is of same size on both model. Lets leave out scaling for the moment.

You could maybe get the World Coordinates of the first plane and then set the location of the piece of road you are wanting to place to those coordinates, adding in the offset of the new piece’s dimensions in order to line them up properly.

For example: the plane on piece 1 is at world coordinates Vector3f(5, 0, 5), so you set the location of piece 2 to Vector3f(5, 0, 5).add(2, 0, 0) because your plane in piece 2 is offset by 2 units from piece 2’s center.

What about rotation then? Your idea is kind of ok in a square box world … but mine is not.

I guess I need the normal vector from both planes, perhaps invert the normal from the 2nd plane. Then I need to figure out the math, which I don’t know atm, to get the amount of rotation. Then I rotate the 2nd plane so it is aligned with the first.
But rotating a child will not rotate a parent (unless jme3 has some cool tricks). If I applied the same rotation to all nodes in the 2nd model, then every bit will be out of position. So every element except the plane need to adjust their position … which I don’t know how to do.
Once the 2nd model is rotated, perhaps I can figure out the distance between the center of the 2 planes and use this to move the 2nd parent model (and the children will follow)
.
I might need a way to calculate the plane center instead of using the pivot point which might be off because the modeler(me) is sloppy. I have yet to figure out this myself.

Maybe … if I know how much to rotate the 2nd plane … I then collect all the pivot points in each node in 2nd model and save them for later, I then move all the pivot points to the center of the plane … i then rotate every node … then reset the pivot points…

graph of road nodes (crossings) and road segments (lanes) will allow you to determine position and rotation of every elements (and also shape, slope, texture coord, etc.) with logical approach. There could be no parent and child, but list of neighbours with no hierarchy at all (but if you need a directionnal graph, it’s almost the same approach). Look for graph !

After computing your logical data, you give jmonkey a list of nodes and segments to draw. jMonkey doesn’t care about hierarchy. You simply create your Geometries at the origin, rotate them (around the origin), then translate them at the correct location.

At update time, you do the same thing (except Geometry creation, of course).