public static AnimationChannel Deserialize(GLTFRoot root, JsonReader reader) { var animationChannel = new AnimationChannel(); while (reader.Read() && reader.TokenType == JsonToken.PropertyName) { var curProp = reader.Value.ToString(); switch (curProp) { case "sampler": animationChannel.Sampler = SamplerId.Deserialize(root, reader); break; case "target": animationChannel.Target = AnimationChannelTarget.Deserialize(root, reader); break; default: animationChannel.DefaultPropertyDeserializer(root, reader); break; } } return(animationChannel); }
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); }
private SamplerId ExportSampler(UnityEngine.Texture texture) { var samplerId = _root.GetSamplerId(texture); if (samplerId != null) { return(samplerId); } var sampler = new Sampler(); if (texture.wrapMode == TextureWrapMode.Clamp) { sampler.WrapS = WrapMode.ClampToEdge; sampler.WrapT = WrapMode.ClampToEdge; } else { sampler.WrapS = WrapMode.Repeat; sampler.WrapT = WrapMode.Repeat; } if (texture.filterMode == FilterMode.Point) { sampler.MinFilter = MinFilterMode.NearestMipmapNearest; sampler.MagFilter = MagFilterMode.Nearest; } else if (texture.filterMode == FilterMode.Bilinear) { sampler.MinFilter = MinFilterMode.NearestMipmapLinear; sampler.MagFilter = MagFilterMode.Linear; } else { sampler.MinFilter = MinFilterMode.LinearMipmapLinear; sampler.MagFilter = MagFilterMode.Linear; } samplerId = new SamplerId { Id = _root.Samplers.Count, Root = _root }; _root.Samplers.Add(sampler); return(samplerId); }
private static void MergeAnimationsAndSkins(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes) { if (mergeFromRoot.Skins != null) { if (mergeToRoot.Skins == null) { mergeToRoot.Skins = new List <Skin>(mergeFromRoot.Skins.Count); } mergeToRoot.Skins.AddRange(mergeFromRoot.Skins); for (int i = previousGLTFSizes.PreviousSkinCount; i < mergeToRoot.Skins.Count; ++i) { Skin skin = mergeToRoot.Skins[i]; if (skin.InverseBindMatrices != null) { skin.InverseBindMatrices.Id += previousGLTFSizes.PreviousAccessorCount; } if (skin.Skeleton != null) { skin.Skeleton.Id += previousGLTFSizes.PreviousNodeCount; } if (skin.Joints != null) { foreach (NodeId joint in skin.Joints) { joint.Id += previousGLTFSizes.PreviousNodeCount; } } } } if (mergeFromRoot.Animations != null) { if (mergeToRoot.Animations == null) { mergeToRoot.Animations = new List <Animation>(mergeFromRoot.Animations.Count); } mergeToRoot.Animations.AddRange(mergeFromRoot.Animations); for (int i = previousGLTFSizes.PreviousAnimationCount; i < mergeToRoot.Animations.Count; ++i) { Animation animation = mergeToRoot.Animations[i]; foreach (AnimationSampler sampler in animation.Samplers) { AccessorId inputId = sampler.Input; inputId.Id += previousGLTFSizes.PreviousAccessorCount; inputId.Root = mergeToRoot; AccessorId outputId = sampler.Output; outputId.Id += previousGLTFSizes.PreviousAccessorCount; outputId.Root = mergeToRoot; } foreach (AnimationChannel channel in animation.Channels) { SamplerId samplerId = channel.Sampler; samplerId.Id += previousGLTFSizes.PreviousSamplerCount; samplerId.Root = mergeToRoot; NodeId nodeId = channel.Target.Node; nodeId.Id += previousGLTFSizes.PreviousNodeCount; nodeId.Root = mergeToRoot; } } } }
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; } } } }