Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Programming and Scripting
How get parent node?
Author Text

2022-03-14 15:46:09

Hi there,

you know we can get child nodes from a parent node by using ccbGetChildSceneNode

Would there be otherwise any solution for getting the parent node of from child node?

Unfortunately "ccbGetParentSceneNode" doesn't exist in CopperCube's scripting reference. Checking an array of all scene nodes might consume lots of resources for the purpose I guess?

Thanks for any ideas.

2022-03-18 00:11:05

This checks the entire scene recursively, with a depth max of ten. When too slow, try run it once to write each child with its parent to a simple array (or two arrays, with corresponding indicies), Wouldn't worry about a few hundred bytes in resources.

var s = ccbGetSceneNodeFromName("cubeMesh2");
var p=ccbGetRootSceneNode();
var count_recursive=0; // must be global

var parr=ccbGetSceneNodeParent(p,s);

alert(ccbGetSceneNodeProperty(parr, "Name") ); // this works only in WebGL

function ccbGetSceneNodeParent(p,s)
var rett=0;
var c=ccbGetSceneNodeChildCount(p);
for (i=0; i<c; i++)
var kid=ccbGetChildSceneNode(p,i);
if(kid==s) {return p;}
if (ccbGetSceneNodeChildCount(kid)>0)
if (count_recursive < 10)
return rett;

Registered User
2022-03-18 10:08:03

Once you know what kind of software you need, you can determine how much the process will cost. The cost of custom software development depends on the size of the software and the developer's availability. Generally, small software solutions are ten to fifteen pages, while larger ones are more than forty pages. As the size of your software increases, so does its complexity. A larger program will require more human resources and more time to develop. But if you have a specific vision and a specific aim for the application, you will get a better return on your investment

2022-03-18 11:16:15

You're welcome. Notice when using recursive function calls (when a function calls itself) there is always some risk of a stack overflow (and crash), for example when there is an internal loop between a parent-child relation. Therefor the count_recursive variable makes sure there's a limit to the recursion depth. That variable must be declared outside the function, so it keeps it's value when the function ends = is kind of global (contrary to local).

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "In?ernational" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



Copyright© 2020 Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact