Basic Objects
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/05/2008 at 11:08, xxxxxxxx wrote:
You can't just cast the primitive into a PolygonObject. It is a BaseObject and you'll need to make it editable before it can be used as a PolygonObject. In order to do make it editable, you will need to take the sphere primitive and use it with SendModelingCommand(MCOMMAND_MAKEEDITABLE). See this method in the docs for how to set up (similar to the first example there).
I wouldn't call blDelete(sphere) if it is NULL and instead you should call BaseObject::Free(sphere) when you delete a BaseObject so that all of the instance's resources are released.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 01:53, xxxxxxxx wrote:
@Robert: Actually you can cast the result of GeneratePrimitive() to a PolygonObject.
Here a very simple but complete example of a polygonal sphere generator plugin.
>
\> #include "c4d.h" \> #include "c4d_symbols.h" \> #include "oatom.h" \> \> class AtomObject : public ObjectData \> { \> public: \> virtual Bool Init(GeListNode \*node); \> virtual BaseObject\* GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh); \> \> static NodeData \*Alloc(void) { return gNew AtomObject; } \> }; \> \> // initialize settings \> Bool AtomObject::Init(GeListNode \*node) \> { \> BaseObject \*op = (BaseObject\* )node; \> BaseContainer \*data = op->GetDataInstance(); \> \> return TRUE; \> } \> \> // main routine: build virtual atom objects \> BaseObject \*AtomObject::GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh) \> { \> BaseContainer bc; \> PolygonObject \*sphere = NULL; \> sphere = (PolygonObject\* )GeneratePrimitive(NULL,Osphere,bc,1.0,FALSE,hh->GetThread()); \> \> if(!sphere) goto Error; \> \> return sphere; \> \> Error: \> blDelete(sphere); \> return NULL; \> } \> \> // be sure to use a unique ID obtained from www.plugincafe.com \> #define ID_ATOMOBJECT 1001153 \> \> Bool RegisterAtomObject(void) \> { \> // decide by name if the plugin shall be registered - just for user convenience \> String name=GeLoadString(IDS_ATOM); if (!name.Content()) return TRUE; \> return RegisterObjectPlugin(ID_ATOMOBJECT,name,OBJECT_GENERATOR,AtomObject::Alloc,"Oatom","atom.tif",0); \> } \>
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 05:19, xxxxxxxx wrote:
Thanks Matthias for this simple example. This works and creates an "objected" polygon sphere. Objected means, it is a convertable object. Now I have to make this one editable, to access its vertex points and egdes.
I've tried to make this object editable with MCOMMAND_CURRENTSTATETOOBJECT and MCOMMAND_MAKEEDITABLE but getting either the result NULL or a crash.
I read it is not recommended using SendModelingCommand within GetVirtualObject since Cache is beeing rebuild by SMC. But I recognized no difference in result using it there or calling another function within GetVirtualObjects (like Bool ConvertObject(PolygonObject *sphere) ).> <code>BaseObject *GenerateObject::GetVirtualObjects(PluginObject *op, HierarchyHelp *hh)
> {
> BaseContainer bc;
> bc.SetReal(PRIM_SPHERE_RAD,100.0);
> bc.SetLong(PRIM_SPHERE_SUB,4);
> PolygonObject *sphere = (PolygonObject* )GeneratePrimitive(NULL,Osphere,bc,1.0,FALSE,hh->GetThread());
> PolygonObject *poly=NULL;
>
> ModelingCommandData mcd;
> BaseDocument *doc;
> mcd.bc = &bc;
> mcd.doc = doc;
> mcd.op = sphere;
> if(!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT,mcd)) return NULL;
>
> poly=static_cast<PolygonObject*>(mcd.result->GetIndex(0));
>
> if(!poly) goto Error;
> return poly;
>
> Error:
> blDelete(sphere);
> blDelete(poly);
> GePrint("no Objects");
> return NULL;
> }
> [/CODE]</code>I assume the error is cause of *doc. But doc=GetActiveDocument(); leads to a crash too. Don't know how to obtain the current open document at another way...
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 05:25, xxxxxxxx wrote:
Well, if you want to have a polygon object you can't use a generator plugin since it always creates generators not polygon objects. In this case you have to use a tag. Maybe you can tell us what you actually want to achieve with your plugin. This would help to find a good solution.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 07:17, xxxxxxxx wrote:
In the first step, I want to create a polygonal okta (like a sphere-primitive with 4 segments). The second step is to make this object editable, so I can gain access to its polys and vertex points.
As mentioned above a CLOD-Algorithm for coarsing/refining a mesh view-dependent has to be applied on this mesh.
View-dependency is at the moment a secondary goal, primary I want to create a polygonal planet based on a given dataset. Therfor I need the vertex points and their connecting edges (building its triangles).For interested people: have look at Cloddy
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 07:36, xxxxxxxx wrote:
If you are using a command plugin you have of course to insert the polygon object into your scene with InsertObject(). See also this thread how to create and insert objects.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 08:52, xxxxxxxx wrote:
@Matthias: Well, yeah, you can cast it as a PolygonObject* but it doesn't make it a PolygonObject instance. An Osphere doesn't have GetPolygon(), GetPoint(), etc. because it is not a PolygonObject.
@SnakeByte: If you go the tag route you might have an easier time here. You will be needing to affect a Polygon object to which the tag is attached by changing its vertices and polygons. Actually, the beauty of a tag plugin here is that you don't have to reinvent the wheel with a plugin object that works like a Polygon object - and you could generalize the CLOD to work with any Polygon object (not just spheres) either now or later.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 09:43, xxxxxxxx wrote:
Hey Robert
In fact, that would be great. I've thought about it some time ago. But at the moment I need to simplify it on a specific type of object (writing my Diplomathesis) and want to keep it with less user interaction. Thiswhy I am trying to create either a primitive and transfer it into polygonal state or setting up a polyobject by obtaining its vertex vectors from a primitive (seen above). And to be honest - I am a worse coder (as you might have seen ;P).
If this thesis is complete and working so far (and satisfiying my prof), I won't hesitate continuing the development in generalizing this method for all input objects using a tag.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 15:06, xxxxxxxx wrote:
Hmm, it seems I figured out, what is causing the crash after the MCOMMAND_CURRENTSTATETOOBJECT. The static_cast<_ANYTYPE*_>(cd.result->GetIndex(0)); leads to apllication crash, when inserting a filled object into the scene (doc->InsertObject(poly,NULL,NULL)). If I use the "old" cd.result_ex it works fine, and the current state to object creates a polygonal object of my BaseObject *sphere=BaseObject::Alloc(Osphere). I don't know what is made behind the scenes and there must be a reason why it is noted with "don't use"... So what is crap with result->GetIndex(0) that this one crashes and the "don't use" runs fine?
Cheers
Sascha -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 17:16, xxxxxxxx wrote:
Where are you doing this - in GetVirtualObjects() or in a tag (Execute())?
Since this feature was added, I've not had trouble with this:
// +++ CurrentStateToObject
ModelingCommandData mcd;
mcd.doc = doc;
BaseContainer mbc;
mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);
mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION, FALSE);
mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_NOGENERATE, FALSE);
mcd.bc = &mbc;
mcd.mode = MODIFY_ALL;
mcd.flags = 0L;
mcd.op = orig;
if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd)) return NULL;
BaseObject* proxy = static_cast<BaseObject*>(mcd.result->GetIndex(0L));
if (!proxy) return NULL;
// If the converted object is under a Null object:
// insert result
// remove converted object
// insert converted object under Figure
// remove and free result (Null)
BaseObject* op = proxy->GetDown();
if (proxy->IsInstanceOf(Onull) && op)
{
doc->InsertObject(proxy, NULL, NULL, FALSE);
op->Remove();
doc->InsertObject(op, orig, orig->GetDownLast(), FALSE);
proxy->Remove();
BaseObject::Free(proxy);
proxy = op;
}
// else, insert result under Figure
else doc->InsertObject(proxy, orig, orig->GetDownLast(), FALSE);
doc->AddUndo(UNDO_NEW, proxy);Note that the converted object in the AtomArray result may be under a Null object.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/05/2008 at 17:21, xxxxxxxx wrote:
I should note that if you are converting an Osphere object into a PolygonObject, you might want to use MCOMMAND_MAKEEDITABLE instead. This doesn't require any of the mbc settings.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 03:35, xxxxxxxx wrote:
Hi Rob,
at the moment I am running it in ::Execute, I havent tried this in ::GetVirtualObject yet.
Debugging "result_ex" output in VC and C4D Console did not result in a memoryleak or sth else.I've used your codesample within ::Execute, which results in that nice exception
> <code>Object.cdl!CLODDY4D::Execute(BaseDocument * doc=0x05486a0c) Line 28 + 0x1f bytes C++</code>while executing
> <code>BaseObject* proxy = static_cast<BaseObject*>(mcd.result->GetIndex(0));</code>
You set mcd.flag = OL - what is this flag OL? And why you are using the "flag" in mcd.reslut->GetIndex(OL)? I replaced the flag with : MODELINGCOMMANDFLAG_CREATEUNDO;
and the Indexvalue with zero - getting the result above. this regular result says "Children cannot be evaluated".Cheers
Sascha -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 13:50, xxxxxxxx wrote:
0L is 'zero - long value'. This just guarantees that the (LONG) flags variable is cleared.
Don't know about your crashing situation - would need to see the code or it may be that you can't do this in Execute() (?).
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 16:13, xxxxxxxx wrote:
Using your code above does not work for me either in Execute() nor GetVirtualObjects() nor any self defined method.
I just have no idea where it comes from, perhaps because I create an object by code... but that make no sense...An further question, is it possible mcd.result_ex does not return a "real" polyobject ? I get crashes getting the Array start from the resulting poly...
I even don't get it using some terms from "roundedTube.cpp"
like
>\> BaseObject \*obj = BaseObject::Alloc(Osphere); // or any (\*obj) assigned by method call... \> PointObject \*pointObject = ToPoint(obj); \> const Vector \*pt = pointObject->GetPointR(); \>
Roundet tube is setting
>
Vector \*vector = obj->GetPointW();
But that should make no difference (for me)...
Of this usage is incorrect -> how is it used correctly with a
>PolygonObject \*obj = static_cast<PolygonObject\*>(mcd.result->GetIndex(0L))
or
>
PolygonObject \*obj = static_cast<PolygonObject\*>(mcd.result_ex)
Cheers
Sascha -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 16:51, xxxxxxxx wrote:
'roundedTube.cpp' doesn't have that at all.
It has:
PolygonObject* op = NULL;
...
op = PolygonObject::Alloc(pcnt,vcnt);You have to consider class derivation here:
BaseObject
--PointObject
----PolygonObjectAn Osphere is a BaseObject (and a procedural primitive) where as a PolygonObject is a BaseObject class extended with points and polygons support. These are not the same which is why you need to make the procedural primitive (Osphere) editable - which turns it into an Opolygon. Again, doing ToPoint(obj) or ToPoly(obj) just casts the pointer to another type - it doesn't actually change the BaseObject into a PolygonObject.
I have no idea why mcd.result->GetIndex(0) crashes on you. You should verify the actual crash location by commenting out code until the crash disappears and uncommenting until it reappears. It may not be what you think it is.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 17:00, xxxxxxxx wrote:
Jepp thats right. It justs casts the type of pointer. Somehow it runs in this example...
We are two, I also have no idea. I did that commenting out the code... either it crashes on casting the result from sendModelingCommand or when inserting into doc.
Cheers
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 17:05, xxxxxxxx wrote:
You might want to check that mcd.result is not NULL (the AtomArray was allocated) as well as checking the retrieved object similarly.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/05/2008 at 17:08, xxxxxxxx wrote:
Thats a good idea to check...
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/05/2008 at 03:36, xxxxxxxx wrote:
I recently tried the following code, with three methods of object generation. Everyone crashes at the static_cast, no matter to what type the result is casted...
>
BaseObject \*CLODDY4D::GetVirtualObjects(BaseObject \*op, HierarchyHelp \*hh){ \> \> BaseContainer bc; \> ModelingCommandData mcd; \> bc.SetReal(PRIM_SPHERE_RAD,100.0); \> bc.SetLong(PRIM_SPHERE_SUB,4); \> \> //BaseObject \*sphere = GeneratePrimitive(NULL,Osphere,bc,1.0,FALSE,hh->GetThread()); \> //BaseObject \*sphere = BaseObject::Alloc(Osphere); \> AutoAlloc<BaseObject>sphere(Osphere); \> if(!sphere) return NULL; \> \> mcd.doc = GetActiveDocument(); \> mcd.bc = &bc; \> mcd.flags = 0L; \> mcd.op = sphere; \> if(!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd)) return NULL; \> PolygonObject\* poly = static_cast<PolygonObject\*>(mcd.result->GetIndex(0L)); \> //if(mcd.result->GetIndex(0L)->GetType()!=Opolygon) return NULL; \> if(!poly) return NULL; \> return poly; \> }
Perhaps I am really running into a dead end, with my vision of the need of a polygonal object (I am much more a c4d user ) to access its points and polygons.
At the end, all I need is access to the point array of my octa to perfom cutting operations on the edges by mid-point and merging vertex points.Cheers
Sascha -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/05/2008 at 03:45, xxxxxxxx wrote:
Hello again,
I just can't get rid of this converting. I cannot get it run properly when using code like this:
>
\> static PolygonObject \*PolyObject(BaseObject \*sphere) \> { \> PolygonObject \*polyOb = NULL; \> ModelingCommandData mcd; \> mcd.doc = GetActiveDocument(); \> mcd.bc = sphere->GetDataInstance(); \> mcd.op = sphere; \> if(!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT,mcd)) return NULL; \> polyOb = static_cast<PolygonObject\*>(mcd.result->GetIndex(0)); \> if(polyOb->GetType()!=Opolygon) return NULL; \> \> return polyOb; \> } \> \> PolygonObject \*CLODDY4D::GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh) \> { \> BaseObject \*sphere = BaseObject::Alloc(Osphere); \> if(!sphere) return NULL; \> \> BaseContainer \*bc = sphere->GetDataInstance(); \> bc->SetReal(PRIM_SPHERE_RAD,100); \> bc->SetLong(PRIM_SPHERE_SUB,4); \> \> return PolyObject(sphere); \> } \>
The debugger stops at polyOb = static_cast<..>;
If modelingcommand fails, it should return NULL, so there should be some result, but this cast does not work as it should! (According to documentation). I am running out of clues and time...*sigh*
Sascha