Ejemplo n.º 1
0
        private string _getTextureFullPath(Assimp.TextureSlot texture)
        {
            string dir = Directory.GetParent(_filename).FullName;

            string p = texture.FilePath;

            if (p.Substring(0, 2) == ".\\")
            {
                p = p.Substring(2, p.Length - 2);
            }

            return(dir + "/" + p);
        }
Ejemplo n.º 2
0
        private static Ai.Material CreateAiMaterialFromMaterial(Material material, TextureSet textureSet)
        {
            var aiMaterial = new Ai.Material();

            aiMaterial.Name          = material.Name;
            aiMaterial.ColorDiffuse  = material.Diffuse.ToAssimp();
            aiMaterial.ColorAmbient  = material.Ambient.ToAssimp();
            aiMaterial.ColorSpecular = material.Ambient.ToAssimp();
            aiMaterial.ColorEmissive = material.Emission.ToAssimp();
            aiMaterial.Shininess     = material.Shininess;
            aiMaterial.IsTwoSided    = material.DoubleSided;

            var exportedTypes = new HashSet <MaterialTextureType>();

            foreach (var materialTexture in material.MaterialTextures)
            {
                if (!sTextureTypeMap.TryGetValue(materialTexture.Type, out var type) ||
                    exportedTypes.Contains(materialTexture.Type))
                {
                    continue;
                }

                exportedTypes.Add(materialTexture.Type);

                var texture = textureSet?.Textures?.FirstOrDefault(x => x.Id == materialTexture.TextureId);
                if (texture == null)
                {
                    continue;
                }

                var aiTextureSlot = new Ai.TextureSlot();

                if (TextureFormatUtilities.IsBlockCompressed(texture.Format) && !texture.IsYCbCr)
                {
                    aiTextureSlot.FilePath = texture.Name + ".dds";
                }

                else
                {
                    aiTextureSlot.FilePath = texture.Name + ".png";
                }

                aiTextureSlot.TextureType = type;

                aiMaterial.AddMaterialTexture(in aiTextureSlot);
            }

            return(aiMaterial);
        }
Ejemplo n.º 3
0
        private static TextureInfo ConvertTexture(Ai.TextureSlot aiTextureSlot, string baseDirectoryPath)
        {
            var relativeFilePath = aiTextureSlot.FilePath;
            var fullFilePath     = Path.GetFullPath(Path.Combine(baseDirectoryPath, relativeFilePath));
            var textureName      = AssimpConverterCommon.UnescapeName(Path.GetFileNameWithoutExtension(relativeFilePath) + ".dds");

            Texture texture;

            if (!File.Exists(fullFilePath))
            {
                texture = Texture.CreateDefaultTexture(textureName);
            }
            else if (relativeFilePath.EndsWith(".dds", StringComparison.InvariantCultureIgnoreCase))
            {
                texture = new Texture(textureName, TextureFormat.DDS, File.ReadAllBytes(fullFilePath));
            }
            else
            {
                var bitmap = new Bitmap(fullFilePath);
                texture = TextureEncoder.Encode(textureName, TextureFormat.DDS, bitmap);
            }

            return(TextureInfo.GetTextureInfo(texture));
        }
Ejemplo n.º 4
0
        private SEAObject AppendTextureFromSlot(Scene scene, TextureSlot slot)
        {
            if (slot.FilePath.Length > 0 && slot.FilePath[0] != '*')
            {
                return AppendTexture(getURL(slot.FilePath));
            }
            else if (slot.TextureIndex < scene.TextureCount)
            {
                return AppendTexture(scene.Textures[slot.TextureIndex]);
            }

            return null;
        }
