From 8de735de94d59213a05637b5b86aba1cc1534d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Wed, 25 Jul 2012 14:53:05 +0000 Subject: [PATCH] Made bottom and top vertex for primitives plugin scriptable. git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15105 383ad7c9-94d9-4d36-a494-682f7c89f535 --- .../PrimitivesGenerator.cc | 47 ++++++++++++------- .../PrimitivesGenerator.hh | 4 +- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Plugin-PrimitivesGenerator/PrimitivesGenerator.cc b/Plugin-PrimitivesGenerator/PrimitivesGenerator.cc index 0a3a679ec..5984169bb 100644 --- a/Plugin-PrimitivesGenerator/PrimitivesGenerator.cc +++ b/Plugin-PrimitivesGenerator/PrimitivesGenerator.cc @@ -73,8 +73,8 @@ void PrimitivesGeneratorPlugin::initializePlugin() emit setSlotDescription("addSphere()" ,tr("Generates a sphere (ObjectId is returned)") ,QStringList(), QStringList()); emit setSlotDescription("addTriangulatedCylinder(Vector,Vector,double,double)", tr("Generates a triangulated cylinder (ObjectId is returned)") , - QStringList("position,Axis,Radius,Height"), - QStringList("Bottom center vertex position,Center axis,radius,height")); + QString("position,Axis,Radius,Height,Top,Bottom").split(","), + QString("Bottom center vertex position,Center axis,radius,height,add top vertex,add bottom vertex").split(",")); } void PrimitivesGeneratorPlugin::pluginsInitialized() { @@ -298,7 +298,7 @@ ACG::Vec3d PrimitivesGeneratorPlugin::positionOnCylinder(const int _sliceNumber, return position; } -int PrimitivesGeneratorPlugin::addTriangulatedCylinder(Vector _position, Vector _axis, double _radius, double _height) { +int PrimitivesGeneratorPlugin::addTriangulatedCylinder(Vector _position, Vector _axis, double _radius, double _height, bool _top, bool _bottom ) { // TODO: Generate texture coordinates for cylinder (Glu compatible) int newObject = addTriMesh(); @@ -318,8 +318,7 @@ int PrimitivesGeneratorPlugin::addTriangulatedCylinder(Vector _position, Vector //triMesh_->request_vertex_texcoords2D(); TriMesh::VertexHandle vh; - - vh = triMesh_->add_vertex(positionOnCylinder(0, 0,_position,_axis,_radius,_height)); + TriMesh::VertexHandle top = triMesh_->add_vertex(positionOnCylinder(0, 0,_position,_axis,_radius,_height)); //triMesh_->set_texcoord2D(vh, texCoordOnSphere(0, 0)); for (int st = 1; st < stacks_; ++st) { @@ -329,21 +328,26 @@ int PrimitivesGeneratorPlugin::addTriangulatedCylinder(Vector _position, Vector } } - vh = triMesh_->add_vertex(positionOnCylinder(slices_, stacks_,_position,_axis,_radius,_height)); + TriMesh::VertexHandle bottom = triMesh_->add_vertex(positionOnCylinder(slices_, stacks_,_position,_axis,_radius,_height)); //triMesh_->set_texcoord2D(vh, texCoordOnSphere(slices_, stacks_)); std::vector vhandles; // Add top triangle fan ( Vertex index is shifted by one for the first slice ) - for (int sl = 1; sl < slices_ + 1; ++sl) { + if ( _top ) { + for (int sl = 1; sl < slices_ + 1; ++sl) { - vhandles.clear(); + vhandles.clear(); - vhandles.push_back(triMesh_->vertex_handle(sl)); - vhandles.push_back(triMesh_->vertex_handle(0)); - vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_))); + vhandles.push_back(triMesh_->vertex_handle(sl)); + vhandles.push_back(triMesh_->vertex_handle(0)); + vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_))); - triMesh_->add_face(vhandles); + triMesh_->add_face(vhandles); + } + } else { + triMesh_->delete_vertex(top); + std::cerr << "Removed top" << std::endl; } for (int st = 0; st < stacks_ - 2; ++st) { @@ -378,17 +382,24 @@ int PrimitivesGeneratorPlugin::addTriangulatedCylinder(Vector _position, Vector const int bottomVertex = 1 + (stacks_ - 1) * slices_; // Add bottom triangle fan - for (int sl = 0; sl < slices_; ++sl) { + if ( _bottom) { + for (int sl = 0; sl < slices_; ++sl) { - vhandles.clear(); + vhandles.clear(); - vhandles.push_back(triMesh_->vertex_handle(bottomVertex)); - vhandles.push_back(triMesh_->vertex_handle(startTop + sl)); - vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_))); + vhandles.push_back(triMesh_->vertex_handle(bottomVertex)); + vhandles.push_back(triMesh_->vertex_handle(startTop + sl)); + vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_))); - triMesh_->add_face(vhandles); + triMesh_->add_face(vhandles); + } + } else { + triMesh_->delete_vertex(bottom); } + // Cleanup if bottom or top vertex is missing + triMesh_->garbage_collection(); + triMesh_->update_normals(); emit updatedObject(newObject,UPDATE_ALL); diff --git a/Plugin-PrimitivesGenerator/PrimitivesGenerator.hh b/Plugin-PrimitivesGenerator/PrimitivesGenerator.hh index 8c539a3d4..ee0b482c5 100644 --- a/Plugin-PrimitivesGenerator/PrimitivesGenerator.hh +++ b/Plugin-PrimitivesGenerator/PrimitivesGenerator.hh @@ -102,7 +102,9 @@ public slots: int addTriangulatedCylinder(Vector _position = Vector(0.0,0.0,0.0), Vector _axis = Vector(0.0,0.0,1.0), double _radius = 1.0, - double _height = 5.0); + double _height = 5.0, + bool _top = true, + bool _bottom = true); int addSphere(); int addTetrahedron(); int addPyramid(); -- GitLab