From ef0fe2dcfe034c61a7574520d20208429bfb7661 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Sat, 3 Dec 2022 17:37:15 +1100 Subject: [PATCH] Rename skeleton generator to bone generator --- application/application.pro | 6 ++- application/sources/bone_generator.cc | 35 ++++++++++++++++++ application/sources/bone_generator.h | 20 ++++++++++ ...keleton_generator.cc => bone_generator.cc} | 37 +++++++++++-------- ...{skeleton_generator.h => bone_generator.h} | 9 +++-- 5 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 application/sources/bone_generator.cc create mode 100644 application/sources/bone_generator.h rename dust3d/rig/{skeleton_generator.cc => bone_generator.cc} (84%) rename dust3d/rig/{skeleton_generator.h => bone_generator.h} (95%) diff --git a/application/application.pro b/application/application.pro index d68cfe57..58c79bd8 100644 --- a/application/application.pro +++ b/application/application.pro @@ -95,6 +95,8 @@ include(third_party/QtAwesome/QtAwesome/QtAwesome.pri) HEADERS += sources/about_widget.h SOURCES += sources/about_widget.cc +HEADERS += sources/bone_generator.h +SOURCES += sources/bone_generator.cc HEADERS += sources/bone_list_model.h SOURCES += sources/bone_list_model.cc HEADERS += sources/bone_manage_widget.h @@ -310,8 +312,8 @@ HEADERS += ../dust3d/mesh/tube_mesh_builder.h SOURCES += ../dust3d/mesh/tube_mesh_builder.cc HEADERS += ../dust3d/mesh/weld_vertices.h SOURCES += ../dust3d/mesh/weld_vertices.cc -HEADERS += ../dust3d/rig/skeleton_generator.h -SOURCES += ../dust3d/rig/skeleton_generator.cc +HEADERS += ../dust3d/rig/bone_generator.h +SOURCES += ../dust3d/rig/bone_generator.cc HEADERS += ../dust3d/uv/chart_packer.h SOURCES += ../dust3d/uv/chart_packer.cc HEADERS += ../dust3d/uv/max_rectangles.h diff --git a/application/sources/bone_generator.cc b/application/sources/bone_generator.cc new file mode 100644 index 00000000..2ad920f9 --- /dev/null +++ b/application/sources/bone_generator.cc @@ -0,0 +1,35 @@ +#include "bone_generator.h" +#include +#include + +void BoneGenerator::process() +{ + generate(); + + m_bonePreviewMeshes = std::make_unique>>(); + for (auto& it : bonePreviews()) { + dust3d::trimVertices(&it.second.vertices, true); + for (auto& it : it.second.vertices) { + it *= 2.0; + } + std::vector previewTriangleNormals; + previewTriangleNormals.reserve(it.second.triangles.size()); + for (const auto& face : it.second.triangles) { + previewTriangleNormals.emplace_back(dust3d::Vector3::normal( + it.second.vertices[face[0]], + it.second.vertices[face[1]], + it.second.vertices[face[2]])); + } + std::vector> previewTriangleVertexNormals; + dust3d::smoothNormal(it.second.vertices, + it.second.triangles, + previewTriangleNormals, + 0, + &previewTriangleVertexNormals); + (*m_bonePreviewMeshes)[it.first] = std::make_unique(it.second.vertices, + it.second.triangles, + previewTriangleVertexNormals); + } + + emit finished(); +} diff --git a/application/sources/bone_generator.h b/application/sources/bone_generator.h new file mode 100644 index 00000000..324b4076 --- /dev/null +++ b/application/sources/bone_generator.h @@ -0,0 +1,20 @@ +#ifndef DUST3D_APPLICATION_BONE_GENERATOR_H_ +#define DUST3D_APPLICATION_BONE_GENERATOR_H_ + +#include "model_mesh.h" +#include +#include +#include + +class BoneGenerator : public QObject, public dust3d::BoneGenerator { + Q_OBJECT +public slots: + void process(); +signals: + void finished(); + +private: + std::unique_ptr>> m_bonePreviewMeshes; +}; + +#endif diff --git a/dust3d/rig/skeleton_generator.cc b/dust3d/rig/bone_generator.cc similarity index 84% rename from dust3d/rig/skeleton_generator.cc rename to dust3d/rig/bone_generator.cc index 58c4251a..4730e991 100644 --- a/dust3d/rig/skeleton_generator.cc +++ b/dust3d/rig/bone_generator.cc @@ -20,46 +20,46 @@ * SOFTWARE. */ -#include +#include #include namespace dust3d { -SkeletonGenerator::SkeletonGenerator() +BoneGenerator::BoneGenerator() { } -void SkeletonGenerator::setVertices(const std::vector& vertices) +void BoneGenerator::setVertices(const std::vector& vertices) { m_vertices = vertices; } -void SkeletonGenerator::setTriangles(const std::vector>& triangles) +void BoneGenerator::setTriangles(const std::vector>& triangles) { m_triangles = triangles; } -void SkeletonGenerator::setPositionToNodeMap(const std::map& positionToNodeMap) +void BoneGenerator::setPositionToNodeMap(const std::map& positionToNodeMap) { m_positionToNodeMap = positionToNodeMap; } -void SkeletonGenerator::addBone(const Uuid& boneId, const Bone& bone) +void BoneGenerator::addBone(const Uuid& boneId, const Bone& bone) { m_boneMap.emplace(std::make_pair(boneId, bone)); } -void SkeletonGenerator::addNode(const Uuid& nodeId, const Node& node) +void BoneGenerator::addNode(const Uuid& nodeId, const Node& node) { m_nodeMap.emplace(std::make_pair(nodeId, node)); } -void SkeletonGenerator::addNodeBinding(const Uuid& nodeId, const NodeBinding& nodeBinding) +void BoneGenerator::addNodeBinding(const Uuid& nodeId, const NodeBinding& nodeBinding) { m_nodeBindingMap.emplace(std::make_pair(nodeId, nodeBinding)); } -void SkeletonGenerator::buildEdges() +void BoneGenerator::buildEdges() { for (const auto& triangle : m_triangles) { for (size_t i = 0; i < 3; ++i) { @@ -70,7 +70,7 @@ void SkeletonGenerator::buildEdges() } } -Uuid SkeletonGenerator::resolveVertexSourceByBreadthFirstSearch(size_t vertexIndex, std::unordered_set& visited) +Uuid BoneGenerator::resolveVertexSourceByBreadthFirstSearch(size_t vertexIndex, std::unordered_set& visited) { visited.insert(vertexIndex); auto findNeighbors = m_edges.find(vertexIndex); @@ -90,7 +90,7 @@ Uuid SkeletonGenerator::resolveVertexSourceByBreadthFirstSearch(size_t vertexInd return Uuid(); } -void SkeletonGenerator::resolveVertexSources() +void BoneGenerator::resolveVertexSources() { m_vertexSourceNodes.resize(m_vertices.size()); for (size_t i = 0; i < m_vertices.size(); ++i) { @@ -108,7 +108,7 @@ void SkeletonGenerator::resolveVertexSources() } } -void SkeletonGenerator::buildBoneJoints() +void BoneGenerator::buildBoneJoints() { for (auto& boneIt : m_boneMap) { boneIt.second.startPositions.resize(boneIt.second.joints.size()); @@ -126,12 +126,12 @@ void SkeletonGenerator::buildBoneJoints() } } -void SkeletonGenerator::assignVerticesToBoneJoints() +void BoneGenerator::assignVerticesToBoneJoints() { // TODO: } -void SkeletonGenerator::groupBoneVertices() +void BoneGenerator::groupBoneVertices() { for (size_t i = 0; i < m_vertexSourceNodes.size(); ++i) { const Uuid& sourceNodeId = m_vertexSourceNodes[i]; @@ -146,7 +146,7 @@ void SkeletonGenerator::groupBoneVertices() } } -void SkeletonGenerator::generate() +void BoneGenerator::generate() { buildEdges(); resolveVertexSources(); @@ -156,7 +156,12 @@ void SkeletonGenerator::generate() generateBonePreviews(); } -void SkeletonGenerator::generateBonePreviews() +std::map& BoneGenerator::bonePreviews() +{ + return m_bonePreviews; +} + +void BoneGenerator::generateBonePreviews() { for (const auto& it : m_boneVertices) { BonePreview bonePreview; diff --git a/dust3d/rig/skeleton_generator.h b/dust3d/rig/bone_generator.h similarity index 95% rename from dust3d/rig/skeleton_generator.h rename to dust3d/rig/bone_generator.h index cb8af3d9..6d9591fb 100644 --- a/dust3d/rig/skeleton_generator.h +++ b/dust3d/rig/bone_generator.h @@ -20,8 +20,8 @@ * SOFTWARE. */ -#ifndef DUST3D_RIG_SKELETON_GENERATOR_H_ -#define DUST3D_RIG_SKELETON_GENERATOR_H_ +#ifndef DUST3D_RIG_BONE_GENERATOR_H_ +#define DUST3D_RIG_BONE_GENERATOR_H_ #include #include @@ -35,7 +35,7 @@ namespace dust3d { -class SkeletonGenerator { +class BoneGenerator { public: struct NodeBinding { std::set boneIds; @@ -63,7 +63,7 @@ public: std::vector> triangles; }; - SkeletonGenerator(); + BoneGenerator(); void setVertices(const std::vector& vertices); void setTriangles(const std::vector>& triangles); void setPositionToNodeMap(const std::map& positionToNodeMap); @@ -71,6 +71,7 @@ public: void addNodeBinding(const Uuid& nodeId, const NodeBinding& nodeBidning); void addNode(const Uuid& nodeId, const Node& node); void generate(); + std::map& bonePreviews(); private: std::vector m_vertices;