Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
I see we have a "ccbGetChildSceneNode()". I do not see something like ""ccbGetParentSceneNode()". or something like cbGetSceneNodeProperty(s, "Parent"); any idea how we can get this ? |
||||
|
Hi ssatguru, I don't think there is a direct way of doing that. You probably, should compose the structure of you project the other way somehow. If there is no other way, I would write a recursive search function like https://stackoverflow.com/a/9133680. The algorithm would be: 1. Pass node to the function (root node on 1st iteration); 2. Check if the root node has your child node - if yes return the node, if no: 3. Call the function for every child node. I'm also not sure how to match the nodes, since they can have the same names. I can, probably, come up with the exact implementation tonight, if you don't have another answer before that. |
||||
|
function getNodeParent(nodeToFind) { Sorry, not that elegant solution, but it kinda works for me. The biggest issue is that it compares nodes by names, so all your nodes should have the unique ones for the function to work. It would be really nice to get nodes IDs somehow, but I don't think it's possible. |
||||
|
@okeoke Thanks for looking into this and providing a nice solution. You are right about non uniqueness of name.. A unique id would have helped. Would use your solution for now Simplest solution would be to update cbGetSceneNodeProperty() to provide parent option example.
@niko, @just_in_case any thoughts ? |
||||
|
maybe, can extend the API to get the parent node as well. Will look into this. |
||||
|
Nice. Also how do we check if two nodes provided by the API are the same? We can compare their names but names may not be unique. |
||||
|
@ssatguru, just added the API command to my extended JS API for getting the parent node. You can also compare using the ID of a node if you don't wanna compare using Name. hope that helps :) |
||||
|
@just_in_case Looking forward to your extended JS API. About ID. How do I get the ID of a node? |
||||
|
I am not sure but I think you can use the command ccbGetSceneNodeProperty(scenenode,"ID")that way you might get the ID of the CC object. |
||||
|
"ID" (or anything similar like "Id" or "id", etc.) seems not implemented as javascript accessible node property yet - no solution this way ... ![]() |
||||
|
Like @hadoken, I didn't find that either. Maybe another addition to your extended API ? ![]() |
||||
|
You guys right, there is already code for this in the C++ source, there is probably something buggy in there or something is missing. Will look into this. |
||||
|
I also see this in the CopperLicht javascript source code and documentation see https://www.ambiera.com/copperli... What makes me wonder though is the description. Both the Id and Name description says completely freely usable by the user. does that mean then that "Id" like "Name" maynot be unique? If that is the case then maybe we need a function like ccbSceneNodesEqual(node1,node2) which returns true or false if equal or not equal. |
||||
|
Would it be easier to just define a unique name for every node? You can just have a global index variable and add up it everytime you clone/create a new entity. Then you add it's value to a node name. Or you can generate a random string and set it as a node name as well. The simplest way to do this in js I know is something like: Math.random().toString(36).slice(2, 10); |
||||
|
@okeoke Yes it would be easier, as long as I own that project. I can then follow some naming convention which would ensure that the names are unique. But what if I am developing an extension or a plugin meant to be used by others in their projects. I cannot force them to follow some such naming convention. |
[ 1 2 ] Page 1 of 2 |
|