aFalcon
February 28, 2019, 9:06pm
1
Hello,
Made a playground to show the example…
https://www.babylonjs-playground.com/#7EBFAF
//QUESTION: HOW TO GET WORLD COORDINATES of ExtrudeShape path3D getCurve points?
The GOAL: is to get a single array of all the vectors in world space - then make 1 seamless halfpipe.
But the points returned from getCurve() look like they are local positioned not world.
Not seeing path3D in playground. How best to get the world points?
I’ve tried a few things…
invert the ExtrudeShape matrix and transform coordinate.
add, addInPlace (the extrudeShape.position to the path point)
Is there a way to get world coordinates for the points? or convert to world? Or should I to “continue”?
Thanks so much,
You should be able to multiply by the world matrix to get world position if I understand your question correctly. Does this do what you want?
https://www.babylonjs-playground.com/#7EBFAF#3
1 Like
The PG didn’t load, but I will try multiply. Thanks much!
Also I was reading the source code for .continue() on splines and it does an interesting subtract().add().
The problem is challenging because of rotations. For example - it makes sense that the world coordinate of all the path3D points might not be known because of rotation.
So I get it. Open to any other tips. Thank you.
jerome
March 1, 2019, 5:43am
4
As trevordev said, just multiply each curve point coordinates by the mesh world matrix to get the world coordinates.
If the mesh isn’t rotated, nor scaled, you can then only add the mesh position vector to each point coordinates instead of multiplying by the WM.
The method .continue() allows to “concatenate” curves to each other from an initial one… in its local space, to get a final longer and more complex curve.
1 Like
Thank you. I see the options. It took 24 hours, but can imagine the problem clearer now… and it is interesting!
The creation of curves, and concatenation - happens in separate matrix spaces.
So to make many curves and assemble them perfectly - considering:
What is good artistic method of smooth complex curve, assembly.
Fun problem!
And looks like a translation/transform solution across pos,rot,scale.
Luckily not scaled (yet). That would have been a great surprise. Nice TIPs!
PLAN:
bring back path-editor from a few years ago. give it origin-transform.
Finding the offset position quickly is nice, useful for many things. Maybe rotation and scale later.
But also, transform & translate experiments to help visualize
matrix multiply, and point: add, subtract to Ref.
Good time to learn both.
Fascinating what becomes of a line when curved in 3D space.
Thanks, I’ll try to make a PG of transform examples of glowing spheres and cubes! : )
Strangely (for me), no PGs loading today…? Just spinners. Idk. Fyi. Anyone else?
I see how a CURVE-EDITOR would be really challenging and interesting !
1 Like
SOLVED!
Solution, to create a smooth and seamless ROLLER-COASTER (or halfpipe, etc):
DESCRIPTION: loop the points of an extrusion and convert to world coordinates.
var localPathToWorld = function(localMesh, localPath){
localMesh.computeWorldMatrix();
var matrix = localMesh.getWorldMatrix();
var global_position, worldPath=[];
for(var i=0; i<localPath.length;i++){
global_position = BABYLON.Vector3.TransformCoordinates(localPath[i], matrix);
//var traceSphere = BABYLON.Mesh.CreateSphere("sphere", 3, 8 , nx.scene);
//traceSphere.position = new BABYLON.Vector3(global_position.x, global_position.y, global_position.z);
worldPath.push(global_position);
}
return worldPath
}
var worldPath = localPathToWorld(anExtrudeShape, anExtrudeShapePath.reverse())
Still building PG. Hmm works locally. PG has a fragment in it.
UPDATE: fragments can be removed by spacing the separations out (and aligning to tangent).
CONCEPT: the worldPath is then used to create a single seamless halfpipe (with smooth curves).
Hope this helps someone…
2 Likes