public static new OcclusionTextureInfo Deserialize(GLTFRoot root, JsonReader reader) { var textureInfo = new OcclusionTextureInfo(); if (reader.Read() && reader.TokenType != JsonToken.StartObject) { throw new Exception("Asset must be an object."); } while (reader.Read() && reader.TokenType == JsonToken.PropertyName) { var curProp = reader.Value.ToString(); switch (curProp) { case "index": textureInfo.Index = TextureId.Deserialize(root, reader); break; case "texCoord": textureInfo.TexCoord = reader.ReadAsInt32().Value; break; case "strength": textureInfo.Strength = reader.ReadAsDouble().Value; break; default: textureInfo.DefaultPropertyDeserializer(root, reader); break; } } return(textureInfo); }
private TextureId ExportTexture(UnityEngine.Texture textureObj) { TextureId id = _root.GetTextureId(textureObj); if (id != null) { return(id); } var texture = new Texture(); if (ExportNames) { texture.Name = textureObj.name; } texture.Source = ExportImage(textureObj); texture.Sampler = ExportSampler(textureObj); texture.Contents = textureObj; id = new TextureId { Id = _root.Textures.Count, Root = _root }; _root.Textures.Add(texture); return(id); }
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; } } } }