Пример #1
0
        private static List <ObjObject> GetObjObjects(ShaderProgram aProgram, List <ObjData> tempObjData,
                                                      List <MtlData> tempMtlDatas, string fileDirectory)
        {
            List <ObjObject> temObjObjects = new List <ObjObject>();


            int vertexOffset = 0;
            int uVOffset     = 0;
            int normalOffset = 0;

            foreach (ObjData anObjData in tempObjData)
            {
                MeshData tempMeshData = ParseFromLines(anObjData.Lines, vertexOffset, uVOffset, normalOffset);
                vertexOffset += tempMeshData.Vertices.Length;
                uVOffset     += tempMeshData.TexCoords.Length;
                normalOffset += tempMeshData.Normals.Length;

                ObjObject tempObjObject = tempMeshData.ToObjObject();
                tempObjObject.Name = anObjData.Name;

                // Add the material
                if (tempMtlDatas != null)
                {
                    MtlData     tempMtlData         = tempMtlDatas.Find(x => x.Name == anObjData.UseMtl);
                    ObjMaterial tempMat             = new ObjMaterial(aProgram, tempMtlData);
                    string      tempDiffuseTextPath = Path.Combine(fileDirectory, tempMtlData.DiffuseMapFileName);
                    Texture     tempTexture         = new Texture(tempDiffuseTextPath);
                    tempMat.DiffuseMap     = tempTexture;
                    tempObjObject.Material = tempMat;
                }

                temObjObjects.Add(tempObjObject);
            }
            return(temObjObjects);
        }
Пример #2
0
        private static List <MtlData> GetMtlDatas(List <string> mtlLines)
        {
            List <MtlData> mtlDatas = new List <MtlData>();

            char[]  splitChars = { ' ' };
            string  line;
            MtlData tempData = null;

            foreach (string aLine in mtlLines)
            {
                line = aLine.Trim(splitChars);
                line = line.Replace("  ", " ");

                string[] parameters = line.Split(splitChars);

                switch (parameters[0])
                {
                case "newmtl":
                    tempData = new MtlData(parameters[1]);
                    mtlDatas.Add(tempData);
                    break;

                case "Ns":
                    if (tempData != null)
                    {
                        tempData.Ns = double.Parse(parameters[1]);
                    }
                    break;

                case "Ni":
                    if (tempData != null)
                    {
                        tempData.Ni = double.Parse(parameters[1]);
                    }
                    break;

                case "d":
                    if (tempData != null)
                    {
                        tempData.d = double.Parse(parameters[1]);
                    }
                    break;

                case "illum":
                    if (tempData != null)
                    {
                        tempData.illum = int.Parse(parameters[1]);
                    }
                    break;

                case "Ka":
                    if (tempData != null)
                    {
                        tempData.Ka = new Vector3(float.Parse(parameters[1]), float.Parse(parameters[2]),
                                                  float.Parse(parameters[3]));
                    }
                    break;

                case "Kd":
                    if (tempData != null)
                    {
                        tempData.Kd = new Vector3(float.Parse(parameters[1]), float.Parse(parameters[2]),
                                                  float.Parse(parameters[3]));
                    }
                    break;

                case "Ks":
                    if (tempData != null)
                    {
                        tempData.Ks = new Vector3(float.Parse(parameters[1]), float.Parse(parameters[2]),
                                                  float.Parse(parameters[3]));
                    }
                    break;

                case "map_Kd":
                    if (tempData != null)
                    {
                        tempData.DiffuseMapFileName = parameters[1];
                    }
                    break;
                }
            }

            return(mtlDatas);
        }