COFFEE understanding polygons

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  01 January 2006
COFFEE understanding polygons

Hi all !!!

i need your help again ... and i don't think it's the last one !!! ....

here we are... i've understand the arrays and a lot of process by sdk manual and reserches on this incredible forum !!! ...

now my request is about the polygons : i really don't understand how they works... for example, if i have the points of a simple cube and i want to "bridge" it... how is the best way to do it ?? ... I've try to do that with SendModelingCommand() but i don't have find any example about how to do it .... i've also tried bridge with op->AddQuadrangle(a,b,c,d); but it doesn't work too...

so ... maybe i mis some basical information about polygons ...

please, help my self-learning of this language ...
i've a lot of idea to develope !!! ...

many thanks
__________________
Liquid + francescobuffi.com
 
  01 January 2006
You can get the polygon of an object by using

BaseObject::GetPolygon(index)

index is a number between 0 and BaseObject::GetPolygonCount();
0 <= index < GetPolygonCount()

// This will get the first polygon of the object
var poly = op->GetPolygon(0);

The result is stored in the poly variable. The SDK docs say the return datatype for GetPolyong() is a [Polygon]

If you look in the docs for 'Polygon', you can see you have access to 4 variables inside the Polygon class.
Variables a,b,c and d

a points to the first point index of that polygon
b points to the second
c points to the third
d points to the fourth (or third if this polygon is a triangle)
(not sure how ngons work)

so if you want to get the second point of the first polygon you would do something like this


 var poly = op->GetPolygon(0); // 0: because thats the first polygon index
 var v = op->GetPoint(poly->b); // v is a vector
 


The C4D structure manager is a great way to view the point/polygon data of an object.
If you change the mode to polygons, you can see in a nice spreadsheet view all the polygons
and what each a,b,c,d is pointing too

Another example
This gets the 4 points of the last polygon of the object and prints it in the console

 var pcnt = op->GetPointCount();
 var polycnt = op->GetPolygonCount();
 
 var poly = op->GetPolygon(polycnt-1);
 
 var a = op->GetPoint(poly->a);
 var b = op->GetPoint(poly->b);
 var c = op->GetPoint(poly->c);
 var d = op->GetPoint(poly->d);
 
 println(a);
 println(b);
 println(c);
 println(d);
 
 


Thats just a basic explanation of polygons within coffee.
__________________
http://www.iangorse.co.uk/

Latest Plugin: GroupConnect
 
  01 January 2006
Quick question
Where have you got op->AddQuadrangle(a,b,c,d); from? I dont see it in the docs
__________________
http://www.iangorse.co.uk/

Latest Plugin: GroupConnect
 
  01 January 2006


thank you very much !!! you have open my mind !!!
now it's clear ! ...

ehehehe AddQuadrangle is a function i've found on the web (other forum) but doesn't work !!

you have let me understand these instruction in a few seconds !! ...
the sdk is a little bit difficult for me .. a lot of double commands and not very clear ..

thank you again !
__________________
Liquid + francescobuffi.com
 
  01 January 2006
yeah... i'm here again ....

another question :

how can i add some rows in the polygon array if this array has no items (surfaces) ??

example : i have a cube with only points. I want add surfaces ...
This is what i need for finish my experiment !!!

thank you very much for your help !!
__________________
Liquid + francescobuffi.com
 
  01 January 2006
EDIT: I just noticed you was asking for something slightly different, The principles are the same as below anyway

You have to use a VariableChanged class for this,
In the SDK docs, search for VariableChanged. It gives three very good examples (with points, but the principles are the same with polygons)

Is practise you would do the following

Add two new points to your object using VariableChanged
Dont forget to position them
Add 1 new polygon to your object using VariableChanged
With your new polygon,
set a = an existing point on object
set b = another existing point on object
set c = your new created point
set d = your other new created point

....or....
Create 4 new points instead of 2, Create 1 new polygon, Set a,b,c,d to all 4 new points, then execute the Optimize command after

I don't have an example, Ive never used VariableChanged before, but thats how it should work
__________________
http://www.iangorse.co.uk/

Latest Plugin: GroupConnect

Last edited by Geespot : 01 January 2006 at 09:37 PM.
 
  01 January 2006
I just made a quick example,

If you create a polygon primitive and make it editable, then use this script. It will create a new polygon


 // Basically copied from SDK Docs
 // POINTS
 // ***************************************
 var vc = new (VariableChanged); if(!vc) return;
 var cnt = op->GetPointCount();
 
 vc->Init(cnt,cnt+2); // Want to add two points, hence the cnt+2
 
 var ok = op->MultiMessage(MSG_POINTS_CHANGED, vc);
 
 // These are the two new points
 var p1 = vector(-50,100,-50);
 var p2 = vector(50, 100, -50);
 op->SetPoint(cnt,p1);  // Last point -1
 op->SetPoint(cnt+1,p2); // Last point
 op->Message(MSG_UPDATE); // Notify object of change
 // **************************************************  
 
 // Do the same as above but for polygons
 // POLYGONS
 // *************************************************
 var vc = new (VariableChanged); if(!vc) return;
 var cnt = op->GetPolygonCount();
 vc->Init(cnt, cnt+1); // Want to add just 1 new polygon
 
 var ok = op->MultiMessage(MSG_POLYGONS_CHANGED, vc);
 
 // Get the last polygon of the object (this was the enw one added)
 var poly = op->GetPolygon(cnt);
 
 // Set the point indices for this new polygon
 poly->a = 0;  // Two existing points (I got these from structure manager)
 poly->b = 3;
 poly->c = op->GetPointCount()-1; // The new point
 poly->d = op->GetPointCount()-2; // The other new point
 
 op->SetPolygon(cnt, poly);
 op->Message(MSG_UPDATE); // Notify object of change
 // ***********************************************
 
 
