Hi, i am currently facing some difficulties setting a parent child-relationship. I want to ask several things. First let me explain what i want to do, it’s simple:
What i want to do?
I have a scene and in it i load multiple models using loadsubtreefromscsfile method. Now i want to set a parent-child relationship, so that the child inherits location, rotation, scale values from the parent.
What have i done?
For it to work i am currently deleting the child node, and load it freshly out of the scs file with a matrix applied using loadsubtreefromscsfile.
My questions
why do i have to load the scs file freshly again and before delete the old model. This seems i have missed something. Is there a setParent(parentNodeId, childNodeId) function somewhere? Currently i only know of this way to set the parent-child relationship
after using this approach, i can not seem to retrieve the proper matrix values of the child using getNodeNetMatrix or getNodeMatrix. They all remain on Identity values? What is the difference between those matrices and how to retrieve the local transform matrix of the child, which should be given with parent space coordinates?
There is an assembly building example available in the quickstart module of the Visualize Web package that could prove useful. Please do the following:
Launch the server by double-clicking start_server.bat found in the directory HOOPS_Visualize_Web_2025.X.x\quick_start
looking at the example i see that it uses loadsubtreefrommodel. I tried that function before, but it throws this error:
“Incompatible load types.“
I searched, and i think it is because i do not use and do not plan to use streaming mode.
Two questions:
regarding this function, what is the model name, i have following model tree, and i passed in “EWS_MODEL_225978”, “EWS_225978_DIN4003” and also the complete filename including .scs suffix.
You can certainly keep the existing model tree. You will have to create a child node (if one does not already exists) under the existing parent node via the function createNode. You can use this child node in which you can load your other model.
I’ve attached a video with audio narration (which is a simplified version of the example from my first post): Forum_loadsubtree.zip (6.8 MB)
Below is the code I used in the video:
//Clear the model
await hwv.model.clear();
//Create a parent and child node
let parent0 = hwv.model.createNode(hwv.model.getAbsoluteRootNode(), "parent0");
let child0 = hwv.model.createNode(parent0, "child0");
//Apply a transformation matrix to the parent node only
let matrix = new Communicator.Matrix();
matrix.setTranslationComponent(0, 0.05, 0);
await hwv.model.setNodeMatrix(parent0, matrix);
//Load an SCS to the root node
await hwv.model.loadSubtreeFromScsFile(hwv.model.getAbsoluteRootNode(), "bnc.scs");
//Load an SCS to the child node which inherits the parent nodes transformation matrix
await hwv.model.loadSubtreeFromScsFile(child0, "bnc.scs");
In the video near the end is the crucial point. I do not want to load a new model, instead, i want to attach an already existing / loaded model from the scene. So both models are already loaded, and now i want to set one node as a child of the other.
a) i want to avoid loading an entirely new model by calling loadsubtreefromscsfile, because in our real world application, it would mean i would need to make a 200 ms network call to get the .scs model / file buffer
b) if this is the only way, i still struggle to get the matrices of the child node (they all remain on identity values). I call getNodeMatrix or getNodeNetMatrix for this.
Thanks for providing additional clarification. To confirm, once a model is loaded in the Web Viewer, it is not possible to move/re-parent it to another node. Re-loading the model to the desired parent node is the only way.
If a transformation matrix is applied to the child node in question, I would expect both getNodeMatrix and getNodeNetMatrix to return a non-identity matrix. If a transformation matrix is applied to only any parent of the child node, then getNodeNetMatrix should also return a non-identity matrix.
We’d like to take a closer look at the model in question. In that regard, it would be best to create a ticket in our support portal as it is easier to upload documents.
Thanks. I might open the ticket to investigate further if i get stuck on the Identity Matrix problem.
To summarize: there is no other way to set a parent-child relationship of two already existing models in the scene without first deleting the nodeid representing the child model and then reloading the same model via loadsubtreefromscsfile func and parentId as parameter.