Forum: Poser Python Scripting


Subject: Moving morphs between different figures

Cage opened this issue on Dec 20, 2006 · 1232 posts


Spanki posted Fri, 12 January 2007 at 4:25 AM

Quote - "the intersection/bounds checking code doesn't really distinguish the direction of  the ray being cast" - Are you suggesting that it needs to?  Or is this a moot point once the region code is repaired?

Possibly moot, once repaired, but I need to think about that more.

Quote - "if you're not using the  center version, then the direction vector ('ang') needed is just the vertex normal" - So the normal vector itself serves in place of the line?  Nothing needs to replace the removed calculations?  (I've never been able to puzzle out how a vector can be equivalent to a point in some regards, yet possess direction or magnitude....  Cage is a bit slow.)

Yeah, it's not always clear whether a 'vector' is actually being used as a vertex/point or as a direction/normal vector...

To cast a ray, you need 2 things - a starting point and a direction vector.  To get the direction vector (for a line), you subtract the starting point from the ending point and then 'normalize' the result - divide each axis by the magnitude (distance/length) of that line - this produces what's commonly known as a 'unit vector' (Normals are unit vectors).

Unit vector's have the defining characteristic that thier 'length' is 1.0, so they describe a direction only.  If you want a line starting from vertex startV, with a length/distance/magnitude of length along the direction/unit vector angle, you can get the end point of the line with:

endV = startV + (length * angle)

So, if we look back at that code, you can see what's ultimately happening with 'ang' down below there a bit... 

point = [(ang[0]*intersect)+v[0],(ang[1]*intersect)+v[1],(ang[2]*intersect)+v[2]]

...v is the startV point of the line, intersect is actually the length/distance of the line and ang is the unit/direction vector being used to come up with point, which is the endV point of the line.

In the case of casting a ray out from the vertex, the code is doing some redundant stuff to produce what is essentially the normal for that vertex...

v = coord_list(geom2,vi) # get vertex
vn = normals_list(geom2,vi) # get normal
vnv = vecadd(v,vn) # add normal to vertex (effectively the end point of a line from v to vnv along it's normal, with a length of 1.0)
dist = point_distance(v,vnv) # now compute distance of that line (it'll be 1.0)
ang = [(v[0]-vnv[0])/dist,(v[1]-vnv[1])/dist,(v[2]-vnv[2])/dist] # and 'normalize' the vector by dividing each axis by the distance

...and voila! - you're back where you started from - with the normal for that vertex :).

If you are casting the ray out from the center of the mesh, then you're not actually using the vertex's normal, so you create a new angle/vector starting at the center and just passing through the vertex.  You can see similar code being used to determine that angle.

Cinema4D Plugins (Home of Riptide, Riptide Pro, Undertow, Morph Mill, KyamaSlide and I/Ogre plugins) Poser products Freelance Modelling, Poser Rigging, UV-mapping work for hire.