private static void LoadTextures(AssetImporterGltfMeshContext context)
        {
            if (context.Model.Textures == null)
            {
                return;
            }

            for (int t = 0; t < context.Model.Textures.Length; t++)
            {
                glTFLoader.Schema.Texture tex = context.Model.Textures[t];
                if (tex.Source == null)
                {
                    continue;
                }

                int   imageIndex = tex.Source.Value;
                Image img        = context.Model.Images[imageIndex];

                using (Stream str = glTFLoader.Interface.OpenImageFile(context.Model, imageIndex, context.FullFilename))
                {
                    string surfaceAssetName = GetImageAssetName(img, imageIndex, context.FullFilename);

                    AssetImporterSurface2D.Import(str, surfaceAssetName, context.PackageToSaveIn.PackageName, context.FullFilename, out Surface2D surface);
                    if (surface != null)
                    {
                        context.ImportedAssets.Add(surface);
                    }
                }
            }
        }
    private Texture2D LoadTexture(glTFLoader.Schema.Texture texture)
    {
        string path = "Assets/cache_" + texture.Name + ".png";

        string sourceID = texture.Source;

        glTFLoader.Schema.Image image = m_model.Images[sourceID];
        Bitmap bitmap = image.Uri;

        bitmap.Save(path);

        byte[]    data = File.ReadAllBytes(path);
        Texture2D res  = new Texture2D(2, 2);

        res.LoadImage(data); // auto resize

        string          samplerID = texture.Sampler;
        Sampler         sampler   = m_model.Samplers[samplerID];
        TextureWrapMode wrapS     = s_wrapSMode[sampler.WrapS];
        TextureWrapMode wrapT     = s_wrapTMode[sampler.WrapT];

        if (wrapS == wrapT)
        {
            res.wrapMode = wrapS;
        }
        else
        {
            throw new System.NotImplementedException("Texture wrap mode not supported");
        }
        return(res);
    }
Ejemplo n.º 3
0
        private int GetTextureFromBitmap(Bitmap bitmap)
        {
            var image = GetImageFromBitmap(bitmap);

            int imageIdx = dummy.Images.AddAndReturnIndex(image);

            var texture = new glTFLoader.Schema.Texture()
            {
                Source  = imageIdx,
                Sampler = 0
            };

            return(dummy.Textures.AddAndReturnIndex(texture));
        }
Ejemplo n.º 4
0
        private int AddTextureToBuffers(string texturePath)
        {
            var image = GetImageFromFile(texturePath);

            int imageIdx = dummy.Images.AddAndReturnIndex(image);

            var texture = new glTFLoader.Schema.Texture()
            {
                Source  = imageIdx,
                Sampler = 0
            };

            return(dummy.Textures.AddAndReturnIndex(texture));
        }