# Scale model in gltf

**URL:** https://discourse.slicer.org/t/scale-model-in-gltf/31639
**Category:** Support
**Tags:** segmentation, surface-toolbox, openanatomy
**Created:** [September 11, 2023, 9:24am UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639 "2023-09-11T09:24:54Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 11, 2023, 9:24am UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/1 "2023-09-11T09:24:54Z")

</div>

Good morning,  
I performed segmentation and I would like to scale the results of segmentation in gltf format.  
Actually I can scale the model in stl using Surface Toolbox or save the unscaled model in gltf.  
I need to scale the model and export it in gltf.  
Can I hace suggestion about this topic?  
Thanks

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [September 11, 2023, 2:58pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/2 "2023-09-11T14:58:27Z")

</div>

Then why can’t you export the scaled model from Surface toolbox as GLTF?

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 12, 2023, 8:21am UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/3 "2023-09-12T08:21:15Z")

</div>

Surface Toolbox allows to scale segmentation objects (stl or obj).  
OpenAnatomy allows to export gltf model but it doesn’t see segmentation objects previously scaled with Surface Toolbox.

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [September 12, 2023, 4:20pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/4 "2023-09-12T16:20:24Z")

</div>

That doesn’t sound right.

You should be able to export models from OpenAnatomy, not just segmentation. They need to be under a subject hierarachy, thought i believe. So try making a folder within your data module, move your scaled model under that folder and then try the OA one more time.

This worked for me with 5.4.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/8/6814f63f6835ab10a7acdf485fce4aee2613517e.png)

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 20, 2023, 12:47pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/5 "2023-09-20T12:47:34Z")

</div>

Thanks for suggestions.  
Since my segmentation is made up of many segmentations (result from TotalSegmentation), when I export the models, many models are also created. Is there a way to merge them together before scaling them and then export them to gltf?Thanks

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 20, 2023, 1:51pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/6 "2023-09-20T13:51:37Z")

</div>

I’ve checked the glTF standard and actually the length unit is specified to be in meters. So, I’ve [updated the OpenAnatomy export module to always export in meters](https://github.com/PerkLab/SlicerOpenAnatomy/commit/ce61de8995aebdbf0ff0e7293f6d41aef1019568). You can get the updated extensions from the Extensions Manager tomorrow or later.

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 21, 2023, 8:03am UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/7 "2023-09-21T08:03:31Z")

</div>

Thank you very much for support and for information. Hasn’t the unit of measurement for the OpenAnatomy export module been meters so far? Concerning the way to merge the segmentations together and then export them to gltf, can you please suggest me a solution?  
Thanks

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 21, 2023, 3:13pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/8 "2023-09-21T15:13:30Z")

</div>

> [@Caterina](#):
>
> Hasn’t the unit of measurement for the OpenAnatomy export module been meters so far?

Length unit in Slicer (and in DICOM and in all medical image computing software) is millimeters. OpenAnatomy export module has exported all models in millimeters, too.

In the latest module, I’ve included a millimeter to meter scaling transformation in the root of the glTF file, so we comply to glTF specifications.

You can verify distances in a glTF file using an independent viewer, such as [3dviewer.net](http://3dviewer.net) - just drag-and-drop the exported glTF file to the viewer and use the measurement tool.

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 27, 2023, 3:09pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/9 "2023-09-27T15:09:32Z")

</div>

Dear Prof Lasso,  
thanks a lot for the updates and for modifying the OpenAnatomy Export module.  
However, I can’t see a millimeter to meter scaling transformation in the root of the glTF file.  
Can you please share with me a screenshot of the modified module?  
Thanks

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 27, 2023, 3:17pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/10 "2023-09-27T15:17:51Z")

</div>

I’ve already provided the link to the change above, but here it is again:

