Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

GVO PolygonObject inside NullObject untargetable

 Post Reply Post Reply
Author
Message
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Topic: GVO PolygonObject inside NullObject untargetable
    Posted: 2018 Apr 27 at 1:02pm

User Information:

Cinema 4D Version:   R19.053 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hi! I have a generator plugin that creates PolygonObjects and returns them collectively under a
single Null-Object.

It may choose to reuse some of the PolygonObjects from the previously generated  cache. it does
so using the cach e from op->GetCache(hh); , then finding the res pectivePolygonObject, calling
Remove() and inserting it under the new Null-Object that will be returned with InsertUnderLast().

When it creates the PolygonObject from scratch, it allocates it, uses ResizeObject(), then sets
the polygons and points in GetPointW() and GetPolygonW() and calls Message(MSG_UPDATE);.

The reason why I think that the MSG_UPDATE message has no effect is because the bounding
box of the PolygonObject does not seem to be updated properly. Also the PolygonObject returned
by the generator can not be target with the "navigation pivot" in the C4D viewport.

Is there anything else that I need to do to "complete" the PolygonObject after I built it?

Thanks,
Niklas


Edited by NiklasR - 2018 May 05 at 6:48am
Back to Top
MaximeA View Drop Down
Forum Moderator
Forum Moderator

Forum Moderator

Joined: 2018 Jan 04
Location: France - Nantes
Online Status: Offline
Posts: 48
Post Options Post Options   Quote MaximeA Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 30 at 2:08am
Hi Niklas,

Polygon objects within a cache are read-only.
You can't modify them, but you can clone it and then SetPoint/Polygon will work.

About your issue of the bounding box, make sure to override GetDimension.

Cheers,
Maxime


Edited by MaximeA - 2018 Apr 30 at 8:14am
MAXON
SDK Specialist
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1785
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 03 at 2:51am
Hi,

not sure, this is already solved.
Still, I'd like to add a link to the extended number of ObjectData examples for future readers.

Cheers,
Andreas
SDK Support Engineer
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 03 at 6:01am
Hi Maxime & Andreas, thanks for the reply.

>> Polygon objects within a cache are read-only.

I am not making modifications to the polygon objects inside existing caches -- I am creating new
Polygon Objects. However when I recognize that the Polygon Object that I would build from scratch
already exists in the cache due to the previous call to GetVirtualObjects(), I want to re-use that.

Similar to returning the whole cache, as it can be seen in some of the example ObjectData plugins:

if (nothing changed) {
  return op->GetCache(hh);
}


I may want to select only some of the Polygon Objects in the cache.

AutoAlloc<BaseObject> root(Onull);
BaseObject* cache = op->GetCache(hh);
for (auto&& obj : input_objects) {
  if (nothing_changed && cache) {
    BaseObject* cache_obj = FindObjectInCache(cache, GetUuid(obj));
    if (cache_obj) {  // Reuse the object
      cache_obj->Remove();
      cache_obj->InsertUnder(root);
      continue;
    }
    AutoAlloc<PolygonObject> poly(0, 0);
    // ... build polygon object
    poly->InsertUnder(root);
    poly.Release();
  }
}


This works without problems as far as I can see. Just to check whether this causes the issue that
you can not navigate on top of the object, I tried cloning the object from the cache (which would
not be desirable) and I get the same problem.

    if (cache_obj) {  // Reuse the object
      cache_obj = (BaseObject*) cache_obj->GetClone(COPYFLAGS_0, nullptr);
      if (cache_obj) {
        cache_obj->Remove();
        cache_obj->InsertUnder(root);
        continue;
      }
    }


>> About your issue of the bounding box, make sure to override GetDimension.

Overriding GetDimension() will not solve the problem that I am facing.


I try to be more descriptive: When you have an object in the Viewport, you can press ALT and LEFT
MOUSE BUTTON to pivot around the object at the location where your cursor intersects with the
geometry.

This does not work in my case. And I am wondering if you have any clues where this could be
coming from. My initial guess was that I needed to use MSG_UPDATE before I return the object,
but that didn't help.

Here is a small video that hopefully clarifies the issues: https://public.niklasrosenstein.com/_quickshare/2018-05-03-generator-polygonobject-navpivot.flv

The cube is a standard cube, the two cars are both Polygon Objects returned by my generator.

Any idea what could cause the Pivot to not recognize the geometry from my generator?

Thanks for looking into this.

Cheers,
Niklas
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1785
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 04 at 2:57am
Hi Niklas,

just as a test, can you please leave all optimizations aside. If you build the output of your generator from scratch, does it work properly then?

Cheers,
Andreas
SDK Support Engineer
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 05 at 3:02am
Hi Andreas,  I get the same problem without reusing the cache but building the PolygonObject
anew every time (although the geometry information does come from a different representation
fromanother SDK).

However from your suggestions, I tried to reproduce it my just building a simply triangle to be sure
that it's not an issue with the geometry that I get from the SDK. It seems like the culprit is actually
that the PolygonObject is inside a Null-Object. When I return the PolygonObject directly, it works
fine.

    AutoAlloc<BaseObject> root(Onull);
    AutoAlloc<PolygonObject> poly(3, 1);
    auto p = poly->GetPointW();
    p[0] = Vector(100, 0, 0);
    p[1] = Vector(100, 0, 100);
    p[2] = Vector(0, 0, 100);
    auto c = poly->GetPolygonW();
    c[0] = CPolygon(0, 1, 2);
    poly->InsertUnder(root);
    poly->Message(MSG_UPDATE);
    poly.Release();
    return root.Release();


Cheers,
Niklas



Edited by NiklasR - 2018 May 05 at 3:09am
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 05 at 6:48am
Renamed from MSG_UPDATE for PolygonObject has no effect in GVO to GVO PolygonObject inside NullObject untargetable.
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1785
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 08 at 8:16am
Hi Niklas,

I need to ask you for a bit of patience. I can reproduce the issue, but to be honest I don't get it. Take for example the Array object with a polygon object as input. The resulting cache structure is exactly the same and there it works as expected. Haven't been able to spot the difference, yet. Stay tuned.

Cheers,
Andreas
SDK Support Engineer
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1785
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 14 at 6:04am
Hi Niklas,

sorry, this took a bit longer. In the end it's a matter of proper use of the cache. The "pivot feature" relies on a somewhat constant cache.
By just adding these three lines to the top of your example, the pivot feature works just fine:
  Bool dirty = op->CheckCache(hh) || op->IsDirty(DIRTYFLAGS_DATA);
  if (!dirty)
    return op->GetCache(hh);

Cheers,
Andreas
SDK Support Engineer
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 15 at 9:26am
Thank you Andreas. Making sure that I keep returning the same Null-Object makes it work.
I pick certain objects from the cache and insert them under a new hierarchy. Now instead of
returning that new hierarchy, I simply replace the parent of the hierarchy with the previous
parent.

    // The navigation pivot in C4D seems to require a rather "constant cache"
    // from the object if a Null-Object is used as root. We'll just reuse the
    // previous cache null object if there is any.
    if (cache) {
      for (BaseObject* child = cache->GetDown(); child;) {
        BaseObject* next = child->GetNext();
        BaseObject::Free(child);
        child = next;
      }
      for (BaseObject* child = root->GetDown(); child;) {
        BaseObject* next = child->GetNext();
        child->Remove();
        child->InsertUnderLast(cache);
        child = next;
      }
      return cache;
    }

    return root.Release();


Cheers,
Niklas


Edited by NiklasR - 2018 May 15 at 9:27am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.