__________________
http://www.iangorse.co.uk/

Latest Plugin: GroupConnect
 
  01 January 2006
it works it works !!!
now i'm ready to finish my experiment ...
just practice a bit with Init and VariableChanged ....

thank you very much again master


cheers
__________________
Liquid + francescobuffi.com
 
  01 January 2006
ok .. i've made a self-construct algorithm with polygons !!! ...

i've practice a bit with variablechanged() function but i don't understand it very well ... i think ...

however now i've to delete the last row of the polygon object ... i suppose i've to do it with variablechanged again but i don't understand how to do it !!! ... maybe because i don't have understand this function as well ....

i've use this code for put a new poly if n_sup = 0;


 if (n_sup==0){	// condition
 
  var vc = new (VariableChanged); if(!vc) return;
  var cnt = op->GetPolygonCount();
  vc->Init(cnt, cnt+1); // Want to add just 1 new polygon
  var ok = op->MultiMessage(MSG_POLYGONS_CHANGED, vc);
  
 op->Message(MSG_UPDATE);
 
  // Get the last polygon of the object (this was the new one added)
  var poly = op->GetPolygon(cnt);
  
  // Set the point indices for this new polygon
  poly->a = i;  // Two existing points (I got these from structure manager)
  poly->b = intp1;
  poly->c = intp2; // The new point
  poly->d = i; // The other new point
  var polytest = poly;
  op->SetPolygon(cnt, poly);
  n_sup++;
  op->Message(MSG_UPDATE);
 
 



i want delete the last poly now if another condition it's true ...

suggestion are welcome !!! ..
thank you very much
__________________
Liquid + francescobuffi.com
 
  01 January 2006
If you have new points or delete points you need to use VariableChanged for those as well, not just the polys. Also you should use the Backuptags class to be safe, check the sdk for an example.

Last edited by JDP : 01 January 2006 at 02:19 PM.
 
  01 January 2006
ok thank you !!!

but i continue don't understand how to delete with vc()...

if i try to change varaiblechanged(cnt,cnt+1) to varaiblechanged(cnt,cnt-1) it gives me an error ...

i don't have find any example for deleting in the sdk, tutorial, etc ...

cheers
__________________
Liquid + francescobuffi.com
 
  01 January 2006
To be honest it is probably easier to use the delete command within the SendModelingCommand() function, however here is an example of deleting polygons with VariableChanged. If you change the polygon/point count to something less than it currently is then these will get removed from the end of the list i.e. if you look in the structure manager and you have 10 polys listed from 0 to 9, you changed the count to count-1, this will remove the poly listed as number 9. To remove specific polygons you will have to move them to the end of the list and then ripple the list. You achieve this by using the translation table map part of VariableChanged. How does this work? You need to create an array and the array slots correspond to the original poly numbers i.e array[2] = poly number 2. The values in the slots equal the destination poly number, so if array[2] has the value 4 when you send this with VariableChanged poly 2 now becomes poly 4. I hope this is not too confusing. Here's an example for deleting selected polys. I used the optimise command at the end to remove unused points. HTH

/////////////////////////////////////////////////////


var i, j;
var found = 0;
var select = op->GetPolygonSelection();
var cnt = op->GetPolygonCount();
var vc = new(VariableChanged);
var map = new(array, cnt);

// fill map array with initial values
for(i=0; i<cnt; i++)
map[i] = i;

//move selected polys to end of map array and ripple list
for(i=0; i<cnt; i++)
{
if(found >= select->GetCount()) break;
if(select->IsSelected(i))
{
map[i] = cnt-1-found;
for(j=i+1; j<cnt; j++)
{
if(select->IsSelected(j)) break;
map[j]= j-1-found;
}
found++;
}
}
if(!found) return FALSE; // if no selection return

doc->StartUndo();
doc->AddUndo(UNDO_OBJECT_BASEDATA, op);

// Send mapping table, no resizing
vc->Init(cnt, cnt, map);

var bt = new(BackupTags);
bt->Init(op); // backup op

var ok = op->MultiMessage(MSG_POLYGONS_CHANGED, vc);

if(!ok)
{
bt->Restore(); // Restore the object if something went wrong
return FALSE;
}


// delete polygons
vc->Init(cnt, cnt-found); // Resize Polygon count

bt->Init(op); // backup op

var ok = op->MultiMessage(MSG_POLYGONS_CHANGED, vc);

if(!ok)
{
bt->Restore(); // Restore the object if something went wrong
return FALSE;
}

//optimise object
var bc = new(BaseContainer);
bc->SetData(MDATA_OPTIMIZE_TOLERANCE, 0.01);
bc->SetData(MDATA_OPTIMIZE_POINTS, 1);
bc->SetData(MDATA_OPTIMIZE_POLYGONS, 1);
bc->SetData(MDATA_OPTIMIZE_UNUSEDPOINTS, 1);

SendModelingCommand(MCOMMAND_OPTIMIZE, doc, op, bc, MODIFY_ALL);

doc->EndUndo();

Last edited by JDP : 01 January 2006 at 09:07 AM. Reason: Tried to sort out formatting :(
 
  01 January 2006
thank you, thank you very much JDP !!!
now i've only to study this code ... ehehehehhe !!!

i'm trying to finish the delaunay triangulation with COFFEE ... i'm very closed to do that ...
but i've a lot of other works to finish this day .. i hope next days could be more easy !!!


thank you again !!!

cheers
__________________
Liquid + francescobuffi.com
 
  01 January 2006
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:52 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.