importing_3d_scenes.rst 17 KB

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