Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. when isMainModule:
  2. import
  3. atlas,
  4. skeleton_json,
  5. yaml.serialization as yaml,
  6. streams,
  7. tables
  8.  
  9. type
  10. SkeletonJson = object
  11. skeleton: Skeleton
  12. bones: seq[Bone]
  13. slots: seq[Slot]
  14. path: seq[Path]
  15. skins: Table[string, Table[string, Table[string, Attachment]]]
  16. animations: Table[string, Animation]
  17.  
  18. Skeleton = object
  19. hash: string
  20. spine: string
  21. width: float
  22. height: float
  23. fps: int
  24. images: string
  25.  
  26. Bone = object
  27. name: string
  28. parent: string
  29. length: float
  30. rotation: float
  31. x, y: float
  32. color: string
  33.  
  34. Slot = object
  35. name: string
  36. bone: string
  37. attachment: string
  38.  
  39. RotateMode {.pure.} = enum
  40. ChainScale = "chainScale"
  41.  
  42. Path = object
  43. name: string
  44. order: int
  45. bones: seq[string]
  46. target: string
  47. rotateMode: RotateMode
  48.  
  49. AttachmentType {.pure.} = enum
  50. Mesh = "mesh", Path = "path"
  51.  
  52. Attachment = object
  53. `type`: AttachmentType
  54. uvs: seq[float]
  55. triangles: seq[int]
  56. vertices: seq[float]
  57. hull: int
  58. edges: seq[int]
  59. width: int
  60. height: int
  61. lengths: seq[float]
  62. vertexCount: int
  63.  
  64. Animation = object
  65. slots: Table[string, SlotTimeline]
  66. bones: Table[string, BoneTimeline]
  67.  
  68. SlotTimeline = object
  69. color: seq[ColorKeyframe]
  70. attachment: seq[AttachmentKeyframe]
  71.  
  72. AttachmentKeyframe = object
  73. time: float
  74. name: string
  75.  
  76. ColorKeyframe = object
  77. time: float
  78. color: string
  79. curve: seq[float]
  80.  
  81. BoneTimeline = object
  82. rotate: seq[RotateKeyframe]
  83. translate: seq[TranslateKeyframe]
  84. scale: seq[ScaleKeyframe]
  85. shear: seq[ShearKeyframe]
  86.  
  87. RotateKeyframe = object
  88. time: float
  89. curve: seq[float]
  90. angle: float
  91.  
  92. TransformKeyframe = object
  93. time: float
  94. curve: seq[float]
  95. x, y: float
  96.  
  97. TranslateKeyframe = TransformKeyframe
  98. ScaleKeyframe = TransformKeyframe
  99. ShearKeyframe = TransformKeyframe
  100.  
  101. var sk: SkeletonJson
  102.  
  103. var s = newFileStream("../spine-sfml/data/vine.json")
  104.  
  105.  
  106. setDefaultValue(Bone, parent, nil)
  107. setDefaultValue(Bone, length, 0.0)
  108. setDefaultValue(Bone, rotation, 0.0)
  109. setDefaultValue(Bone, x, 0.0)
  110. setDefaultValue(Bone, y, 0.0)
  111. setDefaultValue(Bone, color, nil)
  112.  
  113. setDefaultValue(Attachment, triangles, nil)
  114. setDefaultValue(Attachment, uvs, nil)
  115. setDefaultValue(Attachment, hull, 0)
  116. setDefaultValue(Attachment, edges, nil)
  117. setDefaultValue(Attachment, width, 0)
  118. setDefaultValue(Attachment, height, 0)
  119.  
  120. setDefaultValue(Attachment, lengths, nil)
  121. setDefaultValue(Attachment, vertexCount, 0)
  122.  
  123. setDefaultValue(SlotTimeline, attachment, nil)
  124. setDefaultValue(SlotTimeline, color, nil)
  125.  
  126. setDefaultValue(BoneTimeline, rotate, nil)
  127. setDefaultValue(BoneTimeline, translate, nil)
  128. setDefaultValue(BoneTimeline, scale, nil)
  129. setDefaultValue(BoneTimeline, shear, nil)
  130.  
  131. setDefaultValue(ColorKeyframe, curve, nil)
  132.  
  133. setDefaultValue(RotateKeyframe, curve, nil)
  134. setDefaultValue(TransformKeyframe, curve, nil)
  135.  
  136.  
  137. yaml.load(s, sk)
  138. s.close()
  139.  
  140. echo repr sk.animations["animation"].slots["vine"].color[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement