Malkalypse
06-12-2009, 08:03 PM
Hi, what I want to do is pretty simple, and I more or less know how to do each step separately, but for some reason am having a hard time putting the steps together. My goal is:
Create an object, and place it on the face of another object, such that it is
1) located on the midpoint of the face's shortest edge, and
2) is oriented perpendicular to that edge along the face
--First create an array of the point locations and lengths for each of the sides
triData = #(#(),#(),#())
for p = 1 to 3 do
(
append triData[1] ($.getVertex ($.getEdgeVertex p 1)) -- coords for 1st point of edge p
append triData[2] ($.getVertex ($.getEdgeVertex p 2)) -- coords for 2nd point of edge p
append triData[3] ( distance ($.getVertex ($.getEdgeVertex p 1)) ($.getVertex ($.getEdgeVertex p 2)) ) -- length of edge p
)
-- Next, determine the shortest edge
theShortest = aMin triData[3]; theShortest = findItem triData[3] theShortest
-- Create points at each corner of the shortest edge, and one in the middle
n = point pos:(($.getVertex ($.getEdgeVertex theShortest 1)) + $.pos)
o = point pos:(($.getVertex ($.getEdgeVertex theShortest 2)) + $.pos)
p = point pos:((n.pos + o.pos) / 2)
I also have a simple script based on the "How do I align the UVW_Modifier's Gizmo to a selected face?" lesson from the maxscript reference, which looks like thus (still need to rewrite the script to use the points as its basis rather than a world upnode):
fn alignToFace theObj theTgt theFace =
(
faceNormal = in coordsys theTgt (getFaceNormal theTgt theFace)
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal )
theMatrix = matrix3 rightVector upVector faceNormal [0, 0, 0]
theObj.transform = theMatrix
)
alignToFace $TheObject $TheTarget 1 -- $TheObject and $TheTarget being the temporary names for the objects in question
Now, part of the problem is that the first script is made to work on editable poly objects, and the second script to work on editable mesh objects. I know that between polyOp and MeshOp most of the same things can be done with either, but I'm just not finding a way to make it happen. Any suggestions?
Create an object, and place it on the face of another object, such that it is
1) located on the midpoint of the face's shortest edge, and
2) is oriented perpendicular to that edge along the face
--First create an array of the point locations and lengths for each of the sides
triData = #(#(),#(),#())
for p = 1 to 3 do
(
append triData[1] ($.getVertex ($.getEdgeVertex p 1)) -- coords for 1st point of edge p
append triData[2] ($.getVertex ($.getEdgeVertex p 2)) -- coords for 2nd point of edge p
append triData[3] ( distance ($.getVertex ($.getEdgeVertex p 1)) ($.getVertex ($.getEdgeVertex p 2)) ) -- length of edge p
)
-- Next, determine the shortest edge
theShortest = aMin triData[3]; theShortest = findItem triData[3] theShortest
-- Create points at each corner of the shortest edge, and one in the middle
n = point pos:(($.getVertex ($.getEdgeVertex theShortest 1)) + $.pos)
o = point pos:(($.getVertex ($.getEdgeVertex theShortest 2)) + $.pos)
p = point pos:((n.pos + o.pos) / 2)
I also have a simple script based on the "How do I align the UVW_Modifier's Gizmo to a selected face?" lesson from the maxscript reference, which looks like thus (still need to rewrite the script to use the points as its basis rather than a world upnode):
fn alignToFace theObj theTgt theFace =
(
faceNormal = in coordsys theTgt (getFaceNormal theTgt theFace)
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal )
theMatrix = matrix3 rightVector upVector faceNormal [0, 0, 0]
theObj.transform = theMatrix
)
alignToFace $TheObject $TheTarget 1 -- $TheObject and $TheTarget being the temporary names for the objects in question
Now, part of the problem is that the first script is made to work on editable poly objects, and the second script to work on editable mesh objects. I know that between polyOp and MeshOp most of the same things can be done with either, but I'm just not finding a way to make it happen. Any suggestions?
