[Closed] transform matrix problem
Hej Guys,
I created two boxes, then I transformed the second one. I took its TM matrix and I am trying to use the TM matrix to set the first box vertices’s to match the other one.
the vertarray contains the vertices of Box001
it doesn’t really doing it right… I wonder what I do wrong. THX!
tm = $Box002.transform.
for i=1 to vertarray.count do (
v = vertarray[i]
v[1] = (v[1] * tm[1][1]) + (v[2]* tm[1][2]) + (v[3] * tm[1][3]) + tm[4][1]
v[2] = (v[1] * tm[2][1]) + (v[2]* tm[2][2]) + (v[3] * tm[2][3]) + tm[4][2]
v[3] = (v[1] * tm[3][1]) + (v[2]* tm[3][2]) + (v[3] * tm[3][3]) + tm[4][3]
setvert $Box001 i v
)
update $Box001
You’d have to multiply the positions by the matrix, not its components. However if you get/set the positions directly on the baseObject you would not need to do that at all.
I suppose the easiest way would be the following
in coordsys local (
for i=1 to $Box002.verts.count do (
setVert $Box001 i (getVert $Box002 i)
)
)
update $Box001
Why not just use the object offset properties of the node to assign the values you want?
<node>.objectOffsetPos
<node>.objectOffsetRot
<node>.objectOffsetScale
The above will affect a node’s geometry offset from its pivot.
I actually have to do this in python. In max now it works now fine but in python I got to break it apart because python doesn’t support point3 * matrix3
v[1] = (v[1] * tm[1][1]) + (v[2]* tm[1][2]) + (v[3] * tm[1][3]) + tm[4][1]
v[2] = (v[1] * tm[2][1]) + (v[2]* tm[2][2]) + (v[3] * tm[2][3]) + tm[4][2]
v[3] = (v[1] * tm[3][1]) + (v[2]* tm[3][2]) + (v[3] * tm[3][3]) + tm[4][3]
But this doesnt work for some reason… I need to know what the max matrix * point3 does.
Anybody can explain it in mathematical way?
THX
Just use the PointTransform method of Matrix3. By the way, what’s the reason you ‘have’ to do it in python and why don’t you get/set the mesh vertex positions directly on the baseObject’s triMesh?
because I write an exporter and python is much faster in saving files (BOBO please fix this)
Even though getting vertex data is slower in python the file saving so much faster that it is worth.
I check out the point transform method thx!
this is not true. c++ is the fastest, c# is next, python is after… mxs working with mem or file binary stream is much faster than python working with text…
If the saving is not fast enough for you, why don’t you save your files using dotNet APIs?
I was pleasantly surprised the other day with MXS and binary, it’s much faster than text!