Пример #1
0
        private static void MergeAnimationsAndSkins(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes)
        {
            if (mergeFromRoot.Skins != null)
            {
                if (mergeToRoot.Skins == null)
                {
                    mergeToRoot.Skins = new List <Skin>(mergeFromRoot.Skins.Count);
                }

                mergeToRoot.Skins.AddRange(mergeFromRoot.Skins);
                for (int i = previousGLTFSizes.PreviousSkinCount; i < mergeToRoot.Skins.Count; ++i)
                {
                    Skin skin = mergeToRoot.Skins[i];
                    if (skin.InverseBindMatrices != null)
                    {
                        skin.InverseBindMatrices.Id += previousGLTFSizes.PreviousAccessorCount;
                    }

                    if (skin.Skeleton != null)
                    {
                        skin.Skeleton.Id += previousGLTFSizes.PreviousNodeCount;
                    }

                    if (skin.Joints != null)
                    {
                        foreach (NodeId joint in skin.Joints)
                        {
                            joint.Id += previousGLTFSizes.PreviousNodeCount;
                        }
                    }
                }
            }

            if (mergeFromRoot.Animations != null)
            {
                if (mergeToRoot.Animations == null)
                {
                    mergeToRoot.Animations = new List <Animation>(mergeFromRoot.Animations.Count);
                }

                mergeToRoot.Animations.AddRange(mergeFromRoot.Animations);

                for (int i = previousGLTFSizes.PreviousAnimationCount; i < mergeToRoot.Animations.Count; ++i)
                {
                    Animation animation = mergeToRoot.Animations[i];
                    foreach (AnimationSampler sampler in animation.Samplers)
                    {
                        AccessorId inputId = sampler.Input;
                        inputId.Id  += previousGLTFSizes.PreviousAccessorCount;
                        inputId.Root = mergeToRoot;

                        AccessorId outputId = sampler.Output;
                        outputId.Id  += previousGLTFSizes.PreviousAccessorCount;
                        outputId.Root = mergeToRoot;
                    }

                    foreach (AnimationChannel channel in animation.Channels)
                    {
                        SamplerId samplerId = channel.Sampler;
                        samplerId.Id  += previousGLTFSizes.PreviousSamplerCount;
                        samplerId.Root = mergeToRoot;

                        NodeId nodeId = channel.Target.Node;
                        nodeId.Id  += previousGLTFSizes.PreviousNodeCount;
                        nodeId.Root = mergeToRoot;
                    }
                }
            }
        }
Пример #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();
                    var mat  = new Matrix4x4();
                    for (var i = 0; i < 16; i++)
                    {
                        mat[i] = (float)list[i];
                    }
                    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);
        }