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);
        }
示例#2
0
        /// <summary>
        /// Export a normal texture from Unity to glTF.
        /// </summary>
        /// <param name="texture">Normal texture to export</param>
        /// <param name="material">Material the normal is used on</param>
        /// <param name="gltf">Context glTF to export to</param>
        /// <returns>glTF texture info</returns>
        protected static NormalTextureInfo ExportNormalTextureInfo(
            UnityEngine.Texture texture,
            UnityEngine.Material material,
            IGltfWritable gltf
            )
        {
            var texture2d = texture as Texture2D;

            if (texture2d == null)
            {
                return(null);
            }
            var imageExport = new NormalImageExport(texture2d);

            if (AddImageExport(gltf, imageExport, out var textureId))
            {
                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);
            }
            return(null);
        }
        private NormalTextureInfo ExportNormalTextureInfo(UnityEngine.Texture texture, UnityEngine.Material material)
        {
            var info = new NormalTextureInfo();

            info.Index = ExportTexture(texture);

            if (material.HasProperty("_BumpScale"))
            {
                info.Scale = material.GetFloat("_BumpScale");
            }

            return(info);
        }
示例#4
0
        private Schema.MaterialNormalTextureInfo ConvertNormalTextureInfo(NormalTextureInfo runtimeTextureInfo)
        {
            var textureInfo = CreateInstance <Schema.MaterialNormalTextureInfo>();

            textureInfo.Index = ConvertTexture(runtimeTextureInfo.Texture);

            if (runtimeTextureInfo.TexCoord.HasValue)
            {
                textureInfo.TexCoord = runtimeTextureInfo.TexCoord.Value;
            }

            if (runtimeTextureInfo.Scale.HasValue)
            {
                textureInfo.Scale = runtimeTextureInfo.Scale.Value;
            }

            return(textureInfo);
        }