Recreate the OM tree in another app? [SOLVED]
-
On 26/09/2016 at 08:41, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform: Windows ;
Language(s) : C++ ;---------
Hi,I am writing an application in Qt that communicates with .c4d files using Melange.
One of the things that I'm wanting to do is recreate the OM tree that is in the .c4d file in my app. But I don't see any functions for doing this in the sdk.
Since I'm new with the Melange sdk. I might be missing them?I was wondering if there was anything in it that would help me reconstruct the OM tree?
I do know how to iterate the .c4d file and grab the objects. But I don't see anything in the sdk that allows me to determine where that object is within the OM tree.
Example: A root node, a parent node, a child node, etc...I did some looking around about making trees. And the info I'm finding is mostly about how to use existing trees controls. Or making them from scratch using link lists. But don't think this is what I need.
I just need a way to determine if a c4d object is a root, parent, or child node. And then get it's parent if it is a child node.
With that information I think I would be able to recreate the tree in Qt.Any ideas?
-ScottA
-
On 27/09/2016 at 08:15, xxxxxxxx wrote:
Hi ScottA, thanks for writing us.
With reference to your request, consider that Melange API is provided with a GeListNode class (where BaseList2D and BaseObject are derived from) exposing two relevant methods to traverse the scene tree.
The first is GetDown() which allows to access the first child of the current object.
The second is GetNext() which allows to access the next object in the same hierarchy level of the current object.
Last but not least to access the first object of the scene tree from a loaded document you're provided with the GetFirstObject() method in the BaseDocument class.
Considering that Melange API has been designed to mimic most of the functionalities provided through the CINEMA 4D API being you already used to deal with the latter you won't find big issue on your own way.
By properly using these methods you're able to reach each single nested object found in the scene tree and properly rebuild the same in your qt application.
For the sake of completeness the following schema/snippet might be helpful.// Doc // |-obj01 // | |-child01Obj01 // | |-child02Obj01 // |-obj02 ... BaseDocument* doc = LoadDocument(myscenefile, SCENEFILTER_0); if (doc) { BaseObject* obj01 = doc->GetFirstObject(); if (obj01) { BaseObject* child01Obj01 = obj01->GetDown(); BaseObject* obj02 = obj01->GetNext(); } } ...
Best, Riccardo.
-
On 27/09/2016 at 09:00, xxxxxxxx wrote:
I'm familiar with the traversal functions GetNext(), GetDown(), GetUp(), etc...
But I was hoping that there might be things in the sdk that would help to describe where each object(node) is within the tree.
Traversing the tree with those functions is only the first step. I need to somehow save where each object is in the tree:
-Is the current object a child of another object?
-If so. Is that parent itself a child of another object. Or a child of the root?
Things like that.I think they call this mapping a tree structure.
I don't see anything in the sdk's that helps with this. Only those traversing functions. But I wanted to ask to be sure I wasn't missing them.At this point all I know how to do is use recursion to get at all of the objects.
But since the tree can have infinite branches and sub branches. It's kind of boggling my mind how to map their locations within the tree. So that I use them in a Qt tree.-ScottA
-
On 27/09/2016 at 12:00, xxxxxxxx wrote:
Scott, if I understand you correctly, this information is all derivable from the functions that allow
you to access the ancestors of a node.if (op->GetUp() != nullptr) // object is a child (has a parent) if (op->GetDown() != nullptr) // object has a child (is a parent) Int32 depth = 0; while (op) { depth += 1; op = op->GetNext(); }
Regards,
Niklas -
On 27/09/2016 at 13:06, xxxxxxxx wrote:
Hi Niklas,
I've tried similar code. But I'm having trouble with the sub branches.A tree is really just a table of columns and rows. And every parent object belongs to a column.
What I really need is some way to be able to read the objects in the tree. And determine what column they belong to.
If an object has no children. It belongs to column 0.
If an object has children. The children will belong to column 1.
If any of those child object's has children. They will belong to column2.
etc...Once I know what column an object belongs to. I think I can then use that column ID to create a tree structure in my app. But I'm having a hell of time figuring out how to code this.
-ScottA
-
On 30/09/2016 at 09:57, xxxxxxxx wrote:
Hi ScottA,
please find here an example suitable for your needs.
Best, Riccardo
-
On 30/09/2016 at 11:20, xxxxxxxx wrote:
Thanks Riccardo.
I'm still struggling in Qt to map their QtTreeWidget to the C4D OM tree with it's sub branches correctly. And this might be helpful in making it work.
I won't ask support for anything more on this because it's not a C4D SDK issue.If anyone out there is a Qt user and has done this. Please feel free to chime in.
I've been trying to crack this nut for 4 days. And my head is starting to hurt. !Wacko
[URL-REMOVED]-ScottA
*Edit- Never mind. I think I finally figured it out!
I feel like I just gave birth.....................................................................To an accountant!
If I get the chance. I'll post an example on my website.
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.