Rename skeleton generator to bone generator

master
Jeremy HU 2022-12-03 17:37:15 +11:00
parent 374f16038d
commit ef0fe2dcfe
5 changed files with 85 additions and 22 deletions

View File

@ -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

View File

@ -0,0 +1,35 @@
#include "bone_generator.h"
#include <dust3d/mesh/smooth_normal.h>
#include <dust3d/mesh/trim_vertices.h>
void BoneGenerator::process()
{
generate();
m_bonePreviewMeshes = std::make_unique<std::map<dust3d::Uuid, std::unique_ptr<ModelMesh>>>();
for (auto& it : bonePreviews()) {
dust3d::trimVertices(&it.second.vertices, true);
for (auto& it : it.second.vertices) {
it *= 2.0;
}
std::vector<dust3d::Vector3> 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<std::vector<dust3d::Vector3>> previewTriangleVertexNormals;
dust3d::smoothNormal(it.second.vertices,
it.second.triangles,
previewTriangleNormals,
0,
&previewTriangleVertexNormals);
(*m_bonePreviewMeshes)[it.first] = std::make_unique<ModelMesh>(it.second.vertices,
it.second.triangles,
previewTriangleVertexNormals);
}
emit finished();
}

View File

@ -0,0 +1,20 @@
#ifndef DUST3D_APPLICATION_BONE_GENERATOR_H_
#define DUST3D_APPLICATION_BONE_GENERATOR_H_
#include "model_mesh.h"
#include <QObject>
#include <dust3d/rig/bone_generator.h>
#include <memory>
class BoneGenerator : public QObject, public dust3d::BoneGenerator {
Q_OBJECT
public slots:
void process();
signals:
void finished();
private:
std::unique_ptr<std::map<dust3d::Uuid, std::unique_ptr<ModelMesh>>> m_bonePreviewMeshes;
};
#endif

View File

@ -20,46 +20,46 @@
* SOFTWARE.
*/
#include <dust3d/rig/skeleton_generator.h>
#include <dust3d/rig/bone_generator.h>
#include <unordered_map>
namespace dust3d {
SkeletonGenerator::SkeletonGenerator()
BoneGenerator::BoneGenerator()
{
}
void SkeletonGenerator::setVertices(const std::vector<Vector3>& vertices)
void BoneGenerator::setVertices(const std::vector<Vector3>& vertices)
{
m_vertices = vertices;
}
void SkeletonGenerator::setTriangles(const std::vector<std::vector<size_t>>& triangles)
void BoneGenerator::setTriangles(const std::vector<std::vector<size_t>>& triangles)
{
m_triangles = triangles;
}
void SkeletonGenerator::setPositionToNodeMap(const std::map<PositionKey, Uuid>& positionToNodeMap)
void BoneGenerator::setPositionToNodeMap(const std::map<PositionKey, Uuid>& 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<size_t>& visited)
Uuid BoneGenerator::resolveVertexSourceByBreadthFirstSearch(size_t vertexIndex, std::unordered_set<size_t>& 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<Uuid, BoneGenerator::BonePreview>& BoneGenerator::bonePreviews()
{
return m_bonePreviews;
}
void BoneGenerator::generateBonePreviews()
{
for (const auto& it : m_boneVertices) {
BonePreview bonePreview;

View File

@ -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 <array>
#include <dust3d/base/color.h>
@ -35,7 +35,7 @@
namespace dust3d {
class SkeletonGenerator {
class BoneGenerator {
public:
struct NodeBinding {
std::set<Uuid> boneIds;
@ -63,7 +63,7 @@ public:
std::vector<std::vector<size_t>> triangles;
};
SkeletonGenerator();
BoneGenerator();
void setVertices(const std::vector<Vector3>& vertices);
void setTriangles(const std::vector<std::vector<size_t>>& triangles);
void setPositionToNodeMap(const std::map<PositionKey, Uuid>& 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<Uuid, BonePreview>& bonePreviews();
private:
std::vector<Vector3> m_vertices;