Get PolygonCount of generator objects?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 13:52, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   10.1&11 
Platform:   Windows  ;   Mac OSX  ; 
Language(s) :     C++  ;

---------
Hi,

when I open the Object Information on any kind ob object (polygon object or generator) in CINEMA 4D, I see the polygon count.

I need to do the same in my plugin.

> ToPoly(obj)->GetPolygonCount();

This only works if "obj" is a converted polygon object. If it's a generator (e.g. a cube primitive), I always get zero.

How can I get the polygon count from any kind of object?

Cheers & thanks for help,
Jack

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 14:10, xxxxxxxx wrote:

Try GetCache(). It returns the cached polygonal (not sure if always, better check) object.

like:

if (object->GetCache() && object->GetCache()->GetType() == Opolygon)
((PolygonObject* )object->GetCache())->GetPolygonCount();

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 14:13, xxxxxxxx wrote:

or ToPoly(object->GetCache()) if you like, but its the same as ((PolygonObject* )object->GetCache())...

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 14:33, xxxxxxxx wrote:

Thankt, but I tried that, too.

But it seems, since the object is a child of my generator, GetCache() returns NULL.

Cheers,
Jack

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 15:01, xxxxxxxx wrote:

you would have to go through the hierarchy to get the childs , too.

have a look at the GetCache() description in the R11 docs, theres an example function on how to do that, iirc.

but... i find my function easier to understand (or at least easier to read :) ) :

> void CindigoHierarchy::RecourseHierarchy(BaseObject\* object, Bool childsOnly) \> { \>      while(object) \>      { \>           if (object->GetDeformCache()) //if theres deform cache, go down the cache \>           { \>                RecourseHierarchy(object->GetDeformCache(), FALSE); \>           } \>           else if (object->GetCache()) //if theres cache, go down the cache \>           { \>                RecourseHierarchy(object->GetCache(), FALSE); \>           } else { \>                //add to counter \>                if (!object->GetBit(BIT_CONTROLOBJECT) && object->GetType() == Opolygon) \>                     mPolyCounter += ToPoly(object)->GetPolygonCount(); \>           } \>            \>           if(object->GetDown()) RecourseHierarchy(object->GetDown(), FALSE); \>           if(!childsOnly) object = object->GetNext(); \>           else object = NULL; \>      } \> }

you would the do something like:

mPolyCounter = 0;
RecourseHierarchy(yourObject, TRUE);

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 15:32, xxxxxxxx wrote:

But wouldn't that just add the polycount of all polygon objects? Because, for generators it would still require to get the Cache from the generators, which doesn't work with my children.

I think it doesn't work, because I do this in GetVirtualObjects(). And when that function is called, the cache hierarchy is not yet built. Or am I wrong?

Cheers,
Jack

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 15:40, xxxxxxxx wrote:

it would add the poycount of all childs(i thought you wanted to do that, nvm, just me jumping to conclusions...), but you are maybe right that the cache of the childs is not built while you are in GetVirtualObjects()...

i dont know, tho.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 15/06/2009 at 17:21, xxxxxxxx wrote:

In GetVirtualObjects(), use something like this (based on Atom.cpp) :

>      // Get input object \>      BaseObject\*          orig =          op->GetDown(); \>      if (!orig)                         return NULL; \> \>      // Generate polygonalized clone of input object \>      // NOTE: 'res' is the polygonized original returned with greebler-generated objects \>      hh->AddVFlags(VFLAG_POLYGONAL); \>      Bool               dirty =          FALSE; \>      BaseObject\*          res =          op->GetAndCheckHierarchyClone(hh, orig, HCLONE_ASPOLY, &dirty;, NULL, FALSE); \>      // - if !dirty object is already cached and doesn't need to be rebuilt \>      if (!dirty)                         return res; \>      if (!res)                         return NULL;

You can then check that it returned a polygon object - sometimes there is a Null object at top so you should recurse the hierarchy from 'res'.

Then check:

> LONG cnt; \> ... \> if (obj->IsInstanceOf(Opolygon)) \> { \>    cnt += ToPoly(obj)->GetPolygonCount(); \> }

The cache is built but either dirty or not. If not dirty, 'res' represents what GetVirtualObjects returned when generating. If dirty, it represents the objects affected by/under the generator.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 16/06/2009 at 01:18, xxxxxxxx wrote:

Just a note, it is NOT safe to use GetCache() in GetVirtualObjects() since you can't be sure all caches are build. There are only few places where you can use GetCache() savily. It is save for instance to use GetCache() on objects returned by an initialised VolumenData.

cheers,
Matthias