# transfer scene files from 3DSlicer to Unity3D

**URL:** <https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729>\
**Category:** Support\
**Created:** [January 28, 2021, 10:51pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729 "2021-01-28T22:51:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [January 28, 2021, 10:51pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/1 "2021-01-28T22:51:49Z")

</div>

Hi, anybody know how to take the segmentation of the 3DSlicer scene and put those same segmentation on Unity3D with the same characteristics (size, dimension, position of objects), please? I need this for a Project in Zspace screen which works with Unity3D

---

<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:** [January 28, 2021, 11:03pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/2 "2021-01-28T23:03:11Z")

</div>

Slicer can export the segmentation to obj format (and some others) that Unity can use.

[https://slicer.readthedocs.io/en/latest/user\_guide/modules/segmentations.html#export-segmentation-to-model-surface-mesh-file](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html#export-segmentation-to-model-surface-mesh-file)

The length unit is mm by default. You can change the scale in the export window but I would recommend keeping the default, as mm is used as length unit by DICOM and all clinical imaging software.

Note that while Unity is an awesome gaming engine, it is quite poor for medical imaging applications. For example, you may find that Unity cannot import the full-quality meshes with all details (it has a limit on maximum polygon count per mesh). If you run into this limitation but still want to work with Unity then you either need to split the mesh to multiple pieces or decimate it before exporting it to file in Slicer (export segments to model, decimate using Surface Toolbox module, then save the models using File / Save data).

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [January 29, 2021, 6:47am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/3 "2021-01-29T06:47:13Z")

</div>

So let’s imagine I have a segmentation scene file and I want to put these segmentations in unity3D from slicer without changing the characteristics of the segmentations. So how do I do this? because concretely I think it is possible but I cannot find exactly what to do.

---

<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:** [January 29, 2021, 4:04pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/4 "2021-01-29T16:04:42Z")

</div>

You can use use SlicerOpenAnatomy extension’s OpenAnatomy export module, which can export a segmentation as a set of low-poly models by a single click of a button in OBJ or glTF format.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 29, 2021, 4:41pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/5 "2021-01-29T16:41:40Z")

</div>

Once you have the exported OBJ files, if you drop them into the Assets folder (or a subdirectory of the Assets folder if you want to keep things more organized) of your Unity project, Unity will automatically import them as assets. Then you can add them to your scene within Unity. It’s been a while since I’ve done it, but I recall the import process working smoothly. You need both the .obj file and the associated .mtl file to bring along the associated color you have from Slicer. The obj file holds the mesh and the mtl file holds the material properties, which includes color.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 29, 2021, 4:46pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/6 "2021-01-29T16:46:51Z")

</div>

About the scaling, the Slicer export has units of mm, and I think the Unity default might interpret numbers as meters, but scaling things in Unity is very easy, and if your objects are 1000x too big, just scale them down. For what I was doing, only relative sizes mattered and all meshes were coming from Slicer, so I didn’t end up having to change anything.

---

<div class="post-metadata">

**Author:** ![pll\_llq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pll_llq/32/9408_2.png) [@pll\_llq](https://discourse.slicer.org/u/pll_llq)\
**Post date:** [January 29, 2021, 7:09pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/7 "2021-01-29T19:09:22Z")

</div>

If you want to avoid changing the segmentation to a mesh model and display the segmentation as a volume in unity - there are also several options to do this.

Basically speaking - you can export the segmentation as a sequence of 2D slices and import them into a 3D texture. The same way as volumetric clouds are rendered.

If you want to use DICOM you might need to write an import plugin that will read and convert the files to a texture sequence or a 3D texture, but if you just want simple visualisation you can export a sequence of images using the Screen Capture module and use the sequence with volume renderers like [this one](https://bitbucket.org/it-medex/volume-rendering-engine/src/master/).

There were a couple of very nice looking prototypes to do volume rendering of medical images in UE4 that appeared to show better performance - so Unity is not the only game engine that can give you this functionality.

Edit: there is a [Simple DICOM Loader](https://assetstore.unity.com/packages/tools/input-management/simple-dicom-loader-116915) in the Unity Asset Store.

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 1, 2021, 10:39pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/8 "2021-02-01T22:39:02Z")

</div>

Thank you everyone, you have helped me a lot.  
I have another question. How do I PRECISELY transfer the volume rendering of the sections I have on 3DSlicer to Unity3D without changing the orientation, the scale etc … PLEASE ??

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 3, 2021, 11:58pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/9 "2021-02-03T23:58:04Z")

</div>

yes I have a complete Proyecto fist you need to create a 3D model and save it as .ply file and go to this website so you don’t need Blender to convert to fix the file  
this is because is the format that unity needs.  
[https://products.aspose.app/3d/conversion/ply-to-fbx](https://products.aspose.app/3d/conversion/ply-to-fbx)

after converting your 3d model format you can drag it in unity I guess you want to do an AR or something like it, if that’s the case feel free to ask me

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 4, 2021, 1:22am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/10 "2021-02-04T01:22:51Z")

</div>

thanks , Basically I have MRI sections that I transferred from 3Dslicer to unity3D and now I want to have the volume rendering of these images in unity3D, how do I do that?

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 4, 2021, 1:23am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/11 "2021-02-04T01:23:17Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/e/7e2fdc3f51fa330fa4188fe698348fcbfa8cb0bf.png)

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 4, 2021, 1:24am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/12 "2021-02-04T01:24:11Z")

</div>

they are in .PNG format

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 4, 2021, 1:55am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/13 "2021-02-04T01:55:15Z")

</div>

pleas open Slicer and see the name of your file you can see these by going to Data in Modules

after that pleas change the name of your file mi file name is aseg.presurf-IXI061-A  
so try this:  
You can open python code by crl+3

```python
nodo='aseg.presurf-IXI061-A'

sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
compositeNode = sliceLogic.GetSliceCompositeNode()
compositeNode.SetLinkedControl(1)
#link the slice control
slicer.util.getNode('vtkMRMLSliceNodeRed').SetUseLabelOutline(1);
#Thickness line 
labelMapNode=getNode(nodo)
labelMapNode.GetDisplayNode().SetSliceIntersectionThickness(1)

#####3d

seg=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode')
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(getNode(nodo), seg)
seg.CreateClosedSurfaceRepresentation()

```

After this code you will have a 3d model

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

You will have to go to segment edit click segmentation  
after click go to this menu  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/8/58aab3cc336f4b3b3f9fad8567341884c95656da.png)  
and you will have you 3d protect in stl file

---

<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:** [February 4, 2021, 3:14am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/14 "2021-02-04T03:14:10Z")

</div>

> [@Amine\_Ziane](#):
>
> I want to have the volume rendering

Implementing medical image viewer in Unity is a huge pain. You essentially need to redevelop everything from scratch. You find a few very basic volume rendering packages that you should be able to set up a simple demo with it, but they are nowhere near to what real users would expect as a minimum requirement for a clinical software.

I would only recommend Unity for very special use cases, for example for building simulation-based training applications, where the emphasis is on fluid computer-game-like immersive experience and you don’t need clinical-grade visualization and tools.

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 4, 2021, 4:39pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/17 "2021-02-04T16:39:02Z")

</div>

I have this error

```auto
>>> #####3d
>>> seg=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode')
>>>slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(getNode(nodo), seg)
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: arguments do not match any overloaded methods
>>> seg.CreateClosedSurfaceRepresentation()
True

```

---

<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:** [February 5, 2021, 4:33am UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/18 "2021-02-05T04:33:52Z")

</div>

First argument of `ImportLabelmapToSegmentationNode` must be a labelmap volume. See more examples [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Segmentations).

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 7, 2021, 6:44pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/19 "2021-02-07T18:44:52Z")

</div>

Yes I know but I have to do this on unity3D even if the result is not perfect but I have to show something to my professor

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 7, 2021, 7:08pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/20 "2021-02-07T19:08:34Z")

</div>

Actually I already have my images in unity3D so now from unity3D I have to do the volume rendering, thanks to a plugin I guess

---

<div class="post-metadata">

**Author:** ![Amine\_Ziane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine_ziane/32/8989_2.png) [@Amine\_Ziane](https://discourse.slicer.org/u/Amine_Ziane)\
**Post date:** [February 7, 2021, 9:30pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/21 "2021-02-07T21:30:44Z")

</div>

Or how use the surface rendering instead of volume rendering in unity3D ?

---

<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:** [February 7, 2021, 9:57pm UTC](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729/22 "2021-02-07T21:57:52Z")

</div>

You would load the image into Slicer, use Segment Editor to segment all the structures that you are interested in, and export the segmentation to OBJ files (see step-by-step instructions [here](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html#use-cases)). You can import the OBJ files into Unity.

[Next page](https://discourse.slicer.org/t/transfer-scene-files-from-3dslicer-to-unity3d/15729.md?page=2)
