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

Detect change of geometry

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


Joined: 2015 Dec 01
Online Status: Offline
Posts: 157
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Topic: Detect change of geometry
    Posted: 2017 Dec 01 at 5:21am

User Information:

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

---------

Continued on the problem of initializing a tag with information from the object it has been assigned to:
http://www.plugincafe.com/forum/forum_posts.asp?TID=13893

The above thread provided some information related to MSG_POLYGONS_CHANGED and while I was close to a solution, further testing resulting in even more questions.

What I noticed so far:
- moving a tag from one object to another -> MSG_POLYGONS_CHANGED is sent twice to the tag
- selecting edges and apply connect -> MSG_POLYGONS_CHANGED is sent twice to the tag
- apply a subdivide on the full object or selected polygons -> MSG_POLYGONS_CHANGED is sent 3 times
- using knife tool to cut some polygons -> MSG_POLYGONS_CHANGED is sent once

As mentioned in the above thread, the second message is the important one in case when using "connect", since it's only at that point that the internal structure is (almost) finalized and ready to be used for initialization. (At time of first message the internal structure is still being "modeled" so not good to be used).
So, my original solution was to initialize the tag on the second message, but then subdivide or knife tool came along and ruined that.

Seems I cannot find anything consistent to detect a change of geometry. Very frustrating indeed.


Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1599
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 04 at 8:32am
I will discuss this topic with a developer. But this will take some time, so stay tuned.

Until then, leaving any optimization purposes aside, would it hurt, if you initialized the tag on every MSG_POLYGONS_CHANGED?

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


Joined: 2015 Dec 01
Online Status: Offline
Posts: 157
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 04 at 8:37am
In short, yes.
As discussed in the other thread (mentioned in the original post) this MSG_POLYGONS_CHANGED can be sent before the actual structural changes of the object has been completed. In test cases I detected that ngons were present, while the action of changing the geometry would not introduce ngons. After the second message comes in, no ngons are present.

But doing an initialization on every message will cause some of these initializations to trigger "warnings" since ngons are detected.
Not sure how I will process these warnings, but in general it would be best to avoid this intermediate state in the first place.

Looking forward what this topic will provide as feedback from developers. Please, take your time.
And thanks in advance.
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1599
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 04 at 8:39am
Sorry, forgot about your ngon issues. I'll emphasize this in discussion with development.

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: 1599
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 06 at 7:08am
I discussed your request with a developer.
Not easy, as you already figured out. Internally we just need the polygon count from MSG_POLYGONS_CHANGED.

We came up with an idea for your situation:
In MSG_POLYGONS_CHANGED just store a flag, that you may need to re-initialize.
Then in Execute() valid point, polygon and ngon counts are available, do the initialization based on the above flag.
Use SpecialEventAdd() to postpone any needed warnings to a MessageData.

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


Joined: 2015 Dec 01
Online Status: Offline
Posts: 157
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 06 at 7:43am
It was definitely worth trying out.
Unfortunately, while being real close to a valid solution. There is still something missing.

When I drag-n-drop any tag to the object the MSG_POLYGONS_CHANGED is also sent to my tag, resulting in a false positive. When I simply assign a tag to the object then only MSG_MENUPREPARE is sent. But the problem is a user can simply drag a tag from one object to another, or even simply re-organizing the tags on the object ... resulting in the "geometry-might-have-changed" flag being set.

There needs to be additional filtering in order to avoid these false positives.
I could keep track of the order and types of the tag, in order to detect a change.

Simply keeping track of points, polygons and ngons is not sufficient because a modification in geometry might potentially result in the same values.
Unless it's technically not possible to merge and split polygons in a single step?

EDIT:
You mention internally you only need the polygon count from MSG_POLYGONS_CHANGED.
But depending the tool used to change the geometry this message is sent more than once, with different polygon counts. There needs to be some additional checks to know which message is the right one to process, not?



Edited by C4DS - 2017 Dec 06 at 7:50am
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1599
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 07 at 9:04am
You mention internally you only need the polygon count from MSG_POLYGONS_CHANGED.
But depending the tool used to change the geometry this message is sent more than once, with different polygon counts. There needs to be some additional checks to know which message is the right one to process, not?

No, not really. The number of polygons (or points with MSG_POINTS_CHANGED) delivered with the message is correct. So for us all messages are right ones.

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


Joined: 2015 Dec 01
Online Status: Offline
Posts: 157
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 08 at 3:17am
Hi Andreas,
I am not sure how to respond to this latest remark. Do you mean that the fact there are multiple messages sent (with different polygon counts) is only happening within plugins?

Anyway.
Thanks again for the suggestions you guys made about the detection.
While I was about to wrap up, having figured out how to deal with this geometry-change, I started playing with the plugin.
While trying to get the plugin to crash by doing some unusual stuff, in order to fix those things I overlooked, I ended up with no polygon count change, no point count change, but change of ngon.
Basically, a geometry change not being triggered (since same number of points and polygons).

Scenario to reproduce:
Take a simple cube with 6 faces, in polygon mode select 2 adjacent faces and perform a "melt".
The 2 faces will form an ngon, but still 8 points, 6 polygons -> no trigger.


Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Offline
Posts: 157
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Dec 08 at 4:52am
EDIT
Please ignore this post, as I am working out a solution.
I'm simply going to leaving the text as is for posperity.
/EDIT

Next problem!
I have saved a scene file with my tag assigned to a cube made editable.
When I load the scene file, the tag gets MSG_POLYGON_CHANGED and thus I perform a re-initialize, since geometry "has" changed.
I would prefer to filter this out, since re-initializing will result in a change of what was originally stored.
What mechanism can I use to only start checking on MSG_POLYGON_CHANGED after the document was fully loaded?

I can check on MSG_DOCUMENTINFO_TYPE_LOAD and only start detecting any geometry change after this message came along. But then I will also need to check for MSG_DOCUMENTINFO_MERGE ... maybe others as well?




Edited by C4DS - 2017 Dec 10 at 11:56pm
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.