THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/10/2010 at 03:08, xxxxxxxx wrote:
Here's the stripped version of my plugin.
#define ID_TOOTHEDWHEEL 1025798
#include "c4d.h"
#include "c4d_symbols.h"
#include "Otoothedwheel.h"
///////////////////////////////////////////////////////////////////////////////
class ToothedWheel : public ObjectData{ // TOOTHED WHEEL OBJECT
public:
String test;
virtual Bool Read (GeListNode *node, HyperFile *hf, LONG level);
virtual Bool Write (GeListNode *node, HyperFile *hf);
virtual void GetDimension (PluginObject *op, Vector *mp, Vector *rad);
virtual BaseObject* GetVirtualObjects(PluginObject*op, HierarchyHelp *hh);
virtual Bool Message(GeListNode *node, LONG type, void *t_data);
static NodeData *Alloc(void) { return gNew ToothedWheel; }
};
///////////////////////////////////////////////////////////////////////////////
// read from hyperfile
Bool ToothedWheel::Read(GeListNode *node, HyperFile *hf, LONG level){
if (level>=0){
hf->ReadString(&test);
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Write to hyperfile
Bool ToothedWheel::Write(GeListNode *node, HyperFile *hf){
hf->WriteString(test);
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// respond to messages
Bool ToothedWheel::Message(GeListNode *node, LONG type, void *t_data){
if(type == MSG_DESCRIPTION_VALIDATE){//check if values are valid
}
else if(type==MSG_MENUPREPARE){
((BaseObject* )node)->SetPhong(TRUE,TRUE, pi/6);
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// for object's bounding box
void ToothedWheel::GetDimension(PluginObject *op, Vector *mp, Vector *rad){
BaseContainer *data = op->GetDataInstance();
Real r, h, th;
r = data->GetReal(TOOTHEDWHEELOBJECT_R);
h = data->GetReal(TOOTHEDWHEELOBJECT_H);
th = data->GetReal(TOOTHEDWHEELOBJECT_TOOTHHEIGHT);
*mp = 0.0;
*rad = Vector(r+th, h*.5, r+th);
}
///////////////////////////////////////////////////////////////////////////////
// create geometry
static BaseObject *GenerateLathe(Vector *cpadr, LONG loopCount, Real segmentAngle, LONG toothCount, BaseThread *bt){
PolygonObject *op = NULL;
Vector *vadr = NULL;
CPolygon *padr = NULL;
LONG i,j,segmentNumber,vcnt,pcnt,a,b,c,d;
Real len = 0.0, sn, cs, v1, v2, *uvadr = NULL;//sn = sine component, cs = cosine component
segmentNumber = toothCount*3;
vcnt = loopCount*segmentNumber;//vertex count
pcnt = loopCount*segmentNumber;//polygon count
op = PolygonObject::Alloc(vcnt, pcnt);
if (!op) goto Error;
vadr = op->GetPointW();//writable point array
padr = op->GetPolygonW();//writable polygon array
pcnt = 0;
for(i = 0; i<segmentNumber; i++){//loop for point locations + polygon assignments aound circle
v1=Real(i )/Real(segmentNumber);
v2=Real(i+1)/Real(segmentNumber);
if (bt && bt->TestBreak()) goto Error;
for(j = 0; j<loopCount; j++){//0-7
a = loopCount*i \+ j;
SinCos(segmentAngle*(Real(i)+0.5), sn, cs);
a = loopCount*i \+ j;
vadr[a] = Vector(cpadr[j].x*cs, cpadr[j].y, cpadr[j].x*sn);
if(i<segmentNumber){
b = loopCount*i \+ (j+1)%loopCount;
c = loopCount*( (i+1)%segmentNumber) \+ (j+1)%loopCount;
d = loopCount*( (i+1)%segmentNumber) \+ j;
}
if(j<loopCount-1) padr[pcnt++] = CPolygon(a,b,c,d);
}
}
op->Message(MSG_UPDATE);
op->SetPhong(TRUE, TRUE, Rad(80.0));
return op;
Error:
blDelete(op);
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
// virtual objects
BaseObject *ToothedWheel::GetVirtualObjects(PluginObject *op, HierarchyHelp *hh){
LineObject *lop = NULL;
BaseObject *ret = NULL;
///////////////////////////////////////
Bool dirty = op->CheckCache(hh) || op->IsDirty(DIRTY_DATA);//check chache data
if (!dirty) return op->GetCache(hh);
BaseContainer *data = op->GetDataInstance();//get ToothedWheel object data
Real r = data->GetReal(TOOTHEDWHEELOBJECT_R);
Real h = data->GetReal(TOOTHEDWHEELOBJECT_H);
Real br = data->GetReal(TOOTHEDWHEELOBJECT_BR);
Real bd = data->GetReal(TOOTHEDWHEELOBJECT_BD);
Real holer = data->GetReal(TOOTHEDWHEELOBJECT_HOLER);
Real holebr = data->GetReal(TOOTHEDWHEELOBJECT_HOLEBR);
Real holebd = data->GetReal(TOOTHEDWHEELOBJECT_HOLEBD);
LONG tc = data->GetLong(TOOTHEDWHEELOBJECT_TOOTHCOUNT);
Real tr = data->GetReal(TOOTHEDWHEELOBJECT_TOOTHHEIGHT);
LONG segmentNumber = tc*3;
Real sectorAngle = pi2/tc;
Real segmentAngle = pi2/tc/3;
///////////////////////////////////////
LONG loopCount = 8;//eight reference circles: (bevel radius, hole bevel radius, hole bevel depth)*(upper and lower)
Vector *cpadr = (Vector* )GeAlloc(loopCount*sizeof(Vector));//allocate memory for ring array
if(!cpadr) return NULL;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cylindrical distance array for rings. [radial distance, height, 0.0]
if(tr > br){
cpadr[0] = Vector(r, h*.5, 0.0);
cpadr[7] = Vector(r, -h*.5, 0.0);
}
else{
cpadr[0] = Vector(r, tr*bd/br+(h*0.5-bd), 0.0);
cpadr[7] = Vector(r, -tr*bd/br-(h*0.5-bd), 0.0);
}
if(tr > br){
cpadr[1] = Vector(r, h*.5, 0.0);
cpadr[6] = Vector(r, -h*.5, 0.0);
}
else{
cpadr[1] = Vector(r+tr-br, h*.5, 0.0);
cpadr[6] = Vector(r+tr-br, -h*.5, 0.0);
}
cpadr[2] = Vector(holer+holebr, h*.5, 0.0);
cpadr[5] = Vector(holer+holebr, -h*.5, 0.0);
cpadr[3] = Vector(holer, h*.5-holebd, 0.0);
cpadr[4] = Vector(holer, -h*.5+holebd, 0.0);
if(hh->GetVFlags()&VFLAG_POLYGONAL){
ret = GenerateLathe(cpadr, loopCount, segmentAngle, tc, hh->GetThread());//third item is point count, toothcount*3
if (!ret) goto Error;
ret->KillTag(Tphong);
if(!op->CopyTagsTo(ret, TRUE, FALSE, FALSE, NULL) ) goto Error;
}
else{
ret = PolygonObject::Alloc(0,0);
if (!ret) goto Error;
}
ret->SetName(op->GetName());
GeFree(cpadr);
return ret;
Error:
GeFree(cpadr);
blDelete(ret);
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
//register plugin
Bool PluginStart(void){// the main function C4D calls to begin your plugin (think of it as main)
const Filename pluginPath = GeGetPluginPath();
if (!resource.Init(pluginPath)) return FALSE;
return RegisterObjectPlugin(ID_TOOTHEDWHEEL,"Toothed Wheel",
OBJECT_GENERATOR,
ToothedWheel::Alloc,"Otoothedwheel",
"toothed-wheel-icon.png", 0);
// registers a object plugin with C4D
}
///////////////////////////////////////////////////////////////////////////////
void PluginEnd(void){// called when the plugin is unloaded from C4D
}
///////////////////////////////////////////////////////////////////////////////
Bool PluginMessage(LONG id, void *data){ // allows you to receive plugin messages from C4D or other plugins
return TRUE;
}
Still trying to figure out what I missed. I'll just work on optimizing my code for now.
Thanks for the help,
-gene