Exemplo n.º 1
0
        /// <summary>
        /// Constructs a new Material.
        /// </summary>
        /// <param name="material">Unmanaged AiMaterial struct.</param>
        internal Material(AiMaterial material)
        {
            _properties = new Dictionary<String, MaterialProperty>();
            _textures = new Dictionary<int, List<TextureSlot>>();

            if(material.NumProperties > 0 && material.Properties != IntPtr.Zero) {
                AiMaterialProperty[] properties = MemoryHelper.MarshalArray<AiMaterialProperty>(material.Properties, (int) material.NumProperties, true);
                for(int i = 0; i < properties.Length; i++) {
                    MaterialProperty prop = new MaterialProperty(properties[i]);
                    _properties.Add(prop.FullyQualifiedName, prop);
                }
            }
            //Idea is to look at each texture type, and get the "TextureSlot" struct of each one. They're essentially stored in a dictionary where each type contains a bucket
            //of textures. It seems just looping over properties will yield duplicates (no idea what the non $tex.file properties are, but they all seem to contain the same texture info).
            //So hopefully doing it this way will give a nice and concise list of textures that can easily be retrieved, and all pertinent info (file path, wrap mode, etc) will be available to
            //the user.
            foreach(var texType in Enum.GetValues(typeof(TextureType))) {
                TextureType type = (TextureType) texType;
                if(type != TextureType.None) {
                    uint count = AssimpMethods.GetMaterialTextureCount(ref material, type);
                    for(uint i = 0; i < count; i++) {
                        List<TextureSlot> slots;
                        if(!_textures.TryGetValue((int) type, out slots)) {
                            slots = new List<TextureSlot>();
                            _textures.Add((int) type, slots);
                        }
                        slots.Add(AssimpMethods.GetMaterialTexture(ref material, type, i));
                    }
                }
            }
        }
Exemplo n.º 2
0
 private static extern ReturnCode aiGetMaterialTexture(ref AiMaterial mat, TextureType type, uint index, out AiString path, out TextureMapping mapping, out uint uvIndex, out float blendFactor, out TextureOperation textureOp, out TextureWrapMode wrapMode, out uint flags);
Exemplo n.º 3
0
 private static extern ReturnCode aiGetMaterialProperty(ref AiMaterial mat, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] String key, uint texType, uint texIndex, out IntPtr propertyOut);
Exemplo n.º 4
0
 private static extern ReturnCode aiGetMaterialString(ref AiMaterial mat, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] String key, uint texType, uint texIndex, out AiString str);
Exemplo n.º 5
0
 private static extern ReturnCode aiGetMaterialColor(ref AiMaterial mat, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] String key, uint texType, uint texIndex, IntPtr colorOut);
Exemplo n.º 6
0
 private static extern ReturnCode aiGetMaterialIntegerArray(ref AiMaterial mat, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] String key, uint texType, uint texIndex, IntPtr ptrOut, ref uint valueCount);
Exemplo n.º 7
0
 public static extern uint GetMaterialTextureCount(ref AiMaterial mat, TextureType type);
