void StackedPlot::draw(float width, float height) const { ofPushMatrix(); ofPushStyle(); int d = dimensions(); vector<ofMesh> meshes(d); for(int i = 0; i < d; i++) { meshes[i].setMode(OF_PRIMITIVE_TRIANGLE_STRIP); } list<vector<float> >::const_iterator itr; int i; for(itr = history.begin(), i = 0; itr != history.end(); itr++, i++) { const vector<float>& cur = *itr; for(int j = 0; j < d; j++) { meshes[j].addVertex(ofVec2f(i, cur[j])); meshes[j].addVertex(ofVec2f(i, cur[j + 1])); } } ofScale(width / (historyLength - 1), height); for(int i = 0; i < d; i++) { if(colors.size()) { ofSetColor(colors[i % colors.size()]); } else { float hue = ofMap(i, 0, d, 0, 255); ofSetColor(ofColor::fromHsb(hue, 255, 255)); } meshes[i].draw(); } ofPopMatrix(); ofPopStyle(); }
BaseMesh* LBSPBoolOp::ComputeBoolean(BaseMesh* mesh1, BaseMesh* mesh2, BOOL_OP op) { std::vector<BaseMesh*> meshes(2); meshes[0] =mesh1; meshes[1]= mesh2; OctTree * pOctTree = new OctTree(); pOctTree->BuildOctTree(meshes); // pOctTree->CarveTree(); // std::vector<FixedPlaneMesh*> criticalMeshes; std::vector<BaseMesh*> criticalMeshes; std::vector<BaseMesh*> nonecriticalMeshes; // pOctTree->GenMeshesFromCells(criticalMeshes, true); pOctTree->GenMeshesFromCells(nonecriticalMeshes, eCritical); delete pOctTree; // delete criticalMeshes[1]; delete nonecriticalMeshes[1]; /* for (int i = 0; i < nonecriticalMeshes[0]->PrimitiveCount(); i++) { const TriInfo& info= nonecriticalMeshes[0]->TriangleInfo(i); criticalMeshes[0]->Add(nonecriticalMeshes[0]->Vertex(info.VertexId[0]) , nonecriticalMeshes[0]->Vertex(info.VertexId[1]), nonecriticalMeshes[0]->Vertex(info.VertexId[2])); }*/ //delete nonecriticalMeshes[0]; return nonecriticalMeshes[0]; FixedBSPTree::SET_OP BSPOp; switch (op) { case eUnion: BSPOp = FixedBSPTree::OP_UNION; break; case eIntersect: BSPOp = FixedBSPTree::OP_INTERSECT; break; case eDiff: BSPOp = FixedBSPTree::OP_DIFFERENCE; break; default : break; } BaseMesh *result = new BaseMesh; BSPOctree *tree = new BSPOctree(BSPOp); tree->BSPOperation(mesh1, mesh2, &result); return result; }
GLVertexArray::GLVertexArray(const char *filename) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(filename, aiProcess_Triangulate); if(!scene){ fprintf(stderr, "%s", importer.GetErrorString()); } std::vector<const aiMesh *> meshes(scene->mMeshes,scene->mMeshes+scene->mNumMeshes); aiMesh *mesh = scene->mMeshes[0]; GLuint buffer; glGenVertexArrays(1, &_object); glBindVertexArray(_object); _point_count = mesh->mNumFaces * 3; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 *_point_count, mesh->mVertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0 , 3, GL_FLOAT, 0, 0, 0); float *tex_coords = new float[_point_count * 2]; for(int i = 0; i < meshes[0]->mNumVertices; i++) { tex_coords[i * 2] = mesh->mTextureCoords[0][i].x; tex_coords[i * 2 + 1] = mesh->mTextureCoords[0][i].y; } glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 2 * _point_count, tex_coords, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, 0, 0, 0); glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * _point_count, mesh->mNormals, GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, 0, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); }
//================================================================================================================================= /// Initializes the internal data structures used by the ray tracer. /// \param pVertexPositions The vertices of the mesh /// \param pIndices The face indices /// \param pFaceNormals The triangle normals /// \param nVertices The number of vertices /// \param nIndices The number of faces. /// \param pFaceClusters An array giving the cluster ID for each face /// \return True if successful, false if out of memory //================================================================================================================================= bool TootleRaytracer::Init(const float* pVertexPositions, const UINT* pIndices, const float* pFaceNormals, UINT nVertices, UINT nFaces, const UINT* pFaceClusters) { m_pFaceClusters = pFaceClusters; std::vector<JRTMesh*> meshes (1); m_pMesh = JRTMesh::CreateMesh((const Vec3f*) pVertexPositions, (const Vec3f*) pFaceNormals, nVertices, nFaces, pIndices); if (!m_pMesh) { return false; } // fix mesh so its centered on the origin // also scale down (doesn't scale up) it so it is inside the radius 1 ball in the origin. JRTBoundingBox bb = m_pMesh->ComputeBoundingBox(); Vec3f center = bb.GetCenter(); Vec3f size = bb.GetMax() - bb.GetMin(); float fLongestSide = std::max(size[0], size[1]); fLongestSide = 2.0f * std::max(fLongestSide, size[2]); fLongestSide = std::max(1.0f, fLongestSide); // make it at least 1 for (UINT i = 0; i < nVertices; i++) { float x = m_pMesh->GetVertex(i).x - center.x; float y = m_pMesh->GetVertex(i).y - center.y; float z = m_pMesh->GetVertex(i).z - center.z; m_pMesh->SetVertex(i, Vec3f(x, y, z) / fLongestSide); } meshes[0] = m_pMesh ; m_pCore = JRTCore::Build(meshes); if (!m_pCore) { JRT_SAFE_DELETE(m_pMesh); return false; } return true; }
std::vector<const SimpleAgentMeshHandler *> getMeshes() const { std::vector<const SimpleAgentMeshHandler *> meshes(1, &mesh); return meshes; }
//---------------------------------------------------------------------------- std::vector<TriMesh*> Castle::LoadMeshPNT1Multi (const std::string& name) { // Get the vertex format. VertexFormat* vformat = VertexFormat::Create(3, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_NORMAL, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); int vstride = vformat->GetStride(); // Get the positions. std::string filename = Environment::GetPathR(name); std::ifstream inFile(filename.c_str()); int numPositions; Float3* positions; GetFloat3(inFile, numPositions, positions); // Get the normals. int numNormals; Float3* normals; GetFloat3(inFile, numNormals, normals); // Get the texture coordinates. int numTCoords; Float2* tcoords; GetFloat2(inFile, numTCoords, tcoords); // Get the vertices and indices. int numMeshes; inFile >> numMeshes; std::vector<int> numTriangles(numMeshes); int numTotalTriangles = 0; int m; for (m = 0; m < numMeshes; ++m) { inFile >> numTriangles[m]; numTotalTriangles += numTriangles[m]; } std::vector<std::vector<int> >indices(numMeshes); VertexPNT1* vertices = new1<VertexPNT1>(3*numTotalTriangles); std::vector<VertexPNT1> PNT1Array; std::map<VertexPNT1,int> PNT1Map; for (m = 0; m < numMeshes; ++m) { for (int t = 0; t < numTriangles[m]; ++t) { for (int j = 0, k = 3*t; j < 3; ++j, ++k) { VertexPNT1& vertex = vertices[k]; inFile >> vertex.PIndex; inFile >> vertex.NIndex; inFile >> vertex.TIndex; std::map<VertexPNT1,int>::iterator miter = PNT1Map.find(vertex); int index; if (miter != PNT1Map.end()) { // Second or later time the vertex is encountered. index = miter->second; } else { // First time the vertex is encountered. index = (int)PNT1Array.size(); PNT1Map.insert(std::make_pair(vertex, index)); PNT1Array.push_back(vertex); } indices[m].push_back(index); } } } inFile.close(); // Build the meshes. int numVertices = (int)PNT1Array.size(); VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, vstride); VertexBufferAccessor vba(vformat, vbuffer); for (int i = 0; i < numVertices; ++i) { VertexPNT1& vertex = PNT1Array[i]; vba.Position<Float3>(i) = positions[vertex.PIndex]; vba.Normal<Float3>(i) = normals[vertex.NIndex]; vba.TCoord<Float2>(0, i) = tcoords[vertex.TIndex]; } std::vector<TriMesh*> meshes(numMeshes); for (m = 0; m < numMeshes; ++m) { int numIndices = (int)indices[m].size(); IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int)); memcpy(ibuffer->GetData(), &indices[m][0], numIndices*sizeof(int)); meshes[m] = new0 TriMesh(vformat, vbuffer, ibuffer); } delete1(vertices); delete1(tcoords); delete1(normals); delete1(positions); return meshes; }
//mark all meshes which touch domains with 0 conductivity void Geometry::mark_current_barrier() { //figure out the connectivity of meshes std::vector<int> mesh_idx; for(unsigned i=0;i<meshes().size();i++) mesh_idx.push_back(i); std::vector<std::vector<int> > mesh_conn; std::vector<int> mesh_connected,mesh_diff; std::set_difference(mesh_idx.begin(),mesh_idx.end(),mesh_connected.begin(),mesh_connected.end(),std::insert_iterator<std::vector<int> >(mesh_diff,mesh_diff.end())); while(!mesh_diff.empty()){ std::vector<int> conn; int se=mesh_diff[0]; conn.push_back(se); mesh_connected.push_back(se); for(unsigned iit=0;iit<conn.size();++iit){ const Mesh& me=meshes()[conn[iit]]; for(Meshes::iterator mit=begin();mit!=end();++mit) if(sigma(me,*mit)!=0.0){ int id=mit-begin(); std::vector<int>::iterator ifind=std::find(mesh_connected.begin(),mesh_connected.end(),id); if(ifind==mesh_connected.end()){ mesh_connected.push_back(id); conn.push_back(id); } } } mesh_conn.push_back(conn); std::sort(mesh_connected.begin(),mesh_connected.end()); mesh_diff.clear(); std::set_difference(mesh_idx.begin(),mesh_idx.end(),mesh_connected.begin(),mesh_connected.end(),std::insert_iterator<std::vector<int> >(mesh_diff,mesh_diff.end())); } //find isolated meshes and touch 0-cond meshes; std::set<std::string> touch_0_mesh; for(Domains::iterator dit=domains_.begin();dit!=domains_.end();++dit){ if(dit->sigma()==0.0) for(Domain::iterator hit=dit->begin();hit!=dit->end();++hit) for(Interface::iterator omit=hit->first.begin();omit!=hit->first.end();++omit){ omit->mesh().current_barrier()=true; std::pair<std::set<std::string>::iterator, bool> ret=touch_0_mesh.insert(omit->mesh().name()); if(!ret.second){ omit->mesh().isolated()=true; omit->mesh().outermost()=false; std::cout<<"Mesh \""<<omit->mesh().name()<<"\" will be excluded from computation because it touches non-conductive domains on both sides."<<std::endl; //add all of its vertices to invalid_vertices for(Mesh::const_vertex_iterator vit=omit->mesh().vertex_begin();vit!=omit->mesh().vertex_end();++vit) invalid_vertices_.insert(**vit); } } } std::vector<std::vector<int> > new_conn; for(std::vector<std::vector<int> >::const_iterator git=mesh_conn.begin();git!=mesh_conn.end();++git) if(git->size()>1||!meshes()[*git->begin()].isolated()) new_conn.push_back(*git); mesh_conn=new_conn; //do not delete shared vertices std::set<Vertex> shared_vtx; for(std::set<Vertex>::const_iterator vit=invalid_vertices_.begin();vit!=invalid_vertices_.end();++vit){ for(Meshes::const_iterator mit=begin();mit!=end();++mit){ if(!mit->isolated()){ std::vector<Vertex*>::const_iterator vfind; for(vfind=mit->vertex_begin();vfind!=mit->vertex_end();++vfind){ if(**vfind==*vit) break; } if(vfind!=mit->vertex_end()) shared_vtx.insert(**vfind);//a shared vertex is found } } } for(std::set<Vertex>::const_iterator vit=shared_vtx.begin();vit!=shared_vtx.end();++vit) invalid_vertices_.erase(*vit); //redefine outermost interface //the inside of a 0-cond domain is considered as a new outermost for(Domains::iterator dit=domain_begin();dit!=domain_end();++dit) if(dit->sigma()==0.0) for(Domain::iterator hit=dit->begin();hit!=dit->end();++hit) if(!hit->inside()) for(Interface::iterator omit=hit->first.begin();omit!=hit->first.end();++omit) if(omit->mesh().current_barrier()&&!omit->mesh().isolated()) omit->mesh().outermost()=true; //detect isolated geometries if(mesh_conn.size()>1){ std::cout<<"The geometry is cut into several unrelated parts by non-conductive domains."<<std::endl; std::cout<<"The computation will continue. But please note that the electric potentials from different parts are no longer comparable."<<std::endl; for(unsigned iit=0,p=0;iit<mesh_conn.size();++iit){ std::cout<<"Part "<<++p<<" is formed by meshes: { "; for(unsigned miit=0;miit<mesh_conn[iit].size();++miit) std::cout<<"\""<<meshes()[mesh_conn[iit][miit]].name()<<"\" "; std::cout<<"}."<<std::endl; } } //count geo_group for(unsigned git=0;git<mesh_conn.size();++git){ std::vector<std::string> gg; for(unsigned mit=0;mit<mesh_conn[git].size();++mit) gg.push_back(meshes()[mesh_conn[git][mit]].name()); geo_group_.push_back(gg); } }
BOOL CSampleExportMeshPlugIn::WriteFile( const wchar_t* filename, int index, CRhinoDoc& doc, const CRhinoFileWriteOptions& options ) { // Description: // Rhino calls WriteFile() to write document geometry to an external file. // Parameters: // filename [in] The name of file to write. // index [in] The index of file extension added to list in AddToFileType(). // doc [in] The current Rhino document. // options [in] File write options. // Remarks: // The plug-in is responsible for opening the file and writing to it. // Return TRUE if successful, otherwise return FALSE. // TODO: Add file export code here. // Are we saving or exporting? bool bExport = options.Mode( CRhinoFileWriteOptions::SelectedMode ); // Are we in interactive or scripted mode? bool bScript = options.Mode( CRhinoFileWriteOptions::BatchMode ); ON_SimpleArray<const CRhinoObject*> objects( 256 ); // Get objects to save/export CRhinoObjectIterator it( doc, CRhinoObjectIterator::undeleted_objects ); if( bExport ) { it.EnableSelectedFilter(); it.EnableVisibleFilter(); } // Do the iteration... const CRhinoObject* obj = 0; for( obj = it.First(); obj; obj = it.Next() ) objects.Append( obj ); ON_ClassArray<CRhinoObjectMesh> meshes( objects.Count() ); ON_MeshParameters mesh_parameters = m_mesh_parameters; int mesh_ui_style = ( bScript ) ? 2 : m_mesh_ui_style; // Get the meshes to save/export CRhinoCommand::result res = RhinoMeshObjects( objects, mesh_parameters, mesh_ui_style, meshes ); if( res == CRhinoCommand::success ) { if( mesh_ui_style >= 0 && mesh_ui_style <= 1 ) m_mesh_ui_style = mesh_ui_style; m_mesh_parameters = mesh_parameters; } else { if( bExport ) RhinoApp().Print( L"\nNo meshes to export.\n" ); else RhinoApp().Print( L"\nNo meshes to save.\n" ); return FALSE; } // Write the mesh file FILE* fp = 0; errno_t err = _wfopen_s( &fp, filename, L"w" ); bool rc = ( 0 == err || 0 != fp ); if( !rc ) { RhinoApp().Print( L"\nUnable to open \"%s\" for writing.\n", filename ); return FALSE; } // Write mesh count ON_wString s; s.Format( L"meshcount=%d\n", meshes.Count() ); rc = ( fputws(s, fp) >= 0 ); int i, j; for( i = 0; rc && i < meshes.Count(); i++ ) { const CRhinoObjectMesh& obj_mesh = meshes[i]; const ON_Mesh* mesh = obj_mesh.m_mesh; rc = ( 0 != mesh ); // Write mesh number if( rc ) { s.Format( L"mesh=%d\n", i ); rc = ( fputws(s, fp) >= 0 ); } // Write mesh vertex count if( rc ) { s.Format( L"vertexcount=%d\n", mesh->m_V.Count() ); rc = ( fputws(s, fp) >= 0 ); } // Write mesh face count if( rc ) { s.Format( L"facecount=%d\n", mesh->m_F.Count() ); rc = ( fputws(s, fp) >= 0 ); } // Write mesh vertices if( rc ) { for( j = 0; rc && j < mesh->m_V.Count(); j++ ) { const ON_3fPoint& p = mesh->m_V[j]; s.Format( L"vertex=(%.16f,%.16f,%.16f)\n", p.x, p.y, p.z ); rc = ( fputws(s, fp) >= 0 ); } } // Write mesh faces if( rc ) { for( j = 0; rc && j < mesh->m_F.Count(); j++ ) { const ON_MeshFace& f = mesh->m_F[j]; s.Format( L"face=(%d,%d,%d,%d)\n", f.vi[0], f.vi[1], f.vi[2], f.vi[3] ); rc = ( fputws(s, fp) >= 0 ); } } } fclose( fp ); return ( rc ) ? TRUE : FALSE; }
CRhinoCommand::result CCommandSampleBrepBoxWithMesh::RunCommand( const CRhinoCommandContext& context ) { // Get the corners of the box CArgsRhinoGetBox args; ON_3dPoint corners[8]; CRhinoCommand::result rc = RhinoGetBox( args, corners ); if( rc != CRhinoCommand::success ) return rc; // Create a brep from the corners. // Note, we are responsible for this memory. ON_Brep* brep = ON_BrepBox( corners ); if( 0 == brep ) { ON_Plane plane( corners[0], corners[1], corners[3] ); if( ON_ZERO_TOLERANCE > plane.plane_equation.ValueAt(corners[7]) ) RhinoApp().Print( L"Box must have a height.\n" ); return CRhinoCommand::failure; } // Meshing parameters to use when creating a render mesh. const ON_MeshParameters& mp = context.m_doc.Properties().RenderMeshParameters(); // Calculates polygon mesh approximation of the brep. // Note, we are responsible for this memory. ON_SimpleArray<ON_Mesh*> meshes( brep->m_F.Count() ); int mesh_count = brep->CreateMesh( mp, meshes ); if( mesh_count == brep->m_F.Count() ) { // Remove an previous values of this type of mesh. // Note, not necessary with new ON_Brep objects. brep->DestroyMesh( ON::render_mesh, true ); // Transfer meshes from meshes[] array to brep->m_F[]. // Note, brep will delete meshes. for( int i = 0; i < mesh_count; i++ ) { if( meshes[i] ) { ON_BrepFace& face = brep->m_F[i]; // Again, not necessary with new ON_Brep objects face.DestroyMesh( ON::render_mesh, true ); face.SetMesh( ON::render_mesh, meshes[i] ); } } // Create the runtime brep object CRhinoBrepObject* brep_obj = new CRhinoBrepObject(); // Attach the brep. // Note, object will delete brep. brep_obj->SetBrep( brep ); // Add object to the doucment if( !context.m_doc.AddObject(brep_obj) ) { delete brep_obj; // Don't leak... return CRhinoCommand::failure; } } context.m_doc.Redraw(); return CRhinoCommand::success; }
std::vector<std::shared_ptr<Visual>> CastleWindow::LoadMeshPNT1Multi(std::string const& name) { // Get the positions, normals, and texture coordinates. std::string filename = mEnvironment.GetPath(name); std::ifstream inFile(filename); std::vector<Vector3<float>> positions, normals; std::vector<Vector2<float>> tcoords; GetTuple3(inFile, positions); GetTuple3(inFile, normals); GetTuple2(inFile, tcoords); // Get the vertices and indices. unsigned int numMeshes; inFile >> numMeshes; std::vector<unsigned int> numTriangles(numMeshes); unsigned int numTotalTriangles = 0; for (unsigned int m = 0; m < numMeshes; ++m) { inFile >> numTriangles[m]; numTotalTriangles += numTriangles[m]; } std::vector<std::vector<unsigned int>> indices(numMeshes); std::vector<LookupPNT1> lookups(3 * numTotalTriangles); std::vector<LookupPNT1> PNT1Array; std::map<LookupPNT1, unsigned int> PNT1Map; for (unsigned int m = 0; m < numMeshes; ++m) { for (unsigned int t = 0; t < numTriangles[m]; ++t) { for (unsigned int j = 0, k = 3 * t; j < 3; ++j, ++k) { LookupPNT1& lookup = lookups[k]; inFile >> lookup.PIndex; inFile >> lookup.NIndex; inFile >> lookup.TIndex; auto iter = PNT1Map.find(lookup); unsigned int index; if (iter != PNT1Map.end()) { // Second or later time the vertex is encountered. index = iter->second; } else { // First time the vertex is encountered. index = static_cast<unsigned int>(PNT1Array.size()); PNT1Map.insert(std::make_pair(lookup, index)); PNT1Array.push_back(lookup); } indices[m].push_back(index); } } } inFile.close(); // Build the meshes. unsigned int numVertices = static_cast<unsigned int>(PNT1Array.size()); std::shared_ptr<VertexBuffer> vbuffer = std::make_shared<VertexBuffer>(mPNT1Format, numVertices); VertexPNT1* vertex = vbuffer->Get<VertexPNT1>(); for (unsigned int i = 0; i < numVertices; ++i) { LookupPNT1& lookup = PNT1Array[i]; vertex[i].position = positions[lookup.PIndex]; vertex[i].normal = normals[lookup.NIndex]; vertex[i].tcoord = tcoords[lookup.TIndex]; } std::vector<std::shared_ptr<Visual>> meshes(numMeshes); for (unsigned int m = 0; m < numMeshes; ++m) { unsigned int numIndices = static_cast<unsigned int>(indices[m].size()); std::shared_ptr<IndexBuffer> ibuffer = std::make_shared<IndexBuffer>(IP_TRIMESH, numIndices, sizeof(unsigned int)); memcpy(ibuffer->GetData(), &indices[m][0], numIndices * sizeof(unsigned int)); meshes[m] = std::make_shared<Visual>(vbuffer, ibuffer); } return meshes; }
int TetMesh::remesh(double alpha) { int ndm = OPS_GetNDM(); if (ndm != 3) { opserr << "WARNING: TetMesh::remesh is only for 3D problem\n"; return -1; } Domain* domain = OPS_GetDomain(); if (domain == 0) { opserr << "WARNING: domain is not created\n"; return -1; } // get all nodes std::map<int, std::vector<int> > ndinfo; TaggedObjectIter& meshes = OPS_getAllMesh(); ID nodetags; Mesh* msh = 0; while((msh = dynamic_cast<Mesh*>(meshes())) != 0) { int id = msh->getID(); int mtag = msh->getTag(); if (id == 0) continue; // get bound nodes const ID& tags = msh->getNodeTags(); for (int i=0; i<tags.Size(); ++i) { std::vector<int>& info = ndinfo[tags(i)]; info.push_back(mtag); info.push_back(id); nodetags.insert(tags(i)); } // get internal nodes const ID& newtags = msh->getNewNodeTags(); for (int i=0; i<newtags.Size(); ++i) { std::vector<int>& info = ndinfo[newtags(i)]; info.push_back(mtag); info.push_back(id); nodetags.insert(newtags(i)); } } if (nodetags.Size() == 0) return 0; // calling mesh generator TetMeshGenerator gen; int nodecounter = nextNodeTag(); for(int i=0; i<nodetags.Size(); ++i) { // get node Node* theNode = domain->getNode(nodetags(i)); if(theNode == 0) { opserr<<"WARNING: node "<<nodetags(i)<<" is not defined\n"; return -1; } const Vector& crds = theNode->getCrds(); const Vector& disp = theNode->getTrialDisp(); if(crds.Size() < ndm || disp.Size() < ndm) { opserr<<"WARNING: ndm < 3 or ndf < 3\n"; return -1; } // create pc if not Pressure_Constraint* thePC = domain->getPressure_Constraint(nodetags(i)); if(thePC != 0) { thePC->setDomain(domain); } else { // create pressure node Node* pnode = 0; pnode = new Node(nodecounter++, 1, crds(0), crds(1), crds(2)); if (pnode == 0) { opserr << "WARNING: run out of memory -- BgMesh::gridNodes\n"; return -1; } if (domain->addNode(pnode) == false) { opserr << "WARNING: failed to add node to domain -- BgMesh::gridNodes\n"; delete pnode; return -1; } thePC = new Pressure_Constraint(nodetags(i), pnode->getTag()); if(thePC == 0) { opserr<<"WARNING: no enough memory for Pressure_Constraint\n"; return -1; } if (domain->addPressure_Constraint(thePC) == false) { opserr << "WARNING: failed to add PC to domain -- BgMesh::gridNodes\n"; delete thePC; return -1; } } // add point gen.addPoint(crds(0)+disp(0), crds(1)+disp(1), crds(2)+disp(2), 0); } // meshing gen.remesh(alpha); // get elenodes std::map<int,ID> meshelenodes; for(int i=0; i<gen.getNumTets(); i++) { // get points int p1,p2,p3,p4; gen.getTet(i,p1,p2,p3,p4); // get nodes int nds[4]; nds[0] = nodetags(p1); nds[1] = nodetags(p2); nds[2] = nodetags(p3); nds[3] = nodetags(p4); // check if all nodes in same mesh std::vector<int>& info1 = ndinfo[nds[0]]; int mtag = 0, id = 0; bool same = false; for (int k=0; k<(int)info1.size()/2; ++k) { // check if any mesh of node 1 is same for another three nodes mtag = info1[2*k]; id = info1[2*k+1]; int num = 0; for (int j=1; j<4; ++j) { std::vector<int>& infoj = ndinfo[nds[j]]; for (int kj=0; kj<(int)infoj.size()/2; ++kj) { int mtagj = infoj[2*kj]; if (mtag == mtagj) { ++num; break; } } } if (num == 3) { same = true; break; } } // nodes in different mesh if (!same) { mtag = 0; id = 0; for (int j=0; j<4; ++j) { std::vector<int>& info = ndinfo[nds[j]]; for (int k=0; k<(int)info.size()/2; ++k) { if (info[2*k+1] < id) { if (dynamic_cast<TetMesh*>(OPS_getMesh(info[2*k])) != 0) { mtag = info[2*k]; id = info[2*k+1]; } } } } } // if all connected to structure if (id >= 0) continue; // add elenodes to its mesh ID& elenodes = meshelenodes[mtag]; for (int j=0; j<4; ++j) { elenodes[elenodes.Size()] = nds[j]; } } // creat elements for (std::map<int,ID>::iterator it=meshelenodes.begin(); it!=meshelenodes.end(); ++it) { int mtag = it->first; ID& elenodes = it->second; msh = OPS_getMesh(mtag); if (msh != 0) { int id = msh->getID(); // remove mesh for id<0 if (id < 0) { if (msh->clearEles() < 0) { opserr << "WARNING: failed to clear element in mesh"<<mtag<<"\n"; return -1; } if (msh->newElements(elenodes) < 0) { opserr << "WARNING: failed to create new elements in mesh"<<mtag<<"\n"; return -1; } } } } return 0; }
std::shared_ptr<room_entity> create_room_entity( ID3D11Device* device, const gx::shader_database* database, std::istream& in ) { uint32_t version = 0; int8_t header[9] = {"AtiModel"}; int8_t read_header[9]; int32_t animation_type = 0; offset_table offsets = {}; thread_local_context_initializer initializer(device); concurrency::combinable<thread_local_context> ctx ( initializer ); concurrency::structured_task_group tasks; d3d11::itexture2d_ptr m_textures[7]; auto task0 = concurrency::make_task( wic_loader( device, &m_textures[0], L"media/giroom/lopal.bmp", &ctx )); auto task1 = concurrency::make_task( wic_loader( device, &m_textures[1], L"media/giroom/headpal.bmp", &ctx )); auto task2 = concurrency::make_task( dds_loader( device, &m_textures[2], L"media/giroom/picture.dds") ); auto task3 = concurrency::make_task( dds_loader( device, &m_textures[3], L"media/giroom/floor.dds") ) ; auto task4 = concurrency::make_task( dds_loader( device, &m_textures[4], L"media/giroom/globe.dds") ) ; auto task5 = concurrency::make_task( wic_loader( device, &m_textures[5], L"media/giroom/wall_lm.bmp", &ctx )); auto task6 = concurrency::make_task( dds_loader( device, &m_textures[6], L"media/giroom/ceiling_lm.dds")); tasks.run(task0); tasks.run(task1); tasks.run(task2); tasks.run(task3); tasks.run(task4); tasks.run(task5); tasks.run(task6); in.read((char*) &read_header[0], 8); if ( in.eof() ) { return nullptr; } read_header[8] = '\0'; if ( _strnicmp( (char*) &read_header[0], (char*) &header[0], 8 ) !=0 ) { return nullptr; } in.read( (char*) &animation_type, sizeof(animation_type)); in.read( (char*) &version, sizeof(version)); in.read( (char*) &offsets, sizeof(offsets) ); in.seekg(offsets.m_material_chunk, std::ios_base::beg); uint32_t material_count = 0; in.read( (char*) &material_count, sizeof(material_count) ); std::vector<material> materials( material_count ); for (uint32_t i = 0 ; i < material_count; ++i) { in.seekg(64, std::ios_base::cur); in.seekg(sizeof(float4), std::ios_base::cur); in.seekg(sizeof(float4), std::ios_base::cur); in.seekg(sizeof(float), std::ios_base::cur); in.read( (char*) &materials[i].diffuse_mp_file, 64 ); in.seekg(64, std::ios_base::cur); in.read( (char*) &materials[i].bump_map_file, 64 ); in.seekg(64, std::ios_base::cur); in.seekg(64, std::ios_base::cur); } in.seekg(offsets.m_vertex_chunk, std::ios_base::beg); uint32_t vertex_count = 0; in.read( (char*) &vertex_count, sizeof(vertex_count) ); std::vector<float3> positions( vertex_count ); std::vector<float3> normal( vertex_count ); std::vector<float3> tangent( vertex_count ); std::vector<float3> binormal( vertex_count ); std::vector<float2> uv( vertex_count ); std::vector<float4> color( vertex_count ); in.read( (char*) &positions[0], vertex_count * sizeof(float3) ); in.read( (char*) &normal[0], vertex_count * sizeof(float3) ); in.read( (char*) &tangent[0], vertex_count * sizeof(float3) ); in.read( (char*) &binormal[0], vertex_count * sizeof(float3) ); in.read( (char*) &uv[0], vertex_count * sizeof(float2) ); in.read( (char*) &color[0], vertex_count * sizeof(float4) ); size_t size = positions.size(); size_t padded_size = 24 * ( ( size + 23 ) / 24 ) ; for (uint32_t i = 0; i < padded_size - size; ++i) { float3 pad3 = {0.0f, 0.0f, 0.0f}; float2 pad2 = {0.0f, 0.0f}; float4 pad4 = {1.0f, 1.0f,1.0f,1.0f}; positions.push_back(pad3); normal.push_back(pad3); tangent.push_back(pad3); binormal.push_back(pad3); uv.push_back(pad2); color.push_back(pad4); } in.seekg(offsets.m_triangle_chunk, std::ios_base::beg); uint32_t triangle_count = 0; in.read( (char*) &triangle_count, sizeof(triangle_count) ); std::vector<triangle> triangles(triangle_count); in.read( (char*) &triangles[0], triangle_count * sizeof(triangle) ); in.seekg(offsets.m_mesh_chunk, std::ios_base::beg); uint32_t mesh_count = 0; in.read( (char*) &mesh_count, sizeof(mesh_count) ); std::vector<mesh> meshes(mesh_count); for ( uint32_t i = 0; i < mesh_count; ++i) { meshes[i].m_id = i; in.read( (char*) &meshes[i].m_name[0], 64 ); in.read( (char*) &meshes[i].m_material_index, sizeof(uint32_t) ); in.read( (char*) &meshes[i].m_base_vertex, sizeof(uint32_t) ); in.read( (char*) &meshes[i].m_vertex_count, sizeof(uint32_t) ); in.read( (char*) &meshes[i].m_base_triangle, sizeof(uint32_t) ); in.read( (char*) &meshes[i].m_triangle_count, sizeof(uint32_t) ); uint32_t bone_count = 0; in.read( (char*) &bone_count, sizeof(uint32_t) ); meshes[i].m_bones.resize(bone_count); if (bone_count > 0 ) { in.read( (char*) &meshes[i].m_bones[0], bone_count * sizeof(uint32_t) ); } in.read( (char*) &meshes[i].m_parent_id, sizeof(uint32_t) ); uint32_t child_count = 0; in.read( (char*) &child_count, sizeof(uint32_t) ); meshes[i].m_children.resize(child_count); if (child_count > 0) { in.read( (char*) &meshes[i].m_children[0], child_count * sizeof(uint32_t) ); } uint32_t primitive_count = 0; in.read( (char*) &primitive_count, sizeof(uint32_t) ); meshes[i].m_primitives.resize(primitive_count); for(uint32_t j = 0; j < primitive_count;++j) { uint32_t type = 0; in.read( (char*) &type, sizeof(uint32_t) ); switch (type) { case PL_TRIANGLE_STRIP: meshes[i].m_primitives[j].m_type = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; break; case PL_TRIANGLE_LIST: default: meshes[i].m_primitives[j].m_type = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; break; } uint32_t indices_count = 0; in.read( (char*) &indices_count, sizeof(uint32_t) ); meshes[i].m_primitives[j].m_indices.resize(indices_count); if (indices_count > 0) { in.read( (char*) &meshes[i].m_primitives[j].m_indices[0], indices_count * sizeof(uint32_t) ); } } uint32_t position_key_count = 0; in.read( (char*) &position_key_count, sizeof(uint32_t) ); meshes[i].m_position_keys.resize(position_key_count); if (position_key_count > 0) { in.read( (char*) &meshes[i].m_position_keys[0], position_key_count * sizeof(animation_key) ); } uint32_t rotation_key_count = 0; in.read( (char*) &rotation_key_count, sizeof(uint32_t) ); meshes[i].m_rotation_keys.resize(rotation_key_count); if ( rotation_key_count > 0) { in.read( (char*) &meshes[i].m_rotation_keys[0], rotation_key_count * sizeof(animation_key) ); } uint32_t scale_key_count = 0; in.read( (char*) &scale_key_count, sizeof(uint32_t) ); meshes[i].m_scale_keys.resize(scale_key_count); if (scale_key_count > 0) { in.read( (char*) &meshes[i].m_scale_keys[0], scale_key_count * sizeof(animation_key) ); } } std::vector<math::half> positions_h( 4 * padded_size ); std::vector<math::half> normals_h( 4 * padded_size ); std::vector<math::half> uv_h( 2 * padded_size ); math::convert_3_x_f32_f16_stream( reinterpret_cast<float*> ( &positions[0]), 3 * padded_size, 1.0f, &positions_h[0]); math::convert_3_x_f32_f16_stream( reinterpret_cast<float*> ( &normal[0]), 3 * padded_size, 1.0f, &normals_h[0]); math::convert_f32_f16_stream( reinterpret_cast<float*> ( &uv[0]), 2 * padded_size, &uv_h[0]); //combine normals and uvs std::vector<math::half> normals_uv( 6 * padded_size); uint32_t j = 0; uint32_t k = 0; for ( uint32_t i = 0; i < 6 * padded_size; i+=6, j+=4, k+=2) { normals_uv[i] = normals_h[j]; normals_uv[i+1] = normals_h[j+1]; normals_uv[i+2] = normals_h[j+2]; normals_uv[i+3] = normals_h[j+3]; normals_uv[i+4] = uv_h[k]; normals_uv[i+5] = uv_h[k+1]; } uint32_t material_range[14]; std::vector<uint32_t> indices( triangle_count * 3); uint32_t index = 0; material_range[0] = 0; // Untextured materials add_to_material_range(&indices[0], index, 0, 19, 1, &meshes[0], &triangles[0], &material_range[0]); // Hand add_to_material_range(&indices[0], index, 1, 20, 1, &meshes[0], &triangles[0], &material_range[0]); // Ball add_to_material_range(&indices[0], index, 1, 23, 1, &meshes[0], &triangles[0], &material_range[0]); // Horse add_to_material_range(&indices[0], index, 1, 25, 1, &meshes[0], &triangles[0], &material_range[0]); // Sci-Fi weirdo add_to_material_range(&indices[0], index, 1, 28, 1, &meshes[0], &triangles[0], &material_range[0]); // Bench add_to_material_range(&indices[0], index, 1, 30, 1, &meshes[0], &triangles[0], &material_range[0]); // Frame add_to_material_range(&indices[0], index, 2, 24, 1, &meshes[0], &triangles[0], &material_range[0]); // Horse stand add_to_material_range(&indices[0], index, 2, 26, 1, &meshes[0], &triangles[0], &material_range[0]); // Sci-Fi weirdo stand add_to_material_range(&indices[0], index, 2, 32, 1, &meshes[0], &triangles[0], &material_range[0]); // Globe stand add_to_material_range(&indices[0], index, 3, 3, 15, &meshes[0], &triangles[0], &material_range[0]); // Ceiling, Pillars, Stands, Wall lights add_to_material_range(&indices[0], index, 4, 0, 1, &meshes[0], &triangles[0], &material_range[0]); // Walls add_to_material_range(&indices[0], index, 5, 21, 1, &meshes[0], &triangles[0], &material_range[0]); // Teapot // Masked materials add_to_material_range(&indices[0], index, 6, 27, 1, &meshes[0], &triangles[0], &material_range[0]); // Globe // Textured materials add_to_material_range(&indices[0], index, 7, 18, 1, &meshes[0], &triangles[0], &material_range[0]); // Ball-horse add_to_material_range(&indices[0], index, 8, 22, 1, &meshes[0], &triangles[0], &material_range[0]); // Head add_to_material_range(&indices[0], index, 9, 29, 1, &meshes[0], &triangles[0], &material_range[0]); // Picture add_to_material_range(&indices[0], index, 10, 1, 1, &meshes[0], &triangles[0], &material_range[0]); // Floor // Lightmapped materials add_to_material_range(&indices[0], index, 11, 2, 1, &meshes[0], &triangles[0], &material_range[0]); // Ceiling add_to_material_range(&indices[0], index, 12, 31, 1, &meshes[0], &triangles[0], &material_range[0]); // Wall light quads //create buffers auto positions_vb = d3d11::create_immutable_vertex_buffer( device, &positions_h[0], positions_h.size() * sizeof(math::half) ); auto normals_uvs_vb = d3d11::create_immutable_vertex_buffer( device, &normals_uv[0], normals_uv.size() * sizeof(math::half) ); auto indices_ib = d3d11::create_immutable_index_buffer( device, &indices[0], indices.size() * sizeof(uint32_t) ); //wait until initializer lists are supported in vs2012 std::vector<room_entity::material> materials_shade; room_entity::material materials_shade_[10]= { { math::set( 0.816f, 0.216f, 0.227f, 0.0f), math::set( 0.45f, 0.15f, 0.15f, gx::encode_specular_power(16.0f)) }, { math::set( 0.435f, 0.443f, 0.682f, 0.0f), math::set( 0.3f, 0.3f, 0.6f, gx::encode_specular_power(16.0f)) }, { math::set( 0.29f, 0.482f, 0.298f, 0.0f), math::set( 0.15f, 0.3f, 0.15f, gx::encode_specular_power(16.0f)) }, { math::set( 0.973f, 0.894f, 0.8f, 0.0f), math::set( 0.5f, 0.5f, 0.5f, gx::encode_specular_power(16.0f)) }, { math::set( 1.0f, 0.6f, 0.2f, 0.0f), math::set( 4.0f, 2.4f, 1.6f, gx::encode_specular_power(24.0f)) }, { math::set( 1.0f, 1.0f, 1.0f, 0.0f), math::set( 0.3f, 0.4f, 0.6f, gx::encode_specular_power(4.0f)) }, { math::set( 0.25f, 0.7f, 0.8f, 0.0f), math::set( 0.7f, 0.7f, 0.8f, gx::encode_specular_power(4.0f)) }, { math::set( 0.2f, 0.2f, 0.2f, 0.0f), math::set( 0.7f, 0.7f, 0.7f, gx::encode_specular_power(16.0f)) }, { math::set( 0.616f, 0.494f, 0.361f, 0.0f), math::set( 0.1f, 0.1f, 0.1f, gx::encode_specular_power(32.0f)) }, { math::set( 0.5f, 0.5f, 0.5f, 0.0f), math::set( 0.7f, 0.7f, 0.7f, gx::encode_specular_power(16.0f)) } }; std::copy ( &materials_shade_[0], &materials_shade_[0] + 10, std::back_insert_iterator<std::vector<room_entity::material>>(materials_shade)); std::vector<room_entity::draw_call> indexed_draw_calls; indexed_draw_calls.reserve(13); for(uint32_t i = 0; i < 13; ++i) { room_entity::draw_call::index_info info = {}; info.m_vertex_size[0] = 8; info.m_vertex_size[1] = 12; uint32_t start = material_range[i]; uint32_t end = material_range[i+1]; info.m_start_index_location = start; info.m_index_count = end - start; d3d11::ibuffer_ptr vertex_buffer_s[] = { positions_vb, normals_uvs_vb } ; indexed_draw_calls.push_back ( room_entity::draw_call( info, vertex_buffer_s, indices_ib ) ) ; } if ( in.eof() ) { return nullptr; } tasks.wait(); ctx.combine_each([&](thread_local_context& local) { d3d11::icommandlist_ptr command_list; local.m_device_context->FinishCommandList( false, dx::get_pointer(command_list)); d3d11::idevicecontext_ptr immediate_context; device->GetImmediateContext(dx::get_pointer(immediate_context) ); immediate_context->ExecuteCommandList(command_list.get(), true ); } ); float specular_power = gx::encode_specular_power(25.0f); std::vector<gx::gbuffer_dt_ng_sc_gc_material> textures_materials; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[0], math::set(0.05f, 0.05f, 0.05f, specular_power ), false ) ) ; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[1], math::set(0.05f, 0.05f, 0.05f, specular_power ), false ) ) ; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[2], math::set(0.05f, 0.05f, 0.05f, specular_power ), false ) ) ; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[3], math::set(0.05f, 0.05f, 0.05f, specular_power ), false ) ) ; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[4], math::set(0.05f, 0.05f, 0.05f, specular_power ), true ) ) ; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[5], math::set(0.05f, 0.05f, 0.05f, specular_power ), false ) ) ; textures_materials.push_back( gx::create_gbuffer_dt_ng_sc_gc_material( device, database, m_textures[6], math::set(0.05f, 0.05f, 0.05f, specular_power ), false ) ) ; return std::make_shared<room_entity> ( std::begin(indexed_draw_calls), std::end(indexed_draw_calls), gx::create_blinn_phong_shift_invairant_material( database, math::set( 1.0f, 0.0f, 0.0f, 0.0f), math::set(0.05f, 0.05f, 0.05f, specular_power )), std::move(materials_shade), std::move(textures_materials) ); }
void MeshFactory::CreateFromFile(const std::string & filePath, std::vector<Mesh*> & meshesOut, std::vector<Vertex> & verticesOut, std::vector<VertexBoneData> & boneDataOut, std::vector<uint32_t> & indicesOut, std::vector<MeshEntry> & entriesOut, bool loadTextures, bool indexMesh) { float startLoadTime = Time::GetTimeSinceStarted(); mImporter.SetPropertyInteger(AI_CONFIG_PP_LBW_MAX_WEIGHTS, RENDERER_NUM_BONES_PER_VERTEX); mImporter.ReadFile(filePath, aiProcess_CalcTangentSpace | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_Triangulate | aiProcess_LimitBoneWeights); // | aiProcess_JoinIdenticalVertices const aiScene * scene = mImporter.GetOrphanedScene(); if (!scene) { LOG_ERROR(mImporter.GetErrorString()); return; } LOG_INFO("Loaded " + std::to_string(scene->mNumMeshes) + " meshes in " + std::to_string(Time::GetTimeSinceStarted() - startLoadTime) + " seconds"); float startParseTime = Time::GetTimeSinceStarted(); std::vector<Mesh *> meshes(scene->mNumMeshes); uint32_t verticesCount = 0; uint32_t indicesCount = 0; uint32_t textureCount = 0; std::vector<MeshEntry> entries(meshes.size()); for (uint32_t i = 0; i < meshes.size(); i++) { entries[i].mNumVertices = scene->mMeshes[i]->mNumVertices; entries[i].mNumIndices = scene->mMeshes[i]->mNumFaces * 3; entries[i].mBaseVertexOffset = verticesCount; entries[i].mBaseIndexOffset = indicesCount; verticesCount += scene->mMeshes[i]->mNumVertices; indicesCount += scene->mMeshes[i]->mNumFaces * 3; //textureCount += scene->mMeshes[i]->mMaterialIndex; if (loadTextures) { std::string fileDirectory = filePath.substr(0, filePath.find_last_of("/")); aiMaterial * mat = scene->mMaterials[scene->mMeshes[i]->mMaterialIndex]; for (uint32_t x = 0; x < mat->GetTextureCount(aiTextureType_DIFFUSE); x++) { aiString path; mat->GetTexture(aiTextureType_DIFFUSE, x, &path); entries[i].mDiffuseTexture = TextureManager::GetTextureInstance(std::string(fileDirectory + "\\" + path.C_Str())); //mDiffuse = new Texture(std::string(fileDirectory + "\\" + path.C_Str())); } for (uint32_t x = 0; x < mat->GetTextureCount(aiTextureType_NORMALS); x++) { aiString path; mat->GetTexture(aiTextureType_NORMALS, x, &path); entries[i].mNormalTexture = TextureManager::GetTextureInstance(std::string(fileDirectory + "\\" + path.C_Str())); } for (uint32_t x = 0; x < mat->GetTextureCount(aiTextureType_SPECULAR); x++) { aiString path; mat->GetTexture(aiTextureType_SPECULAR, x, &path); entries[i].mSpecularTexture = TextureManager::GetTextureInstance(std::string(fileDirectory + "\\" + path.C_Str())); } } } std::vector<Vertex> vertices; std::vector<VertexBoneData> boneData; std::vector<uint32_t> indices; vertices.reserve(verticesCount); boneData.resize(verticesCount); indices.reserve(indicesCount); bool hasBones = false; for (uint32_t i = 0; i < meshes.size(); i++) { meshes[i] = new Mesh(); meshes[i]->mBaseVertexOffset = entries[i].mBaseVertexOffset; meshes[i]->mBaseIndexOffset = entries[i].mBaseIndexOffset; meshes[i]->ParseFromScene(i, scene, scene->mMeshes[i], filePath, vertices, boneData, indices, entries, loadTextures, indexMesh); if (meshes[i]->GetHasBones()) { hasBones = true; } } if (hasBones == false) { boneData.resize(0); } meshesOut = meshes; verticesOut = vertices; boneDataOut = boneData; indicesOut = indices; entriesOut = entries; LOG_INFO("Parsed " + std::to_string(scene->mNumMeshes) + " meshes in " + std::to_string(Time::GetTimeSinceStarted() - startParseTime) + " seconds"); }
renderer::DrawablePtr Cube3<T>::drawable(renderer::Renderer& r) const { ETC_TRACE.debug(*this, "Creating drawable"); auto scene = scene::Scene::from_string(nff_cube(), "nff"); return scene->meshes()[0]->drawable(r); }
void TutorFramework::OnCreate() { font_ = KlayGE::SyncLoadFont("gkai00mp.kfont"); KlayGE::OBBox boxRange(KlayGE::MathLib::convert_to_obbox(KlayGE::AABBox(KlayGE::float3(-1.0f, -0.25f, -0.25f), KlayGE::float3(-0.5f, 0.25f, 0.25f)))); KlayGE::Color boxColor(1.0f, 0.0f, 0.0f, 1.0f); renderableBox_ = KlayGE::MakeSharedPtr<KlayGE::SceneObjectHelper>( KlayGE::MakeSharedPtr<KlayGE::RenderableTriBox>(boxRange, boxColor), KlayGE::SceneObject::SOA_Cullable); renderableBox_->AddToSceneManager(); KlayGE::RenderModelPtr loadedModel = KlayGE::SyncLoadModel("teapot.meshml", KlayGE::EAH_GPU_Read, KlayGE::CreateModelFactory<KlayGE::RenderModel>(), KlayGE::CreateMeshFactory<RenderPolygon>()); renderableFile_ = KlayGE::MakeSharedPtr<KlayGE::SceneObjectHelper>(loadedModel, KlayGE::SceneObject::SOA_Cullable); renderableFile_->ModelMatrix(KlayGE::MathLib::translation(0.0f, 0.5f, 0.0f)); renderableFile_->AddToSceneManager(); std::vector<KlayGE::float3> vertices; vertices.push_back(KlayGE::float3(0.5f,-0.25f, 0.25f)); vertices.push_back(KlayGE::float3(1.0f,-0.25f, 0.25f)); vertices.push_back(KlayGE::float3(1.0f,-0.25f,-0.25f)); vertices.push_back(KlayGE::float3(0.5f,-0.25f,-0.25f)); vertices.push_back(KlayGE::float3(0.5f, 0.25f, 0.25f)); vertices.push_back(KlayGE::float3(1.0f, 0.25f, 0.25f)); vertices.push_back(KlayGE::float3(1.0f, 0.25f,-0.25f)); vertices.push_back(KlayGE::float3(0.5f, 0.25f,-0.25f)); KlayGE::RenderModelPtr model = KlayGE::MakeSharedPtr<KlayGE::RenderModel>(L"model"); std::vector<KlayGE::StaticMeshPtr> meshes(2); std::vector<KlayGE::uint16_t> indices1; indices1.push_back(0); indices1.push_back(4); indices1.push_back(1); indices1.push_back(5); indices1.push_back(2); indices1.push_back(6); indices1.push_back(3); indices1.push_back(7); indices1.push_back(0); indices1.push_back(4); meshes[0] = KlayGE::MakeSharedPtr<RenderPolygon>(model, L"side_mesh"); meshes[0]->AddVertexStream(&vertices[0], static_cast<KlayGE::uint32_t>(sizeof(vertices[0]) * vertices.size()), KlayGE::vertex_element(KlayGE::VEU_Position, 0, KlayGE::EF_BGR32F), KlayGE::EAH_GPU_Read); meshes[0]->AddIndexStream(&indices1[0], static_cast<KlayGE::uint32_t>(sizeof(indices1[0]) * indices1.size()), KlayGE::EF_R16UI, KlayGE::EAH_GPU_Read); meshes[0]->GetRenderLayout().TopologyType(KlayGE::RenderLayout::TT_TriangleStrip); meshes[0]->PosBound(KlayGE::AABBox(KlayGE::float3(-1, -1, -1), KlayGE::float3(1, 1, 1))); std::vector<KlayGE::uint16_t> indices2; indices2.push_back(0); indices2.push_back(1); indices2.push_back(2); indices2.push_back(0); indices2.push_back(2); indices2.push_back(3); indices2.push_back(7); indices2.push_back(6); indices2.push_back(5); indices2.push_back(7); indices2.push_back(5); indices2.push_back(4); meshes[1] = KlayGE::MakeSharedPtr<RenderPolygon>(model, L"cap_mesh"); meshes[1]->AddVertexStream(&vertices[0], static_cast<KlayGE::uint32_t>(sizeof(vertices[0]) * vertices.size()), KlayGE::vertex_element(KlayGE::VEU_Position, 0, KlayGE::EF_BGR32F), KlayGE::EAH_GPU_Read); meshes[1]->AddIndexStream(&indices2[0], static_cast<KlayGE::uint32_t>(sizeof(indices2[0]) * indices2.size()), KlayGE::EF_R16UI, KlayGE::EAH_GPU_Read); meshes[1]->GetRenderLayout().TopologyType(KlayGE::RenderLayout::TT_TriangleList); meshes[1]->PosBound(KlayGE::AABBox(KlayGE::float3(-1, -1, -1), KlayGE::float3(1, 1, 1))); for (size_t i = 0; i < meshes.size(); ++ i) { meshes[i]->BuildMeshInfo(); } model->AssignSubrenderables(meshes.begin(), meshes.end()); renderableMesh_ = KlayGE::MakeSharedPtr<KlayGE::SceneObjectHelper>(model, KlayGE::SceneObject::SOA_Cullable); renderableMesh_->AddToSceneManager(); this->LookAt(KlayGE::float3(0, 0,-4.0f), KlayGE::float3(0, 0, 0)); this->Proj(0.1f, 20.0f); tbController_.AttachCamera(this->ActiveCamera()); tbController_.Scalers(0.01f, 0.05f); }