|
erroneous seth, Newbie
Posted: 20 October 2011 10:37 PM Total Posts: 28
Hello to everyone,
Say for example:
var width : Number = model.maxX - model.minX; var height ... var depth ... var shape : AWPBoxShape = new AWPBoxShape(width, height, depth); var rigidBody : AWPRigidBody = new AWPRigidBody(shape, model, 1);
The model belongs to an “ObjectContainer3D” and its starting position is at
(4, 0, 0) in the global space. However, its position returns (0, 0, 0) as that is its position relative to its container.
So, an attempt to create a collision shape for this model would give a shape with the same dimensions but a starting position at (0, 0, 0) global point and not container space.
So, could someone let me know how can I transform the (0, 0, 0) position returned by:
model.position
into world space coordinates (4, 0, 0)?
Thanks a lot!
|
erroneous seth, Newbie
Posted: 20 October 2011 11:47 PM Total Posts: 28
[ # 1 ]
Hello to everyone,
If I write:
mesh.position
I get the coordinates of the mesh relative to its container.
However, how can I get the global coordinates of a mesh?
Thanks a lot.
P.S. I have mistakenly asked the same thing in the AwayPhysics forum. Is there a way to remove from there?
|
Richard Olsson, Administrator
Posted: 21 October 2011 07:03 AM Total Posts: 1192
[ # 2 ]
Use the parent’s transform matrix to transform the position vector of the contained object. Use the sceneTransform instead if you want to know world space.
EDIT: Please do not double-post. The same people read all forums, so posting in several forums will not yield quicker replies.
|
erroneous seth, Newbie
Posted: 21 October 2011 10:54 AM Total Posts: 28
[ # 3 ]
Thank you for your answer.
Richard Olsson - 21 October 2011 07:03 AM EDIT: Please do not double-post. The same people read all forums, so posting in several forums will not yield quicker replies.
I’m sorry for that.
|
erroneous seth, Newbie
Posted: 21 October 2011 12:18 PM Total Posts: 28
[ # 4 ]
All of the following give the same position: (0, 0, 0)
var containter : ObjectContainer3D = ObjectContainer3D(event.target); var cube1 : Mesh = container.getChildAt(0) as Mesh; var cube2 : Mesh = container.getChildAt(1) as Mesh;
trace(container.position); trace(cube1.position); trace(cube2.position);
First question: I know that “cube.position” gives the position relative to the “container” but, the two cubes have different positions in the container. How come they both trace to (0, 0, 0)?
Second question: I assign a rotation to both cubes and the cubes are not rotated around their center. Their pivot point is at (0, 0, 0). So, is there anything I could to make the models load with their original pivot point set correctly?
P.S.: I have attached the “.blend”, “.obj” and “.as” files.
File Attachments
|
John Brookes, Moderator
Posted: 21 October 2011 01:33 PM Total Posts: 732
[ # 5 ]
MeshUtils.recenter(yourMesh);
Should recenter the pivot to your cubes.
position gives the pivot point in local space. Your geometry (vertices) may be different. Think obj has a habbit of centering the pivot at 0,0,0
|
erroneous seth, Newbie
Posted: 21 October 2011 05:17 PM Total Posts: 28
[ # 6 ]
Thank you very much for your reply!
The “recenter” function puts my meshes to world space’s origin (0, 0, 0). So, it centers them globally.
After taking a look at its source code, I see that in order to calculate the offset of a mesh from the world’s origin, the Bounds class is used.
This info, the offset of my mesh from (0, 0, 0) before recentering, is useful if I want to move them to (0, 0, 0) and then move them back to their original position.
That is why I think that a function such as “offsetFromWorldOrigin” would be useful to be added to the MeshHelper class.
|
rich, Newbie
Posted: 05 June 2012 03:10 PM Total Posts: 17
[ # 7 ]
I am having similar trouble to the question above:
First question: I know that “cube.position” gives the position relative to the “container” but, the two cubes have different positions in the container. How come they both trace to (0, 0, 0)?
Basically, we have a model with many different parts. Some of these parts are planes that are more or less templates that we replace at runtime. Originally, this worked fine when we we were parsing an AWD file. Each mesh had x,y, & z values populated where the x value for one mesh was different from the other meshes (what you would expect). However, we have recently switched over to parsing ASD (with Prefab2) because it is MUCH faster (40% faster)!!! Our problem is that now the x,y,&z values are always 0. I’m guessing this is because each sub-part has its own ASD file, having it’s own coordinate system. But there has to be some way that mesh 1 (mesh1.asd) is accurately oriented to the right of mesh2 (mesh2.asd)....my guess is that this is due to the embedded geometry data having some global context. In any event, I’m guessing a whole lot here and could really use some help.
We trace (after the container has been added to the view) the value of each mesh, where each mesh holds a different visible, global position:
trace(obj.bounds.boundingRenderable.x);
trace(obj.name + “: “+ obj.scenePosition);
trace(obj.name + “: “+ obj.position);
trace(obj.transform.position);
trace(obj.sceneTransform.position);
trace(obj.sceneTransform.transformVector(obj.position));
trace(container.transform.transformVector(obj.position));
trace(container.sceneTransform.transformVector(obj.position));
Here are the results:
0.32245849817991257
Mesh1: Vector3D(0, -50, 0)
Mesh1: Vector3D(0, 0, 0)
Vector3D(0, 0, 0)
Vector3D(0, -50, 0)
Vector3D(0, -50, 0)
Vector3D(0, -50, 0)
Vector3D(0, -50, 0)
0.10394449718296528
Mesh2: Vector3D(0, -50, 0)
Mesh2: Vector3D(0, 0, 0)
Vector3D(0, 0, 0)
Vector3D(0, -50, 0)
Vector3D(0, -50, 0)
Vector3D(0, -50, 0)
Vector3D(0, -50, 0)
The only reliable way that we have found to tell that each mesh has a different position (so that we can do our mesh replacement) is to use the “obj.bounds.boundingRenderable.x” approach. Any ideas on a better approach to getting the coordinates to each mesh? As the previous poster, we don’t quiet understand how 2 meshes having different visible positions have the same position and scene position within the same container. Thanks in advance.
|
Fabrice Closier, Administrator
Posted: 05 June 2012 07:38 PM Total Posts: 1265
[ # 8 ]
Glad to hear you enjoy the speed boost
The asd data is objectspace. The asd file that prefab exports are formated for geometry data only. it needs, once inserted as geometry to get its scene transform.
That two objects can have same similar visual position on screen and not same position once you ask their position is simple. The Object space data is offsetted. In other word a “pivot”, probably the distance to center of the world is added to the mesh geomerty data. In Prefab you can go to prefs and set “autocenter at load” on or off. You can also select a mesh and hit recenter on properties panel. It is of course recommanded to do this for all the meshes, if not, as asd has no concepts of the scene, it could lead to a happy puzzle Because asd will respect the offset if there.
|
rich, Newbie
Posted: 06 June 2012 01:42 PM Total Posts: 17
[ # 9 ]
Hey Fabrice,
Thank you for your speedy reply. Forgive me here, but I’m still a little fuzzy on how I can find the world or scene coordinates of a given (asd-based mesh) given our scenario. Any information that you can provide on the following items would be most appreciated:
1.) If we wanted to draw a line between 2 points relative to 2 meshes, how could we do that? Do we just have to use the bbox approach?
2.) Will it eventually be possible to export all meshes of a model into a single asd file so that x,y,&z values are set and we still get the load speed of the asd model.
3.) How can I get the pivot or data offset value of a given asd-based mesh?
Thanks in advance.
-Richard
|
Fabrice Closier, Administrator
Posted: 06 June 2012 02:41 PM Total Posts: 1265
[ # 10 ]
“how I can find the world or scene coordinates of a given (asd-based mesh)”
you can’t, considering the asd is just an abstract bunch of data. Pivot could be anywhere. Unless you always want it to be the center of the bounds which you of course can extract from min and max values of the vertices.
In the AS3 case, as you can see, the classes do know where the position should be, that is recentered or not. Because Prefab exports them while parsing the scenegraph. Unless you do keep track somehow of the scene positions (by modifying Prefab’s exports for instance), you’ll always have one or more meshes at 0,0,0.
1/ this problem would be same even if you would know the position and the bounds.
Speaking here for a mesh shape that could be anything.(a cube or sphere would be doable with other solution)
You have to project twice a given direction and hit test the geometry. The direction is the line between the two objects.
The hits are Rays that returns you a hit on the scenetransformed geometry. Once you inverse the direction, you repeat for the second hit test on second mesh. After these are known, you can adjust the start/end of the line by substracting some distance (you have the direction in both sides already for that). In order to not have a line that is not exactly on surface of the object for design reasons. I would also consider a zero hit case, for instance is the mesh data is excentered or is a donuts, where you would have no hit. In this case, start of end of the line would be the position vector itself.
2/ Prefab format is under development is using same code. At some point I will have to manage to restore the scene that you save:)
So I can imagine once done, that I could offer more export options. Tho, AWD 2 should probably be what you need.
3/ The asd doesn’t care at all. If your loaded mesh was exported with a pivot added at objectspace level (so position set at xxx while visually looking like at yyy). Prefab will export it exactly as is. Condition sine qua non being of course that the “autorecenter at load” option in prefs, is set off before you load the source file.
Hope it helps
|