// mesh chooser file dialog void MainWindow::chooseMesh() { mesh.Clear(); QString plyext("ply"); QString objext("obj"); QString extoptions = QString("Poly Model (*.") + plyext + ");;OBJ Model (*." + objext + ")"; QString fileName = QFileDialog::getOpenFileName(this, tr("Open Mesh"), QDir::currentPath(), extoptions); QFileInfo fi(fileName); QTime loadingtime; loadingtime.start(); int err=0; if (fi.suffix() == plyext) err=vcg::tri::io::ImporterPLY<CMeshO>::Open(mesh,(fileName.toStdString()).c_str(),qCallBack); else if (fi.suffix() == objext) { int loadmask; err=vcg::tri::io::ImporterOBJ<CMeshO>::Open(mesh,(fileName.toStdString()).c_str(),loadmask,qCallBack); } int msec = loadingtime.elapsed(); if(err!=0) { const char* errmsg=vcg::tri::io::ImporterPLY<CMeshO>::ErrorMsg(err); QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg)); } QString msg = fileName + " vtx: " + QString::number(mesh.VN()) + " fcs: " + QString::number(mesh.FN()) + " loading time: " + QString::number(msec) + " msec"; initMesh(msg); }
Physics3DShape* Physics3DShape::createMesh( const cocos2d::Vec3 *triangles, int numTriangles ) { auto shape = new (std::nothrow) Physics3DShape(); shape->initMesh(triangles, numTriangles); shape->autorelease(); return shape; }
// 加载 model bool StaticMesh::loadModelFromFile(const std::string& filepath) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(filepath, m_FlipUVs ? (aiProcessPreset_TargetRealtime_Quality | aiProcess_FlipUVs) : aiProcessPreset_TargetRealtime_Quality); if (!scene) { std::cout << "Couldn't load model, Error Importing Asset :" << filepath << std::endl; Log::Instance()->OutputError("Couldn't load model, Error Importing Asset : %s", filepath.c_str()); return false; } m_MeshEntries.resize(scene->mNumMeshes); m_Textures.resize(scene->mNumMaterials); initMesh(scene, scene->mRootNode); // init mesh // 加载所有 texture if (scene->mNumMaterials > 0) { if (!initMaterial(scene, filepath)) { std::cout << "Material 加载不完整" << std::endl; m_IsLoaded = false; return false; } } m_IsLoaded = true; return true; }
bool ImportedModel::initFromAiScene(const aiScene* scene, const string& filename) { m_meshes.resize(scene->mNumMeshes); /// for some reason Assimp always creates one extra mNumMaterials m_textures.resize(scene->mNumMaterials); bool b = initMaterials2(scene, filename); for (unsigned int i=0; i<m_meshes.size(); i++) { const aiMesh* mesh = scene->mMeshes[i]; initMesh(i, mesh, scene); } // utl::debug("m_meshes size", m_meshes.size()); // utl::debug("m_textures size", m_textures.size()); /* for(int i=0; i<m_meshes.size(); i++) { utl::debug("mesh texture Index", m_meshes[i].m_textureIndex); } for(int i=0; i<m_textures.size(); i++) { utl::debug("textures Id", m_textures[i].m_id); } */ return b; }
void RenderableMesh::fromAssimpScene (const aiScene* scene) { meshes.resize (scene->mNumMeshes); for (unsigned int i = 0; i < meshes.size (); ++i) { const aiMesh* mesh = scene->mMeshes[i]; initMesh (i, mesh); } }
void Mesh::initFromScene(const aiScene* _scene) { std::cout<<"init from scene\n"; m_entries.resize(_scene->mNumMeshes); std::vector<ngl::Vec3> positions; std::vector<ngl::Vec3> normals; std::vector<ngl::Vec2> texCords; std::vector<VertexBoneData> bones; std::vector<GLuint > indices; unsigned int NumVertices = 0; unsigned int NumIndices = 0; // Count the number of vertices and indices unsigned int size=m_entries.size(); for (unsigned int i = 0 ; i < size; ++i) { m_entries[i].NumIndices = _scene->mMeshes[i]->mNumFaces * 3; m_entries[i].BaseVertex = NumVertices; m_entries[i].BaseIndex = NumIndices; NumVertices += _scene->mMeshes[i]->mNumVertices; NumIndices += m_entries[i].NumIndices; } // Reserve space in the vectors for the vertex attributes and indices positions.reserve(NumVertices); normals.reserve(NumVertices); texCords.reserve(NumVertices); bones.resize(NumVertices); indices.reserve(NumIndices); // Initialize the meshes in the scene one by one for (unsigned int i = 0 ; i < size ; ++i) { const aiMesh* paiMesh = _scene->mMeshes[i]; initMesh(i, paiMesh, positions, normals, texCords, bones, indices); } m_vao->bind(); m_vao->setIndexedData(positions.size()*sizeof(ngl::Vec3),positions[0].m_x,indices.size(),&indices[0],GL_UNSIGNED_INT,GL_STATIC_DRAW); m_vao->setVertexAttributePointer(0,3,GL_FLOAT,0,0); m_vao->setIndexedData(texCords.size()*sizeof(ngl::Vec2),texCords[0].m_x,indices.size(),&indices[0],GL_UNSIGNED_INT,GL_STATIC_DRAW); m_vao->setVertexAttributePointer(1,2,GL_FLOAT,0,0); m_vao->setIndexedData(normals.size()*sizeof(ngl::Vec3),normals[0].m_x,indices.size(),&indices[0],GL_UNSIGNED_INT,GL_STATIC_DRAW); m_vao->setVertexAttributePointer(2,3,GL_FLOAT,0,0); m_vao->setRawIndexedData(sizeof(VertexBoneData) * bones.size(),&bones[0],indices.size(),&indices[0],GL_UNSIGNED_INT,GL_STATIC_DRAW); m_vao->setVertexAttributeIPointer(3,4,GL_INT,sizeof(VertexBoneData),0); m_vao->setVertexAttributePointer(4,4,GL_FLOAT,sizeof(VertexBoneData),4); m_vao->setNumIndices(indices.size()); m_vao->unbind(); }
bool Model::initFromScene(const aiScene *scene, const std::string &filename) { _mesh_entries.resize(scene->mNumMeshes); for (GLuint i = 0; i < _mesh_entries.size(); i++) { const aiMesh* mesh = scene->mMeshes[i]; initMesh(i, mesh); } return 1; //return InitMaterials(scene, filename); }
bool Mesh::initFromScene(const aiScene* pScene, const std::string &filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); for(unsigned int i = 0; i < m_Entries.size(); i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; initMesh(i, paiMesh); } return initMaterials(pScene, filename); }
/*Main Loop*/ void ram(void) { initDisplay(); uint8_t key; do { key = getInput(); if(key == BTN_DOWN) waitMsg(); else if (key == BTN_UP) initMesh(); } while(key != BTN_ENTER); }
bool Model::loadModel(const string& path) { Assimp::Importer Importer; const aiScene* pScene = Importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs); if (pScene) { meshes = new vector<Mesh *>(); for (int i = 0; i < pScene->mNumMeshes; i++) { Mesh * m = initMesh(pScene->mMeshes[i], pScene->mMaterials); meshes->push_back(m); } } else { printf("Error parsing '%s': '%s'\n", path.c_str(), Importer.GetErrorString()); return false; } return true; }
void StaticMesh::initMesh(const aiScene* pScene, const aiNode* pNode) { for (unsigned int n = 0; n < pNode->mNumMeshes; ++n) { const struct aiMesh* paiMesh = pScene->mMeshes[pNode->mMeshes[n]]; std::vector<Vertex> vertices; std::vector<unsigned int> indices; const aiVector3D Zero3D(0.0f, 0.0f, 0.0f); vertices.reserve(paiMesh->mNumVertices); indices.reserve(paiMesh->mNumFaces); std::cout << "mesh : " << paiMesh->mName.C_Str() << m_NumMeshEntries << " init! " << std::endl; // 设置 mesh 的纹理索引 m_MeshEntries[m_NumMeshEntries].m_MaterialIndex = paiMesh->mMaterialIndex; for (unsigned int i = 0; i < paiMesh->mNumVertices; i++) { const aiVector3D* pPos = &(paiMesh->mVertices[i]); const aiVector3D* pNormal = &(paiMesh->mNormals[i]); const aiVector3D* pTexCoord = paiMesh->HasTextureCoords(0) ? &(paiMesh->mTextureCoords[0][i]) : &Zero3D; Vertex v(Vector3(pPos->x, pPos->y, pPos->z), Vector2(pTexCoord->x, pTexCoord->y), Vector3(pNormal->x, pNormal->y, pNormal->z) ); vertices.push_back(v); } // 初始化顶点索引 for (unsigned int i = 0; i < paiMesh->mNumFaces; i++) { const aiFace& Face = paiMesh->mFaces[i]; assert(Face.mNumIndices == 3); indices.push_back(Face.mIndices[0]); indices.push_back(Face.mIndices[1]); indices.push_back(Face.mIndices[2]); } // 初始化 mesh m_MeshEntries[m_NumMeshEntries++].init(vertices, indices); } for (unsigned int i = 0; i < pNode->mNumChildren; i++) { initMesh(pScene, pNode->mChildren[i]); } }
bool Mesh::load(const std::string &filename){ Assimp::Importer importer; const aiScene *pScene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs); if(pScene){ entries.resize(pScene->mNumMeshes); textures.resize(pScene->mNumMaterials); for(size_t i = 0; i < entries.size(); i++){ const aiMesh *pMesh = pScene->mMeshes[i]; initMesh(i,pMesh); } initMaterials(pScene,filename); } else{ printf("Error parsing '%s': '%s'\n",filename.c_str(),importer.GetErrorString()); return false; } return true; }
void BusyQuadRenderer::render(const G3MRenderContext* rc, const GLState& parentState) { GL* gl = rc->getGL(); GLState state(parentState); state.enableBlend(); if (_quadMesh == NULL){ if (!initMesh(rc)) { return; } } // init modelview matrix int currentViewport[4]; gl->getViewport(currentViewport); const int halfWidth = currentViewport[2] / 2; const int halfHeight = currentViewport[3] / 2; MutableMatrix44D M = MutableMatrix44D::createOrthographicProjectionMatrix(-halfWidth, halfWidth, -halfHeight, halfHeight, -halfWidth, halfWidth); gl->setProjection(M); gl->loadMatrixf(MutableMatrix44D::identity()); // clear screen gl->clearScreen(_backgroundColor->getRed(), _backgroundColor->getGreen(), _backgroundColor->getBlue(), _backgroundColor->getAlpha()); gl->setState(state); gl->setBlendFuncSrcAlpha(); gl->pushMatrix(); MutableMatrix44D R2 = MutableMatrix44D::createRotationMatrix(Angle::fromDegrees(_degrees), Vector3D(0, 0, 1)); gl->multMatrixf(R2); // draw mesh _quadMesh->render(rc, parentState); gl->popMatrix(); }
void BvHierarchyAlgorithm::addTopLevelProxy(Proxy* proxy) { std::list<Proxy*> queue; queue.push_back(proxy); while (!queue.empty()) { Proxy* p = queue.front(); queue.pop_front(); for (std::list<Proxy*>::const_iterator it = p->getChildProxies().begin(); it != p->getChildProxies().end(); ++it) { queue.push_back(*it); } if (!p->getShape()) { continue; } if (p->getShape()->getShapeType() != Shape::SHAPE_TYPE_MESH) { throw Exception("Deformable proxy has non-mesh shape - this is not allowed!"); } initMesh(p, static_cast<Mesh*>(p->getShape())); } }
void EntityTest::setUp() { mesh_filename_ = "Data\\mesh_connectivity.mesh"; initMesh(); }
Foam::polyMesh::polyMesh ( const IOobject& io, const Xfer<pointField>& points, const Xfer<faceList>& faces, const Xfer<labelList>& owner, const Xfer<labelList>& neighbour, const bool syncPar ) : objectRegistry(io), primitiveMesh(), allPoints_ ( IOobject ( "points", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), points ), // To be re-sliced later. HJ, 19/Oct/2008 points_(allPoints_, allPoints_.size()), allFaces_ ( IOobject ( "faces", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), faces ), // To be re-sliced later. HJ, 19/Oct/2008 faces_(allFaces_, allFaces_.size()), owner_ ( IOobject ( "owner", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), owner ), neighbour_ ( IOobject ( "neighbour", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), neighbour ), clearedPrimitives_(false), boundary_ ( IOobject ( "boundary", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), *this, 0 ), bounds_(allPoints_, syncPar), geometricD_(Vector<label>::zero), solutionD_(Vector<label>::zero), pointZones_ ( IOobject ( "pointZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this, 0 ), faceZones_ ( IOobject ( "faceZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this, 0 ), cellZones_ ( IOobject ( "cellZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this, 0 ), globalMeshDataPtr_(NULL), moving_(false), changing_(false), curMotionTimeIndex_(time().timeIndex()), oldAllPointsPtr_(NULL), oldPointsPtr_(NULL) { // Check if the faces and cells are valid forAll (allFaces_, faceI) { const face& curFace = allFaces_[faceI]; if (min(curFace) < 0 || max(curFace) > allPoints_.size()) { FatalErrorIn ( "polyMesh::polyMesh\n" "(\n" " const IOobject& io,\n" " const pointField& points,\n" " const faceList& faces,\n" " const cellList& cells\n" ")\n" ) << "Face " << faceI << "contains vertex labels out of range: " << curFace << " Max point index = " << allPoints_.size() << abort(FatalError); } } // Set the primitive mesh initMesh(); }
Foam::polyMesh::polyMesh(const IOobject& io) : objectRegistry(io), primitiveMesh(), allPoints_ ( IOobject ( "points", time().findInstance(meshDir(), "points"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), // To be re-sliced later. HJ, 19/oct/2008 points_(allPoints_, allPoints_.size()), allFaces_ ( IOobject ( "faces", time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), // To be re-sliced later. HJ, 19/oct/2008 faces_(allFaces_, allFaces_.size()), owner_ ( IOobject ( "owner", time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ), neighbour_ ( IOobject ( "neighbour", time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ), clearedPrimitives_(false), boundary_ ( IOobject ( "boundary", time().findInstance(meshDir(), "boundary"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ), *this ), bounds_(allPoints_), geometricD_(Vector<label>::zero), solutionD_(Vector<label>::zero), pointZones_ ( IOobject ( "pointZones", time().findInstance ( meshDir(), "pointZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), faceZones_ ( IOobject ( "faceZones", time().findInstance ( meshDir(), "faceZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), cellZones_ ( IOobject ( "cellZones", time().findInstance ( meshDir(), "cellZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), globalMeshDataPtr_(NULL), moving_(false), changing_(false), curMotionTimeIndex_(time().timeIndex()), oldAllPointsPtr_(NULL), oldPointsPtr_(NULL) { if (exists(owner_.objectPath())) { initMesh(); } else { cellIOList cLst ( IOobject ( "cells", // Find the cells file on the basis of the faces file // HJ, 8/Jul/2009 // time().findInstance(meshDir(), "cells"), time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ); // Set the primitive mesh initMesh(cLst); owner_.write(); neighbour_.write(); } // Calculate topology for the patches (processor-processor comms etc.) boundary_.updateMesh(); // Calculate the geometry for the patches (transformation tensors etc.) boundary_.calcGeometry(); // Warn if global empty mesh (constructs globalData!) if (globalData().nTotalPoints() == 0) { WarningIn("polyMesh(const IOobject&)") << "no points in mesh" << endl; } if (globalData().nTotalCells() == 0) { WarningIn("polyMesh(const IOobject&)") << "no cells in mesh" << endl; } }
void MainWindow::loadDodecahedron() { mesh.Clear(); vcg::tri::Dodecahedron(mesh); initMesh(tr("Dodecahedron [builtin]")); }
Foam::polyMesh::polyMesh(const IOobject& io) : objectRegistry(io), primitiveMesh(), points_ ( IOobject ( "points", time().findInstance(meshDir(), "points"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), faces_ ( IOobject ( "faces", time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), owner_ ( IOobject ( "owner", faces_.instance(), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ), neighbour_ ( IOobject ( "neighbour", faces_.instance(), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ), clearedPrimitives_(false), boundary_ ( IOobject ( "boundary", time().findInstance(meshDir(), "boundary"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ), *this ), bounds_(points_), comm_(UPstream::worldComm), geometricD_(Vector<label>::zero), solutionD_(Vector<label>::zero), tetBasePtIsPtr_(NULL), cellTreePtr_(NULL), pointZones_ ( IOobject ( "pointZones", time().findInstance ( meshDir(), "pointZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), faceZones_ ( IOobject ( "faceZones", time().findInstance ( meshDir(), "faceZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), cellZones_ ( IOobject ( "cellZones", time().findInstance ( meshDir(), "cellZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), globalMeshDataPtr_(NULL), moving_(false), topoChanging_(false), curMotionTimeIndex_(time().timeIndex()), oldPointsPtr_(NULL) { if (exists(owner_.objectPath())) { initMesh(); } else { cellCompactIOList cLst ( IOobject ( "cells", time().findInstance(meshDir(), "cells"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ); // Set the primitive mesh initMesh(cLst); owner_.write(); neighbour_.write(); } // Calculate topology for the patches (processor-processor comms etc.) boundary_.updateMesh(); // Calculate the geometry for the patches (transformation tensors etc.) boundary_.calcGeometry(); // Warn if global empty mesh if (returnReduce(nPoints(), sumOp<label>()) == 0) { WarningIn("polyMesh(const IOobject&)") << "no points in mesh" << endl; } if (returnReduce(nCells(), sumOp<label>()) == 0) { WarningIn("polyMesh(const IOobject&)") << "no cells in mesh" << endl; } // Initialise demand-driven data calcDirections(); }
GridRenderer::GridRenderer() { initShaders(); initMesh(); }
void HexagonalPrismGeneratorDialog::OngeneratePrismClick(wxCommandEvent& event) { const double SIN60 = 0.866025404; double basicPoints[6][2] = { {1, 0}, {0.5, SIN60}, {-0.5, SIN60}, {-1, 0}, {-0.5, -SIN60}, {0.5, -SIN60} }; //< Points of a hexagon. double prismHeight; prismHeightTextCtrl->GetValue().ToDouble(&prismHeight); vector<int> face; if (kernPrismRadioButton->GetValue()) { // Create Kern basic points. // Kern prism's basal face is triangular. double sideFaceRatio; sideFaceRatioTextBox->GetValue().ToDouble(&sideFaceRatio); const double ANG120 = 3.1415926526 * 2.0/3.0; double angle1 = ANG120 * (sideFaceRatio) / (1 + sideFaceRatio); for (int i = 0; i < 3; i++) { double x = 1; double y = 0; rotate2d(x, y, i * ANG120); basicPoints[2 * i][0] = x; basicPoints[2 * i][1] = y; x = 1; y = 0; rotate2d(x, y, i * ANG120 + angle1); basicPoints[2 * i + 1][0] = x; basicPoints[2 * i + 1][1] = y; } } else if (parryPlateRadioButton->GetValue()) { // generate oblate prism. double height; parryPlateHeightTextBox->GetValue().ToDouble(&height); for (int i = 0; i < 6; i++) { double tmpx = basicPoints[i][0]; double tmpy = basicPoints[i][1]; if (tmpx < 0) { basicPoints[i][0] = tmpx * height + (1 - height)*-1; basicPoints[i][1] = tmpy * height; } else { basicPoints[i][0] = tmpx * height + (1 - height); basicPoints[i][1] = tmpy * height; } } } initMesh(mesh); // Set vertices // First 6 vertex is for the front hexagonal face. for (int i = 0; i < 6; i++) { mesh.vertices.push_back(Vector3(basicPoints[i][0], basicPoints[i][1], prismHeight)); } // Next 6 vertex is for the back hexagonal face for (int i = 0; i < 6; i++) { mesh.vertices.push_back(Vector3(basicPoints[i][0], basicPoints[i][1], -prismHeight)); } // Make front face face.clear(); for (int i = 0; i < 6; i++) { face.push_back(i); } mesh.faces.push_back(face); // Make back face face.clear(); for (int i = 0; i < 6; i++) { face.push_back(i + 6); } mesh.faces.push_back(face); // Make side faces for (int i = 0; i < 6; i++) { int j = i + 1 == 6 ? 0 : i + 1; face.clear(); // Add vertices on the front face face.push_back(i); face.push_back(j); // Add vertices on the back face face.push_back(j + 6); face.push_back(i + 6); mesh.faces.push_back(face); } // Scale the prism to fit in a sphere which has unit radius. double vertexDistance = ~mesh.vertices[0]; // All vertices are the same distance from the center. for (size_t i = 0; i < mesh.vertices.size(); i++) { mesh.vertices[i] /= vertexDistance; } EndModal(ID_BUTTON_GENERATEPRISM); }
CrystalEditorFrame::CrystalEditorFrame(std::vector<CrystalDescriptor> &_crystalMeshes, wxWindow* parent,wxWindowID id): right(1, 0, 0), upward(0, 1, 0), backward(0, 0, 1), target(0, 0, 0), distance(10), crystalMeshes(&_crystalMeshes), dragging(false), prevMousePos(0, 0, 0), rayPos(-10, 0, 0), rayDir(1, 0, 0) { initialize(parent, id); // Put a cube into the mesh. initMesh(crystalMesh); // back face crystalMesh.vertices.push_back(Vector3(-1, -1, -1)); crystalMesh.vertices.push_back(Vector3(-1, 1, -1)); crystalMesh.vertices.push_back(Vector3(1, 1, -1)); crystalMesh.vertices.push_back(Vector3(1, -1, -1)); // front face crystalMesh.vertices.push_back(Vector3(-1, -1, 1)); crystalMesh.vertices.push_back(Vector3(-1, 1, 1)); crystalMesh.vertices.push_back(Vector3(1, 1, 1)); crystalMesh.vertices.push_back(Vector3(1, -1, 1)); // back face vector<int> face; face.push_back(0); face.push_back(1); face.push_back(2); face.push_back(3); crystalMesh.faces.push_back(face); // front face face.clear(); face.push_back(4); face.push_back(5); face.push_back(6); face.push_back(7); crystalMesh.faces.push_back(face); // left face face.clear(); face.push_back(0); face.push_back(1); face.push_back(5); face.push_back(4); crystalMesh.faces.push_back(face); // right face face.clear(); face.push_back(2); face.push_back(3); face.push_back(7); face.push_back(6); crystalMesh.faces.push_back(face); // top face face.clear(); face.push_back(1); face.push_back(5); face.push_back(6); face.push_back(2); crystalMesh.faces.push_back(face); // bottom face face.clear(); face.push_back(0); face.push_back(4); face.push_back(7); face.push_back(3); crystalMesh.faces.push_back(face); minimumIntensity = 0; }
Foam::polyMesh::polyMesh ( const IOobject& io, const Xfer<pointField>& points, const Xfer<faceList>& faces, const Xfer<labelList>& owner, const Xfer<labelList>& neighbour, const bool syncPar ) : objectRegistry(io), primitiveMesh(), points_ ( IOobject ( "points", instance(), meshSubDir, *this, io.readOpt(), IOobject::AUTO_WRITE ), points ), faces_ ( IOobject ( "faces", instance(), meshSubDir, *this, io.readOpt(), IOobject::AUTO_WRITE ), faces ), owner_ ( IOobject ( "owner", instance(), meshSubDir, *this, io.readOpt(), IOobject::AUTO_WRITE ), owner ), neighbour_ ( IOobject ( "neighbour", instance(), meshSubDir, *this, io.readOpt(), IOobject::AUTO_WRITE ), neighbour ), clearedPrimitives_(false), boundary_ ( IOobject ( "boundary", instance(), meshSubDir, *this, io.readOpt(), IOobject::AUTO_WRITE ), *this, polyPatchList() ), bounds_(points_, syncPar), comm_(UPstream::worldComm), geometricD_(Zero), solutionD_(Zero), tetBasePtIsPtr_(NULL), cellTreePtr_(NULL), pointZones_ ( IOobject ( "pointZones", instance(), meshSubDir, *this, io.readOpt(), IOobject::NO_WRITE ), *this, PtrList<pointZone>() ), faceZones_ ( IOobject ( "faceZones", instance(), meshSubDir, *this, io.readOpt(), IOobject::NO_WRITE ), *this, PtrList<faceZone>() ), cellZones_ ( IOobject ( "cellZones", instance(), meshSubDir, *this, io.readOpt(), IOobject::NO_WRITE ), *this, PtrList<cellZone>() ), globalMeshDataPtr_(NULL), moving_(false), topoChanging_(false), curMotionTimeIndex_(time().timeIndex()), oldPointsPtr_(NULL) { // Check if the faces and cells are valid forAll(faces_, facei) { const face& curFace = faces_[facei]; if (min(curFace) < 0 || max(curFace) > points_.size()) { FatalErrorInFunction << "Face " << facei << "contains vertex labels out of range: " << curFace << " Max point index = " << points_.size() << abort(FatalError); } } // Set the primitive mesh initMesh(); }
bool TessMeshApp::Init(){ bool res = App::Init(); if (!res) { return res; } initMeshShader(); meshShaderProgram->use(); initMesh(); //mouse: { Shader vertexShader(GL_VERTEX_SHADER); vertexShader.loadFromFile("shaders/mouse.vert"); vertexShader.compile(); Shader fragmentShader(GL_FRAGMENT_SHADER); fragmentShader.loadFromFile("shaders/mouse.frag"); fragmentShader.compile(); // Shader geometryShader(GL_GEOMETRY_SHADER); // geometryShader.loadFromFile("shaders/mouse.geom"); // geometryShader.compile(); mouseShaderProgram = new ShaderProgram(); mouseShaderProgram->attachShader(vertexShader); mouseShaderProgram->attachShader(fragmentShader); // mouseShaderProgram->attachShader(geometryShader); mouseShaderProgram->linkProgram(); mouse = new Mesh(); vector<vec3> vertices; vertices.push_back(vec3(0.0f, 0.0f, -5.0f)); vector<vec3> colors; colors.push_back(vec3(1.0f, 0.0f, 0.0f)); vector<GLuint> indices; indices.push_back(0); mouse->addIndices(indices); // position { Attribute positionAttrib; positionAttrib.name = "position"; positionAttrib.num_of_components = 3; positionAttrib.data_type = GL_FLOAT; positionAttrib.buffer_type = GL_ARRAY_BUFFER; mouse->addVBO(vertices, positionAttrib); mouseShaderProgram->use(); positionAttrib.id = mouseShaderProgram->addAttribute(positionAttrib.name); glEnableVertexAttribArray(positionAttrib.id); glVertexAttribPointer(positionAttrib.id, positionAttrib.num_of_components, GL_FLOAT, GL_FALSE, 0, 0); mouseShaderProgram->disable(); mouse->attributes.push_back(positionAttrib); } // color: { Attribute colorAttrib; colorAttrib.name = "color"; colorAttrib.num_of_components = 3; colorAttrib.data_type = GL_FLOAT; colorAttrib.buffer_type = GL_ARRAY_BUFFER; mouse->addVBO(colors, colorAttrib); mouseShaderProgram->use(); colorAttrib.id = mouseShaderProgram->addAttribute(colorAttrib.name); glEnableVertexAttribArray(colorAttrib.id); glVertexAttribPointer(colorAttrib.id, colorAttrib.num_of_components, GL_FLOAT, GL_FALSE, 0, 0); mouseShaderProgram->disable(); mouse->attributes.push_back(colorAttrib); } // uniforms: { mouseShaderProgram->use(); GLuint model = mouseShaderProgram->addUniform("model"); glUniformMatrix4fv(model, 1, GL_FALSE, glm::value_ptr(mesh->modelMatrix)); GLuint view = mouseShaderProgram->addUniform("view"); glUniformMatrix4fv(view, 1, GL_FALSE, glm::value_ptr(camera.view)); GLuint projection = mouseShaderProgram->addUniform("projection"); glUniformMatrix4fv(projection, 1, GL_FALSE, glm::value_ptr(camera.projection)); GLuint mousePosition = mouseShaderProgram->addUniform("mousePosition"); vec3 mouse_pos(1.0f, 0.0f, -5.0f); glUniform3fv(mousePosition, 1, glm::value_ptr(mouse_pos)); mouseShaderProgram->disable(); } } return res; }
void MeshBoundaryConditionReaderTest::setUp() { mesh_filename_ = "Data\\boundary_conditions.mesh"; initMesh(); }
void MainWindow::loadTetrahedron() { mesh.Clear(); vcg::tri::Tetrahedron(mesh); initMesh(tr("Tethraedron [builtin]")); }
Foam::polyMesh::polyMesh ( const IOobject& io, const Xfer<pointField>& points, const Xfer<faceList>& faces, const Xfer<cellList>& cells, const bool syncPar ) : objectRegistry(io), primitiveMesh(), points_ ( IOobject ( "points", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), points ), faces_ ( IOobject ( "faces", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), faces ), owner_ ( IOobject ( "owner", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), 0 ), neighbour_ ( IOobject ( "neighbour", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), 0 ), clearedPrimitives_(false), boundary_ ( IOobject ( "boundary", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), *this, 0 ), bounds_(points_, syncPar), comm_(UPstream::worldComm), geometricD_(Vector<label>::zero), solutionD_(Vector<label>::zero), tetBasePtIsPtr_(NULL), cellTreePtr_(NULL), pointZones_ ( IOobject ( "pointZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this, 0 ), faceZones_ ( IOobject ( "faceZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this, 0 ), cellZones_ ( IOobject ( "cellZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this, 0 ), globalMeshDataPtr_(NULL), moving_(false), topoChanging_(false), curMotionTimeIndex_(time().timeIndex()), oldPointsPtr_(NULL) { // Check if faces are valid forAll(faces_, facei) { const face& curFace = faces_[facei]; if (min(curFace) < 0 || max(curFace) > points_.size()) { FatalErrorIn ( "polyMesh::polyMesh\n" "(\n" " const IOobject&,\n" " const Xfer<pointField>&,\n" " const Xfer<faceList>&,\n" " const Xfer<cellList>&\n" ")\n" ) << "Face " << facei << "contains vertex labels out of range: " << curFace << " Max point index = " << points_.size() << abort(FatalError); } } // transfer in cell list cellList cLst(cells); // Check if cells are valid forAll(cLst, celli) { const cell& curCell = cLst[celli]; if (min(curCell) < 0 || max(curCell) > faces_.size()) { FatalErrorIn ( "polyMesh::polyMesh\n" "(\n" " const IOobject&,\n" " const Xfer<pointField>&,\n" " const Xfer<faceList>&,\n" " const Xfer<cellList>&\n" ")\n" ) << "Cell " << celli << "contains face labels out of range: " << curCell << " Max face index = " << faces_.size() << abort(FatalError); } } // Set the primitive mesh initMesh(cLst); }
void PeaksAndValleys::init(int row, int column) { initMesh(row, column); //Create Effect Technique int shaderFlag = D3D10_SHADER_ENABLE_STRICTNESS; #if defined(DEBUG) || defined(_DEBUG ) shaderFlag |= D3D10_SHADER_DEBUG |D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Device *device = DirectEngine::getInstance()->getDevice(); ID3D10Blob *errorBlob = nullptr; int result = D3DX10CreateEffectFromFile(L"color.fx", nullptr,nullptr, "fx_4_0", shaderFlag, 0, device, nullptr, nullptr, &_effect,&errorBlob,nullptr ); if (result < 0) { if (errorBlob) { MessageBoxA(nullptr, (char*)errorBlob->GetBufferPointer(), nullptr, 0); errorBlob->Release(); } DXTrace(__FILE__, __LINE__, result, L"D3DX10CreateEffectFromFile",true); } _effectTech = _effect->GetTechniqueByName("ColorTech"); _mvpMatrixV = _effect->GetVariableByName("g_MVPMatrix")->AsMatrix(); //Create Layout D3D10_INPUT_ELEMENT_DESC inputDesc[2]; inputDesc[0].SemanticName = "POSITION"; inputDesc[0].SemanticIndex = 0; inputDesc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; inputDesc[0].InputSlot = 0; inputDesc[0].AlignedByteOffset = 0; inputDesc[0].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; inputDesc[0].InstanceDataStepRate = 0; inputDesc[1].SemanticName = "COLOR"; inputDesc[1].SemanticIndex = 0; inputDesc[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; inputDesc[1].InputSlot = 0; inputDesc[1].AlignedByteOffset = sizeof(float) * 3; inputDesc[1].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; inputDesc[1].InstanceDataStepRate = 0; // D3D10_PASS_DESC passDesc; _effectTech->GetPassByName("P0")->GetDesc(&passDesc); result = device->CreateInputLayout(inputDesc, 2, passDesc.pIAInputSignature,passDesc.IAInputSignatureSize,&_inputLayout); assert(result>=0); //Matrix D3DXMatrixIdentity(&_modelMatrix); D3DXMatrixIdentity(&_projMatrix); D3DXMatrixIdentity(&_viewMatrix); //Create Project Matrix auto &winSize = DirectEngine::getInstance()->getWinSize(); D3DXMatrixPerspectiveFovLH(&_projMatrix,M_PI/4,winSize.width/winSize.height,1.0f,400.0f); D3DXVECTOR3 eyePosition(0,80,-120); D3DXVECTOR3 targetPosition(0,0,0); D3DXVECTOR3 upperVec(0,1,0); D3DXMatrixLookAtLH(&_viewMatrix, &eyePosition, &targetPosition, &upperVec); }