Mix body bone color
parent
d2bc7716f2
commit
18c493def6
|
@ -45,7 +45,9 @@ void BoneGenerator::setPositionToNodeMap(const std::map<PositionKey, Uuid>& posi
|
||||||
|
|
||||||
void BoneGenerator::addBone(const Uuid& boneId, const Bone& bone)
|
void BoneGenerator::addBone(const Uuid& boneId, const Bone& bone)
|
||||||
{
|
{
|
||||||
m_boneMap.emplace(std::make_pair(boneId, bone));
|
Bone newBone = bone;
|
||||||
|
newBone.index = m_boneMap.size();
|
||||||
|
m_boneMap.emplace(std::make_pair(boneId, std::move(newBone)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoneGenerator::addNode(const Uuid& nodeId, const Node& node)
|
void BoneGenerator::addNode(const Uuid& nodeId, const Node& node)
|
||||||
|
@ -167,7 +169,8 @@ BoneGenerator::BonePreview& BoneGenerator::bodyPreview()
|
||||||
|
|
||||||
void BoneGenerator::addBonePreviewTriangle(BonePreview& bonePreview,
|
void BoneGenerator::addBonePreviewTriangle(BonePreview& bonePreview,
|
||||||
std::unordered_map<size_t, size_t>& oldToNewVertexMap,
|
std::unordered_map<size_t, size_t>& oldToNewVertexMap,
|
||||||
const std::vector<size_t>& triangle)
|
const std::vector<size_t>& triangle,
|
||||||
|
const Color& color)
|
||||||
{
|
{
|
||||||
std::vector<size_t> newTriangle(3);
|
std::vector<size_t> newTriangle(3);
|
||||||
for (size_t i = 0; i < 3; ++i) {
|
for (size_t i = 0; i < 3; ++i) {
|
||||||
|
@ -176,7 +179,7 @@ void BoneGenerator::addBonePreviewTriangle(BonePreview& bonePreview,
|
||||||
oldToNewVertexMap.insert(std::make_pair(triangle[i], bonePreview.vertices.size()));
|
oldToNewVertexMap.insert(std::make_pair(triangle[i], bonePreview.vertices.size()));
|
||||||
newTriangle[i] = bonePreview.vertices.size();
|
newTriangle[i] = bonePreview.vertices.size();
|
||||||
bonePreview.vertices.push_back(m_vertices[triangle[i]]);
|
bonePreview.vertices.push_back(m_vertices[triangle[i]]);
|
||||||
bonePreview.vertexColors.push_back(Color(1.0, 1.0, 1.0));
|
bonePreview.vertexColors.push_back(color);
|
||||||
} else {
|
} else {
|
||||||
newTriangle[i] = findVertex->second;
|
newTriangle[i] = findVertex->second;
|
||||||
}
|
}
|
||||||
|
@ -186,10 +189,26 @@ void BoneGenerator::addBonePreviewTriangle(BonePreview& bonePreview,
|
||||||
|
|
||||||
void BoneGenerator::generateBonePreviews()
|
void BoneGenerator::generateBonePreviews()
|
||||||
{
|
{
|
||||||
|
const static std::array<Color, 7> s_colors = {
|
||||||
|
Color(155.0 / 255.0, 95.0 / 255.0, 224.0 / 255.0),
|
||||||
|
Color(22.0 / 255.0, 164.0 / 255.0, 216.0 / 255.0),
|
||||||
|
Color(96.0 / 255.0, 219.0 / 255.0, 232.0 / 255.0),
|
||||||
|
Color(139.0 / 255.0, 211.0 / 255.0, 70.0 / 255.0),
|
||||||
|
Color(239.0 / 255.0, 223.0 / 255.0, 72.0 / 255.0),
|
||||||
|
Color(249.0 / 255.0, 165.0 / 255.0, 44.0 / 255.0),
|
||||||
|
Color(214.0 / 255.0, 78.0 / 255.0, 18.0 / 255.0),
|
||||||
|
};
|
||||||
|
|
||||||
for (const auto& it : m_boneVertices) {
|
for (const auto& it : m_boneVertices) {
|
||||||
|
auto findBone = m_boneMap.find(it.first);
|
||||||
|
if (findBone == m_boneMap.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
BonePreview bonePreview;
|
BonePreview bonePreview;
|
||||||
std::unordered_map<size_t, size_t> oldToNewVertexMap;
|
std::unordered_map<size_t, size_t> oldToNewVertexMap;
|
||||||
|
|
||||||
|
const auto& color = s_colors[findBone->second.index % s_colors.size()];
|
||||||
|
|
||||||
for (const auto& triangle : m_triangles) {
|
for (const auto& triangle : m_triangles) {
|
||||||
size_t countedPoints = 0;
|
size_t countedPoints = 0;
|
||||||
for (size_t i = 0; i < 3; ++i) {
|
for (size_t i = 0; i < 3; ++i) {
|
||||||
|
@ -198,16 +217,32 @@ void BoneGenerator::generateBonePreviews()
|
||||||
}
|
}
|
||||||
if (0 == countedPoints)
|
if (0 == countedPoints)
|
||||||
continue;
|
continue;
|
||||||
addBonePreviewTriangle(bonePreview, oldToNewVertexMap, triangle);
|
addBonePreviewTriangle(bonePreview, oldToNewVertexMap, triangle, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bonePreviews.emplace(std::make_pair(it.first, std::move(bonePreview)));
|
m_bonePreviews.emplace(std::make_pair(it.first, std::move(bonePreview)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<size_t, size_t> bodyOldToNewVertexMap;
|
std::unordered_map<size_t, std::vector<Color>> vertexSkinColors;
|
||||||
for (const auto& triangle : m_triangles) {
|
for (const auto& it : m_boneVertices) {
|
||||||
addBonePreviewTriangle(m_bodyPreview, bodyOldToNewVertexMap, triangle);
|
auto findBone = m_boneMap.find(it.first);
|
||||||
|
if (findBone == m_boneMap.end())
|
||||||
|
continue;
|
||||||
|
const auto& color = s_colors[findBone->second.index % s_colors.size()];
|
||||||
|
for (const auto& vertexIndex : it.second)
|
||||||
|
vertexSkinColors[vertexIndex].push_back(color);
|
||||||
}
|
}
|
||||||
|
std::vector<Color> bodyVertexColors(m_vertices.size());
|
||||||
|
for (const auto& it : vertexSkinColors) {
|
||||||
|
Color color;
|
||||||
|
for (const auto& colorIt : it.second)
|
||||||
|
color = color + colorIt;
|
||||||
|
color = color * (1.0 / it.second.size());
|
||||||
|
bodyVertexColors[it.first] = color;
|
||||||
|
}
|
||||||
|
m_bodyPreview.vertices = m_vertices;
|
||||||
|
m_bodyPreview.triangles = m_triangles;
|
||||||
|
m_bodyPreview.vertexColors = std::move(bodyVertexColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Bone {
|
struct Bone {
|
||||||
|
size_t index;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<Uuid> joints;
|
std::vector<Uuid> joints;
|
||||||
std::vector<Vector3> startPositions;
|
std::vector<Vector3> startPositions;
|
||||||
|
@ -100,7 +101,8 @@ private:
|
||||||
void generateBonePreviews();
|
void generateBonePreviews();
|
||||||
void addBonePreviewTriangle(BonePreview& bonePreview,
|
void addBonePreviewTriangle(BonePreview& bonePreview,
|
||||||
std::unordered_map<size_t, size_t>& oldToNewVertexMap,
|
std::unordered_map<size_t, size_t>& oldToNewVertexMap,
|
||||||
const std::vector<size_t>& triangle);
|
const std::vector<size_t>& triangle,
|
||||||
|
const Color& color);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue