void CSketch::glCommands(bool select, bool marked, bool no_color) { if(m_coordinate_system && m_draw_with_transform) { glPushMatrix(); m_coordinate_system->ApplyMatrix(); } ObjList::glCommands(select,marked,no_color); if(m_solidify) { try { //TODO: we should really only be doing this when geometry changes std::vector<TopoDS_Face> faces = GetFaces(); double pixels_per_mm = wxGetApp().GetPixelScale(); for(unsigned i=0; i < faces.size(); i++) { MeshFace(faces[i],pixels_per_mm); DrawFaceWithCommands(faces[i]); } }catch(...) { } } if(m_coordinate_system && m_draw_with_transform) glPopMatrix(); }
void CPrimalGrid::SetCoord_CG(su2double **val_coord) { unsigned short iDim, iNode, NodeFace, iFace; AD::StartPreacc(); AD::SetPreaccIn(val_coord, GetnNodes(), nDim); for (iDim = 0; iDim < nDim; iDim++) { Coord_CG[iDim] = 0.0; for (iNode = 0; iNode < GetnNodes(); iNode++) Coord_CG[iDim] += val_coord[iNode][iDim]/su2double(GetnNodes()); } for (iFace = 0; iFace < GetnFaces(); iFace++) for (iDim = 0; iDim < nDim; iDim++) { Coord_FaceElems_CG[iFace][iDim] = 0.0; for (iNode = 0; iNode < GetnNodesFace(iFace); iNode++) { NodeFace = GetFaces(iFace, iNode); Coord_FaceElems_CG[iFace][iDim] += val_coord[NodeFace][iDim]/su2double(GetnNodesFace(iFace)); } } AD::SetPreaccOut(Coord_CG, nDim); AD::SetPreaccOut(Coord_FaceElems_CG, GetnFaces(), nDim); AD::EndPreacc(); }
void SkeletalObject::CreateVBO() { assert(m_model != NULL); // Calculate the number of faces we have in total GetFaces(); // Allocate memory for our vertices and normals Lib3dsVector * vertices = new Lib3dsVector[m_TotalFaces * 3]; Lib3dsVector * normals = new Lib3dsVector[m_TotalFaces * 3]; Lib3dsTexel* texCoords = new Lib3dsTexel[m_TotalFaces * 3]; Lib3dsMesh * mesh; unsigned int FinishedFaces = 0; // Loop through all the meshes for(mesh = m_model->meshes;mesh != NULL;mesh = mesh->next) { lib3ds_mesh_calculate_normals(mesh, &normals[FinishedFaces*3]); // Loop through every face for(unsigned int cur_face = 0; cur_face < mesh->faces;cur_face++) { Lib3dsFace * face = &mesh->faceL[cur_face]; for(unsigned int i = 0;i < 3;i++) { if(mesh->texels) { memcpy(&texCoords[FinishedFaces*2 + i], mesh->texelL[face->points[ i ]], sizeof(Lib3dsTexel)); } memcpy(&vertices[FinishedFaces*3 + i], mesh->pointL[face->points[ i ]].pos, sizeof(Lib3dsVector)); } FinishedFaces++; } } // Generate a Vertex Buffer SkeletalObject and store it with our vertices glGenBuffers(1, &m_VertexVBO); glBindBuffer(GL_ARRAY_BUFFER, m_VertexVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Lib3dsVector) * 3 * m_TotalFaces, vertices, GL_STATIC_DRAW); // Generate another Vertex Buffer SkeletalObject and store the normals in it glGenBuffers(1, &m_NormalVBO); glBindBuffer(GL_ARRAY_BUFFER, m_NormalVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Lib3dsVector) * 3 * m_TotalFaces, normals, GL_STATIC_DRAW); // Generate a third VBO and store the texture coordinates in it. glGenBuffers(1, &m_TexCoordVBO); glBindBuffer(GL_ARRAY_BUFFER, m_TexCoordVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Lib3dsTexel) * 3 * m_TotalFaces, texCoords, GL_STATIC_DRAW); // Clean up our allocated memory delete vertices; delete normals; delete texCoords; // We no longer need lib3ds lib3ds_file_free(m_model); m_model = NULL; }
void Geometry::Shape2BVHMesh(const TopoDS_Shape &shape, BVHMeshPtr model) { model->beginModel(); BRepMesh_IncrementalMesh(shape, IfcGeom::GetValue(IfcGeom::GV_DEFLECTION_TOLERANCE)); FaceSet faces; GetFaces(shape,faces); for (auto face=faces.begin();face!=faces.end();++face){ Face2BVHMesh(*face,model); } model->endModel(); }
void Geometry::Shape2Polygons(const TopoDS_Shape &s, Geometry::PolySet &polys) { FaceSet faces; GetFaces(s,faces); pcl::PlanarPolygon<PointT> poly; for (FaceSet::iterator it = faces.begin();it!=faces.end();++it) { polys.push_back(new pcl::PlanarPolygon<PointT>); Face2Polygon(*it,poly); polys.at(polys.size()-1)=poly; } }
void CPrimalGrid::SetCG(double **val_coord) { unsigned short iDim, iNode, NodeFace, iFace; for (iDim = 0; iDim < nDim; iDim++) { Coord_CG[iDim] = 0.0; for (iNode = 0; iNode < GetnNodes(); iNode++) Coord_CG[iDim] += val_coord[iNode][iDim]/double(GetnNodes()); } for (iFace = 0; iFace < GetnFaces(); iFace++) for (iDim = 0; iDim < nDim; iDim++) { Coord_FaceElems_CG[iFace][iDim] = 0.0; for (iNode = 0; iNode < GetnNodesFace(iFace); iNode++) { NodeFace = GetFaces(iFace, iNode); Coord_FaceElems_CG[iFace][iDim] += val_coord[NodeFace][iDim]/double(GetnNodesFace(iFace)); } } }
void Geometry::UpdateDiagnostics(Diagnostic& renderer, const D3DXMATRIX& world) { if(renderer.AllowDiagnostics(Diagnostic::MESH)) { std::string id = StringCast(this); const auto& faces = GetFaces(); const float normalsize = 0.6f; for(unsigned int i = 0; i < faces.size(); ++i) { D3DXVECTOR3 center, normal; D3DXVec3TransformCoord(¢er, &faces[i].center, &world); D3DXVec3TransformNormal(&normal, &faces[i].normal, &world); D3DXVec3Normalize(&normal, &normal); renderer.UpdateLine(Diagnostic::MESH, "FaceNormal" + StringCast(i) + id, Diagnostic::CYAN, center, center + (normal * normalsize)); } } }
std::shared_ptr<Scene> SceneFactory::CreateFromFile(const std::string& filename) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_ImproveCacheLocality | aiProcess_JoinIdenticalVertices | aiProcess_PreTransformVertices); if (scene == NULL) { std::printf("\nImport failed:\n\t"); auto errorString = importer.GetErrorString(); std::printf(errorString); std::printf("\n"); return nullptr; } Scene::vertexList vertices = GetVertices(scene); Scene::triangleList faces = GetFaces(scene); Scene::materialList materials = GetMaterials(scene); return std::shared_ptr<Scene>(new Scene(vertices, faces, materials)); }
void main () { char filename[64]; FILE *f; int meshes=0; long start=0, end=0, last=0; mdh_tempholder temp[MAX_MESHES]; printf("WARNING TEXTURE NAMES LACK EXTENSTION!\nASE -> DH Convert v%d\n\n", VERSION); printf ("Enter File name : "); scanf("%s", filename); if (f = fopen(filename, "r")) { while (FindNextToken(f, "*GEOMOBJECT", last, &start, &end)) { char str[64], meshname[64]; char texture[64]; int *faces, *tfaces; float *verts, *vnorms, *tverts = NULL; int numverts=0, numfaces=0, numtverts=0, numtfaces=0; int mesh_no, s, e; // maybe get texture mesh_no = meshes++; GetName(f, str, start, end); str[strlen(str)-1] = 0; sscanf(str, "\"%s", meshname); // TODO : if tag remove! and add tag vectors at end of file //sprintf(texture, "%s.nfo", meshname); strcpy(texture, meshname); printf("Reading node %s.\n", meshname); GetInfo(f, start, end, &numverts, &numfaces, &numtverts, &numtfaces); // Allocate faces = (int *)malloc (numfaces * 3 * sizeof(int)); verts = (float *)malloc (numverts * 3 * sizeof(float)); vnorms = (float *)malloc (numverts * 3 * sizeof(float)); if (numtverts) tverts = (float *)malloc (numtverts * 3 * sizeof(float)); if (numtfaces) tfaces = (int *)malloc (numtfaces * 3 * sizeof(int)); // get the data printf("MESH_VERTEX_LIST "); FindNextToken(f, "*MESH_VERTEX_LIST", start, &s, &e); GetVerts(f, verts, s, e); printf("MESH_FACE_LIST "); FindNextToken(f, "*MESH_FACE_LIST", start, &s, &e); GetFaces(f, faces, s, e); printf("MESH_NORMALS "); FindNextToken(f, "*MESH_NORMALS", start, &s, &e); GetVNorms(f, vnorms, s, e); // Only these are optional if (numtverts) { printf("MESH_TVERTLIST "); FindNextToken(f, "*MESH_TVERTLIST", start, &s, &e); GetTVerts(f, tverts, s, e); } if (numtfaces) { printf("MESH_TFACELIST "); FindNextToken(f, "*MESH_TFACELIST", start, &s, &e); GetTFaces(f, tfaces, s, e); } printf("\n"); rewind(f); last = end; // store them for a mo strcpy (temp[mesh_no].name, meshname); strcpy (temp[mesh_no].texture, texture); temp[mesh_no].num_faces = numfaces; temp[mesh_no].num_verts = numverts; temp[mesh_no].faces = faces; temp[mesh_no].verts = verts; temp[mesh_no].norms = vnorms; if (numtverts) temp[mesh_no].tverts = tverts; else temp[mesh_no].tverts = NULL; // Dunno if i need t verts } fclose(f); filename[strlen(filename)-3] = 0; strcat(filename, "dh4"); if (f = fopen(filename, "wb")) { int i; WriteDH4(f, meshes, temp); fclose(f); for (i = 0; i < meshes; i++) { free (temp[i].faces); free (temp[i].verts); free (temp[i].norms); if (temp[i].tverts) free (temp[i].tverts); } } } }
void ase_model::Load(char *file_name) { long start = 0, end = 0, last = 0; FILE *f; if (f = fopen(file_name, "r")) { int mesh_no = 0; no_meshes = 0; while (FindNextToken(f, "*GEOMOBJECT", last, &start, &end)) { no_meshes++; last = end; } rewind(f); mesh = new ase_mesh_t [no_meshes]; start = 0; end = 0; last = 0; while (FindNextToken(f, "*GEOMOBJECT", last, &start, &end)) { char str[64]; long s, e; // maybe get texture GetName(f, str, start, end); str[strlen(str)-1] = 0; // sscanf(str, "\"%s", mesh->name); strcpy(mesh[mesh_no].name, str+1); //printf("Reading node %s.\n", meshname); GetInfo(f, start, end, &mesh[mesh_no].numverts, &mesh[mesh_no].numfaces, &mesh[mesh_no].numtverts, &mesh[mesh_no].numtfaces); // Allocate mesh[mesh_no].faces = new int[mesh[mesh_no].numfaces * 3]; mesh[mesh_no].verts = new float[mesh[mesh_no].numverts * 3]; mesh[mesh_no].vnorms = new float[mesh[mesh_no].numverts * 3]; if (mesh[mesh_no].numtverts) mesh[mesh_no].tverts = new float[mesh[mesh_no].numtverts * 3]; if (mesh[mesh_no].numtfaces) mesh[mesh_no].tfaces = new int[mesh[mesh_no].numtfaces * 3]; // get the data //printf("MESH_VERTEX_LIST "); FindNextToken(f, "*MESH_VERTEX_LIST", start, &s, &e); GetVerts(f, mesh[mesh_no].verts, s, e); //printf("MESH_FACE_LIST "); FindNextToken(f, "*MESH_FACE_LIST", start, &s, &e); GetFaces(f, mesh[mesh_no].faces, s, e); //printf("MESH_NORMALS "); FindNextToken(f, "*MESH_NORMALS", start, &s, &e); GetVNorms(f, mesh[mesh_no].vnorms, s, e); // Only these are optional if (mesh[mesh_no].numtverts) { // printf("MESH_TVERTLIST "); FindNextToken(f, "*MESH_TVERTLIST", start, &s, &e); GetTVerts(f, mesh[mesh_no].tverts, s, e); } if (mesh[mesh_no].numtfaces) { // printf("MESH_TFACELIST "); FindNextToken(f, "*MESH_TFACELIST", start, &s, &e); GetTFaces(f, mesh[mesh_no].tfaces, s, e); } //printf("\n"); rewind(f); last = end; mesh_no++; } fclose(f); } }