importing_3d_scenes.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. .. _doc_importing_3d_scenes:
  2. Importing 3D scenes
  3. ===================
  4. Introduction
  5. ------------
  6. Most game engines just import 3D objects, which may contain skeletons or
  7. animations, and then all further work is done in the engine UI, like
  8. object placement, full scene animations, etc. In Godot, given the node
  9. system is very similar to how 3D DCC tools (such as Maya, 3DS Max or Blender)
  10. work, full 3D scenes can be imported in all their glory. Additionally, by using
  11. a simple language tag system, it is possible to specify that objects are
  12. imported as several things, such as collidable, rooms and portals, vehicles
  13. and wheels, LOD distances, billboards, etc.
  14. This allows for some interesting features:
  15. - Importing simple scenes, rigged objects, animations, etc.
  16. - Importing full scenes. Entire scenarios can be created and updated in
  17. the 3D DCC and imported to Godot each time they change, then only
  18. little editing is needed from the engine side.
  19. - Full cutscenes can be imported, including multiple character
  20. animation, lighting, camera motion, etc.
  21. - Scenes can be further edited and scripted in the engine, where
  22. shaders and environment effects can be added, enemies can be
  23. instanced, etc. The importer will update geometry changes if the
  24. source scene changes but keep the local changes too (in real-time
  25. while using the Godot editor!)
  26. - Textures can be all batch-imported and updated when the source scene
  27. changes.
  28. This is achieved by using a very simple language tag that will be
  29. explained in detail later.
  30. Exporting DAE files
  31. -------------------
  32. Why not FBX?
  33. ~~~~~~~~~~~~
  34. Most game engines use the FBX format for importing 3D scenes, which is
  35. definitely one of the most standardized in the industry. However, this
  36. format requires the use of a closed library from Autodesk which is
  37. distributed with a more restrictive licensing terms than Godot. The plan
  38. is, sometime in the future, to implement an external conversion binary,
  39. but meanwhile FBX is not really supported.
  40. Exporting DAE files from Maya and 3DS Max
  41. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. Autodesk added built-in collada support to Maya and 3DS Max, but It's
  43. really broken and should not be used. The best way to export this format
  44. is by using the
  45. `OpenCollada <https://github.com/KhronosGroup/OpenCOLLADA/wiki/OpenCOLLADA-Tools>`__
  46. plugins. They work really well, although they are not always up-to date
  47. with the latest version of the software.
  48. Exporting DAE files from Blender
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. Blender also has built-in collada support, but It's really broken and
  51. should not be used either.
  52. Godot provides a `Python
  53. Plugin <https://github.com/godotengine/godot/tree/master/tools/export/blender25>`__
  54. that will do a much better job at exporting the scenes.
  55. The import process
  56. ------------------
  57. Import process begins with the 3D scene import menu:
  58. .. image:: /img/3dimp_menu.png
  59. That opens what is probably the biggest of all the import dialogs:
  60. .. image:: /img/3dimp_dialog.png
  61. Many options exist in there, so each section will be explained as
  62. follows:
  63. Source & target paths
  64. ~~~~~~~~~~~~~~~~~~~~~
  65. To import, two options are needed. The first is a source .dae file
  66. (.dae stands for Collada. More import formats will eventually added,
  67. but Collada is the most complete open format as of this writing).
  68. A target folder needs to be provided, so the importer can import the
  69. scene there. The imported scene will have the same filename as the
  70. source one, except for the .scn extension, so make sure you pick good
  71. names when you export!
  72. The textures will be copied and converted. Textures in 3D applications
  73. are usually just PNG or JPG files. Godot will convert them to video
  74. memory texture compression format (s3tc, pvrtc, ericsson, etc.) by
  75. default to improve performance and save resources.
  76. Since the original textures, 3D file and textures are usually not needed,
  77. it's recommended to keep them outside the project. For some hints on
  78. how to do this the best way, you can check the :ref:`doc_project_organization`
  79. tutorial.
  80. Two options for textures are provided. They can be copied to the same
  81. place as the scene, or they can be copied to a common path (configurable
  82. in the project settings). If you choose this, make sure no two textures
  83. are named the same.
  84. 3D rigging tips
  85. ~~~~~~~~~~~~~~~
  86. Before going into the options, here are some tips for making sure your
  87. rigs import properly
  88. - Only up to 4 weights are imported per vertex, if a vertex depends of
  89. more than 4 bones, only the 4 most important bones (the one with the
  90. most weight) will be imported. For most models this usually works
  91. fine, but just keep it in mind.
  92. - Do not use non-uniform scale in bone animation, as this will likely
  93. not import properly. Try to accomplish the same effect with more
  94. bones.
  95. - When exporting from Blender, make sure that objects modified by a
  96. skeleton are children of it. Many objects can be modified by a single
  97. skeleton, but they all should be direct children.
  98. - The same way, when using Blender, make sure that the relative
  99. transform of children nodes to the skeleton is zero (no rotation, no
  100. translation, no scale. All zero and scale at 1.0). The position of
  101. both objects (the little orange dot) should be at the same place.
  102. 3D import options
  103. ~~~~~~~~~~~~~~~~~
  104. This section contains many options to change the way import workflow
  105. works. Some (like HDR) will be better explained in other sections, but
  106. in general a pattern can be visible in the options and that is, many of
  107. the options end with "-something". For example:
  108. - Remove Nodes (-noimp)
  109. - Set Alpha in Materials (-alpha)
  110. - Create Collisions (-col).
  111. This means that the object names in the 3D DCC need to have those
  112. options appended at the end for the importer to tell what they are. When
  113. imported, Godot will convert them to what they are meant to be.
  114. **Note:** Maya users must use “_" (underscore) instead of "-" (minus).
  115. Here is an example of how a scene in the 3D DCC looks (using Blender),
  116. and how it is imported to Godot:
  117. .. image:: /img/3dimp_blender.png
  118. Notice that:
  119. - The camera was imported normally.
  120. - A Room was created (-room).
  121. - A Portal was created (-portal).
  122. - The Mesh got static collision added (-col).
  123. - The Light was not imported (-noimp).
  124. Options in detail
  125. ~~~~~~~~~~~~~~~~~
  126. Following is a list of most import options and what they do in more
  127. detail.
  128. Remove nodes (-noimp)
  129. ^^^^^^^^^^^^^^^^^^^^^
  130. Node names that have this at the end will be removed at import time, mo
  131. matter their type. Erasing them afterwards is most of the times
  132. pointless because the will be restored if the source scene changes.
  133. Import animations
  134. ^^^^^^^^^^^^^^^^^
  135. Some scene formats (.dae) support one or more animations. If this is
  136. checked, an `AnimationPlayer <class_animationplayer>`__ node will be
  137. created, containing the animations.
  138. Compress geometry
  139. ^^^^^^^^^^^^^^^^^
  140. This option (disabled [STRIKEOUT:or more like, always enabled] at the
  141. moment at the time of writing this) will compress geometry so it takes
  142. less space and renders faster (at the cost of less precision).
  143. Force generation of tangent arrays
  144. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  145. The importer detects when you have used a normalmap texture, or when the
  146. source file contains tangent/binormal information. These arrays are
  147. needed for normalmapping to work, and most exporters know what they do
  148. when they export this. However, it might be possible to run into source
  149. scenes that do not have this information which, as a result, make
  150. normal-mapping not work. If you notice that normal-maps do not work when
  151. importing the scene, turn this on!
  152. SRGB -> linear of diffuse textures
  153. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  154. When rendering using HDR (High Dynamic Range) it might be desirable to
  155. use linear-space textures to achieve a more real-life lighting.
  156. Otherwise, colors may saturate and contrast too much when exposure
  157. changes. This option must be used together with the SRGB option in
  158. `WorldEnvironment <class_worldenvironment>`__. The texture import
  159. options also have the option to do this conversion, but if this one is
  160. turned on, conversion will always be done to diffuse textures (usually
  161. what is desired). For more information, read the :ref:`doc_high_dynamic_range`
  162. tutorial.
  163. Set alpha in materials (-alpha)
  164. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  165. When working with most 3D DCCs, its pretty obvious when a texture is
  166. transparent and has opacity and this rarely affects the workflow or
  167. final rendering. However, when dealing with real-time rendering,
  168. materials with alpha blending are usually less optimal to draw, so they
  169. must be explicitly marked as such.
  170. Originally Godot detected this based on whether if the source texture
  171. had an alpha channel, but most image manipulation applications like Photoshop or
  172. Gimp will export this channel anyway even if not used. Code was added
  173. later to check manually if there really was any transparency in the
  174. texture, but artists will anyway and very often lay uvmaps into opaque
  175. parts of a texture and leave unused areas (where no UV exists)
  176. transparent, making this detection worthless.
  177. Finally, it was decided that it's best to import everything as opaque
  178. and leave artists to fix materials that need transparency when it's
  179. obvious that they are not looking right (see the :ref:`doc_materials`
  180. tutorial).
  181. As a helper, since every 3D DCC allows naming the materials and keeping
  182. their name upon export, the (-alpha) modifier in their name will hint
  183. the 3D scene importer in Godot that this material will use the alpha
  184. channel for transparency.
  185. Set vert. color in materials (-vcol)
  186. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  187. Most 3D DCCs support vertex color painting. This is generally applied as
  188. multiplication or screen blending. However, it is also often the case
  189. that your exporter will export this information as all 1s, or export it
  190. as something else and you will not realize it. Since most of the cases
  191. this option is not desired, just add this to any material to confirm
  192. that vertex colors are desired.
  193. Create collisions (-col, -colonly)
  194. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  195. These will only work for Mesh nodes, If the "-col" option is detected, a
  196. child static collision node will be added, using the same geometry as
  197. the mesh.
  198. However, it is often the case that the visual geometry is too complex or
  199. too un-smooth for collisions, which end up not working well. To solve
  200. this, the "-colonly" modifier exists, which will remove the mesh upon
  201. import and create a `StaticBody <class_staticbody>`__ collision instead.
  202. This helps the visual mesh and actual collision to be separated.
  203. Create rooms (-room)
  204. ^^^^^^^^^^^^^^^^^^^^
  205. This is used to create a room. As a general rule, any node that is a
  206. child of this node will be considered inside the room (including
  207. portals).
  208. .. For more information about rooms/portals, look at the [[Portals and Rooms]] tutorial.
  209. There are two ways in which this modifier can be used. The first is
  210. using a Dummy/Empty node in the 3D application with the "-room" tag. For this to
  211. work, the "interior" of the room must be closed (geometry of the
  212. children should contain walls, roof, floor, etc. and the only holes to
  213. the outside should be covered with portals). The importer will then
  214. create a simplified version of the geometry for the room.
  215. The second way is to use the "-room" modifier on a mesh node. This will
  216. use the mesh as the base for the BSP tree that contains the room bounds.
  217. Make sure that the mesh shape is **closed**, all normals **point
  218. outside** and that the geometry is **not self-intersecting**, otherwise
  219. the bounds may be computed wrong (BSP Trees are too picky and difficult
  220. to work with, which is why they are barely used anymore..).
  221. Anyway, the room will need portals, which are described next.
  222. Create portals (-portal)
  223. ^^^^^^^^^^^^^^^^^^^^^^^^
  224. Portals are the view to look outside a room. They are always some flat
  225. shape on the surface of a room. If the portal is left alone, it is used
  226. to activate occlusion when looking inside<->outside the room.
  227. .. Again, more information on the [[Portals and Rooms]] tutorial.
  228. Basically, the conditions to make and import a portal from the 3D DCC
  229. are:
  230. - It should be a child of a room.
  231. - It should lay on the surface of the room (this doesn't need to be
  232. super exact, just make it as close as you can by eye and Godot will
  233. adjust it)
  234. - It must be a flat, convex shape, any flat and convex shape is okay, no
  235. matter the axis or size.
  236. - Normals for the flat shape faces must **all point towards the
  237. OUTSIDE** of the room.
  238. Here is how it usually looks:
  239. .. image:: /img/3dimp_portal.png
  240. To connect to rooms, simply make two identical portals for both rooms
  241. and place them overlapped. This does not need to be perfectly exact,
  242. again, as Godot will fix it.
  243. [..]
  244. ^^^^
  245. The rest of the tags in this section should be rather obvious, or will
  246. be documented/changed in the future.
  247. Double-sidedness
  248. ~~~~~~~~~~~~~~~~
  249. Collada and other formats support specifying the double-sidedness of
  250. the geometry (in other words, when not double-sided, back-faces are
  251. not drawn). Godot supports this option per Material, not per Geometry.
  252. When exporting from 3D DCCs that work with per-object double-sidedness
  253. (such as Blender of Maya), make sure that the double sided objects do
  254. not share a material with the single sided ones or the importer will
  255. not be able to discern.
  256. Animation options
  257. ~~~~~~~~~~~~~~~~~
  258. Some things to keep in mind when importing animations. 3D DCCs allow
  259. animating with curves for every x,y,z component, doing IK constraints
  260. and other stuff. When imported for real-time, animations are sampled
  261. (at small intervals) so all this information is lost. Sampled
  262. animations are fast to process, but can use considerable amounts of
  263. memory.
  264. Because of this, the "Optimize" option exists but, in some cases, this
  265. option might break an animation, so make it sure to disable it if
  266. you notice any issues.
  267. Some animations are meant to be cycled (like walk animations) if this is
  268. the case, animation names that end in "-cycle" or "-loop" are
  269. automatically set to loop.
  270. Import script
  271. ~~~~~~~~~~~~~
  272. Creating a script to parse the imported scene is actually really simple.
  273. This is great for post processing, changing materials, doing funny stuff
  274. with the geometry, etc.
  275. Create a script that basically looks like this:
  276. ::
  277. tool # needed so it runs in editor
  278. extends EditorScenePostImport
  279. func post_import(scene):
  280. # do your stuff here
  281. pass # scene contains the imported scene starting from the root node
  282. The post-import function takes the imported scene as parameter (the
  283. parameter is actually the root node of the scene).
  284. Update logic
  285. ~~~~~~~~~~~~
  286. Other types of resources (like samples, meshes, fonts, images, etc.) are
  287. re-imported entirely when changed and user changes are not kept.
  288. Because of 3D Scenes can be really complex, they use a different update
  289. strategy. The user might have done local changes to take advantage of
  290. the engine features and it would be really frustrating if everything is
  291. lost on re-import because the source asset changed.
  292. This led to the implementation of a special update strategy. The idea
  293. behind is that the user will not lose anything he or she did, and only
  294. added data or data that can't be edited inside Godot will be updated.
  295. It works like this:
  296. Strategy
  297. ^^^^^^^^
  298. Upon changes on the source asset (ie: .dae), and on re-import, the
  299. editor will remember the way the scene originally was, and will track
  300. your local changes like renaming nodes, moving them or reparenting them.
  301. Finally, the following will be updated:
  302. - Mesh Data will be replaced by the data from the updated scene.
  303. - Materials will be kept if they were not modified by the user.
  304. - Portal and Room shapes will be replaced by the ones from the updated
  305. scene.
  306. - If the user moved a node inside Godot, the transform will be kept. If
  307. the user moved a node in the source asset, the transform will be
  308. replaced. Finally, if the node was moved in both places, the
  309. transform will be combined.
  310. In general, if the user deletes anything from the imported scene (node,
  311. mesh, material, etc.), updating the source asset will restore what was
  312. deleted. This is a good way to revert local changes to anything. If you
  313. really don't want a node anymore in the scene, either delete it from
  314. both places or add the "-noimp" tag to it in the source asset.
  315. Fresh re-import
  316. ^^^^^^^^^^^^^^^
  317. It can also happen that the source asset changed beyond recognition and
  318. a full fresh re-import is desired. If so, simply re-open the 3D scene
  319. import dialog from the Import -> Re-Import menu and perform re-import.