View Full Version : Setting an object's axis position in COFFEE
Jorge Arango 09-18-2010, 07:16 PM I know the SetPosition() command but how does one set just the object's axis to a position?
|
|
rui_mac
09-18-2010, 09:30 PM
Of course this only works with converted objects (polygon or spline). You have to move all the points of your object, the negative amount that you moved the axis. So, determine the vector that is the difference between the old position of the axis and the new position (that is, actually, the old position of your object as returned by GetPosition minus the new position).
Now add that difference to all the point coordinates of your object.
I made a little sample file for you to check out the COFFEE for it.
Rui Batista
Jorge Arango
09-19-2010, 12:52 PM
Thank you Rui! What I had in mind was a script that would set all the polygon's objects axis to 0,0,0 to create vray proxies. The scenes only have polygon objects. So, I combined your code with the one in this thread:
http://forums.cgsociety.org/showthread.php?f=182&t=920222
var f,pos;
AllObjects(op)
{
while(op)
{
if(op->IsInstanceOf(5100)) // polygon object
{
println(op->GetName());
println(op->GetPosition());//Print the object's coordinates to the console
var old_axis=op->GetPosition();
op->SetPosition(vector(0,0,0));
var axis=op->GetPosition();
var points=op->GetPoints();
var np=op->GetPointCount();
for(f=0;f<np;f++)
{
pos=points[f];
pos.x+=old_axis.x-axis.x;
pos.y+=old_axis.y-axis.y;
pos.z+=old_axis.z-axis.z;
points[f]=pos;
}
op->SetPoints(points);
op->Message(MSG_UPDATE);
}
AllObjects(op->GetDown());
op = op->GetNext();
}
}
main(doc,op)
{
AllObjects(doc->GetFirstObject()); // Use our iteration function
}
The pintln commands were for control during coding (forgot to remove them).
Another option would be to use your coffee tag on a parent object along with the copy tag to children command.
Thanks again!
CGTalk Moderation
09-19-2010, 12:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.