source: OniSplit/Totoro/BodyDaeWriter.cs

Last change on this file was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 2.6 KB
RevLine 
[1114]1using System;
2using Oni.Motoko;
3
4namespace Oni.Totoro
5{
6 internal class BodyDaeWriter
7 {
8 private static readonly Vector3[] defaultPose =
9 {
10 new Vector3(0.0f, 90.0f, 90.0f),
11
12 new Vector3(0.0f, 180.0f, 0.0f),
13 new Vector3(0.0f, 0.0f, 0.0f),
14 new Vector3(0.0f, 0.0f, 0.0f),
15
16 new Vector3(0.0f, 180.0f, 0.0f),
17 new Vector3(0.0f, 0.0f, 0.0f),
18 new Vector3(0.0f, 0.0f, 0.0f),
19
20 new Vector3(0.0f, 0.0f, 0.0f),
21 new Vector3(0.0f, 0.0f, 0.0f),
22 new Vector3(0.0f, 0.0f, 0.0f),
23 new Vector3(0.0f, 0.0f, 0.0f),
24
25 new Vector3(90.0f, 90.0f, 90.0f),
26 new Vector3(0.0f, 90.0f, 0.0f),
27 new Vector3(0.0f, 0.0f, 0.0f),
28 new Vector3(-90.0f, 0.0f, 0.0f),
29
30 new Vector3(-90.0f, -90.0f, 90.0f),
31 new Vector3(0.0f, -90.0f, 0.0f),
32 new Vector3(0.0f, 0.0f, 0.0f),
33 new Vector3(90.0f, 0.0f, 0.0f)
34 };
35
36 private readonly GeometryDaeWriter geometryWriter;
37
38 public BodyDaeWriter(GeometryDaeWriter geometryWriter)
39 {
40 this.geometryWriter = geometryWriter;
41 }
42
43 public Dae.Node Write(Body body, bool noAnimation, InstanceDescriptor[] textures)
44 {
45 return WriteNode(body.Root, noAnimation, textures);
46 }
47
48 private Dae.Node WriteNode(BodyNode bodyNode, bool useDefaultPose, InstanceDescriptor[] textures)
49 {
50 if (textures != null)
51 bodyNode.Geometry.Texture = textures[bodyNode.Index];
52
53 var daeNode = geometryWriter.WriteNode(bodyNode.Geometry, bodyNode.Name);
54
55 daeNode.Transforms.Translate("pos", bodyNode.Translation);
56
57 if (useDefaultPose)
58 {
59 var rot = defaultPose[bodyNode.Index];
60
61 daeNode.Transforms.Rotate("rotX", Vector3.Right, rot.X);
62 daeNode.Transforms.Rotate("rotY", Vector3.Up, rot.Y);
63 daeNode.Transforms.Rotate("rotZ", Vector3.Backward, rot.Z);
64 }
65 else
66 {
67 daeNode.Transforms.Rotate("rotX", Vector3.Right, 0.0f);
68 daeNode.Transforms.Rotate("rotY", Vector3.Up, 0.0f);
69 daeNode.Transforms.Rotate("rotZ", Vector3.Backward, 0.0f);
70 }
71
72 foreach (var childBodyNode in bodyNode.Nodes)
73 daeNode.Nodes.Add(WriteNode(childBodyNode, useDefaultPose, textures));
74
75 return daeNode;
76 }
77 }
78}
Note: See TracBrowser for help on using the repository browser.