Example #1
0
        /// <summary>
        /// Extract each .bmp texture from the material or group and store it into the TextureName attributes
        /// </summary>
        /// <param name="objData">Data parsed from the obj file</param>
        public static void ParseTextures(ObjData objData)
        {
            foreach (ObjectObj objectObj in objData.ObjectsList)
            {
                if (objectObj.GroupName == null)
                {
                    if (objectObj.ObjectName != null)
                    {
                        objectObj.GroupName = objectObj.ObjectName;
                    }
                    else // Impossible to set a group name (unlikely to happen)
                    {
                        continue;
                    }
                }

                if (objectObj.MaterialName == null) // If no material
                {
                    objectObj.MaterialName = objectObj.GroupName;
                }

                if (objectObj.TextureName == null) // No texture assigned currently
                {
                    string textureName = GenericUtils.ExtractTextureNameFromMaterial(objectObj.MaterialName);
                    if (textureName == null) // No bmp found in the material
                    {
                        textureName = GenericUtils.ExtractTextureNameFromMaterial(objectObj.GroupName);
                    }
                    objectObj.TextureName = textureName;
                }
            }
        }