/// \param nSubmodel Specifies the index of the submodel. /// \param v Specifies the vector of displacement. void ArticulatedModel::moveSubmodel(int nSubmodel,const Vector3 &v){ //move origin of submodel if (nSubmodel >= m_nSubmodelCount) return; // bail out if bad index //EditTriMesh editMesh; for(int i = 0; i < m_nNextSubmodelPart[nSubmodel]; i++ ) { TriMesh *t = &m_partMeshList[m_nSubmodelPart[nSubmodel][i]]; //t->toEditMesh(editMesh); t->moveVertices(v); if(m_vertexBuffer == NULL) continue; int partID = m_nSubmodelPart[nSubmodel][i]; int offset = m_vertexOffsets[partID]; m_vertexBuffer->lock(); for(int i=0; i < t->getVertexCount(); i++) { (*m_vertexBuffer)[offset+i].p = t->getVertexList()[i].p; } m_vertexBuffer->unlock(); } }
//---------------------------------------------------------------------------- void TriggerActor::SetAreaType(AreaType type) { mAreaType = type; CreateGetHelpNode()->DetachChild(mAreaMovable); VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PC); if (AT_SPHERE == mAreaType) { StandardMesh stdMesh(vf); stdMesh.SetVertexColor(Float4(1.0f, 1.0f, 0.0f, 1.0f)); TriMesh *mesh = stdMesh.Sphere(16, 16, 1.0f); VertexColor4MaterialPtr mtl = new0 VertexColor4Material(); mtl->GetWireProperty(0, 0)->Enabled = true; mtl->GetCullProperty(0, 0)->Enabled = false; mesh->LocalTransform.SetUniformScale(0.5f); mesh->SetMaterialInstance(mtl->CreateInstance()); mAreaMovable = mesh; } else if (AT_BOX == mAreaType) { StandardMesh stdMesh(vf); stdMesh.SetVertexColor(Float4(1.0f, 1.0f, 0.0f, 1.0f)); TriMesh *mesh = stdMesh.Box(1, 1, 1); VertexColor4MaterialPtr mtl = new0 VertexColor4Material(); mtl->GetWireProperty(0, 0)->Enabled = true; mtl->GetCullProperty(0, 0)->Enabled = false; mesh->LocalTransform.SetUniformScale(0.5f); mesh->SetMaterialInstance(mtl->CreateInstance()); mAreaMovable = mesh; } CreateGetHelpNode()->AttachChild(mAreaMovable); }
//---------------------------------------------------------------------------- void CollisionsBoundTree::Response (CRecord& record0, int t0, CRecord& record1, int t1, Intersector<float,Vector3f>*) { CollisionsBoundTree* app = (CollisionsBoundTree*)TheApplication; // Mesh0 triangles that are intersecting change from blue to cyan. TriMesh* mesh = record0.GetMesh(); VertexBufferAccessor vba(mesh); const int* indices = (int*)mesh->GetIndexBuffer()->GetData(); int i0 = indices[3*t0]; int i1 = indices[3*t0 + 1]; int i2 = indices[3*t0 + 2]; vba.TCoord<Float2>(0, i0) = app->mCyanUV; vba.TCoord<Float2>(0, i1) = app->mCyanUV; vba.TCoord<Float2>(0, i2) = app->mCyanUV; app->mRenderer->Update(mesh->GetVertexBuffer()); // Mesh1 triangles that are intersecting change from red to yellow. mesh = record1.GetMesh(); vba.ApplyTo(mesh); indices = (int*)mesh->GetIndexBuffer()->GetData(); i0 = indices[3*t1]; i1 = indices[3*t1 + 1]; i2 = indices[3*t1 + 2]; vba.TCoord<Float2>(0 ,i0) = app->mYellowUV; vba.TCoord<Float2>(0, i1) = app->mYellowUV; vba.TCoord<Float2>(0, i2) = app->mYellowUV; app->mRenderer->Update(mesh->GetVertexBuffer()); // NOTE: See the comments in Wm5CollisionGroup.h about information that // is available from the Intersector<float,Vector3f> object. }
void display() { glEnable(GL_DEPTH_TEST); glClearColor(1, 1, 1, 0); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glMatrixMode(GL_PROJECTION); glLoadIdentity(); camera->setOrtho(-cameraRadius*windowWidth / (float)windowHeight, cameraRadius*windowWidth / (float)windowHeight, -cameraRadius, cameraRadius, 0.1f, 1000); camera->project(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); camera->Look(); float green[3] = { 0, 1, 0 }; float red[3] = { 1, 0.5, 0 }; mesh_in.renderFlat(red); mesh.renderFlatTrans(green, 0.4); glutSwapBuffers(); }
//---------------------------------------------------------------------------- TriMesh* PolyhedronDistance::CreatePlane () { VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride); VertexBufferAccessor vba(vformat, vbuffer); float size = 16.0f; vba.Position<Float3>(0) = Float3(-size, -size, -0.1f); vba.Position<Float3>(1) = Float3(+size, -size, -0.1f); vba.Position<Float3>(2) = Float3(+size, +size, -0.1f); vba.Position<Float3>(3) = Float3(-size, +size, -0.1f); vba.Color<Float3>(0, 0) = Float3(0.0f, 0.50f, 0.00f); vba.Color<Float3>(0, 1) = Float3(0.0f, 0.25f, 0.00f); vba.Color<Float3>(0, 2) = Float3(0.0f, 0.75f, 0.00f); vba.Color<Float3>(0, 3) = Float3(0.0f, 1.00f, 0.00f); IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int)); int* indices = (int*)ibuffer->GetData(); indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; TriMesh* mesh = new0 TriMesh(vformat, vbuffer, ibuffer); mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); return mesh; }
void MeshDenoisingViaL0Minimization::initParameters() { parameter_set_->removeAllParameter(); parameter_set_->addParameter(QString("mu_beta"), 1.414, QString("mu_beta"), QString("Update ratio for beta."), true, 1.001, 10000.0); parameter_set_->addParameter(QString("beta"), 0.001, QString("beta"), QString("Initial beta value in optimization."), true, 1.0e-9, 10000.0); parameter_set_->addParameter(QString("beta_max"), 1000.0, QString("beta_max"), QString("Max beta value in optimization."), true, 10.0, 1.0e9); parameter_set_->addParameter(QString("mu_alpha"), 0.5, QString("mu_alpha"), QString("Update ratio for alpha."), true, 1.0e-9, 0.9999); TriMesh mesh = data_manager_->getNoisyMesh(); if(mesh.n_vertices() == 0) { parameter_set_->addParameter(QString("alpha"), 0.0001, QString("alpha"), QString("Initial alpha value in optimization."), true, 0.0, 1.0e9); parameter_set_->addParameter(QString("lambda"), 0.0001, QString("lambda"), QString("Lambda value in optimization."), true, 1.0e-9, 1.0e9); } else { double mean_edge_length = getAverageEdgeLength(mesh); double mean_dihedral_angle = getAverageDihedralAngle(mesh); parameter_set_->addParameter(QString("alpha"), 0.1 * mean_dihedral_angle, QString("alpha"), QString("Initial alpha value in optimization."), true, 0.0, 1.0e9); parameter_set_->addParameter(QString("lambda"), 0.2 * mean_edge_length * mean_edge_length * mean_dihedral_angle, QString("lambda"), QString("Lambda value in optimization."), true, 1.0e-9, 1.0e9); } parameter_set_->setName(QString("Mesh Denoising via L0 Minimization")); parameter_set_->setLabel(QString("Mesh Denoising via L0 Minimization")); parameter_set_->setIntroduction(QString("Mesh Denoising via L0 Minimization -- Parameters")); }
BOOL CGeometryProcDoc::OnOpenDocument(LPCTSTR lpszPathName) { CString fn = lpszPathName; char* filename = NULL; auto UnicodeToAnsi = [](char** file, CString& fn) { int P_Length = fn.GetLength(); int nBytes = WideCharToMultiByte(CP_ACP, 0, fn, P_Length, NULL, 0, NULL, NULL); *file = new char[nBytes + 1]; memset(*file, 0, P_Length + 1); WideCharToMultiByte(CP_OEMCP, 0, fn, P_Length, *file, nBytes, NULL, NULL); }; UnicodeToAnsi(&filename, fn); string filecheck(filename); filecheck = filecheck.substr(filecheck.size()-4); std::transform(filecheck.begin(), filecheck.end(), filecheck.begin(), tolower); if (filecheck == (".stl")) { TriMesh* mesh = NULL; mesh = TriMesh::read_stl_helper(filename); mesh->need_bbox(); meshes.push_back(mesh); Current_mesh = meshes.size() - 1; return TRUE; } return FALSE; }
//---------------------------------------------------------------------------- void GelatinCube::PhysicsTick () { mModule->Update((float)GetTimeInSeconds()); // Update spline surface. Remember that the spline maintains its own // copy of the control points, so this update is necessary. int numSlices = mModule->GetNumSlices() - 2; int numRows = mModule->GetNumRows() - 2; int numCols = mModule->GetNumCols() - 2; for (int s = 0; s < numSlices; ++s) { for (int r = 0; r < numRows; ++r) { for (int c = 0; c < numCols; ++c) { mSpline->SetControlPoint(c, r, s, mModule->Position(s + 1, r + 1, c + 1)); } } } mBox->UpdateSurface(); for (int i = 0; i < mBox->GetNumChildren(); ++i) { TriMesh* mesh = StaticCast<TriMesh>(mBox->GetChild(i)); mRenderer->Update(mesh->GetVertexBuffer()); } }
int main(int argc, char **argv) { mesh.loadOff("../model/armadillo.off"); double b_min[3], b_max[3]; mesh.buildBbox(b_min, b_max); Levelset lvs(mesh, 1.5, true); printf("Level set initialized\n"); lvs.redist(4.0); lvs.advectAllW(2.0); for (int i = 0; i < 30; i++) { lvs.smooth(0.3); printf("Level set smooth Iter: %d\n", i); } //lvs.mergeCntCmpnt(); // use this to remove island and keep only one piece std::vector<double> mc_verts; std::vector<int> mc_faces; lvs.marchingCubes(mc_verts, mc_faces); mesh_in.loadMesh(mc_verts, mc_faces); printf("Write offset surface to armadillo_in.obj\n"); mesh_in.writeObj("../model/armadillo_in.obj"); opgl_glut_init(argc, argv, "MeshSeg", windowWidth, windowHeight, &windowID, display, reshape, mouse, motion, keyboard, idle); focus[0] = (b_min[0] + b_max[0]) / 2.0; focus[1] = (b_min[1] + b_max[1]) / 2.0; focus[2] = (b_min[2] + b_max[2]) / 2.0; camera = new SphericalCamera(cameraRadius, 0.0f, 0.0f, focus, up, 0.02); glutMainLoop(); return 0; }
void MeshDenoisingBase::getFaceNeighbor(TriMesh &mesh, TriMesh::FaceHandle fh, FaceNeighborType face_neighbor_type, std::vector<TriMesh::FaceHandle> &face_neighbor) { face_neighbor.clear(); if(face_neighbor_type == kEdgeBased) { for(TriMesh::FaceFaceIter ff_it = mesh.ff_iter(fh); ff_it.is_valid(); ff_it++) face_neighbor.push_back(*ff_it); } else if(face_neighbor_type == kVertexBased) { std::set<int> neighbor_face_index; neighbor_face_index.clear(); for(TriMesh::FaceVertexIter fv_it = mesh.fv_begin(fh); fv_it.is_valid(); fv_it++) { for(TriMesh::VertexFaceIter vf_it = mesh.vf_iter(*fv_it); vf_it.is_valid(); vf_it++) { if((*vf_it) != fh) neighbor_face_index.insert(vf_it->idx()); } } for(std::set<int>::iterator iter = neighbor_face_index.begin(); iter != neighbor_face_index.end(); ++ iter) { face_neighbor.push_back(TriMesh::FaceHandle(*iter)); } } }
//---------------------------------------------------------------------------- void ReflectionsAndShadows::CopyNormalToTCoord1 (Object* object) { TriMesh* mesh = DynamicCast<TriMesh>(object); if (mesh) { VertexBufferAccessor vba(mesh); for (int i = 0; i < vba.GetNumVertices(); ++i) { vba.TCoord<Vector3f>(1, i) = vba.Normal<Vector3f>(i); } mRenderer->Update(mesh->GetVertexBuffer()); } Node* node = DynamicCast<Node>(object); if (node) { for (int i = 0; i < node->GetNumChildren(); ++i) { Spatial* child = node->GetChild(i); if (child) { CopyNormalToTCoord1(child); } } } }
void FixMeshSurface::setVel() { double conv_vel[3]; int size, nVec; double scp, tmp[3], facenormal[3], ***v_node; vectorCopy3D(vSurf_,conv_vel); double conv_vSurf_mag = vectorMag3D(conv_vel); size = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->size(); nVec = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->nVec(); v_node = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->begin(); // set mesh velocity TriMesh *trimesh = triMesh(); for (int i = 0; i < size; i++) { trimesh->surfaceNorm(i,facenormal); scp = vectorDot3D(conv_vel,facenormal); vectorScalarMult3D(facenormal,scp,tmp); for(int j = 0; j < nVec; j++) { vectorSubtract3D(conv_vel,tmp,v_node[i][j]); if(vectorMag3D(v_node[i][j]) > 0.) { vectorScalarDiv3D(v_node[i][j],vectorMag3D(v_node[i][j])); vectorScalarMult3D(v_node[i][j],conv_vSurf_mag); } } } }
//---------------------------------------------------------------------------- void EditMap::CreateSphere (PX2::APoint pos) { PX2::Texture2D *tex = DynamicCast<PX2::Texture2D>( ResourceManager::GetSingleton().BlockLoad("ToolRes/images/default.png")); if (!tex) return; StandardMesh stdMesh(mVertexFormat); TriMesh *mesh = stdMesh.Sphere(16, 16, 1); mesh->SetName("NoName"); Texture2DMaterialPtr material = new0 Texture2DMaterial; mesh->SetMaterialInstance(material->CreateInstance(tex)); ActorPtr actor = new0 Actor(); actor->SetName("NoName"); actor->SetMovable(mesh); actor->SetPosition(pos); actor->ComeInToEventWorld(); AddActor(actor); Event *event = 0; event = EditorEventSpace::CreateEventX (EditorEventSpace::AddActor); event->SetData<Actor*>(actor); EventWorld::GetSingleton().BroadcastingLocalEvent(event); ActorAddDeleteCommand *command = new0 ActorAddDeleteCommand(actor); EditSystem::GetSingleton().GetCM()->PushUnDo(command); }
//---------------------------------------------------------------------------- void EditMap::CreateSphere (PX2::APoint pos) { PX2::Texture2D *tex = DynamicCast<PX2::Texture2D>( ResourceManager::GetSingleton().BlockLoad("ToolRes/images/default.png")); if (!tex) return; StandardMesh stdMesh(mVertexFormat); TriMesh *mesh = stdMesh.Sphere(16, 16, 1); mesh->SetName("NoName"); //Texture2DMaterialPtr material = new0 Texture2DMaterial; //mesh->SetMaterialInstance(material->CreateInstance(tex)); StandardESMaterial_DefaultPtr mtl = new0 StandardESMaterial_Default(); mesh->SetMaterialInstance(mtl->CreateInstance(tex, 0 ,0)); ActorPtr actor = new0 Actor(); actor->SetName("NoName"); actor->SetMovable(mesh); actor->SetPosition(pos); actor->ComeInToEventWorld(); AddActor(actor); ActorAddDeleteCommand *command = new0 ActorAddDeleteCommand(actor); EditSystem::GetSingleton().GetCM()->PushUnDo(command); }
// display texture // XXX: NEEDS TO BE IMPLEMENTED void Texture::display(void){ // setup model matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(rayTraceMode){ normQuadShader.bind(); rayTexture.bind(); quad.draw(); normQuadShader.unbind(); rayTexture.unbind(); }else{ mesh1.draw(); mesh.draw(); mesh2.draw(); } glutSwapBuffers(); // glPopAttrib(); }
//---------------------------------------------------------------------------- void IntersectingBoxes::ModifyMesh (int i) { Vector3f center( 0.5f*(mBoxes[i].Min[0] + mBoxes[i].Max[0]), 0.5f*(mBoxes[i].Min[1] + mBoxes[i].Max[1]), 0.5f*(mBoxes[i].Min[2] + mBoxes[i].Max[2])); float xExtent = 0.5f*(mBoxes[i].Max[0] - mBoxes[i].Min[0]); float yExtent = 0.5f*(mBoxes[i].Max[1] - mBoxes[i].Min[1]); float zExtent = 0.5f*(mBoxes[i].Max[2] - mBoxes[i].Min[2]); Vector3f xTerm = xExtent*Vector3f::UNIT_X; Vector3f yTerm = yExtent*Vector3f::UNIT_Y; Vector3f zTerm = zExtent*Vector3f::UNIT_Z; TriMesh* mesh = StaticCast<TriMesh>(mScene->GetChild(i)); VertexBufferAccessor vba(mesh); vba.Position<Vector3f>(0) = center - xTerm - yTerm - zTerm; vba.Position<Vector3f>(1) = center + xTerm - yTerm - zTerm; vba.Position<Vector3f>(2) = center + xTerm + yTerm - zTerm; vba.Position<Vector3f>(3) = center - xTerm + yTerm - zTerm; vba.Position<Vector3f>(4) = center - xTerm - yTerm + zTerm; vba.Position<Vector3f>(5) = center + xTerm - yTerm + zTerm; vba.Position<Vector3f>(6) = center + xTerm + yTerm + zTerm; vba.Position<Vector3f>(7) = center - xTerm + yTerm + zTerm; mesh->UpdateModelSpace(Visual::GU_NORMALS); mRenderer->Update(mesh->GetVertexBuffer()); }
//---------------------------------------------------------------------------- Character::Character() : mAnimType(AT_SKELETON), mDefaultAnimID(0), mBaseHPCurLevel(0.0f), mIsDieDoDelete(true), mBaseAPCurLevel(0.0f), mIsDead(false), mIsMovableAutoWorldBound(true), mMovableAutoWorldBoundRadius(2.0f) { SetName("Chara"); PX2_INIT_PM_F(HP); PX2_INIT_PM_F(AP); VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PC); StandardMesh stdMesh(vf); stdMesh.SetVertexColor(Float4(1.0f, 0.0f, 0.0f, 1.0f)); TriMesh *mesh = stdMesh.Box(0.5f, 0.5f, 0.5f); PX2::VertexColor4MaterialPtr mtl = new0 VertexColor4Material(); mtl->GetWireProperty(0, 0)->Enabled = true; mtl->GetCullProperty(0, 0)->Enabled = false; mesh->LocalTransform.SetUniformScale(0.5f); mesh->SetMaterialInstance(mtl->CreateInstance()); CreateGetHelpNode()->DetachAllChildren(); CreateGetHelpNode()->AttachChild(mesh); CreateGetHelpNode()->SetParentTransformIngore(false, false, true); }
void ObjLoaderApp::keyDown( KeyEvent event ) { if( event.getChar() == 'o' ) { std::string path = getOpenFilePath(); if( ! path.empty() ) { ObjLoader loader( loadFileStream( path ) ); loader.load( &mMesh, true ); mVBO = gl::VboMesh( mMesh ); console() << "Total verts: " << mMesh.getVertices().size() << std::endl; } } else if( event.getChar() == 's' ) { std::string path = getSaveFilePath( "output.trimesh" ); if( ! path.empty() ) { console() << "Saving to " << path; OStreamFileRef out = writeFileStream( path ); mMesh.write( out.get() ); } } else if( event.getChar() == 'f' ) { frameCurrentObject(); } else if( event.getChar() == 'd' ) { gDebug = ! gDebug; } }
TriMesh<FloatType> Shapes<FloatType>::cylinder(const vec3<FloatType>& p0, const vec3<FloatType>& p1, FloatType radius, UINT stacks, UINT slices, const vec4<FloatType>& color) { FloatType height = (p1 - p0).length(); TriMesh<FloatType> result = Shapesf::cylinder(radius, height, stacks, slices, color); result.transform(mat4f::translation(p0) * mat4f::face(vec3<FloatType>::eZ, p1 - p0)); return result; }
//---------------------------------------------------------------------------- void IntersectingBoxes::ModifyBoxes () { const int numBoxes = (int)mBoxes.size(); int i; for (i = 0; i < numBoxes; ++i) { AxisAlignedBox3f box = mBoxes[i]; float dx = Mathf::IntervalRandom(-4.0f, 4.0f); if (-mSize <= box.Min[0] + dx && box.Max[0] + dx <= mSize) { box.Min[0] += dx; box.Max[0] += dx; } float dy = Mathf::IntervalRandom(-4.0f, 4.0f); if (-mSize <= box.Min[1] + dy && box.Max[1] + dy <= mSize) { box.Min[1] += dy; box.Max[1] += dy; } float dz = Mathf::IntervalRandom(-4.0f, 4.0f); if (-mSize <= box.Min[2] + dz && box.Max[2] + dz <= mSize) { box.Min[2] += dz; box.Max[2] += dz; } mManager->SetBox(i, box); ModifyMesh(i); } mManager->Update(); mScene->Update(); // Switch material to red for any box that overlaps another. TriMesh* mesh; for (i = 0; i < numBoxes; ++i) { // Reset all boxes to blue. mesh = StaticCast<TriMesh>(mScene->GetChild(i)); mesh->SetEffectInstance(mNoIntersectEffect); } const std::set<EdgeKey>& overlap = mManager->GetOverlap(); std::set<EdgeKey>::const_iterator iter = overlap.begin(); std::set<EdgeKey>::const_iterator end = overlap.end(); for (/**/; iter != end; ++iter) { // Set intersecting boxes to red. i = iter->V[0]; mesh = StaticCast<TriMesh>(mScene->GetChild(i)); mesh->SetEffectInstance(mIntersectEffect); i = iter->V[1]; mesh = StaticCast<TriMesh>(mScene->GetChild(i)); mesh->SetEffectInstance(mIntersectEffect); } }
void FixMeshSurface::initAngVel() { int size, nVec; double rot_origin[3],rot_axis[3],rot_omega; vectorCopy3D(origin_,rot_origin); vectorCopy3D(axis_,rot_axis); rot_omega = omegaSurf_; double tmp[3], scp, unitAxis[3], tangComp[3], Utang[3], surfaceV[3]; double node[3],facenormal[3], magAxis, magUtang, ***v_node; // register new element property v - error if exists already via moving mesh mesh()->prop().addElementProperty<MultiVectorContainer<double,3,3> >("v","comm_none","frame_invariant","restart_no"); size = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->size(); nVec = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->nVec(); size = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->size(); nVec = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->nVec(); v_node = mesh()->prop().getElementProperty<MultiVectorContainer<double,3,3> >("v")->begin(); // calculate unit vector of rotation axis magAxis = vectorMag3D(rot_axis); vectorScalarDiv3D(rot_axis,magAxis,unitAxis); TriMesh *trimesh = triMesh(); for (int i = 0; i < size; i++) { trimesh->surfaceNorm(i,facenormal); // number of nodes per face (3) for(int j = 0; j < nVec; j++) { // position of node - origin of rotation (to get lever arm) trimesh->node(i,j,node); vectorSubtract3D(node,rot_origin,surfaceV); // lever arm X rotational axis = tangential component vectorCross3D(surfaceV,unitAxis,tangComp); // multiplying by omega scales the tangential component to give tangential velocity vectorScalarMult3D(tangComp,-rot_omega,Utang); // EPSILON is wall velocity, not rotational omega if(vectorMag3D(Utang) < EPSILON_V) error->fix_error(FLERR,this,"Rotation velocity too low"); scp = vectorDot3D(Utang, facenormal); vectorScalarMult3D(facenormal,scp,tmp); // removes components normal to wall vectorSubtract3D(Utang,tmp,v_node[i][j]); magUtang = vectorMag3D(Utang); if(vectorMag3D(v_node[i][j]) > 0.) { vectorScalarDiv3D(v_node[i][j],vectorMag3D(v_node[i][j])); vectorScalarMult3D(v_node[i][j],magUtang); } } } }
TriMesh<FloatType> Shapes<FloatType>::box(const OrientedBoundingBox3f &obb, const vec4<FloatType>& color) { TriMesh<FloatType> result = box(BoundingBox3<FloatType>(vec3<FloatType>::origin, vec3<FloatType>(1.0f, 1.0f, 1.0f)), color); result.transform(obb.getOBBToWorld()); return result; }
void Scene::load_mesh(const string& filename, const Mat4x4f& transform) { cout << "Loading " << filename << endl; TriMesh* mesh = load_background_mesh(filename, transform); // Correct scene bounding box AABB mesh_bbox = mesh->compute_bbox(); bbox.add_AABB(mesh_bbox); }
TriMesh *SimpleMesh::getInternalMesh(Matrix44f transformMatrix) { TriMesh *meshCopy = new TriMesh{_currentMesh}; vector<Vec3f> verts = meshCopy->getVertices(); for (Vec3f &vertex : meshCopy->getVertices()) { vertex = transformMatrix.transformPoint(vertex); } return meshCopy; }
void MeshDenoisingBase::getFaceCentroid(TriMesh &mesh, std::vector<TriMesh::Point> ¢roid) { centroid.resize(mesh.n_faces(), TriMesh::Point(0.0, 0.0, 0.0)); for(TriMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end(); f_it++) { TriMesh::Point pt = mesh.calc_face_centroid(*f_it); centroid[(*f_it).idx()] = pt; } }
//---------------------------------------------------------------------------- void PointInPolyhedron::CreateScene () { mScene = new0 Node(); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); // Create a semitransparent sphere mesh. VertexFormat* vformatMesh = VertexFormat::Create(1, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0); TriMesh* mesh = StandardMesh(vformatMesh).Sphere(16, 16, 1.0f); Material* material = new0 Material(); material->Diffuse = Float4(1.0f, 0.0f, 0.0f, 0.25f); VisualEffectInstance* instance = MaterialEffect::CreateUniqueInstance( material); instance->GetEffect()->GetAlphaState(0, 0)->BlendEnabled = true; mesh->SetEffectInstance(instance); // Create the data structures for the polyhedron that represents the // sphere mesh. CreateQuery(mesh); // Create a set of random points. Points inside the polyhedron are // colored white. Points outside the polyhedron are colored blue. VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(1024, vstride); VertexBufferAccessor vba(vformat, vbuffer); Float3 white(1.0f, 1.0f, 1.0f); Float3 blue(0.0f, 0.0f, 1.0f); for (int i = 0; i < vba.GetNumVertices(); ++i) { Vector3f random(Mathf::SymmetricRandom(), Mathf::SymmetricRandom(), Mathf::SymmetricRandom()); vba.Position<Vector3f>(i) = random; if (mQuery->Contains(random)) { vba.Color<Float3>(0, i) = white; } else { vba.Color<Float3>(0, i) = blue; } } DeleteQuery(); mPoints = new0 Polypoint(vformat, vbuffer); mPoints->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); mScene->AttachChild(mPoints); mScene->AttachChild(mesh); }
//---------------------------------------------------------------------------- RawTerrainPage::RawTerrainPage (VertexFormat* vformat, int size, float* heights, const Float2& origin, float spacing) : mSize(size), mSizeM1(size - 1), mHeights(heights), mOrigin(origin), mSpacing(spacing) { // size = 2^p + 1, p <= 7 assertion(size == 3 || size == 5 || size == 9 || size == 17 || size == 33 || size == 65 || size == 129, "Invalid page size\n"); mInvSpacing = 1.0f/mSpacing; // 创建地形页网格 float ext = mSpacing*mSizeM1; TriMesh* mesh = StandardMesh(vformat).Rectangle(mSize, mSize, ext, ext); mVFormat = vformat; mVBuffer = mesh->GetVertexBuffer(); mIBuffer = mesh->GetIndexBuffer(); delete0(mesh); // 修改地形顶点数据 VertexBufferAccessor vba(mVFormat, mVBuffer); int numVertices = mVBuffer->GetNumElements(); for (int i = 0; i < numVertices; ++i) { int x = i % mSize; int y = i / mSize; vba.Position<Float3>(i) = Float3(GetX(x), GetY(y), GetHeight(i)); vba.Normal<Float3>(i) = Float3(0.0f, 0.0f, 1.0f); } UpdateModelSpace(Renderable::GU_NORMALS); mUV01 = Float4(8.0f, 8.0f, 8.0f, 8.0f); mUV23 = Float4(8.0f, 8.0f, 8.0f, 8.0f); mUV4 = Float4(8.0f, 8.0f, 8.0f, 8.0f); mUV01Float = new0 ShaderFloat(1); mUV23Float = new0 ShaderFloat(1); mUV4Float = new0 ShaderFloat(1); SetUV0(Float2(mUV01[0], mUV01[1])); SetUV1(Float2(mUV01[2], mUV01[3])); SetUV2(Float2(mUV23[0], mUV23[1])); SetUV3(Float2(mUV23[2], mUV23[3])); SetUV4(Float2(mUV4[0], mUV4[1])); mTextureAlpha = new0 Texture2D(Texture::TF_A8R8G8B8, mSize, mSize, 1); mTextureDefault = DynamicCast<Texture2D>(ResourceManager::GetSingleton() .BlockLoad("Data/Images/Terrain/NiTu.dds")); assertion(mTextureDefault!=0, "Load texture %s failed.", "Data/Images/Terrain/NiTu.dds"); }
//---------------------------------------------------------------------------- TriMesh* StandardMesh::Box (float fXExtent, float fYExtent, float fZExtent) { int iVQuantity = 8; int iTQuantity = 12; CreateData(iVQuantity,iTQuantity); // generate geometry m_akVertex[0] = Vector3f(-fXExtent,-fYExtent,-fZExtent); m_akVertex[1] = Vector3f(+fXExtent,-fYExtent,-fZExtent); m_akVertex[2] = Vector3f(+fXExtent,+fYExtent,-fZExtent); m_akVertex[3] = Vector3f(-fXExtent,+fYExtent,-fZExtent); m_akVertex[4] = Vector3f(-fXExtent,-fYExtent,+fZExtent); m_akVertex[5] = Vector3f(+fXExtent,-fYExtent,+fZExtent); m_akVertex[6] = Vector3f(+fXExtent,+fYExtent,+fZExtent); m_akVertex[7] = Vector3f(-fXExtent,+fYExtent,+fZExtent); if (m_bUVs) { m_akUV[0] = Vector2f(0.25f,0.75f); m_akUV[1] = Vector2f(0.75f,0.75f); m_akUV[2] = Vector2f(0.75f,0.25f); m_akUV[3] = Vector2f(0.25f,0.25f); m_akUV[4] = Vector2f(0.0f,1.0f); m_akUV[5] = Vector2f(1.0f,1.0f); m_akUV[6] = Vector2f(1.0f,0.0f); m_akUV[7] = Vector2f(0.0f,0.0f); } // generate connectivity (outside view) m_aiIndex[ 0] = 0; m_aiIndex[ 1] = 2; m_aiIndex[ 2] = 1; m_aiIndex[ 3] = 0; m_aiIndex[ 4] = 3; m_aiIndex[ 5] = 2; m_aiIndex[ 6] = 0; m_aiIndex[ 7] = 1; m_aiIndex[ 8] = 5; m_aiIndex[ 9] = 0; m_aiIndex[10] = 5; m_aiIndex[11] = 4; m_aiIndex[12] = 0; m_aiIndex[13] = 4; m_aiIndex[14] = 7; m_aiIndex[15] = 0; m_aiIndex[16] = 7; m_aiIndex[17] = 3; m_aiIndex[18] = 6; m_aiIndex[19] = 4; m_aiIndex[20] = 5; m_aiIndex[21] = 6; m_aiIndex[22] = 7; m_aiIndex[23] = 4; m_aiIndex[24] = 6; m_aiIndex[25] = 5; m_aiIndex[26] = 1; m_aiIndex[27] = 6; m_aiIndex[28] = 1; m_aiIndex[29] = 2; m_aiIndex[30] = 6; m_aiIndex[31] = 2; m_aiIndex[32] = 3; m_aiIndex[33] = 6; m_aiIndex[34] = 3; m_aiIndex[35] = 7; if (m_bInside) { ReverseTriangleOrder(iTQuantity); } TransformData(iVQuantity); TriMesh* pkMesh = WM3_NEW TriMesh(m_spkVertices,m_spkIndices,false); if (m_spkNormals) { pkMesh->Normals = m_spkNormals; pkMesh->UpdateMS(true); } return pkMesh; }
// used to change the camera view to a colony when selecting a new colony. Vec3f GeoDeVisualizerApp::getAverageVertex(u32 faceIndex) { if (faceIndex >= mTriangles.getNumTriangles()) return Vec3f(0,0,0); auto vertices = mTriangles.getVertices(); Vec3f f1 = vertices[(3*faceIndex)]; Vec3f f2 = vertices[(3*faceIndex)+1]; Vec3f f3 = vertices[(3*faceIndex)+2]; Vec3f ave = (f1 + f2 + f3) / 3.0; return ave; }
double angleBetweenPoints(TriMesh& mesh, TriMesh::VertexHandle& Ah, TriMesh::VertexHandle& Oh, TriMesh::VertexHandle& Bh) { // returns the angle formed by the points AOC TriMesh::Point A, O, B; A = mesh.point( Ah ); O = mesh.point( Oh ); B = mesh.point( Bh ); double a = (A-O) | (B-O); return a; }