示例#1
0
        public Node(Node node, GLTFRoot gltfRoot) : base(node, gltfRoot)
        {
            if (node == null)
            {
                return;
            }

            UseTRS = node.UseTRS;

            if (node.Camera != null)
            {
                Camera = new CameraId(node.Camera, gltfRoot);
            }

            if (node.Children != null)
            {
                Children = new List <NodeId>(node.Children.Count);
                foreach (NodeId child in node.Children)
                {
                    Children.Add(new NodeId(child, gltfRoot));
                }
            }

            if (node.Skin != null)
            {
                Skin = new SkinId(node.Skin, gltfRoot);
            }

            if (node.Matrix != null)
            {
                Matrix = new Matrix4x4(node.Matrix);
            }

            if (node.Mesh != null)
            {
                Mesh = new MeshId(node.Mesh, gltfRoot);
            }

            Rotation = node.Rotation;

            Scale = node.Scale;

            Translation = node.Translation;

            if (node.Weights != null)
            {
                Weights = node.Weights.ToList();
            }

            if (node.Light != null)
            {
                Light = node.Light;
            }
        }
示例#2
0
        public static Node Deserialize(GLTFRoot root, JsonReader reader)
        {
            var node = new Node();

            while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
            {
                var curProp = reader.Value.ToString();

                switch (curProp)
                {
                case "camera":
                    node.Camera = CameraId.Deserialize(root, reader);
                    break;

                case "children":
                    node.Children = NodeId.ReadList(root, reader);
                    break;

                case "skin":
                    node.Skin = SkinId.Deserialize(root, reader);
                    break;

                case "matrix":
                    var list = reader.ReadDoubleList();
                    // gltf has column ordered matricies
                    UnityEngine.Vector4 c1 = new UnityEngine.Vector4((float)list[0], (float)list[1], (float)list[2], (float)list[3]);
                    UnityEngine.Vector4 c2 = new UnityEngine.Vector4((float)list[4], (float)list[5], (float)list[6], (float)list[7]);
                    UnityEngine.Vector4 c3 = new UnityEngine.Vector4((float)list[8], (float)list[9], (float)list[10], (float)list[11]);
                    UnityEngine.Vector4 c4 = new UnityEngine.Vector4((float)list[12], (float)list[13], (float)list[14], (float)list[15]);

                    var mat = new Matrix4x4(c1, c2, c3, c4);

                    node.Matrix = mat;
                    break;

                case "mesh":
                    node.Mesh = MeshId.Deserialize(root, reader);
                    break;

                case "rotation":
                    node.UseTRS   = true;
                    node.Rotation = reader.ReadAsQuaternion();
                    break;

                case "scale":
                    node.UseTRS = true;
                    node.Scale  = reader.ReadAsVector3();
                    break;

                case "translation":
                    node.UseTRS      = true;
                    node.Translation = reader.ReadAsVector3();
                    break;

                case "weights":
                    node.Weights = reader.ReadDoubleList();
                    break;

                default:
                    node.DefaultPropertyDeserializer(root, reader);
                    break;
                }
            }

            return(node);
        }
示例#3
0
 public SkinId(SkinId id, GLTFRoot newRoot) : base(id, newRoot)
 {
 }