tscn.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. The Scene Tree
  47. --------------
  48. The scene tree is made up of ... nodes! The heading of each node consists of
  49. it's name, parent and (most of the time) a type. For example
  50. :code:`[node type="Camera" name="PlayerCamera" parent="Player/Head"]`
  51. Other valid keywords include:
  52. - instance
  53. - instance_placeholder
  54. - owner
  55. - index (if two nodes have the same name)
  56. - groups
  57. The first node in the file should not have the :code:`parent=Path/To/Node`
  58. entry in it's heading, and it is the scene root. All scene files should have
  59. exactly one scene root. It it does not, Godot will fail to import the file.
  60. The parent path of other nodes should be absolute, but without the scene
  61. root's name. If it is a direct child of the scene root, it should be
  62. :code:`"."`. Here is an example scene tree (but without any node content).
  63. ::
  64. [node name="Player" type="Spatial"] ; The scene root
  65. [node name="Arm" parent="." type="Spatial"] ; Parented to the scene root
  66. [node name="Hand" parent="Arm" type="Spatial"]
  67. [node name="Finger" parent="Arm/Hand" type="Spatial"]
  68. Similar to the internal resource, the document for each node is currently
  69. incomplete. Fortunately it is easy to find out because you can simply
  70. save a file with that node in it. Some example nodes are:
  71. ::
  72. [node type="CollisionShape" name="SphereCollision" parent="SpherePhysics"]
  73. shape = SubResource(8)
  74. 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 )
  75. [node type="MeshInstance" name="Sphere" parent="SpherePhysics"]
  76. mesh = SubResource(9)
  77. 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 )
  78. [node type="OmniLight" name="Lamp" parent="."]
  79. light_energy = 1.0
  80. light_specular = 1.0
  81. 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 )
  82. omni_range = 30
  83. shadow_enabled = true
  84. light_negative = false
  85. light_color = Color( 1.0, 1.0, 1.0, 1.0 )
  86. [node type="Camera" name="Camera" parent="."]
  87. projection = 0
  88. near = 0.10000000149011612
  89. fov = 50
  90. 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 )
  91. far = 100.0
  92. Node Path
  93. ~~~~~~~~~
  94. A tree structure is not enough to represent the whole scene, Godot use
  95. a :code:`NodePath(Path/To/Node)` structure to refer to another node or
  96. attribute of the node anywhere in the scene tree. Some typical usages of
  97. NodePath like mesh node use :code:`NodePath()` to point to its skeleton,
  98. animation track use :code:`NodePath()` points to animated attribute in node.
  99. ::
  100. [node name="mesh" type="MeshInstance" parent="Armature001"]
  101. mesh = SubResource(1)
  102. skeleton = NodePath("..:")
  103. ::
  104. [sub_resource id=3 type="Animation"]
  105. ...
  106. tracks/0/type = "transform
  107. tracks/0/path = NodePath("Cube:")
  108. ...
  109. Skeleton
  110. ~~~~~~~~~
  111. Skeleton node inherits Spatial node, besides that it may have a list
  112. of bones described in key, value pair in the format :code:`bones/Id/Attribute=Value`,
  113. attributes of bone consisits of
  114. - name
  115. - parent
  116. - rest
  117. - pose
  118. - enabled
  119. - bound_children
  120. 1) :code:`name` must put as the first attribute of each bone
  121. 2) :code:`parent` is the index of parent bone in the bone list, with parent index,
  122. the bone list is built to a bone tree
  123. 3) :code:`rest` is the transform matrix of bone in rest position
  124. 4) :code:`pose` is the pose matrix use :code:`rest` as basis
  125. 5) :code:`bound_children` is a list of NodePath() points to
  126. BoneAttachments belong to this bone
  127. An example of a skeleton node with two bones:
  128. ::
  129. [node name="Skeleton" type="Skeleton" parent="Armature001" index="0"]
  130. bones/0/name = "Bone.001"
  131. bones/0/parent = -1
  132. bones/0/rest = Transform( 1, 0, 0, 0, 0, -1, 0, 1, 0, 0.038694, 0.252999, 0.0877164 )
  133. bones/0/pose = 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 )
  134. bones/0/enabled = true
  135. bones/0/bound_children = [ ]
  136. bones/1/name = "Bone.002"
  137. bones/1/parent = 0
  138. bones/1/rest = Transform( 0.0349042, 0.99939, 0.000512929, -0.721447, 0.0248417, 0.692024, 0.691589, -0.0245245, 0.721874, 0, 5.96046e-08, -1.22688 )
  139. bones/1/pose = 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 )
  140. bones/1/enabled = true
  141. bones/1/bound_children = [ ]
  142. BoneAttachment
  143. ~~~~~~~~~~~~~~
  144. BoneAttachment node is an intermediate node to describe some node being parented
  145. to a single bone in Skeleton node. The BoneAttachment has a :code:`bone_name=NameOfBone`,
  146. and the corresponding bone being the parent has the BoneAttachment node
  147. in its :code:`bound_children` list.
  148. An example of one MeshInstance parented to a bone in Skeleton:
  149. ::
  150. [node name="Armature" type="Skeleton" parent="."]
  151. transform = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, -0.0219986, 0.0125825, 0.0343127)
  152. bones/0/name = "Bone"
  153. bones/0/parent = -1
  154. bones/0/rest = Transform(1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0)
  155. bones/0/pose = 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)
  156. bones/0/enabled = true
  157. bones/0/bound_children = [NodePath("BoneAttachment:")]
  158. [node name="BoneAttachment" type="BoneAttachment" parent="Armature"]
  159. bone_name = "Bone"
  160. [node name="Cylinder" type="MeshInstance" parent="Armature/BoneAttachment"]
  161. mesh = SubResource(1)
  162. transform = Transform(1.0, 0.0, 0.0, 0.0, 1.86265e-09, 1.0, 0.0, -1.0, 0.0, 0.0219986, -0.0343127, 2.25595)
  163. AnimationPlayer
  164. ~~~~~~~~~~~~~~~~
  165. AnimationPlayer works as an animation lib. it has animations listed in the format
  166. :code:`anim/Name=SubResource(ResourceId)`, each refers to a Animation
  167. internal resource. All the animation resources use the root node of AnimationPlayer.
  168. The root node is stored as :code:`root_node=NodePath(Path/To/Node)`.
  169. ::
  170. [node name="AnimationPlayer" type="AnimationPlayer" parent="." index="1"]
  171. root_node = NodePath("..")
  172. autoplay = ""
  173. playback_process_mode = 1
  174. playback_default_blend_time = 0.0
  175. playback_speed = 1.0
  176. anims/default = SubResource( 2 )
  177. blend_times = [ ]
  178. Resources
  179. ---------
  180. Resources are components that make up the nodes. For example, a MeshInstance
  181. node will have an accompanying ArrayMesh resource. The ArrayMesh resource
  182. may be either internal or external to the TSCN file.
  183. References to the resources are handled by id numbers in the resources heading.
  184. External resources and internal resource are referred to with
  185. :code:`ExtResource(id)` and :code:`SubResource(id)`. Because there have
  186. different methods to refer to internal and external resource, you can have
  187. the same ID for both an internal and external resource.
  188. For example, to refer to the resource
  189. :code:`[ext_resource id=3 type="PackedScene" path=....]` you would use
  190. :code:`ExtResource(3)`
  191. External Resources
  192. ~~~~~~~~~~~~~~~~~~
  193. External resources are links to resources not contained within the TSCN file
  194. itself. An external resource consists of:
  195. - A path
  196. - A type
  197. - An ID
  198. Godot alway generates absolute paths relative to the resource directory and
  199. thus prefixed with :code:`res://`, but paths relative to the TSCN file's
  200. location are also valid.
  201. Some example external resources are:
  202. ::
  203. [ext_resource path="res://characters/player.dae" type="PackedScene" id=1]
  204. [ext_resource path="metal.tres" type="Material" id=2]
  205. Internal Resources
  206. ~~~~~~~~~~~~~~~~~~
  207. A TSCN file can contain meshes, materials and other data, and these are
  208. contained in the internal resources section of the file. The heading
  209. for an internal resource looks similar to those of external resources, but
  210. does not have a path. Internal resources also have :code:`key=value` pairs
  211. under each heading. For example, a capsule collision shape looks like:
  212. ::
  213. [sub_resource type="CapsuleShape" id=2]
  214. radius = 0.5
  215. height = 3.0
  216. Some internal resource contain links to other internal resources (such as a
  217. mesh having a material). In this case, the referring resource must appear
  218. before the reference to it. Thus, in the internal resources section of the
  219. file, order does matter.
  220. Unfortunately, documentation on the formats for these subresources is not
  221. complete, and while some can be found through inspecting resources of
  222. saved files, others can only be found by looking through Godot's source.
  223. ArrayMesh
  224. ~~~~~~~~~
  225. ArrayMesh consists of several surfaces, each in the format :code:`surface\Index={}`,
  226. each surface is a set of vertex and a material.
  227. TSCN support two format of surface,
  228. 1) for the old format, each surface has three essential keys:
  229. - primitive
  230. - arrays
  231. - morph_arrays
  232. i) :code:`primitive` is an enumerate variable, :code:`primitive=4` which is
  233. PRIMITIVE_TRIANGLES is frequently used.
  234. ii) :code:`arrays` as name suggestes is an array of array, it contains:
  235. 1) a array of vertex position
  236. 2) tagents array
  237. 3) vertex color array
  238. 4) UV array 1
  239. 5) UV array 2
  240. 6) bone index array
  241. 7) bone weight array
  242. 8) vertex index array
  243. iii) :code:`morph_arrays` is an array of morph, each morph is exactly an
  244. :code:`arrays` without vertex index array.
  245. An example of ArrayMesh:
  246. ::
  247. [sub_resource id=1 type="ArrayMesh"]
  248. surfaces/0 = {
  249. "primitive":4,
  250. "arrays":[
  251. Vector3Array(0.0, 1.0, -1.0, 0.866025, -1.0, -0.5, 0.0, -1.0, -1.0, 0.866025, 1.0, -0.5, 0.866025, -1.0, 0.5, 0.866025, 1.0, 0.5, -8.74228e-08, -1.0, 1.0, -8.74228e-08, 1.0, 1.0, -0.866025, -1.0, 0.5, -0.866025, 1.0, 0.5, -0.866025, -1.0, -0.5, -0.866025, 1.0, -0.5),
  252. Vector3Array(0.0, 0.609973, -0.792383, 0.686239, -0.609973, -0.396191, 0.0, -0.609973, -0.792383, 0.686239, 0.609973, -0.396191, 0.686239, -0.609973, 0.396191, 0.686239, 0.609973, 0.396191, 0.0, -0.609973, 0.792383, 0.0, 0.609973, 0.792383, -0.686239, -0.609973, 0.396191, -0.686239, 0.609973, 0.396191, -0.686239, -0.609973, -0.396191, -0.686239, 0.609973, -0.396191),
  253. null, ; No Tangents,
  254. null, ; no Vertex Colors,
  255. null, ; No UV1,
  256. null, ; No UV2,
  257. null, ; No Bones,
  258. null, ; No Weights,
  259. IntArray(0, 2, 1, 3, 1, 4, 5, 4, 6, 7, 6, 8, 0, 5, 9, 9, 8, 10, 11, 10, 2, 1, 10, 8, 0, 1, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 5, 0, 3, 0, 9, 11, 9, 5, 7, 9, 10, 11, 11, 2, 0, 10, 1, 2, 1, 6, 4, 6, 1, 8)
  260. ],
  261. "morph_arrays":[]
  262. }
  263. Animation
  264. ~~~~~~~~~~
  265. An animation resource consists of tracks. Besides, it has 'length', 'loop' and
  266. 'step' applied to all the tracks.
  267. - length
  268. - loop
  269. - step
  270. 1) :code:`length` and :code:`step` are both time in seconds
  271. Each track is described by a list of key, value pairt in the format :code:`tracks/Id/Attribute`,
  272. it includs:
  273. - type
  274. - path
  275. - interp
  276. - keys
  277. - loop_wrap
  278. - imported
  279. - enabled
  280. 1) The :code:`type` must be put as the first attribute of each track.
  281. The value of :code:`type` can be:
  282. - 'transform'
  283. - 'value'
  284. - 'method'
  285. 2) The :code:`path` has the format :code:`NodePath(Path/To/Node:Attribute)`.
  286. It is the path from animation root node (property of AnimationPlayer) to the
  287. animated node or attrbute.
  288. 3) The :code:`interp` is the method to interpolate frames from the keyframes.
  289. it is a enum variable and can has value:
  290. - 0 (constant)
  291. - 1 (linear)
  292. - 2 (cubic)
  293. 4) The :code:`keys` is the keyframes, it appears as a PoolRealArray()
  294. but have different structure for track with different type
  295. - A transform track use every 12 real number in the :code:`keys` to describte a keyframe.
  296. The first number is the timestamp, the second number is the transision (default 1.0
  297. in transform track), followed by a three number translation vector, followed by
  298. four number rotation quaternion (x,y,z,w) and finally a three number scale vector.
  299. ::
  300. [sub_resource type="Animation" id=2]
  301. length = 4.95833
  302. loop = false
  303. step = 0.1
  304. tracks/0/type = "transform"
  305. tracks/0/path = NodePath("Armature001")
  306. tracks/0/interp = 1
  307. tracks/0/loop_wrap = true
  308. tracks/0/imported = true
  309. tracks/0/enabled = true
  310. tracks/0/keys = PoolRealArray( 0, 1, -0.0358698, -0.829927, 0.444204, 0, 0, 0, 1, 0.815074, 0.815074, 0.815074, 4.95833, 1, -0.0358698, -0.829927, 0.444204, 0, 0, 0, 1, 0.815074, 0.815074, 0.815074 )
  311. tracks/1/type = "transform"
  312. tracks/1/path = NodePath("Armature001/Skeleton:Bone.001")
  313. tracks/1/interp = 1
  314. tracks/1/loop_wrap = true
  315. tracks/1/imported = true
  316. tracks/1/enabled = false
  317. tracks/1/keys = PoolRealArray( 0, 1, 0, 5.96046e-08, 0, 0, 0, 0, 1, 1, 1, 1, 4.95833, 1, 0, 5.96046e-08, 0, 0, 0, 0, 1, 1, 1, 1 )