PDA

View Full Version : COFFEE Point Array Question


Darter
01-04-2006, 03:39 AM
Iíve created a COFFEE expression to offset an objectís points by storing them in an array, adding an offset to each array value and updating the object. At the moment, the array is automatically updating with the new point values but I donít want this to happen. I want it to maintain the original point values as a constant reference while the offset value is changed.

Does anyone know how to achieve this or an equivalent result?

main(doc,op)
{
if(!instanceof(op, PointObject)) return;
var pointArray = op->GetPoints();
var pointCount = sizeof(pointArray);
var i = 0;
var offset = 100;
for(i=0; i < pointCount; i++)
{
var p = pointArray[i];
var pointModified = vector(p.x, p.y - offset, p.z);
op->SetPoint(i, pointModified);
}
op->Message(MSG_UPDATE);
}

Per-Anders
01-04-2006, 04:34 AM
you have to not keep getting the values. make your pointarray a global variable and only set it if it's empty, or if you're on frame 0.

Darter
01-04-2006, 04:54 AM
Thanks for the quick response.

I'm still getting to grips with the basics. I'll revisit your COFFEE node primer and have a look at the section on global variables.

Darter
01-04-2006, 08:33 PM
Iím trying to get my head around how global variables work in COFFEE. If for example, I declare var pointArray before main and put if(!pointArray) pointArray = op->GetPoints(); immediately after main, the expression will reload pointArray each time as previously. It seems that each time main runs, it recognises that a variable called pointArray is valid but says that it hasnít yet been created.

How do I get COFFEE to recognise that pointArray has been declared and contains data upon returning to the beginning of the main function?

COFFEE is my first attempt at coding, so please excuse what may seem like obvious questions.

Darter
01-05-2006, 06:11 AM
I'm not sure what I was doing wrong before but it's working now!

Point offset is controlled by vector User Data on the COFFEE tag. The array will maintain the original point values after they're offset. However, it will update with the offset point values if the Execute button is hit while there is a non-zero offset value. Is there a way around this?

Also, if the tag is dragged straight from one poly object to another, the points of the second object will be messed up. Presumably this is because the array still has the point values from the first object. If however the tag is dragged onto a primitive which is then made editable, all is well. Something else to look into.

Thanks again to mdme_sadie for the help.


var pointArray;

main(doc,op)
{
if(!instanceof(op, PointObject)) return;
if(!pointArray) pointArray = op->GetPoints();
var tag = op->GetFirstTag();
var pointCount = op->GetPointCount();
var i = 0;
var offset = tag#ID_USERDATA:1;
for(i=0; i < pointCount; i++)
{
var p = pointArray[i];
var pointModified = vector(p.x + offset.x, p.y + offset.y, p.z + offset.z);
op->SetPoint(i, pointModified);
}
op->Message(MSG_UPDATE);
}

CGTalk Moderation
01-05-2006, 06:11 AM
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.