From 6335742b174dddfa11421f57f4856832010e1320 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Mon, 14 Nov 2022 23:31:10 +1100 Subject: [PATCH] Add skeleton generator --- application/application.pro | 2 + dust3d/rig/skeleton_generator.cc | 69 ++++++++++++++++++++++++++++++++ dust3d/rig/skeleton_generator.h | 64 +++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 dust3d/rig/skeleton_generator.cc create mode 100644 dust3d/rig/skeleton_generator.h diff --git a/application/application.pro b/application/application.pro index 7dbcdf7d..dbb070e0 100644 --- a/application/application.pro +++ b/application/application.pro @@ -305,6 +305,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/uv/chart_packer.h SOURCES += ../dust3d/uv/chart_packer.cc HEADERS += ../dust3d/uv/max_rectangles.h diff --git a/dust3d/rig/skeleton_generator.cc b/dust3d/rig/skeleton_generator.cc new file mode 100644 index 00000000..e7838352 --- /dev/null +++ b/dust3d/rig/skeleton_generator.cc @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2016-2022 Jeremy HU . 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 + +namespace dust3d { + +SkeletonGenerator::SkeletonGenerator() +{ +} + +void SkeletonGenerator::setVertices(const std::vector& vertices) +{ + m_vertices = vertices; +} + +void SkeletonGenerator::setFaces(const std::vector>& faces) +{ + m_faces = faces; +} + +void SkeletonGenerator::setPositionToNodeMap(const std::map& 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 +} + +} diff --git a/dust3d/rig/skeleton_generator.h b/dust3d/rig/skeleton_generator.h new file mode 100644 index 00000000..c91f927d --- /dev/null +++ b/dust3d/rig/skeleton_generator.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016-2022 Jeremy HU . 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 +#include +#include +#include +#include + +namespace dust3d { + +class SkeletonGenerator { +public: + struct NodeBinding { + std::vector boneIds; + bool bontJoint = false; + }; + + struct Bone { + std::string name; + std::string parent; + }; + + SkeletonGenerator(); + void setVertices(const std::vector& vertices); + void setFaces(const std::vector>& faces); + void setPositionToNodeMap(const std::map& positionToNodeMap); + void addBone(const Uuid& boneId, const Bone& bone); + void addNodeBinding(const Uuid& nodeId, const NodeBinding& node); + void bind(); + +private: + std::vector m_vertices; + std::vector> m_faces; + std::map m_positionToNodeMap; + std::map m_nodeBindingMap; + std::map m_boneMap; +}; + +} + +#endif