コード例 #1
0
        private GameObject CreateScene(GLTFScene scene)
        {
            var sceneObj = new GameObject(scene.Name ?? "GLTFScene");

            foreach (var node in scene.Nodes)
            {
                var nodeObj = CreateNode(node.Value);
                nodeObj.transform.SetParent(sceneObj.transform, false);
            }

            return(sceneObj);
        }
コード例 #2
0
        public static GLTFScene Deserialize(GLTFRoot root, JsonReader reader)
        {
            var scene = new GLTFScene();

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

                switch (curProp)
                {
                case "nodes":
                    scene.Nodes = GLTFNodeId.ReadList(root, reader);
                    break;

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

            return(scene);
        }
コード例 #3
0
        private static void MergeScenes(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes)
        {
            if (mergeFromRoot.Scenes == null)
            {
                return;
            }

            if (mergeToRoot.Scenes == null)
            {
                mergeToRoot.Scenes = new List <GLTFScene>(mergeFromRoot.Scenes.Count);
            }

            mergeToRoot.Scenes.AddRange(mergeFromRoot.Scenes);
            for (int i = previousGLTFSizes.PreviousSceneCount; i < mergeToRoot.Scenes.Count; ++i)
            {
                GLTFScene scene = mergeToRoot.Scenes[i];
                foreach (NodeId nodeId in scene.Nodes)
                {
                    nodeId.Id  += previousGLTFSizes.PreviousNodeCount;
                    nodeId.Root = mergeToRoot;
                }
            }
        }
コード例 #4
0
ファイル: GLTFRoot.cs プロジェクト: seacloud9/UnityGLTFLoader
        public static GLTFRoot Deserialize(JsonReader reader)
        {
            var root = new GLTFRoot();

            if (reader.Read() && reader.TokenType != JsonToken.StartObject)
            {
                throw new Exception("gltf json must be an object");
            }

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

                switch (curProp)
                {
                case "extensionsUsed":
                    root.ExtensionsUsed = reader.ReadStringList();
                    break;

                case "extensionsRequired":
                    root.ExtensionsRequired = reader.ReadStringList();
                    break;

                case "accessors":
                    root.Accessors = reader.ReadList(() => GLTFAccessor.Deserialize(root, reader));
                    break;

                case "animations":
                    root.Animations = reader.ReadList(() => GLTFAnimation.Deserialize(root, reader));
                    break;

                case "asset":
                    root.Asset = GLTFAsset.Deserialize(root, reader);
                    break;

                case "buffers":
                    root.Buffers = reader.ReadList(() => GLTFBuffer.Deserialize(root, reader));
                    break;

                case "bufferViews":
                    root.BufferViews = reader.ReadList(() => GLTFBufferView.Deserialize(root, reader));
                    break;

                case "cameras":
                    root.Cameras = reader.ReadList(() => GLTFCamera.Deserialize(root, reader));
                    break;

                case "images":
                    root.Images = reader.ReadList(() => GLTFImage.Deserialize(root, reader));
                    break;

                case "materials":
                    root.Materials = reader.ReadList(() => GLTFMaterial.Deserialize(root, reader));
                    break;

                case "meshes":
                    root.Meshes = reader.ReadList(() => GLTFMesh.Deserialize(root, reader));
                    break;

                case "nodes":
                    root.Nodes = reader.ReadList(() => GLTFNode.Deserialize(root, reader));
                    break;

                case "samplers":
                    root.Samplers = reader.ReadList(() => GLTFSampler.Deserialize(root, reader));
                    break;

                case "scene":
                    root.Scene = GLTFSceneId.Deserialize(root, reader);
                    break;

                case "scenes":
                    root.Scenes = reader.ReadList(() => GLTFScene.Deserialize(root, reader));
                    break;

                case "skins":
                    root.Skins = reader.ReadList(() => GLTFSkin.Deserialize(root, reader));
                    break;

                case "textures":
                    root.Textures = reader.ReadList(() => GLTFTexture.Deserialize(root, reader));
                    break;

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

            return(root);
        }