Ejemplo n.º 5
0
        private static MaterialTexture CreateMaterialTextureFromAiTextureSlot(Ai.TextureSlot aiTextureSlot,
                                                                              Ai.Material aiMaterial, Material material, TextureSet textureSet, string texturesDirectoryPath)
        {
            MaterialTextureType type;
            MaterialFlags       flags;

            // skyth y u no use dictionary
            switch (aiTextureSlot.TextureType)
            {
            case Ai.TextureType.Diffuse:
            case Ai.TextureType.Ambient:
                type  = MaterialTextureType.Color;
                flags = MaterialFlags.Color;
                break;

            case Ai.TextureType.Specular:
                type  = MaterialTextureType.Specular;
                flags = MaterialFlags.Specular;
                break;

            case Ai.TextureType.Normals:
                type  = MaterialTextureType.Normal;
                flags = MaterialFlags.Normal;
                break;

            case Ai.TextureType.Opacity:
                type  = MaterialTextureType.Transparency;
                flags = MaterialFlags.Transparency;
                break;

            case Ai.TextureType.Reflection:
                type  = MaterialTextureType.Reflection;
                flags = MaterialFlags.Environment;
                break;

            default:
                return(null);
            }

            int materialTextureIndex = -1;

            for (int i = 0; i < material.MaterialTextures.Length; i++)
            {
                if (material.MaterialTextures[i].Type != MaterialTextureType.None)
                {
                    continue;
                }

                materialTextureIndex = i;
                break;
            }

            if (materialTextureIndex == -1)
            {
                return(null);
            }

            var texture = CreateTextureFromFilePath(aiTextureSlot.FilePath,
                                                    type == MaterialTextureType.Normal ? TextureFormat.ATI2 : TextureFormat.Unknown, texturesDirectoryPath, textureSet);

            if (texture == null)
            {
                return(null);
            }

            var materialTexture = new MaterialTexture();

            materialTexture.RepeatU     = aiTextureSlot.WrapModeU == Ai.TextureWrapMode.Wrap;
            materialTexture.RepeatV     = aiTextureSlot.WrapModeV == Ai.TextureWrapMode.Wrap;
            materialTexture.MirrorU     = aiTextureSlot.WrapModeU == Ai.TextureWrapMode.Mirror;
            materialTexture.MirrorV     = aiTextureSlot.WrapModeV == Ai.TextureWrapMode.Mirror;
            materialTexture.ClampToEdge = aiTextureSlot.WrapModeU == Ai.TextureWrapMode.Clamp &&
                                          aiTextureSlot.WrapModeV == Ai.TextureWrapMode.Clamp;

            if (texture.ArraySize == 6 || aiTextureSlot.Mapping == Ai.TextureMapping.Box)
            {
                materialTexture.TextureCoordinateTranslationType = MaterialTextureCoordinateTranslationType.Cube;

                if (type == MaterialTextureType.Reflection)
                {
                    type = MaterialTextureType.EnvironmentCube;
                }
            }

            else if (aiTextureSlot.Mapping == Ai.TextureMapping.Sphere)
            {
                materialTexture.TextureCoordinateTranslationType = MaterialTextureCoordinateTranslationType.Sphere;

                if (type == MaterialTextureType.Reflection)
                {
                    type = MaterialTextureType.EnvironmentSphere;
                }
            }

            materialTexture.Blend  = type == MaterialTextureType.Specular ? 1u : 7;
            materialTexture.Filter = 2;
            materialTexture.MipMap = 2;

            materialTexture.Type      = type;
            materialTexture.TextureId = texture.Id;

            material.Flags |= flags;
            material.MaterialTextures[materialTextureIndex] = materialTexture;

            return(materialTexture);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the specific texture information for the texture type and texture index.
 /// </summary>
 /// <param name="texType">Texture type</param>
 /// <param name="index">Texture index</param>
 /// <returns>Texture information struct</returns>
 public TextureSlot GetTexture(TextureType texType, int index)
 {
     TextureSlot texSlot = new TextureSlot();
     if(texType != TextureType.None) {
         List<TextureSlot> slotList;
         if(_textures.TryGetValue((int) texType, out slotList)) {
             //Note: Unsure if the textures will be in the proper index order in our list, so to play it safe we're looking at all of them until
             //we find the index
             foreach(TextureSlot slot in slotList) {
                 if(slot.TextureIndex == index) {
                     return slot;
                 }
             }
         }
     }
     return texSlot;
 }
Ejemplo n.º 7
0
        private void ApplyMaterial(Material mat, ref OpenGL gl)
        {
            if (mat.GetMaterialTextureCount(TextureType.Diffuse) > 0)
            {
                TextureSlot tex = new TextureSlot();
                mat.GetMaterialTexture(TextureType.Diffuse, 0, out tex);
                LoadModelAsset(tex.FilePath, ref gl);
            }

            Color4 color = new Color4(.8f, .8f, .8f, 1.0f);
            if (mat.HasColorDiffuse)
            {
                // color = FromColor(mat.ColorDiffuse);
            }
            var colorf = new float[4];
            color4_to_float4(color, colorf);
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE, colorf);

            color = new Color4(0, 0, 0, 1.0f);
            if (mat.HasColorSpecular)
            {
                color = FromColor(mat.ColorSpecular);
            }
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_SPECULAR, colorf);

            color = new Color4(.2f, .2f, .2f, 1.0f);
            if (mat.HasColorAmbient)
            {
                color = FromColor(mat.ColorAmbient);
            }
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_AMBIENT, colorf);

            color = new Color4(0, 0, 0, 1.0f);
            if (mat.HasColorEmissive)
            {
                color = FromColor(mat.ColorEmissive);
            }
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_EMISSION, colorf);

            float shininess = 1;
            float strength = 1;
            if (mat.HasShininess)
            {
                shininess = mat.Shininess;
            }
            if (mat.HasShininessStrength)
            {
                strength = mat.ShininessStrength;
            }

            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_SHININESS, shininess * strength);
        }
Ejemplo n.º 8
0
        private Texture2D GetTextureFromSlot(GameMode gameMode, string modelDirectory, TextureSlot textureSlot)
        {
            if (string.IsNullOrEmpty(textureSlot.FilePath)) return null;

            var fileName = Path.GetFileName(textureSlot.FilePath) ?? "";
            var textureFilePath = Path.Combine(modelDirectory, fileName);

            if (!File.Exists(fileName)) return null;

            return gameMode.GetTextureFromRawFolder(textureFilePath);
        }
Ejemplo n.º 9
0
 private IMaterialTexture ConvertMaterialTexture(TextureSlot t)
 {
     return new MaterialTexture
     {
         HintPath = t.FilePath
     };
 }