public ArraySegment <byte> Get(string url)
        {
            var bytes =
                (url.StartsWith("data:"))
                ? UriByteBuffer.ReadEmbeded(url)
                : File.ReadAllBytes(Path.Combine(m_root, url))
            ;

            return(new ArraySegment <byte>(bytes));
        }
Exemplo n.º 2
0
        static TextureItem _ImportTexture(glTF gltf, int index)
        {
            var image = gltf.images[index];

            if (string.IsNullOrEmpty(image.uri))
            {
                // use buffer view
                var texture = new Texture2D(2, 2);
                texture.name = string.IsNullOrEmpty(image.extra.name) ? string.Format("buffer#{0:00}", index) : image.extra.name;
                var byteSegment = gltf.GetViewBytes(image.bufferView);

                var bytes = byteSegment.ToArray();

                texture.LoadImage(bytes, true);
                return(new TextureItem(texture, index, false));
            }
            else if (image.uri.StartsWith("data:"))
            {
                // embeded
                var bytes   = UriByteBuffer.ReadEmbeded(image.uri);
                var texture = new Texture2D(2, 2);
                texture.name = string.IsNullOrEmpty(image.extra.name) ? "embeded" : image.extra.name;
                texture.LoadImage(bytes);
                return(new TextureItem(texture, index, false));
            }
#if UNITY_EDITOR
            else if (gltf.baseDir.StartsWith("Assets/"))
            {
                // local folder
                var path = Path.Combine(gltf.baseDir, image.uri);
                UnityEditor.AssetDatabase.ImportAsset(path);
                var texture = UnityEditor.AssetDatabase.LoadAssetAtPath <Texture2D>(path);
                texture.name = string.IsNullOrEmpty(image.extra.name) ? Path.GetFileNameWithoutExtension(path) : image.extra.name;
                return(new TextureItem(texture, index, true));
            }
#endif
            else
            {
                // external
                var path    = Path.Combine(gltf.baseDir, image.uri);
                var bytes   = File.ReadAllBytes(path);
                var texture = new Texture2D(2, 2);
                texture.name = string.IsNullOrEmpty(image.extra.name) ? Path.GetFileNameWithoutExtension(path) : image.extra.name;
                texture.LoadImage(bytes);
                return(new TextureItem(texture, index, false));
            }
        }
Exemplo n.º 3
0
        public ArraySegment <byte> Get(string url)
        {
            if (url.StartsWith("data:"))
            {
                return(new ArraySegment <byte>(UriByteBuffer.ReadEmbeded(url)));
            }

            var path = Path.Combine(m_root, url);

            if (_cache == null || _cache.Path != path)
            {
                _cache = new Cache
                {
                    Path  = path,
                    Bytes = File.ReadAllBytes(path)
                };
            }
            return(new ArraySegment <byte>(_cache.Bytes));
        }