# How to get transformation values?

**URL:** <https://forum.techsoft3d.com/t/how-to-get-transformation-values/702>\
**Category:** Help\
**Created:** [March 20, 2022, 8:59am UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702 "2022-03-20T08:59:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashwant.raut](https://avatars.discourse-cdn.com/v4/letter/y/c89c15/32.png) [@yashwant.raut](https://forum.techsoft3d.com/u/yashwant.raut)\
**Post date:** [March 20, 2022, 8:59am UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/1 "2022-03-20T08:59:46Z")

</div>

I’ following [Product Configurator](https://docs.techsoft3d.com/communicator/latest/build/tutorials/product-configurator/01.html) 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.

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/guido/32/115_2.png) [@guido](https://forum.techsoft3d.com/u/guido)\
**Post date:** [March 21, 2022, 12:26pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/2 "2022-03-21T12:26:51Z")

</div>

Hi!

there are basically two approaches to retrive all the matrices from a model.

1. 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:

```auto
  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;
    }

```

1. 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](https://docs.techsoft3d.com/communicator/latest/build/prog_guide/viewing/data_model/stream_cache/shattered-workflows.html).

Let me know if you have further questions.

Thanks,  
Guido

---

<div class="post-metadata">

**Author:** ![yashwant.raut](https://avatars.discourse-cdn.com/v4/letter/y/c89c15/32.png) [@yashwant.raut](https://forum.techsoft3d.com/u/yashwant.raut)\
**Post date:** [March 22, 2022, 7:24am UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/3 "2022-03-22T07:24:14Z")

</div>

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](https://docs.techsoft3d.com/communicator/latest/build/tutorials/basic-app/model-loading.html)

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.

`

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/guido/32/115_2.png) [@guido](https://forum.techsoft3d.com/u/guido)\
**Post date:** [March 22, 2022, 11:52am UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/4 "2022-03-22T11:52:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yashwant.raut](https://avatars.discourse-cdn.com/v4/letter/y/c89c15/32.png) [@yashwant.raut](https://forum.techsoft3d.com/u/yashwant.raut)\
**Post date:** [March 22, 2022, 12:34pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/5 "2022-03-22T12:34:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![domylinh987654321](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@domylinh987654321](https://forum.techsoft3d.com/u/domylinh987654321)\
**Post date:** [June 25, 2023, 2:18pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/6 "2023-06-25T14:18:23Z")

</div>

Hi !!! Guido !!  
i have a trouble  
"Please take a look at the image below :

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/7/708b623f607f105b240665cbfea5860c32227bfb.png)  
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).

---

<div class="post-metadata">

**Author:** ![domylinh987654321](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@domylinh987654321](https://forum.techsoft3d.com/u/domylinh987654321)\
**Post date:** [June 25, 2023, 2:19pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/7 "2023-06-25T14:19:09Z")

</div>

The problem posed no difficulties until I encountered this situation:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/b/bcee955220b58b88445f8a4dc8965fbd9d0d6773.png)

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!

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/guido/32/115_2.png) [@guido](https://forum.techsoft3d.com/u/guido)\
**Post date:** [June 26, 2023, 12:29pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/8 "2023-06-26T12:29:28Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![domylinh987654321](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@domylinh987654321](https://forum.techsoft3d.com/u/domylinh987654321)\
**Post date:** [June 26, 2023, 2:01pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/9 "2023-06-26T14:01:41Z")

</div>

I mean

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/5/5f1afb5c630e90eea245c4bc2a8b52fc439bddee.png)

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

---

<div class="post-metadata">

**Author:** ![domylinh987654321](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@domylinh987654321](https://forum.techsoft3d.com/u/domylinh987654321)\
**Post date:** [June 26, 2023, 2:11pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/10 "2023-06-26T14:11:33Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/5/57fb055a3e414f58b125f98cff369d6ee8e91b4e.png)

---

<div class="post-metadata">

**Author:** ![domylinh987654321](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@domylinh987654321](https://forum.techsoft3d.com/u/domylinh987654321)\
**Post date:** [June 26, 2023, 2:12pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/11 "2023-06-26T14:12:45Z")

</div>

Please test my code and you will understand what I mean

[HOOPS Communicator 3D Sandbox (techsoft3d.com)](https://3dsandbox.techsoft3d.com/?snippet=6qTS3ClQGF9Kxyw5GejS7l)

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/guido/32/115_2.png) [@guido](https://forum.techsoft3d.com/u/guido)\
**Post date:** [June 28, 2023, 10:17pm UTC](https://forum.techsoft3d.com/t/how-to-get-transformation-values/702/12 "2023-06-28T22:17:27Z")

</div>

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?