Exemplo n.º 8
0
 /// <summary>
 /// Gets the texture filepath contained in the material.
 /// </summary>
 /// <param name="mat">Material to retrieve the data from</param>
 /// <param name="type">Texture type semantic</param>
 /// <param name="index">Texture index</param>
 /// <returns>The texture filepath, if it exists. If not an empty string is returned.</returns>
 public static String GetMaterialTextureFilePath(ref AiMaterial mat, TextureType type, uint index)
 {
     AiString str;
     TextureMapping mapping;
     uint uvIndex;
     float blendFactor;
     TextureOperation texOp;
     TextureWrapMode wrapMode;
     uint flags;
     ReturnCode code = aiGetMaterialTexture(ref mat, type, index, out str, out mapping, out uvIndex, out blendFactor, out texOp, out wrapMode, out flags);
     if(code == ReturnCode.Success) {
         return str.GetString();
     }
     return String.Empty;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Gets all values pertaining to a particular texture from a material.
 /// </summary>
 /// <param name="mat">Material to retrieve the data from</param>
 /// <param name="type">Texture type semantic</param>
 /// <param name="index">Texture index</param>
 /// <returns>Returns the texture slot struct containing all the information.</returns>
 public static TextureSlot GetMaterialTexture(ref AiMaterial mat, TextureType type, uint index)
 {
     AiString str;
     TextureMapping mapping;
     uint uvIndex;
     float blendFactor;
     TextureOperation texOp;
     TextureWrapMode wrapMode;
     uint flags;
     ReturnCode code = aiGetMaterialTexture(ref mat, type, index, out str, out mapping, out uvIndex, out blendFactor, out texOp, out wrapMode, out flags);
     return new TextureSlot(str.GetString(), type, index, mapping, uvIndex, blendFactor, texOp, wrapMode, flags);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Retrieves a string from the material property table.
 /// </summary>
 /// <param name="mat">Material to retrieve the data from</param>
 /// <param name="key">Ai mat key (base) name to search for</param>
 /// <param name="texType">Texture Type semantic, always zero for non-texture properties</param>
 /// <param name="texIndex">Texture index, always zero for non-texture properties</param>
 /// <returns>The string, if it exists. If not, an empty string is returned.</returns>
 public static String GetMaterialString(ref AiMaterial mat, String key, TextureType texType, uint texIndex)
 {
     AiString str;
     ReturnCode code = aiGetMaterialString(ref mat, key, (uint) texType, texIndex, out str);
     if(code == ReturnCode.Success) {
         return str.GetString();
     }
     return String.Empty;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Retrieves a material property with the specific key from the material.
 /// </summary>
 /// <param name="mat">Material to retrieve the property from</param>
 /// <param name="key">Ai mat key (base) name to search for</param>
 /// <param name="texType">Texture Type semantic, always zero for non-texture properties</param>
 /// <param name="texIndex">Texture index, always zero for non-texture properties</param>
 /// <returns>The material property, if found.</returns>
 public static AiMaterialProperty GetMaterialProperty(ref AiMaterial mat, String key, TextureType texType, uint texIndex)
 {
     IntPtr ptr;
     ReturnCode code = aiGetMaterialProperty(ref mat, key, (uint)texType, texIndex, out ptr);
     AiMaterialProperty prop = new AiMaterialProperty();
     if(code == ReturnCode.Success && ptr != IntPtr.Zero) {
         prop = MemoryHelper.MarshalStructure<AiMaterialProperty>(ptr);
     }
     return prop;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Retrieves an array of integer values with the specific key from the material.
 /// </summary>
 /// <param name="mat">Material to retrieve the data from</param>
 /// <param name="key">Ai mat key (base) name to search for</param>
 /// <param name="texType">Texture Type semantic, always zero for non-texture properties</param>
 /// <param name="texIndex">Texture index, always zero for non-texture properties</param>
 /// <param name="intCount">The maximum number of integers to read. This may not accurately describe the data returned, as it may not exist or be smaller. If this value is less than
 /// the available integers, then only the requested number is returned (e.g. 1 or 2 out of a 4 float array).</param>
 /// <returns>The integer array, if it exists</returns>
 public static int[] GetMaterialIntegerArray(ref AiMaterial mat, String key, TextureType texType, uint texIndex, uint intCount)
 {
     IntPtr ptr = IntPtr.Zero;
     try {
         ptr = Marshal.AllocHGlobal(IntPtr.Size);
         ReturnCode code = aiGetMaterialIntegerArray(ref mat, key, (uint) texType, texIndex, ptr, ref intCount);
         int[] array = null;
         if(code == ReturnCode.Success && intCount > 0) {
             array = new int[intCount];
             Marshal.Copy(ptr, array, 0, (int) intCount);
         }
         return array;
     } finally {
         if(ptr != IntPtr.Zero) {
             Marshal.FreeHGlobal(ptr);
         }
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Retrieves a color value from the material property table.
 /// </summary>
 /// <param name="mat">Material to retrieve the data from</param>
 /// <param name="key">Ai mat key (base) name to search for</param>
 /// <param name="texType">Texture Type semantic, always zero for non-texture properties</param>
 /// <param name="texIndex">Texture index, always zero for non-texture properties</param>
 /// <returns>The color if it exists. If not, the default Color4D value is returned.</returns>
 public static Color4D GetMaterialColor(ref AiMaterial mat, String key, TextureType texType, uint texIndex)
 {
     IntPtr ptr = IntPtr.Zero;
     try {
         ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Color4D)));
         aiGetMaterialColor(ref mat, key, (uint) texType, texIndex, ptr);
         Color4D color = new Color4D();
         if(ptr != IntPtr.Zero) {
             color = MemoryHelper.MarshalStructure<Color4D>(ptr);
         }
         return color;
     } finally {
         if(ptr != IntPtr.Zero) {
             Marshal.FreeHGlobal(ptr);
         }
     }
 }