> <https://github.com/PerkLab/SlicerOpenAnatomy/commit/ce61de8995aebdbf0ff0e7293f6d41aef1019568>
>
> According to glTF specifications (3.4. Coordinate System and Units, https://regi…stry.khronos.org/glTF/specs/2.0/glTF-2.0.html#coordinate-system-and-units):
> 
> glTF uses a right-handed coordinate system. glTF defines +Y as up, +Z as forward, and -X as right; the front of a glTF asset faces +Z.
> The units for all linear distances are meters.
> All angles are in radians.
> Positive rotation is counterclockwise.
> 
> Therefore, we now scale the whole model to meters (apply a factor of 0.001 if scene length unit is mm) when exporting to glTF.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 27, 2023, 3:18pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/11 "2023-09-27T15:18:55Z")

</div>

Note that you need to use the latest Slicer Stable Release or latest Slicer Preview Release to get extension updates.

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 27, 2023, 3:27pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/12 "2023-09-27T15:27:28Z")

</div>

Thanks a lot.  
I’m using 5.4.0 version. I also checked the updates of openAnatomy module from extentions manager.

 ![Screenshot 2023-09-27 alle 17.26.45](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/3/a3df9ac2d6934a45de9d1287aa219d81b681c33b.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 27, 2023, 5:56pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/13 "2023-09-27T17:56:11Z")

</div>

It should be all good then. To confirm, you can click the “Edit” button to load the .py file and see if the changes in the commit that I linked above are there.

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 27, 2023, 6:26pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/14 "2023-09-27T18:26:08Z")

</div>

Thanks again. Here the screen of the .py file in which the changes you made  
are present.

 ![Screenshot 2023-09-27 alle 20.23.16](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/d/bd7e477000fcb1a0d22f0aff50284e20ffb6dcef.jpeg).  
But there is no selection on the user interface related to dimension conversion.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 28, 2023, 1:53am UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/15 "2023-09-28T01:53:40Z")

</div>

According to glTF standard, the distance unit in the world coordinate system is meter. Therefore we do not allow the user to select units but always use meter.

---

<div class="post-metadata">

### Author: ![Caterina](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@Caterina](https://discourse.slicer.org/u/Caterina)
#### Post date: [September 28, 2023, 8:34am UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/16 "2023-09-28T08:34:19Z")

</div>

Dear Prof Lasso,  
thanks a lot for support and for your patience.  
I need to export segmentation results from TotalSegmentation (several volumes) as gltf file with the same dimensions that I see on 3d slicer (for example around 650 mm).  
Actually, after exporting using OpenAnatomy, the dimension will be 650 m.  
So I need to scale before exporting as gltf. Is there a way to scale all volumes of a segmentation at once?  
Thanks

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [September 28, 2023, 3:42pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/17 "2023-09-28T15:42:04Z")

</div>

> [@Caterina](#):
>
> around

There is something amiss here. You wouldn’t see 650mm being reported as 650m. You should see 650mm being reported as 0.65m in the software you are loading the exported glTF file, because the scaleToMeters function shown above divides the values by 1000, if the units are millimeters (which is default in slicer).

Regardless if you want to try this on your own for further troubleshooting, create a linear transform whose first three diagonals are 0.001, and then put your segmentation under it, and harden the transform (that’s what the code snipped above is doing).

Then you can perhaps figure out where the issue is coming from.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 28, 2023, 7:01pm UTC](https://discourse.slicer.org/t/scale-model-in-gltf/31639/18 "2023-09-28T19:01:22Z")

</div>

Please check in the Extensions Manager if you have the latest version of the SlicerOpenAnatomy extension installed:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/5/f54ec83cf12fd9559a7fe4da6ffa22de235b50fe.png)

If you have this version, then you can do a simple test to confirm it works well:

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/f/df81c4c2ad941cece73c8e2213e0bc115f994d33.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/f/df81c4c2ad941cece73c8e2213e0bc115f994d33.mp4)

As you can see, the segment length measurement result was the same in Slicer (114mm) and in the glTF viewer (0.111m).

Maybe you haven’t used the current version of SlicerOpenAnatomy extension or you used a glTF viewer that measured distance incorrectly.
