예제 #1
0
        public static Texture Deserialize(GLTFRoot root, JsonReader reader)
        {
            var texture = new Texture();

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

                switch (curProp)
                {
                case "sampler":
                    texture.Sampler = SamplerId.Deserialize(root, reader);
                    break;

                case "source":
                    texture.Source = ImageId.Deserialize(root, reader);
                    break;

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

            return(texture);
        }
예제 #2
0
        private ImageId ExportImage(UnityEngine.Texture texture)
        {
            ImageId id = _root.GetImageId(texture);

            if (id != null)
            {
                return(id);
            }

            var image = new Image();

            if (ExportNames)
            {
                image.Name = texture.name;
            }

            _images.Add(texture as Texture2D);

            image.Uri      = Uri.EscapeUriString(texture.name + ".png");
            image.Contents = texture;

            id = new ImageId {
                Id   = _root.Images.Count,
                Root = _root
            };

            _root.Images.Add(image);

            return(id);
        }
예제 #3
0
        private static void MergeMaterialsImagesTexturesAndSamplers(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes)
        {
            if (mergeFromRoot.Samplers != null)
            {
                if (mergeToRoot.Samplers == null)
                {
                    mergeToRoot.Samplers = new List <Sampler>(mergeFromRoot.Samplers.Count);
                }

                mergeToRoot.Samplers.AddRange(mergeFromRoot.Samplers);
            }

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

                mergeToRoot.Images.AddRange(mergeFromRoot.Images);
                for (int i = previousGLTFSizes.PreviousImageCount; i < mergeToRoot.Images.Count; ++i)
                {
                    Image image = mergeToRoot.Images[i];
                    if (image.BufferView != null)
                    {
                        BufferViewId bufferViewId = image.BufferView;
                        bufferViewId.Id  += previousGLTFSizes.PreviousBufferViewCount;
                        bufferViewId.Root = mergeToRoot;
                    }
                }
            }

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

                mergeToRoot.Textures.AddRange(mergeFromRoot.Textures);
                for (int i = previousGLTFSizes.PreviousTextureCount; i < mergeToRoot.Textures.Count; ++i)
                {
                    Texture texture = mergeToRoot.Textures[i];

                    if (texture.Sampler != null)
                    {
                        SamplerId samplerId = texture.Sampler;
                        samplerId.Id  += previousGLTFSizes.PreviousSamplerCount;
                        samplerId.Root = mergeToRoot;
                    }

                    if (texture.Source != null)
                    {
                        ImageId samplerId = texture.Source;
                        samplerId.Id  += previousGLTFSizes.PreviousImageCount;
                        samplerId.Root = mergeToRoot;
                    }
                }
            }

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

                mergeToRoot.Materials.AddRange(mergeFromRoot.Materials);
                for (int i = previousGLTFSizes.PreviousMaterialCount; i < mergeToRoot.Materials.Count; ++i)
                {
                    Material material = mergeToRoot.Materials[i];

                    PbrMetallicRoughness pbrMetallicRoughness = material.PbrMetallicRoughness;
                    if (pbrMetallicRoughness != null)
                    {
                        if (pbrMetallicRoughness.BaseColorTexture != null)
                        {
                            TextureId textureId = pbrMetallicRoughness.BaseColorTexture.Index;
                            textureId.Id  += previousGLTFSizes.PreviousTextureCount;
                            textureId.Root = mergeToRoot;
                        }
                        if (pbrMetallicRoughness.MetallicRoughnessTexture != null)
                        {
                            TextureId textureId = pbrMetallicRoughness.MetallicRoughnessTexture.Index;
                            textureId.Id  += previousGLTFSizes.PreviousTextureCount;
                            textureId.Root = mergeToRoot;
                        }
                    }

                    MaterialCommonConstant commonConstant = material.CommonConstant;
                    if (commonConstant?.LightmapTexture != null)
                    {
                        TextureId textureId = material.CommonConstant.LightmapTexture.Index;
                        textureId.Id  += previousGLTFSizes.PreviousTextureCount;
                        textureId.Root = mergeToRoot;
                    }

                    if (material.EmissiveTexture != null)
                    {
                        TextureId textureId = material.EmissiveTexture.Index;
                        material.EmissiveTexture.Index.Id += previousGLTFSizes.PreviousTextureCount;
                        textureId.Root = mergeToRoot;
                    }

                    if (material.NormalTexture != null)
                    {
                        TextureId textureId = material.NormalTexture.Index;
                        textureId.Id  += previousGLTFSizes.PreviousTextureCount;
                        textureId.Root = mergeToRoot;
                    }

                    if (material.OcclusionTexture != null)
                    {
                        TextureId textureId = material.OcclusionTexture.Index;
                        textureId.Id  += previousGLTFSizes.PreviousTextureCount;
                        textureId.Root = mergeToRoot;
                    }
                }
            }
        }