I’ following Product Configurator tutorial in which JSON file is provided which contain transformation for individual parts of bicycle model. I’m building similar application in which I’ve scs model file so How can I get transformation for each part of scs model in JSON file.
For example microengine.scs is my model so how can i get transfomation info for each part in JSON file so I can build microengine from scratch by adding one part at a time.
Hi!
there are basically two approaches to retrive all the matrices from a model.
- After loading the model in the viewer recursively go through all nodes in the model and retrieve the matrices. Below is some code that accomplishes that and returns the result as a stringified JSON object:
function getAllMatrices(node,matrixarray,viewer)
{
let children = viewer.model.getNodeChildren(node);
let matrix = hwv.model.getNodeMatrix(node).toJson();
matrixarray.push({node:node, matrix:matrix});
for (let i=0;i<children.length;i++)
{
getAllMatrices(children[i],matrixarray,viewer);
}
}
function getMatricesAsJSON(viewer)
{
let matrixarray = [];
getAllMatrices(viewer.model.getRootNode(),matrixarray,viewer);
let json = JSON.stringify(matrixarray);
return json;
}
- Generate an assembly tree xml for the model you are interested in during import via converter with the command line option –output_xml_assemblytree. You can then parse that file to retrieve the relevant matrices for every node. You can find more information on the content of that assembly tree file here.
Let me know if you have further questions.
Thanks,
Guido
thanks for your reply
First approached that you’ve mentioned will try to implement.
Second approach I already tried and generated xml file by following Generating XML Model Structure File
What I’ve done is created shattered assembly which contain multiple SCS file and then i tried to load one part at time using this call
model.loadSubtreeFromScsXmlFile(rootNode,"microengine.xml",(name)=>{return microengine_shattered/${name};})
but what it does instead of loading one part at a time it loads whole model I did not understand what third parameter does exactly.
`
Hi,
the third parameter in this function is a callback that allows you to modify the name/path of the scs files referenced in the XML so that they point to one of your local subdirectories or have a specific extension for example.
However, if all you want is load a single scs file you would use loadSubtreeFromScsFile and not this function. In case of querying the matrices the XML file would just be used server-side to query this information.
So just to be clear, the purpose of loadSubtreeFromScsXML file is to load a whole assembly that consists of “shattered” parts, meaning each part in the assembly has its own scs file. In your case what you want is to load a single part but with the appropriate matrix. Of course a part might be referenced multiple times in an assembly so there is no single matrix, you would really have to look at the nodeid for the part instance when parsing the XML.
I hope this helps.
okay this very well written and clearly address my question and clear my doubt.
And yes part might be referenced multiple times in an assembly it never occurred to me thanks for this. I will try this nodeId approach and will use loadSubtreeFromScsFile function.
Hi !!! Guido !!
i have a trouble
"Please take a look at the image below :
I have an object on the coordinate axis Oxyz. My problem is to determine x, y, z on that object based on the orientation of a fixed axis (Ox, Oy, Oz). I draw a bounding object around it ( (Ox, Oy, Oz) , then I project it perpendicular to any plane (Oxy, Oxz, Oyz). From there, I can determine Xmax - Xmin = X (Ymax - Ymin, Zmax - Zmin).
The problem posed no difficulties until I encountered this situation:
As you can see, there is a blue line. I need to determine x, y, z in relation to the direction of that blue line.
The issue is that the line is not parallel to any axis (ox, oy, oz).
Do you have any solution? Please help me.
Thanks!
I will be honest, its a bit hard for me to understand what you are trying to do. Can you explain this in a different way (maybe with code).
I mean
Please observe the image below.
The red arrow indicates a “STRAIGHT LINE” that I want to point out.
It is “PARALLEL” to the Oy axis.
Based on that, I draw a rectangular prism along the direction of the “STRAIGHT LINE” I want to indicate.
I want to calculate X = “LENGTH,” Y = “WIDTH,” and Z = “HEIGHT.”
If the “STRAIGHT LINE” I want to indicate is “PARALLEL” to the oz (ox or oy) axis,
then I can determine the coordinates Xmax and Xmin. Afterwards, Xmin - Xmax = X, and the same applies to Y and Z
However, in this case, the “STRAIGHT LINE” I want to indicate is not “PARALLEL” to any axis (Ox, oy, oz).
Therefore, I cannot draw a rectangular prism to enclose the object along the direction of the “STRAIGHT LINE” I want to indicate.
I cannot calculate X = “LENGTH,” Y = “WIDTH,” and Z = “HEIGHT” based on that rectangular prism.
Furthermore, I cannot determine the coordinates to calculate.
Please test my code and you will understand what I mean
I’m still not fully clear what you are trying to do here. If your object is not aligned with any of the major axis, you will have to find some appropriate face normal to base your alignment on. From there it should be straightforward to find an orthogonal vector so that you can calculate the correct prism geometry. Is that helpful in any way?