} // SkipSection() #region Autodesk Functions void ObjectBuilding() { ClassImportedModel impMesh = new ClassImportedModel(); //this'll be thrown away, but HAS to exist to compile int depthSt = depth; while (true) { Utilities.ReadSkip(fileCompl, white, ref iterator); //puts the iterator on the start of the next word currentWord = Utilities.ReadTill(fileCompl, white, ref iterator); if (currentWord[0] == ';') { //comment line //goes to the next line and restarts the loop Utilities.ReadTill(fileCompl, newLn, ref iterator); continue; } // if if (currentWord[0] == '\"') { Debug.Log("hi"); //handle quoted information. For now this just include the model name //in syntax "Model::NAME" if (System.Text.RegularExpressions.Regex.IsMatch(currentWord.ToString(), "\"Model::\\S+\"")) { //meshNames.Add(currentWord.ToString().Substring(8,currentWord.Length-10)); //Doing this arbitrarily. The next mesh name should come right after creating an impMesh //which means it's for the last member of the impMeshes list impMeshes[impMeshes.Count - 1].SetName(currentWord.ToString().Substring(8, currentWord.Length - 10)); impMeshes[impMeshes.Count - 1].SetOrig(ImpRotPoint()); } // if continue; } // if if (currentWord[0] == '{') { depth++; continue; } // if if (currentWord[0] == '}') { if (--depth == depthSt) { impModels.Add(impMesh); //add last mesh return; // done with Objects: section } // if continue; } // if switch (currentWord.ToString()) { case "Geometry:": if (impMesh.id != 0) { impModels.Add(impMesh); } // if Utilities.ReadSkip(fileCompl, white, ref iterator); //puts the iterator on the start of the next word impMesh = new ClassImportedModel(); impMesh.id = Convert.ToInt32(Utilities.ReadTill(fileCompl, comma, ref iterator).ToString()); //next word should be FBXID, with comma at end iterator++; //get off the comma character break; case "Vertices:": impMesh.SetVerts(ImpVerts()); break; case "PolygonVertexIndex:": impMesh.SetPolyVerts(ImpPolyVerts()); //poly-verts needs the size of the vert array because of how Unity does norms/uvs break; case "Model:": Utilities.ReadSkip(fileCompl, white, ref iterator); //puts the iterator on the start of the next word impMeshes.Add(new ClassImpMesh(Convert.ToInt32(Utilities.ReadTill(fileCompl, comma, ref iterator).ToString()))); // next word should be modelID, with comma at end iterator++; //get off the comma character break; case "LayerElementNormal:": impMesh.SetNorms(ImpNorms()); break; case "UV:": impMesh.SetUVs(ImpUVPoints()); break; case "UVIndex:": impMesh.SetUVIndex(ImpUVIndex()); break; default: break; } // switch } //while(true) } // ObjectBuilding()
} // Connections() #endregion #region Blender Functions void BlenderObjectBuilding() { ClassImportedModel impMesh = new ClassImportedModel(); //this'll be thrown away, but HAS to exist to compile int depthSt = depth; while(true) { Utilities.ReadSkip(fileCompl, white, ref iterator); //puts the iterator on the start of the next word currentWord = Utilities.ReadTill(fileCompl, white, ref iterator); if(currentWord[0] == ';') { //comment line //goes to the next line and restarts the loop Utilities.ReadTill(fileCompl, newLn, ref iterator); continue; } // if if(currentWord[0] == '\"') { //handle quoted information. For now this just include the model name //in syntax "Model::NAME" if(System.Text.RegularExpressions.Regex.IsMatch(currentWord.ToString(), "\"Model::\\S+\"")) { //meshNames.Add(currentWord.ToString().Substring(8,currentWord.Length-10)); //Doing this arbitrarily. The next mesh name should come right after creating an impMesh //which means it's for the last member of the impMeshes list impMeshes[impMeshes.Count-1].SetName(currentWord.ToString().Substring(8,currentWord.Length-10)); impMeshes[impMeshes.Count-1].SetOrig(ImpRotPoint()); } // if continue; } // if if(currentWord[0] == '{') { depth++; continue; } // if if(currentWord[0] == '}') { if(--depth==depthSt) { impModels.Add(impMesh);//add last mesh return; // done with Objects: section } // if continue; } // if switch(currentWord.ToString()) { case "Geometry:": if(impMesh.id != 0) { impModels.Add(impMesh); } // if Utilities.ReadSkip(fileCompl, white, ref iterator); //puts the iterator on the start of the next word impMesh = new ClassImportedModel(); impMesh.id = Convert.ToInt32(Utilities.ReadTill(fileCompl, comma, ref iterator).ToString()); //next word should be FBXID, with comma at end iterator++;//get off the comma character break; case "Vertices:": impMesh.SetVerts(ImpVerts()); break; case "PolygonVertexIndex:": impMesh.SetPolyVerts(ImpPolyVerts()); //poly-verts needs the size of the vert array because of how Unity does norms/uvs break; case "Model:": Utilities.ReadSkip(fileCompl, white, ref iterator); //puts the iterator on the start of the next word impMeshes.Add(new ClassImpMesh(Convert.ToInt32(Utilities.ReadTill(fileCompl, comma, ref iterator).ToString()))); // next word should be modelID, with comma at end iterator++;//get off the comma character break; case "LayerElementNormal:": impMesh.SetNorms(ImpNorms()); break; case "UV:": impMesh.SetUVs(ImpUVPoints()); break; case "UVIndex:": impMesh.SetUVIndex(ImpUVIndex()); break; default: break; } // switch } //while(true) } // BlenderObjectBuilding()
} // FinalizeAsset() #region Util Functions void UnifyVerts(ClassImportedModel impModel) { int i, j; int[] polyVerts = impModel.GetPolyVerts(); int[] uvIndex = impModel.GetUVIndex(); Vector3[] verts = impModel.GetVerts(); Vector3[] norms = impModel.GetNorms(); Vector2[] uvs = impModel.GetUVs(); List <VertexClass> vList = new List <VertexClass>(); VertexClass vc; for (i = 0; i < polyVerts.Length; i++) { vc = new VertexClass(); vc.pos = verts[polyVerts[i]]; vc.uv = uvs[uvIndex[i]]; if (norms.Length == verts.Length) { vc.norm = norms[polyVerts[i]]; } // if else { vc.norm = norms[i]; //HERE } if (vList.Count < 1) { polyVerts[i] = i; vList.Add(vc); continue; } // if for (j = 0; j < vList.Count; j++) { if (vList[j].pos == vc.pos && vList[j].uv == vc.uv && vList[j].norm == vc.norm) { polyVerts[i] = j; break; } if (j == vList.Count - 1) { polyVerts[i] = i; vList.Add(vc); } //if } // for } // for verts = new Vector3[vList.Count]; norms = new Vector3[vList.Count]; uvs = new Vector2[vList.Count]; for (i = 0; i < verts.Length; i++) { verts[i] = vList[i].pos; norms[i] = vList[i].norm; uvs[i] = vList[i].uv; } // for impModel.SetVerts(verts); impModel.SetNorms(norms); impModel.SetUVs(uvs); impModel.SetPolyVerts(polyVerts); return; } // UnifyVerts()
} // FinalizeAsset() #region Util Functions void UnifyVerts(ClassImportedModel impModel) { int i,j; int[] polyVerts = impModel.GetPolyVerts(); int[] uvIndex = impModel.GetUVIndex(); Vector3[] verts = impModel.GetVerts(); Vector3[] norms = impModel.GetNorms(); Vector2[] uvs = impModel.GetUVs(); List<VertexClass> vList = new List<VertexClass>(); VertexClass vc; for(i=0;i<polyVerts.Length;i++) { vc = new VertexClass(); vc.pos = verts[polyVerts[i]]; vc.uv = uvs[uvIndex[i]]; if(norms.Length == verts.Length) { vc.norm = norms[polyVerts[i]]; } // if else { vc.norm = norms[i]; //HERE } if(vList.Count<1) { polyVerts[i] = i; vList.Add(vc); continue; } // if for(j = 0; j<vList.Count; j++) { if(vList[j].pos == vc.pos && vList[j].uv == vc.uv && vList[j].norm == vc.norm) { polyVerts[i] = j; break; } if(j==vList.Count-1) { polyVerts[i] = i; vList.Add(vc); } //if } // for } // for verts = new Vector3[vList.Count]; norms = new Vector3[vList.Count]; uvs = new Vector2[vList.Count]; for(i=0;i<verts.Length;i++) { verts[i] = vList[i].pos; norms[i] = vList[i].norm; uvs[i] = vList[i].uv; } // for impModel.SetVerts(verts); impModel.SetNorms(norms); impModel.SetUVs(uvs); impModel.SetPolyVerts(polyVerts); return; } // UnifyVerts()