Exemplo n.º 1
0
        private static GameObject ImportGLTF(string filepath, ImportSettings importSettings, out GLTFAnimation.ImportResult[] animations)
        {
            string json = File.ReadAllText(filepath);

            // Parse json
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            return(gltfObject.LoadInternal(filepath, importSettings, out animations));
        }
Exemplo n.º 2
0
        private static GameObject ImportGLB(string filepath, ImportSettings importSettings, out AnimationClip[] animations)
        {
            FileStream stream = File.OpenRead(filepath);
            long       binChunkStart;
            string     json       = GetGLBJson(stream, out binChunkStart);
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            return(gltfObject.LoadInternal(filepath, null, binChunkStart, importSettings, out animations));
        }
Exemplo n.º 3
0
        private static GameObject ImportGLB(byte[] bytes, ImportSettings importSettings, out AnimationClip[] animations)
        {
            Stream     stream = new MemoryStream(bytes);
            long       binChunkStart;
            string     json       = GetGLBJson(stream, out binChunkStart);
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            return(gltfObject.LoadInternal(null, bytes, binChunkStart, importSettings, out animations));
        }
Exemplo n.º 4
0
        private static void ImportGLB(byte[] bytes, ImportSettings importSettings, Action <GameObject, AnimationClip[]> onFinished)
        {
            Stream     stream = new MemoryStream(bytes);
            long       binChunkStart;
            string     json       = GetGLBJson(stream, out binChunkStart);
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            StaticCoroutine.Start(gltfObject.LoadInternal(null, bytes, binChunkStart, importSettings, onFinished));
        }
Exemplo n.º 5
0
        private static void ImportGLB(string filepath, ImportSettings importSettings, Action <GameObject, AnimationClip[]> onFinished)
        {
            FileStream stream = File.OpenRead(filepath);
            long       binChunkStart;
            string     json       = GetGLBJson(stream, out binChunkStart);
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            StaticCoroutine.Start(gltfObject.LoadInternal(filepath, null, binChunkStart, importSettings, onFinished));
        }
Exemplo n.º 6
0
        private static void ImportGLTF(string filepath, ImportSettings importSettings, Action <GameObject, AnimationClip[]> onFinished)
        {
            string json = File.ReadAllText(filepath);

            // Parse json
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            StaticCoroutine.Start(gltfObject.LoadInternal(filepath, null, 0, importSettings, onFinished));
        }
Exemplo n.º 7
0
        private static GameObject ImportGLB(byte[] bytes, ImportSettings importSettings, out AnimationClip[] animations, Action <GameObject, Dictionary <string, object> > handleExtensions = null)
        {
            Stream     stream = new MemoryStream(bytes);
            long       binChunkStart;
            string     json       = GetGLBJson(stream, out binChunkStart);
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);
            var        go         = gltfObject.LoadInternal(null, bytes, binChunkStart, importSettings, out animations);

            if (gltfObject.extras != null)
            {
                handleExtensions(go, gltfObject.extras);
            }

            return(go);
        }
Exemplo n.º 8
0
        private static GameObject ImportGLB(string filepath, ImportSettings importSettings, out GLTFAnimation.ImportResult[] animations)
        {
            byte[] bytes = File.ReadAllBytes(filepath);
            animations = null;

            // 12 byte header
            // 0-4  - magic = "glTF"
            // 4-8  - version = 2
            // 8-12 - length = total length of glb, including Header and all Chunks, in bytes.
            string magic = Encoding.ASCII.GetString(bytes.SubArray(0, 4));

            if (magic != "glTF")
            {
                Debug.LogWarning("File at " + filepath + " does not look like a .glb file");
                return(null);
            }
            uint version = System.BitConverter.ToUInt32(bytes, 4);

            if (version != 2)
            {
                Debug.LogWarning("Importer does not support gltf version " + version);
                return(null);
            }
            // What do we even need the length for.
            //uint length = System.BitConverter.ToUInt32(bytes, 8);

            // Chunk 0 (json)
            uint chunkLength = System.BitConverter.ToUInt32(bytes, 12);
            // This prints out JSON. So predictable.
            //string chunkType = Encoding.ASCII.GetString(bytes.SubArray(16, 4));
            string json = Encoding.ASCII.GetString(bytes.SubArray(20, (int)chunkLength));
            // Parse json
            GLTFObject gltfObject = JsonConvert.DeserializeObject <GLTFObject>(json);

            return(gltfObject.LoadInternal(filepath, importSettings, out animations));
        }