[Closed] polygon Transformation matrix
consider a plane with 1×1 segments, converted to an editable poly, and has 3 waveform controllers applied to its rotation axis, rotating the plane in all three axis randomly and another waveform controller applied to its z translation axis making it move up and down. now try to align a box to this plane (given the normal is obtained by using the polyop.facenormal function , both the matrixFromNormal function, and the up-vector approach seem to fail!! i.e the box is always out of sync with the orientation of the plane!!) however if i attach-constraint the box to a face of the plane the box aligns itself correctly no matter what the orientation of the plane is (in other words, how does the attachment constraint figure out the correct alignment of the object to the selected face?)
thanks!
attach-constraint makes all calculations in local coordinate system of the plane. You try to attach (align) the box working in world coordinate system.
to make the same as attach-constraint does you can:
c = in coordsys local polyop.getfacecenter <the_plane> <the_face>
n = in coordsys local polyop.getfacenormal <the_plane> <the_face>
<the_box>.transform = (translate (matrixfromnormal n) c)*<the_plane>.transform
ps. but in general case the calculation is a bit more complicated.
thanks for the post!
c = in coordsys local polyop.getfacecenter <the_plane>
n = in coordsys local polyop.getfacenormal <the_plane>
<the_box>.transform = (translate (matrixfromnormal n) c)*.transform
the code works great , unless i go inside the polygon subobject mode and start applying transformation to the polygon! doing so produces the out of sync behavior again! also i tried to use it on a sphere with the same animation controllers applied to it… here is the result:
[right click and select view image, to expand]
the image on the right is the expected result, where as the image on the left shows the result of the above code (out of sync orientations!)… (for the image on the right, i used the up-vector approach, and set the up vector to the rotation axis of the sphere, which is = sphere.dir, but this approach does not work for the plane scenario, also it fails if the sphere has an animated noise modifier – fails implies out of sync orientation of the boxes with the polygons as in the image on the left) )
thanks!
that’s what i call a general case. To get an expected result you have to make the matrix for every poly. And have to define the rules how to make this matrix. To make the matrix we need at least two vectors and one position. The position is the center of the poly. One vector is the poly’s normal. What do you want to use as second vector?
What do you want to use as second vector?
what choices do i have, Heh… the second vector is the problem, the third one is just the cross of the first two! (in the case of the sphere i used the direction vector) :
uV = polymesh.dir
zV = polyop.getfacenormal polymesh faceID
yV = normalize (cross zV uV)
xV = normalize (cross yV zV)
matrix3 xV yV zV (polyop.getfacecenter polymesh faceID)
And have to define the rules how to make this matrix
the objects along a ring of edges must have there x – axis “aligned” and polygons along a loop of edges must have there y – axis “aligned”. does this qualify for a rule? (maybe aligned is not the correct word, what i meant is the (x/y) axis of the object must point in the direction of the next object along the (ring/loop) of edges separating the polygons )
in general is there an algorithm to align an object correctly to a polygon – with its direction vector pointing along the normal of the polygon – (irrespective of the transformations applied to the polygon or the object). given the polygon can have n number of vertices and all the vertices are coplanar.
thanks!
You could use the longest edges of the polygon as the second vector to get the boxes aligned properly.
thanks for the post
You could use the longest edges of the polygon as the second vector to get the boxes aligned properly.
will it work for all cases? for example consider a square polygon rotated 45 degrees.
thanks!
all that is nice would mind trying to apply deformation on the sphere ? like noise or something? try replacing boxes by teapot and watch the direction did u see flipping ? how to fix that ?
all that is nice would mind trying to apply deformation on the sphere ? like noise or something? try replacing boxes by teapot and watch the direction did u see flipping ? how to fix that ?
flipping will occur if the normal of the polygon flips due to some reason, for example if you apply a “hand-fan” bend… [attached 2010 file]
i used attachment constraint to glue all the teapots to the plane because it seems to work best in most cases… (here is a script that does that…)
(
obj = $
converttopoly obj
for i = 1 to (polyop.getnumfaces obj) do
(
tp = teapot radius:3 pos:((polyop.getfacecenter obj i)+[0,0,10]) name: (uniquename (obj.name + "_tp")) segs:1
tp.material = meditmaterials[1]
)
converttomesh obj
for i in (execute ("$" + (obj.name + "_tp") + "*")) do
(
r = ray i.pos [0,0,-1]
fid = (intersectrayex obj r)[2] - 1
bc = (intersectrayex obj r)[3]
controller = attachment()
controller.node = obj
i.pos.controller = controller
addnewkey i.pos.controller 0f
k = attachctrl.getkey i.pos.controller 1
k.face = fid
k.coord = bc
)
)
thank you very much hornberger , thats really smart and easy didnt come to my mind to be such easy it worked fine with me