From 6864f91b053cf4719f566b09315593a9e4f0541f Mon Sep 17 00:00:00 2001 From: Nou Date: Sat, 16 May 2015 09:58:01 -0700 Subject: [PATCH] Quad triangulation --- extensions/common/simulation/object.cpp | 48 ++++++++++++++++++++++--- extensions/common/simulation/object.hpp | 7 +++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/extensions/common/simulation/object.cpp b/extensions/common/simulation/object.cpp index 3313183fb7..c57b222ba1 100644 --- a/extensions/common/simulation/object.cpp +++ b/extensions/common/simulation/object.cpp @@ -28,10 +28,38 @@ ace::simulation::face::face( ace::simulation::lod *object_lod) { this->type = p3d_face->type; - for (uint16_t vertex_id : p3d_face->vertex_table) { - this->vertices.push_back(object_lod->vertices[vertex_id]); - object_lod->vertices[vertex_id]->faces.push_back(this); - } + if (type == 3) { + for (uint16_t vertex_id : p3d_face->vertex_table) { + this->vertices.push_back(object_lod->vertices[vertex_id]); + object_lod->vertices[vertex_id]->faces.push_back(this); + } + } + else if(type == 4) { + this->vertices.push_back(object_lod->vertices[p3d_face->vertex_table[0]]); + object_lod->vertices[p3d_face->vertex_table[0]]->faces.push_back(this); + + this->vertices.push_back(object_lod->vertices[p3d_face->vertex_table[1]]); + object_lod->vertices[p3d_face->vertex_table[1]]->faces.push_back(this); + + this->vertices.push_back(object_lod->vertices[p3d_face->vertex_table[2]]); + object_lod->vertices[p3d_face->vertex_table[2]]->faces.push_back(this); + + this->sub_face = std::make_shared(p3d_face->vertex_table[2], p3d_face->vertex_table[3], p3d_face->vertex_table[0], object_lod); + } +} + +ace::simulation::face::face(uint32_t v1, uint32_t v2, uint32_t v3, ace::simulation::lod *object_lod) { + this->type = 3; + + this->vertices.push_back(object_lod->vertices[v1]); + object_lod->vertices[v1]->faces.push_back(this); + + this->vertices.push_back(object_lod->vertices[v2]); + object_lod->vertices[v2]->faces.push_back(this); + + this->vertices.push_back(object_lod->vertices[v3]); + object_lod->vertices[v3]->faces.push_back(this); + } ace::simulation::face::~face() @@ -59,6 +87,9 @@ ace::simulation::named_selection::named_selection( } for (uint16_t face_id : p3d_selection->faces.data) { this->faces.push_back(object_lod->faces[face_id]); + if (object_lod->faces[face_id]->type == 4) { + this->faces.push_back(object_lod->faces[face_id]->sub_face); + } } } @@ -109,6 +140,15 @@ ace::simulation::lod::lod(const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) { this->selections[p3d_selection->name] = std::make_shared(p3d_selection, p3d_lod, p3d, this); } + std::vector new_faces; + for (auto test_face : this->faces) { + if (test_face->type == 4) { + new_faces.push_back(test_face->sub_face); + } + } + for (auto new_face : new_faces) { + this->faces.push_back(new_face); + } } diff --git a/extensions/common/simulation/object.hpp b/extensions/common/simulation/object.hpp index 01dd24ca8c..cc9412a86e 100644 --- a/extensions/common/simulation/object.hpp +++ b/extensions/common/simulation/object.hpp @@ -26,6 +26,9 @@ namespace ace { class object; typedef std::shared_ptr object_p; + class face; + typedef std::shared_ptr face_p; + typedef std::map animation_transform; class vertex_table { @@ -43,11 +46,13 @@ namespace ace { public: face() {}; face(const ace::p3d::face_p, const ace::p3d::lod_p, const ace::p3d::model_p, ace::simulation::lod *); + face(uint32_t, uint32_t, uint32_t, ace::simulation::lod *); ~face(); uint8_t type; std::vector vertices; + face_p sub_face; }; - typedef std::shared_ptr face_p; + class named_selection { public: