static NormalTextureInfo ExportNormalTextureInfo( UnityEngine.Texture texture, TextureMapType textureMapType, UnityEngine.Material material, IGltfWritable gltf ) { var imageId = gltf.AddImage(texture); if (imageId < 0) { return(null); } var textureId = gltf.AddTexture(imageId); var info = new NormalTextureInfo { index = textureId, // texCoord = 0 // TODO: figure out which UV set was used }; if (material.HasProperty(MaterialGenerator.bumpScalePropId)) { info.scale = material.GetFloat(MaterialGenerator.bumpScalePropId); } return(info); }
private ImageId ExportImage(UnityEngine.Texture texture, TextureMapType texturMapType) { ImageId id = GetImageId(_root, texture); if (id != null) { return(id); } var image = new Image(); if (ExportNames) { image.Name = texture.name; } _imageInfos.Add(new ImageInfo { texture = texture as Texture2D, textureMapType = texturMapType }); var path = _retrieveTexturePathDelegate(texture); var newPath = Path.ChangeExtension(path, ".png"); image.Uri = Uri.EscapeUriString(newPath); id = new ImageId { Id = _root.Images.Count, Root = _root }; _root.Images.Add(image); return(id); }
private TextureInfo ExportTextureInfo(UnityEngine.Texture texture, TextureMapType textureMapType) { var info = new TextureInfo(); info.Index = ExportTexture(texture, textureMapType); return(info); }
private OcclusionTextureInfo ExportOcclusionTextureInfo( UnityEngine.Texture texture, TextureMapType textureMapType, UnityEngine.Material material) { var info = new OcclusionTextureInfo(); info.Index = ExportTexture(texture, textureMapType); if (material.HasProperty("_OcclusionStrength")) { info.Strength = material.GetFloat("_OcclusionStrength"); } return(info); }
private NormalTextureInfo ExportNormalTextureInfo( UnityEngine.Texture texture, TextureMapType textureMapType, UnityEngine.Material material) { var info = new NormalTextureInfo(); info.Index = ExportTexture(texture, textureMapType); if (material.HasProperty("_BumpScale")) { info.Scale = material.GetFloat("_BumpScale"); } return(info); }
static TextureInfo ExportTextureInfo(UnityEngine.Texture texture, TextureMapType textureMapType, IGltfWritable gltf) { var imageId = gltf.AddImage(texture); if (imageId < 0) { return(null); } var textureId = gltf.AddTexture(imageId); var info = new TextureInfo { index = textureId, // texCoord = 0 // TODO: figure out which UV set was used }; return(info); }
private TextureId ExportTexture(UnityEngine.Texture textureObj, TextureMapType textureMapType) { TextureId id = GetTextureId(_root, textureObj); if (id != null) { return(id); } var texture = new GLTF.Schema.Texture(); //If texture name not set give it a unique name using count if (textureObj.name == "") { textureObj.name = (_root.Textures.Count + 1).ToString(); } if (ExportNames) { texture.Name = textureObj.name; } texture.Source = ExportImage(textureObj, textureMapType); texture.Sampler = ExportSampler(textureObj); _textures.Add(textureObj); id = new TextureId { Id = _root.Textures.Count, Root = _root }; _root.Textures.Add(texture); return(id); }
public async Task When_serializing_and_then_deserializing_should_produce_equivalent(string texture, TextureMapType textureMapType, MaterialAttributes materialAttributes) { var chunk = new TextureMapChunk { ParentId = 123, Id = 456, MapChannel = 2, MapType = textureMapType, Attributes = materialAttributes, CreationTime = new DateTime(2008, 8, 13, 16, 50, 13), Texture = texture, TgaTextureSize = 789 }; using (var ms = new MemoryStream()) { await chunk.SerializeAsync(ms, false); ms.Position = 0; // Act var deserializedChunk = new TextureMapChunk(); await deserializedChunk.DeserializeAsync(ms, false); // Assert deserializedChunk.Should().BeEquivalentTo(chunk); ms.Should().BeEof(); } }