[Closed] Align to a Quad?
Say I have a plane with ten faces, naturally as quads, is it possible to align geometry to those quads like you would with say vertices.
I ask because I am finding it difficult:
As the quad is two triangles I end up with two points of reference neither which is smack in the middle of the quad, when I use a loop to distribute geometry I end up with two pieces positioned on the two tris instead of the one intended.
:banghead:
thanks, K
i assume you converted your plane to an editable mesh and then use meshop.getFaceCenter on each face. If you convert it to poly and use polyop.getFaceCenter instead, you will get the result you desire
here is one fast and cheap method using polyOp
(
polyOb = convertToPoly (Torus_Knot radius:8 radius2:3)
teaP= (teapot radius:2)
for f = 1 to (polyop.getnumfaces polyOb) do
(
n = polyop.getFaceNormal polyOb f
p = polyop.getFaceCenter polyOb f
t = instance teaP
t.transform = MatrixFromNormal n
t.position = p
)
)
he-he… learn the matrix algebra:
pretranslate (matrixfromnormal facenormal) facecenter
but it’s not absolutely correct. we were talking about this matter on this forum a lot. just do the search
vapourise, you saw my script jpAligner at scriptspot. it uh… has the .ms attached now. anyway it sounds like your looking for polyop.getFaceCenter like jonahhawk suggested.
Hey and thanks for the replies guys, I guess I got to the point where I couldnt see the wood for the trees. Must have been using a mesh instead of poly.
Thanks for the code Jonah I will try to learn from that:) Yeh Nudity I really like the sound of that script and will have a look at what you have been doing with it and also try to learn!
Denis, I was looking into the matrix stuff when I was getting stumped yesterday and it does look really handy but I still find it a tad overwhelming, will definately try to understand it better though as I progress!
Thanks again people
fn scatterNodes ground brush = if iskindof ground Editable_Mesh and isvalidnode brush do
(
faces = ground.faces as bitarray
done = #{}
for f in faces where not done[f] collect
(
polys = meshop.getpolysusingface ground f
ground.selectedverts = meshop.getvertsusingface ground polys
done += polys
center = (averageSelVertCenter ground)*ground.objecttransform
normal = averageSelVertNormal ground
copy brush pos:center dir:normal wirecolor:green
)
)
/*
(
delete objects
brush =
(
top = Cone smooth:on heightsegs:1 capsegs:1 sides:24 height:8 radius1:2 radius2:0 pos:[0,0,-20]
top.mat = standard diffuse:green
bot = Cylinder name:"tree" smooth:on heightsegs:1 capsegs:1 sides:24 height:2 radius:0.5 pos:[0,0,-22] wirecolor:green
bot.mat = standard diffuse:brown
attach (bot = converttomesh bot) top
bot
)
ground = mesh name:"ground" length:100 width:100 lengthsegs:10 widthsegs:10 wirecolor:yellow pos:[-50,-50,0]
addmodifier ground (Noisemodifier fractal:on strength:[25,25,25] seed:(random 0 1000000)) -- add a little fun
scatterNodes ground brush
)
*/
hehe, Denis…that code looks absolutely brilliant but I have no idea what it does, I feel bad that you took the time to compile it and I have no clue!
I tried out Jonah’s cheap and cheerful way and it works out alright but how do I go about making sure all the aligned objects orientation are the same, at the moment when the objects are aligned to the faces they all have a different rotation.
Cheers, guys
does the code just look good, or it also works right?
to align a node to a poly we only need to know the center and the normal of this poly.
mesh’s poly can be made by several faces. so the center of a poly is average position of its vertices, the normal is the average normal.
the code shows how to get mesh poly by face, get average center and normal, and place an object using this data.
there is minimum of math. only pure mxs
ha, yeh it works for sure I have the mini forest on my screen at the moment I do appreciate all your effort even if I dont always understand it.
I have included a picture of what my main problem is at the moment…
cheers, K
Yes, rotations are quite confusing to me too. I just spent a couple days messing with that stuff for new tool I just made. It aligns objects to verts/edges/faces with offsets and so on.
I wasn’t able to figure out how to get my rotations proper either. But for what I have it isn’t as vital all the time, but I’d also like to know how to align to a face Normal, then rotate based on that so Local Y is along the face Direction.
I guess you could get 2 points on an edge for a Direction Vector and use that, but it’s hard to say what points to get.