And this is a root cause of all problems that are related with my animation system. So if i wont' fix this, i won't finish all the other stuff that is completed and waiting for this stuff to be finally fixed.
Guys, before you skip reading - the thing i am looking for is a small help with transformation matrices - being exact : how do i get untransformed vertex positions from objects in max ( even from those, having physique applied ).
Let me say what i am currently doing.
I am writing scene exporter to my engine, if i understand it right, all vertexes should have object space coordinates, and i need transformation matrix of that object exported separately too - to multiply the vertexes by that transformation matrix later on when rendering ( in shader for example ).
So let me visualize it, this is a box that i have positioned at 50, 50, 50, the size of this box is 10,10,10
EXPORT.
0) Object World Space Transformation Matrix at Frame 0 is achieved by:
Matrix3 mTransformationMatrix = pNode->GetObjTMAfterWSM(0);
1) Every vertex * pNode->GetObjTMAfterWSM(0) ( I suspect this will result in a Vertex Transformed to World Space (right?) )
Matrix3 matWorldSpace = pNode->GetObjTMAfterWSM(0)
for(each vertex....)
{
// calculate normals
// calculate uvs
Point3 p3VertexPosition = matWorldSpace * pMesh->verts[pMesh->faces.v[index]] ;
}
Results
+ [Box01] Processing
+ [Box01] Extracting face data [ 0 ]
+ [Box01] Face.0 Vertex.0 (UNIQUE) <55.00,55.00,55.00>
+ [Box01] Face.0 Vertex.1 (UNIQUE) <45.00,55.00,55.00>
+ [Box01] Face.0 Vertex.2 (UNIQUE) <45.00,45.00,55.00>
+ [Box01] Face.1 Vertex.0 (SHARED - indexed to Vertex.2)
+ [Box01] Face.1 Vertex.1 (UNIQUE) <55.00,45.00,55.00>
+ [Box01] Face.1 Vertex.2 (SHARED - indexed to Vertex.0)
+ [Box01] Face.2 Vertex.0 (UNIQUE) <55.00,55.00,45.00>
+ [Box01] Face.2 Vertex.1 (UNIQUE) <55.00,45.00,45.00>
+ [Box01] Face.2 Vertex.2 (UNIQUE) <45.00,45.00,45.00>
+ [Box01] Face.3 Vertex.0 (SHARED - indexed to Vertex.6)
+ [Box01] Face.3 Vertex.1 (UNIQUE) <45.00,55.00,45.00>
+ [Box01] Face.3 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.4 Vertex.0 (UNIQUE) <55.00,45.00,45.00>
+ [Box01] Face.4 Vertex.1 (UNIQUE) <55.00,45.00,55.00>
+ [Box01] Face.4 Vertex.2 (UNIQUE) <45.00,45.00,55.00>
+ [Box01] Face.5 Vertex.0 (SHARED - indexed to Vertex.10)
+ [Box01] Face.5 Vertex.1 (UNIQUE) <45.00,45.00,45.00>
+ [Box01] Face.5 Vertex.2 (SHARED - indexed to Vertex.8)
+ [Box01] Face.6 Vertex.0 (SHARED - indexed to Vertex.4)
+ [Box01] Face.6 Vertex.1 (UNIQUE) <55.00,55.00,55.00>
+ [Box01] Face.6 Vertex.2 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.0 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.1 (UNIQUE) <55.00,45.00,45.00>
+ [Box01] Face.7 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.8 Vertex.0 (UNIQUE) <45.00,55.00,45.00>
+ [Box01] Face.8 Vertex.1 (UNIQUE) <45.00,55.00,55.00>
+ [Box01] Face.8 Vertex.2 (UNIQUE) <55.00,55.00,55.00>
+ [Box01] Face.9 Vertex.0 (SHARED - indexed to Vertex.16)
+ [Box01] Face.9 Vertex.1 (UNIQUE) <55.00,55.00,45.00>
+ [Box01] Face.9 Vertex.2 (SHARED - indexed to Vertex.14)
+ [Box01] Face.10 Vertex.0 (UNIQUE) <45.00,45.00,45.00>
+ [Box01] Face.10 Vertex.1 (SHARED - indexed to Vertex.2)
+ [Box01] Face.10 Vertex.2 (UNIQUE) <45.00,55.00,55.00>
+ [Box01] Face.11 Vertex.0 (SHARED - indexed to Vertex.19)
+ [Box01] Face.11 Vertex.1 (SHARED - indexed to Vertex.7)
+ [Box01] Face.11 Vertex.2 (SHARED - indexed to Vertex.18)
+ [Box01] Writing mesh final data
+ [Box01] Overall mesh vertices: 20
+ [Box01] Overall mesh indices: 36
+ [Box01] Model Transformation Matrix: <Translation: 50.0,50.0,-55.0>.
What indicates that they are World Space transformed - this is what i expected.
Now what i want is those vertexes to be in Object Space, so i am thinking - If i remove that Multiplication, would i get them right?
2) Vertexes without any matrix multiplication
for(each vertex....)
{
// calculate normals
// calculate uvs
Point3 p3VertexPosition = pMesh->verts[pMesh->faces.v[index]] ;
}
Results
+ [Box01] Processing
+ [Box01] Extracting face data [ 0 ]
+ [Box01] Face.0 Vertex.0 (UNIQUE) <5.00,0.00,5.00>
+ [Box01] Face.0 Vertex.1 (UNIQUE) <-5.00,0.00,5.00>
+ [Box01] Face.0 Vertex.2 (UNIQUE) <-5.00,0.00,-5.00>
+ [Box01] Face.1 Vertex.0 (SHARED - indexed to Vertex.2)
+ [Box01] Face.1 Vertex.1 (UNIQUE) <5.00,0.00,-5.00>
+ [Box01] Face.1 Vertex.2 (SHARED - indexed to Vertex.0)
+ [Box01] Face.2 Vertex.0 (UNIQUE) <5.00,10.00,5.00>
+ [Box01] Face.2 Vertex.1 (UNIQUE) <5.00,10.00,-5.00>
+ [Box01] Face.2 Vertex.2 (UNIQUE) <-5.00,10.00,-5.00>
+ [Box01] Face.3 Vertex.0 (SHARED - indexed to Vertex.6)
+ [Box01] Face.3 Vertex.1 (UNIQUE) <-5.00,10.00,5.00>
+ [Box01] Face.3 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.4 Vertex.0 (UNIQUE) <5.00,10.00,-5.00>
+ [Box01] Face.4 Vertex.1 (UNIQUE) <5.00,0.00,-5.00>
+ [Box01] Face.4 Vertex.2 (UNIQUE) <-5.00,0.00,-5.00>
+ [Box01] Face.5 Vertex.0 (SHARED - indexed to Vertex.10)
+ [Box01] Face.5 Vertex.1 (UNIQUE) <-5.00,10.00,-5.00>
+ [Box01] Face.5 Vertex.2 (SHARED - indexed to Vertex.8)
+ [Box01] Face.6 Vertex.0 (SHARED - indexed to Vertex.4)
+ [Box01] Face.6 Vertex.1 (UNIQUE) <5.00,0.00,5.00>
+ [Box01] Face.6 Vertex.2 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.0 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.1 (UNIQUE) <5.00,10.00,-5.00>
+ [Box01] Face.7 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.8 Vertex.0 (UNIQUE) <-5.00,10.00,5.00>
+ [Box01] Face.8 Vertex.1 (UNIQUE) <-5.00,0.00,5.00>
+ [Box01] Face.8 Vertex.2 (UNIQUE) <5.00,0.00,5.00>
+ [Box01] Face.9 Vertex.0 (SHARED - indexed to Vertex.16)
+ [Box01] Face.9 Vertex.1 (UNIQUE) <5.00,10.00,5.00>
+ [Box01] Face.9 Vertex.2 (SHARED - indexed to Vertex.14)
+ [Box01] Face.10 Vertex.0 (UNIQUE) <-5.00,10.00,-5.00>
+ [Box01] Face.10 Vertex.1 (SHARED - indexed to Vertex.2)
+ [Box01] Face.10 Vertex.2 (UNIQUE) <-5.00,0.00,5.00>
+ [Box01] Face.11 Vertex.0 (SHARED - indexed to Vertex.19)
+ [Box01] Face.11 Vertex.1 (SHARED - indexed to Vertex.7)
+ [Box01] Face.11 Vertex.2 (SHARED - indexed to Vertex.18)
+ [Box01] Writing mesh final data
+ [Box01] Overall mesh vertices: 20
+ [Box01] Overall mesh indices: 36
+ [Box01] Model Transformation Matrix: <Translation: 50.0,50.0,-55.0>.
Success! Vertexes are in Object Space!
Well, not that fast! - Unfortunately.
This works great if there is no animation at all - and i did not say that, but i already got that working - but wanted to introduce you to the problem.
Ok so far i know i have my vertices in Object Space , so let's add a Physique Modifier to this Box and see what will happen.
Remember we are not multiplying vertices's by any matrix, just like i said - we write down their positions without any mangling.
This is still the same box as previously, with a bone attached via Physique Modifier, let's export and see our vertexes positions.
+ [Box01] Processing
+ [Box01] Extracting face data [ 0 ]
+ [Box01] Face.0 Vertex.0 (UNIQUE) <5.00,0.00,5.00>
+ [Box01] Face.0 Vertex.1 (UNIQUE) <-5.00,0.00,5.00>
+ [Box01] Face.0 Vertex.2 (UNIQUE) <-5.00,0.00,-5.00>
+ [Box01] Face.1 Vertex.0 (SHARED - indexed to Vertex.2)
+ [Box01] Face.1 Vertex.1 (UNIQUE) <5.00,0.00,-5.00>
+ [Box01] Face.1 Vertex.2 (SHARED - indexed to Vertex.0)
+ [Box01] Face.2 Vertex.0 (UNIQUE) <5.00,10.00,5.00>
+ [Box01] Face.2 Vertex.1 (UNIQUE) <5.00,10.00,-5.00>
+ [Box01] Face.2 Vertex.2 (UNIQUE) <-5.00,10.00,-5.00>
+ [Box01] Face.3 Vertex.0 (SHARED - indexed to Vertex.6)
+ [Box01] Face.3 Vertex.1 (UNIQUE) <-5.00,10.00,5.00>
+ [Box01] Face.3 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.4 Vertex.0 (UNIQUE) <5.00,10.00,-5.00>
+ [Box01] Face.4 Vertex.1 (UNIQUE) <5.00,0.00,-5.00>
+ [Box01] Face.4 Vertex.2 (UNIQUE) <-5.00,0.00,-5.00>
+ [Box01] Face.5 Vertex.0 (SHARED - indexed to Vertex.10)
+ [Box01] Face.5 Vertex.1 (UNIQUE) <-5.00,10.00,-5.00>
+ [Box01] Face.5 Vertex.2 (SHARED - indexed to Vertex.8)
+ [Box01] Face.6 Vertex.0 (SHARED - indexed to Vertex.4)
+ [Box01] Face.6 Vertex.1 (UNIQUE) <5.00,0.00,5.00>
+ [Box01] Face.6 Vertex.2 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.0 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.1 (UNIQUE) <5.00,10.00,-5.00>
+ [Box01] Face.7 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.8 Vertex.0 (UNIQUE) <-5.00,10.00,5.00>
+ [Box01] Face.8 Vertex.1 (UNIQUE) <-5.00,0.00,5.00>
+ [Box01] Face.8 Vertex.2 (UNIQUE) <5.00,0.00,5.00>
+ [Box01] Face.9 Vertex.0 (SHARED - indexed to Vertex.16)
+ [Box01] Face.9 Vertex.1 (UNIQUE) <5.00,10.00,5.00>
+ [Box01] Face.9 Vertex.2 (SHARED - indexed to Vertex.14)
+ [Box01] Face.10 Vertex.0 (UNIQUE) <-5.00,10.00,-5.00>
+ [Box01] Face.10 Vertex.1 (SHARED - indexed to Vertex.2)
+ [Box01] Face.10 Vertex.2 (UNIQUE) <-5.00,0.00,5.00>
+ [Box01] Face.11 Vertex.0 (SHARED - indexed to Vertex.19)
+ [Box01] Face.11 Vertex.1 (SHARED - indexed to Vertex.7)
+ [Box01] Face.11 Vertex.2 (SHARED - indexed to Vertex.18)
+ [Box01] Writing mesh final data
+ [Box01] Overall mesh vertices: 20
+ [Box01] Overall mesh indices: 36
+ [Box01] Model Transformation Matrix: <Translation: 50.0,50.0,-55.0>.
+ [Box01] Physique found.
Wow, nice stuff it looks like Physique did not modify anything - again NOT SO FAST,
let's say i want to move this bone somewhere else where it should be positioned now, let's move it to 100,100,100
Instead of moving the object i had to move the Bone as it is connected via Physique to our Box, so i translated the Bone to 100.0, 100.0, 100.0 and let's see the export dump now
+ [Box01] Processing
+ [Box01] Extracting face data [ 0 ]
+ [Box01] Face.0 Vertex.0 (UNIQUE) <55.00,-50.00,65.00> ???????????
+ [Box01] Face.0 Vertex.1 (UNIQUE) <45.00,-50.00,65.00> ???????????
+ [Box01] Face.0 Vertex.2 (UNIQUE) <45.00,-50.00,55.00> ???????????
+ [Box01] Face.1 Vertex.0 (SHARED - indexed to Vertex.2)
+ [Box01] Face.1 Vertex.1 (UNIQUE) <55.00,-50.00,55.00> ???????????
+ [Box01] Face.1 Vertex.2 (SHARED - indexed to Vertex.0)
+ [Box01] Face.2 Vertex.0 (UNIQUE) <55.00,-40.00,65.00> ???????????
+ [Box01] Face.2 Vertex.1 (UNIQUE) <55.00,-40.00,55.00>
+ [Box01] Face.2 Vertex.2 (UNIQUE) <45.00,-40.00,55.00>
+ [Box01] Face.3 Vertex.0 (SHARED - indexed to Vertex.6)
+ [Box01] Face.3 Vertex.1 (UNIQUE) <45.00,-40.00,65.00>
+ [Box01] Face.3 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.4 Vertex.0 (UNIQUE) <55.00,-40.00,55.00>
+ [Box01] Face.4 Vertex.1 (UNIQUE) <55.00,-50.00,55.00>
+ [Box01] Face.4 Vertex.2 (UNIQUE) <45.00,-50.00,55.00>
+ [Box01] Face.5 Vertex.0 (SHARED - indexed to Vertex.10)
+ [Box01] Face.5 Vertex.1 (UNIQUE) <45.00,-40.00,55.00>
+ [Box01] Face.5 Vertex.2 (SHARED - indexed to Vertex.8)
+ [Box01] Face.6 Vertex.0 (SHARED - indexed to Vertex.4)
+ [Box01] Face.6 Vertex.1 (UNIQUE) <55.00,-50.00,65.00>
+ [Box01] Face.6 Vertex.2 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.0 (SHARED - indexed to Vertex.3)
+ [Box01] Face.7 Vertex.1 (UNIQUE) <55.00,-40.00,55.00>
+ [Box01] Face.7 Vertex.2 (SHARED - indexed to Vertex.4)
+ [Box01] Face.8 Vertex.0 (UNIQUE) <45.00,-40.00,65.00>
+ [Box01] Face.8 Vertex.1 (UNIQUE) <45.00,-50.00,65.00>
+ [Box01] Face.8 Vertex.2 (UNIQUE) <55.00,-50.00,65.00>
+ [Box01] Face.9 Vertex.0 (SHARED - indexed to Vertex.16)
+ [Box01] Face.9 Vertex.1 (UNIQUE) <55.00,-40.00,65.00>
+ [Box01] Face.9 Vertex.2 (SHARED - indexed to Vertex.14)
+ [Box01] Face.10 Vertex.0 (UNIQUE) <45.00,-40.00,55.00>
+ [Box01] Face.10 Vertex.1 (SHARED - indexed to Vertex.2)
+ [Box01] Face.10 Vertex.2 (UNIQUE) <45.00,-50.00,65.00>
+ [Box01] Face.11 Vertex.0 (SHARED - indexed to Vertex.19)
+ [Box01] Face.11 Vertex.1 (SHARED - indexed to Vertex.7)
+ [Box01] Face.11 Vertex.2 (SHARED - indexed to Vertex.18)
+ [Box01] Writing mesh final data
+ [Box01] Overall mesh vertices: 20
+ [Box01] Overall mesh indices: 36
+ [Box01] Model Transformation Matrix: <Translation: 50.0,50.0,-55.0>.
And here is something i just DON'T UNDERSTAND and keeps me delayed - why my vertexes have changed?
The transformation matrix looks fine, but why my Raw Vertex Positions are affected, is it because of Physique and Bone translation?
How do i get the Object Space vertices positions for all objects (INodes) i am exporting no matter if they are Physique'd or not ?
The physique is to be used for Bone animation system, but it won't work if i have my Vertexes positions wrong / translated by something...
I was told to Inverse the Transformation matrix and multiply it by The vertexes, that gave some strange results and it does not work at all,
i've seen many implementations but they seem to work on World Space Coordinates - which is what i don't understand, especially when thinking of passing Vertexes later on
to the VBO and multiplying their positions when rendering with the Model Transformation Matrix exported from MAX.
Hope you guy can help me, cause i will go into trouble if i won't finish this till the eoy.