Thread: Mel scripting
View Single Post
07-03-2011, 04:38 PM   #2
LauriePriest's Avatar
Join Date: May 2003
Location: London
Posts: 1,001
tis involved for someone who hasn't scripted before.

I guess the script would look something like this:

For each vertex in object :
calculate dot product of the unitized normal with a unitized direction. If the result is bigger positive it will be facing toward the camera, if it is negative it will be facing away.
If it is a positive value add it to a list and then after the for loop convert that list to a selection and then to polygons if needs be.

You will need to look up how to do unitize vectors to do this properly otherwise it won't give you an expected result.

If you want to use an object as your direction you would have to add another for loop before this to add a vector for each object that describes the normalized direction from each vertex to that object.
It might be as easy to write in code as this normalized(objectPos-vertexpos)
but its good to understand whats going on under the hood.

This is a bit mathsy but it looks something like this,
Displacement D to object = (obj.tx, obj.ty, (vetex.tx, vertex.ty,
Length L of the vector D = squareRoot(D.x*D.x + D.y*D.y + D.z*D.z)
Normalized Displacment D = D*(1.0/L)

However you could always just declaire the direction at the beginning of the script as a written vector. As long as its normalized !

I hope that gives you a starting point, it will be worth doing a few tutorials to understand how to do for loops and access information across maya to use before trying to do this.

Does that make some sense?


Also could you not just do backface culling, make your selection and then turn backface culling off, or are you doing something special per frame ?
FX supervisor - double negative
  Reply with quote