Add skeleton generator

master
Jeremy HU 2022-11-14 23:31:10 +11:00
parent 2d5e98d955
commit 6335742b17
3 changed files with 135 additions and 0 deletions

View File

@ -305,6 +305,8 @@ HEADERS += ../dust3d/mesh/tube_mesh_builder.h
SOURCES += ../dust3d/mesh/tube_mesh_builder.cc SOURCES += ../dust3d/mesh/tube_mesh_builder.cc
HEADERS += ../dust3d/mesh/weld_vertices.h HEADERS += ../dust3d/mesh/weld_vertices.h
SOURCES += ../dust3d/mesh/weld_vertices.cc SOURCES += ../dust3d/mesh/weld_vertices.cc
HEADERS += ../dust3d/rig/skeleton_generator.h
SOURCES += ../dust3d/rig/skeleton_generator.cc
HEADERS += ../dust3d/uv/chart_packer.h HEADERS += ../dust3d/uv/chart_packer.h
SOURCES += ../dust3d/uv/chart_packer.cc SOURCES += ../dust3d/uv/chart_packer.cc
HEADERS += ../dust3d/uv/max_rectangles.h HEADERS += ../dust3d/uv/max_rectangles.h

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2016-2022 Jeremy HU <jeremy-at-dust3d dot org>. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <dust3d/rig/skeleton_generator.h>
namespace dust3d {
SkeletonGenerator::SkeletonGenerator()
{
}
void SkeletonGenerator::setVertices(const std::vector<Vector3>& vertices)
{
m_vertices = vertices;
}
void SkeletonGenerator::setFaces(const std::vector<std::vector<size_t>>& faces)
{
m_faces = faces;
}
void SkeletonGenerator::setPositionToNodeMap(const std::map<PositionKey, Uuid>& positionToNodeMap)
{
m_positionToNodeMap = positionToNodeMap;
}
void SkeletonGenerator::addBone(const Uuid& boneId, const Bone& bone)
{
m_boneMap.emplace(std::make_pair(boneId, bone));
}
void SkeletonGenerator::addNodeBinding(const Uuid& nodeId, const NodeBinding& node)
{
m_nodeBindingMap.emplace(std::make_pair(nodeId, node));
}
void SkeletonGenerator::bind()
{
// TODO: Build vertex edge map
// TODO: Bind unbound nodes
// TODO: Build bone skeleton
// TODO: Assign bone to vertex
// TODO: finalize
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2016-2022 Jeremy HU <jeremy-at-dust3d dot org>. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef DUST3D_RIG_SKELETON_GENERATOR_H_
#define DUST3D_RIG_SKELETON_GENERATOR_H_
#include <dust3d/base/position_key.h>
#include <dust3d/base/uuid.h>
#include <dust3d/base/vector3.h>
#include <map>
#include <vector>
namespace dust3d {
class SkeletonGenerator {
public:
struct NodeBinding {
std::vector<Uuid> boneIds;
bool bontJoint = false;
};
struct Bone {
std::string name;
std::string parent;
};
SkeletonGenerator();
void setVertices(const std::vector<Vector3>& vertices);
void setFaces(const std::vector<std::vector<size_t>>& faces);
void setPositionToNodeMap(const std::map<PositionKey, Uuid>& positionToNodeMap);
void addBone(const Uuid& boneId, const Bone& bone);
void addNodeBinding(const Uuid& nodeId, const NodeBinding& node);
void bind();
private:
std::vector<Vector3> m_vertices;
std::vector<std::vector<size_t>> m_faces;
std::map<PositionKey, Uuid> m_positionToNodeMap;
std::map<Uuid, NodeBinding> m_nodeBindingMap;
std::map<Uuid, Bone> m_boneMap;
};
}
#endif