tscn.rst 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. TSCN File Format
  2. ================
  3. A :code:`.tscn` File format is the "Text SCeNe" file format and represents
  4. a single scene-tree inside Godot. TSCN files have the advantage of being
  5. nearly human-readable and easy for version control systems to manage. During
  6. import the TSCN files are compiled into binary :code:`.scn` files stored
  7. inside the .import folder. This reduces the data size and speed up loading.
  8. The :code:`.escn` file format is identical to the TSCN file format, but is used to
  9. indicate to Godot that the file has been exported from another program and
  10. should not be edited by the user from within Godot.
  11. For those looking for a complete description, the parsing is handled in the
  12. file `scene_format_text.cpp <https://github.com/godotengine/godot/blob/master/scene/resources/scene_format_text.cpp>`_
  13. in the class :code:`ResourceFormatLoaderText`
  14. File Structure
  15. --------------
  16. There are five main sections inside the TSCN File:
  17. 0. File Descriptor
  18. 1. External resources
  19. 2. Internal resources
  20. 3. Nodes
  21. 4. Connections
  22. The file descriptor looks like :code:`[gd_scene load_steps=1 format=2]` And
  23. should be the first entry in the file. The load_steps parameter should (in
  24. theory) be the number of resources within the file, though in practice it's
  25. value seems not to matter.
  26. These sections should appear in order, but it can be hard to distinguish
  27. them. The only difference between them is the first element in the heading
  28. for all of the items in the section.
  29. For example, the heading of all external resources should start with
  30. :code:`[ext_resource .....]`
  31. Entries inside the file
  32. ~~~~~~~~~~~~~~~~~~~~~~~
  33. A heading looks like:
  34. :code:`[<resource_type> key=value key=value key=value ...]`
  35. Where resource_type is one of:
  36. - ext_resource
  37. - sub_resource
  38. - node
  39. - connection
  40. Underneath every heading comes zero or more :code:`key = value` pairs. The
  41. values can be complex datatypes such as arrays, transformations, colors, and
  42. so on. For example, a spatial node looks like:
  43. ::
  44. [node name="Cube" type="Spatial" parent="."]
  45. transform=Transform( 1.0, 0.0, 0.0 ,0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 )
  46. Resources
  47. ---------
  48. Resources are components that make up the nodes. For example, a MeshInstance
  49. node will have an accompanying ArrayMesh resource. The ArrayMesh resource
  50. may be either internal or external to the TSCN file.
  51. References to the resources are handled by id numbers in the resources heading.
  52. External resources and internal resource are referred to with
  53. :code:`ExtResource(id)` and :code:`SubResource(id)`. Because there have
  54. different methods to refer to internal and external resource, you can have
  55. the same ID for both an internal and external resource.
  56. For example, to refer to the resource
  57. :code:`[ext_resource id=3 type="PackedScene" path=....]` you would use
  58. :code:`ExtResource(3)`
  59. External Resources
  60. ~~~~~~~~~~~~~~~~~~
  61. External resources are links to resources not contained within the TSCN file
  62. itself. An external resource consists of:
  63. - A path
  64. - A type
  65. - An ID
  66. Godot alway generates absolute paths relative to the resource directory and
  67. thus prefixed with :code:`res://`, but paths relative to the TSCN file's
  68. location are also valid.
  69. Some example external resources are:
  70. ::
  71. [ext_resource path="res://characters/player.dae" type="PackedScene" id=1]
  72. [ext_resource path="metal.tres" type="Material" id=2]
  73. Internal Resources
  74. ~~~~~~~~~~~~~~~~~~
  75. A TSCN file can contain meshes, materials and other data, and these are
  76. contained in the internal resources section of the file. The heading
  77. for an internal resource looks similar to those of external resources, but
  78. does not have a path. Internal resources also have :code:`key=value` pairs
  79. under each heading. For example, a capsule collision shape looks like:
  80. ::
  81. [sub_resource type="CapsuleShape" id=2]
  82. radius = 0.5
  83. height = 3.0
  84. Some internal resource contain links to other internal resources (such as a
  85. mesh having a material). In this case, the referring resource must appear
  86. before the reference to it. Thus, in the internal resources section of the
  87. file, order does matter.
  88. Unfortunately, documentation on the formats for these subresources is
  89. completely absent, and while some can be found through inspecting resources of
  90. saved files, but others can only be found by looking through Godot's source.
  91. The Scene Tree
  92. --------------
  93. The scene tree is made up of ... nodes! The heading of each node consists of
  94. it's name, parent and (most of the time) a type. For example
  95. :code:`[node type="Camera" name="PlayerCamera" parent="Player/Head"]`
  96. Other valid keywords include:
  97. - instance
  98. - instance_placeholder
  99. - owner
  100. - index (if two nodes have the same name)
  101. - groups
  102. The first node in the file should not have the :code:`parent=Path/To/Node`
  103. entry in it's heading, and it is the scene root. All scene files should have
  104. exactly one scene root. It it does not, Godot will fail to import the file.
  105. The parent path of other nodes should be absolute, but without the scene
  106. root's name. If it is a direct child of the scene root, it should be
  107. :code:`"."`. Here is an example scene tree (but without any node content).
  108. ::
  109. [node name="Player" type="Spatial"] ; The scene root
  110. [node name="Arm" parent="." type="Spatial"] ; Parented to the scene root
  111. [node name="Hand" parent="Arm" type="Spatial"]
  112. [node name="Finger" parent="Arm/Hand" type="Spatial"]
  113. Similar to the internal resource, the content for each node is currently
  114. undocumented. Fortunately it is easy to find out because you can simply
  115. save a file with that node in it. Some example nodes are:
  116. ::
  117. [node type="CollisionShape" name="SphereCollision" parent="SpherePhysics"]
  118. shape = SubResource(8)
  119. transform = Transform( 1.0 , 0.0 , -0.0 , 0.0 , -4.371138828673793e-08 , 1.0 , -0.0 , -1.0 , -4.371138828673793e-08 ,0.0 ,0.0 ,-0.0 )
  120. [node type="MeshInstance" name="Sphere" parent="SpherePhysics"]
  121. mesh = SubResource(9)
  122. transform = Transform( 1.0 , 0.0 , -0.0 , 0.0 , 1.0 , -0.0 , -0.0 , -0.0 , 1.0 ,0.0 ,0.0 ,-0.0 )
  123. [node type="OmniLight" name="Lamp" parent="."]
  124. light_energy = 1.0
  125. light_specular = 1.0
  126. transform = Transform( -0.29086464643478394 , -0.7711008191108704 , 0.5663931369781494 , -0.05518905818462372 , 0.6045246720314026 , 0.7946722507476807 , -0.9551711678504944 , 0.199883371591568 , -0.21839118003845215 ,4.076245307922363 ,7.3235554695129395 ,-1.0054539442062378 )
  127. omni_range = 30
  128. shadow_enabled = true
  129. light_negative = false
  130. light_color = Color( 1.0, 1.0, 1.0, 1.0 )
  131. [node type="Camera" name="Camera" parent="."]
  132. projection = 0
  133. near = 0.10000000149011612
  134. fov = 50
  135. transform = Transform( 0.6859206557273865 , -0.32401350140571594 , 0.6515582203865051 , 0.0 , 0.8953956365585327 , 0.44527143239974976 , -0.7276763319969177 , -0.3054208755493164 , 0.6141703724861145 ,14.430776596069336 ,10.093015670776367 ,13.058500289916992 )
  136. far = 100.0