# Export 3D or 2D world designed in Castle Game Engine editor to X3D or STL

**URL:** <https://forum.castle-engine.io/t/export-3d-or-2d-world-designed-in-castle-game-engine-editor-to-x3d-or-stl/1354>\
**Category:** News\
**Created:** [September 18, 2024, 10:52am UTC](https://forum.castle-engine.io/t/export-3d-or-2d-world-designed-in-castle-game-engine-editor-to-x3d-or-stl/1354 "2024-09-18T10:52:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [September 18, 2024, 10:52am UTC](https://forum.castle-engine.io/t/export-3d-or-2d-world-designed-in-castle-game-engine-editor-to-x3d-or-stl/1354/1 "2024-09-18T10:52:07Z")

</div>

| [![export_to_x3d_stl](https://forum.castle-engine.io/uploads/default/original/2X/7/7a0a1e1eb89a662d7eb6021883c3659c1fefab2f.png)](https://castle-engine.io/wp/wp-content/uploads/2024/09/export_to_x3d_stl.png "export\_to\_x3d\_stl") |

This is a cool new feature that allows you to use our [editor](https://castle-engine.io/editor) in a bit non-standard way. Use the new menu item _“Data -\> Export Viewport to X3D, STL”_ to export the contents of the `TCastleViewport` to X3D or STL file.

To be clear, the main purpose of our editor remains to save the design to a _Castle Game Engine_-specific format (`*.castle-user-interface`, which is a JSON serialization of engine components, that can be later read back using `CastleComponentSerialize` routines). But this new feature allows to use our editor for other purposes. You can design a 3D or 2D world, export it to X3D or STL, and use it with a plethora of other 3D software. For example, you can:

- Open the X3D file in other X3D viewers, including viewers that can render X3D in a browser. Here’s a non-exhaustive list of software that can “consume” X3D files:
  - [X\_ITE](https://create3000.github.io/x_ite/) that can render X3D in a web browser,
  - [X3DOM](https://www.x3dom.org/), again able to render X3D in a web browser,
  - [FreeWRL](https://freewrl.sourceforge.io/),
  - Our [Castle Model Viewer](https://castle-engine.io/castle-model-viewer),
  - Our [Castle Model Viewer Mobile](https://castle-engine.io/castle-model-viewer-mobile),
  - see [X3D Resources](https://www.web3d.org/x3d/content/examples/X3dResources.html) for more tools. Many of them are free and/or open-source. 

- Import the resulting X3D or STL files into other 3D software, like [Blender](https://castle-engine.io/blender).

_Try it out!_ Just [download the engine](https://castle-engine.io/download), create a new project (or open one of the examples) and use _“Data -\> Export Viewport to X3D, STL”_ to see what happens. Try out the new project template like _“3D FPS Game”_. Add there more engine components (see our [documentation](https://castle-engine.io/documentation.php) and in particular [overview of components useful in the viewport](https://castle-engine.io/viewport_and_scenes)) and have fun 🙂

In case of X3D, remember that:

1. The resulting file will refer to the resources (like models loaded in `TCastleScene` or textures) using relative paths. So you should keep the directory structure of the exported files intact, or adjust the paths in the X3D file manually.

2. The exported X3D files may use some X3D extensions, specific to our engine. You can just remove them as necessary to make the models compatible with other X3D browsers.

3. While you can load the resulting X3D back inside the engine editor, this will be just a single component `TCastleScene`, not all the components you exported. Solution: If you want to use CGE editor for authoring X3D or other model formats, just keep the original CGE editor files (`.castle-user-interface`) around, as the “source” version of your 3D / 2D world and export it to X3D as many times as you wish.

All the features supported by the export are listed below:

- 

- Exported file by default is saved as `export.x3d` or `export.stl` in the `data` directory of your project. This is comfortable, just double-click on it to open it in [Castle Model Viewer](https://castle-engine.io/castle-model-viewer).

- `TCastleScene` is exported (as X3D `Inline` node wrapped in the appropriate `Transform` node).

- Transformation hierarchy (`TCastleTransform`) is naturally exported as `Transform` nodes hierarchy.

- All the lights. E.g. `TCastlePointLight` is exported as X3D `PointLight` node.

- All the primitives: `TCastleBox`, `TCastleSphere`, `TCastleCone`, `TCastleCylinder` are exported as X3D `Box`, `Sphere`, `Cone`, `Cylinder` nodes.

- Text is exported (`TCastleText` to X3D `Text` with `FontStyle`).

- Cameras (`TCastleCamera`) are exported as X3D `Viewpoint` or `OrthoViewpoint` nodes, depending on the projection type.

- Background (`TCastleBackground`) is exported as X3D `Background` node.

- Our navigation components, like `TCastleWalkNavigation` and `TCastleExamineNavigation` result in an X3D `NavigationInfo` node. The X3D node offers a subset of functionality from our engine components.

- Fog (`TCastleFog`) is exported as X3D `Fog` node.

- [Tiled maps](https://castle-engine.io/tiled_maps), that is `TCastleTiledMap`, is exported as a collection of X3D nodes that express given map.

- Terrain (`TCastleTerrain`, see our demo [examples/terrain](https://github.com/castle-engine/castle-engine/tree/master/examples/terrain)) is exported.

- Images in the viewport (`TCastleImageTransform`) are exported.

An additional use-case of this feature is to debug what some engine routines are doing.

- While in some cases we create X3D nodes during the export (e.g. for viewpoints and navigation info, in which case we have somewhat similar but far from identical functionality offered by our components like `TCastleCamera` and `TCastleWalkNavigation`)…

- …but in other cases the export just “reveals” the actual nodes used to to render given things (this is the case with e.g. lights, primitives, fog and background).

Have fun with _Castle Game Engine_ and X3D!
