Fix object color
parent
5fd836bfdd
commit
65c793e670
|
@ -130,12 +130,6 @@ ModelMesh::ModelMesh(dust3d::Object& object)
|
|||
m_vertices = object.vertices;
|
||||
m_faces = object.triangleAndQuads;
|
||||
|
||||
//std::map<std::pair<dust3d::Uuid, dust3d::Uuid>, const dust3d::ObjectNode*> nodeMap;
|
||||
//for (size_t i = 0; i < object.nodes.size(); ++i) {
|
||||
// const auto& node = object.nodes[i];
|
||||
// nodeMap.insert({ { node.partId, node.nodeId }, &node });
|
||||
//}
|
||||
|
||||
m_triangleVertexCount = (int)object.triangles.size() * 3;
|
||||
m_triangleVertices = new ModelOpenGLVertex[m_triangleVertexCount];
|
||||
int destIndex = 0;
|
||||
|
@ -146,10 +140,10 @@ ModelMesh::ModelMesh(dust3d::Object& object)
|
|||
const dust3d::Vector2 defaultUv = dust3d::Vector2(0, 0);
|
||||
const dust3d::Vector3 defaultTangent = dust3d::Vector3(0, 0, 0);
|
||||
for (size_t i = 0; i < object.triangles.size(); ++i) {
|
||||
const auto& triangleColor = &object.triangleColors[i];
|
||||
for (auto j = 0; j < 3; j++) {
|
||||
int vertexIndex = (int)object.triangles[i][j];
|
||||
const dust3d::Vector3* srcVert = &object.vertices[vertexIndex];
|
||||
const dust3d::Color* srcColor = &object.vertexColors[vertexIndex];
|
||||
const dust3d::Vector3* srcNormal = &defaultNormal;
|
||||
if (triangleVertexNormals)
|
||||
srcNormal = &(*triangleVertexNormals)[i][j];
|
||||
|
@ -160,10 +154,10 @@ ModelMesh::ModelMesh(dust3d::Object& object)
|
|||
if (triangleTangents)
|
||||
srcTangent = &(*triangleTangents)[i];
|
||||
ModelOpenGLVertex* dest = &m_triangleVertices[destIndex];
|
||||
dest->colorR = triangleColor->r();
|
||||
dest->colorG = triangleColor->g();
|
||||
dest->colorB = triangleColor->b();
|
||||
dest->alpha = triangleColor->alpha();
|
||||
dest->colorR = srcColor->r();
|
||||
dest->colorG = srcColor->g();
|
||||
dest->colorB = srcColor->b();
|
||||
dest->alpha = srcColor->alpha();
|
||||
dest->posX = srcVert->x();
|
||||
dest->posY = srcVert->y();
|
||||
dest->posZ = srcVert->z();
|
||||
|
|
|
@ -38,32 +38,33 @@
|
|||
namespace dust3d {
|
||||
|
||||
struct ObjectNode {
|
||||
Uuid partId;
|
||||
Uuid nodeId;
|
||||
Vector3 origin;
|
||||
float radius = 0.0;
|
||||
//Uuid partId;
|
||||
//Uuid nodeId;
|
||||
//Vector3 origin;
|
||||
//float radius = 0.0;
|
||||
Color color;
|
||||
float colorSolubility = 0.0;
|
||||
float metalness = 0.0;
|
||||
float roughness = 1.0;
|
||||
Uuid materialId;
|
||||
bool countershaded = false;
|
||||
Uuid mirrorFromPartId;
|
||||
Uuid mirroredByPartId;
|
||||
Vector3 direction;
|
||||
bool joined = true;
|
||||
//float colorSolubility = 0.0;
|
||||
//float metalness = 0.0;
|
||||
//float roughness = 1.0;
|
||||
//Uuid materialId;
|
||||
//bool countershaded = false;
|
||||
//Uuid mirrorFromPartId;
|
||||
//Uuid mirroredByPartId;
|
||||
//Vector3 direction;
|
||||
//bool joined = true;
|
||||
};
|
||||
|
||||
class Object {
|
||||
public:
|
||||
std::vector<Vector3> vertices;
|
||||
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||
std::map<PositionKey, Uuid> positionToNodeIdMap;
|
||||
std::map<Uuid, ObjectNode> nodeMap;
|
||||
std::vector<std::vector<size_t>> triangleAndQuads;
|
||||
std::vector<std::vector<size_t>> triangles;
|
||||
std::unordered_map<Uuid, std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> partTriangleUvs;
|
||||
std::vector<std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> seamTriangleUvs;
|
||||
std::vector<Vector3> triangleNormals;
|
||||
std::vector<Color> triangleColors;
|
||||
std::vector<Color> vertexColors;
|
||||
bool alphaEnabled = false;
|
||||
uint64_t meshId = 0;
|
||||
|
||||
|
|
|
@ -639,6 +639,12 @@ std::unique_ptr<MeshState> MeshGenerator::combinePartMesh(const std::string& par
|
|||
partCache.isSuccessful = false;
|
||||
partCache.joined = (target == PartTarget::Model && !isDisabled);
|
||||
|
||||
partCache.nodeMap.clear();
|
||||
for (const auto& meshNode : meshNodes) {
|
||||
partCache.nodeMap.emplace(std::make_pair(meshNode.sourceId,
|
||||
ObjectNode { partColor }));
|
||||
}
|
||||
|
||||
if (PartTarget::Model == target) {
|
||||
if (1 == meshNodes.size()) {
|
||||
size_t subdivideTimes = subdived ? 1 : 0;
|
||||
|
@ -684,7 +690,7 @@ std::unique_ptr<MeshState> MeshGenerator::combinePartMesh(const std::string& par
|
|||
}
|
||||
const auto& vertexSources = tubeMeshBuilder->generatedVertexSources();
|
||||
for (size_t i = 0; i < vertexSources.size(); ++i) {
|
||||
partCache.sourceNodeMap.emplace(std::make_pair(PositionKey(partCache.vertices[i]), vertexSources[i]));
|
||||
partCache.positionToNodeIdMap.emplace(std::make_pair(PositionKey(partCache.vertices[i]), vertexSources[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -828,8 +834,10 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentMesh(const std::string
|
|||
componentCache.noneSeamVertices.insert(vertex);
|
||||
collectSharedQuadEdges(partCache.vertices, partCache.faces, &componentCache.sharedQuadEdges);
|
||||
componentCache.partTriangleUvs.insert({ Uuid(partIdString), partCache.triangleUvs });
|
||||
for (const auto& it : partCache.sourceNodeMap)
|
||||
componentCache.sourceNodeMap.emplace(it);
|
||||
for (const auto& it : partCache.positionToNodeIdMap)
|
||||
componentCache.positionToNodeIdMap.emplace(it);
|
||||
for (const auto& it : partCache.nodeMap)
|
||||
componentCache.nodeMap.emplace(it);
|
||||
}
|
||||
if (!partCache.joined) {
|
||||
if (mesh)
|
||||
|
@ -963,8 +971,10 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentChildGroupMesh(const s
|
|||
componentCache.sharedQuadEdges.insert(it);
|
||||
for (const auto& it : childComponentCache.partTriangleUvs)
|
||||
componentCache.partTriangleUvs.insert({ it.first, it.second });
|
||||
for (const auto& it : childComponentCache.sourceNodeMap)
|
||||
componentCache.sourceNodeMap.emplace(it);
|
||||
for (const auto& it : childComponentCache.positionToNodeIdMap)
|
||||
componentCache.positionToNodeIdMap.emplace(it);
|
||||
for (const auto& it : childComponentCache.nodeMap)
|
||||
componentCache.nodeMap.emplace(it);
|
||||
|
||||
if (nullptr == subMesh || subMesh->isNull()) {
|
||||
continue;
|
||||
|
@ -1029,7 +1039,16 @@ void MeshGenerator::postprocessObject(Object* object)
|
|||
|
||||
object->triangleNormals = combinedFacesNormals;
|
||||
|
||||
object->triangleColors.resize(object->triangles.size(), Color::createWhite());
|
||||
object->vertexColors.resize(object->vertices.size(), Color::createWhite());
|
||||
for (size_t i = 0; i < object->vertices.size(); ++i) {
|
||||
auto findSourceNode = object->positionToNodeIdMap.find(object->vertices[i]);
|
||||
if (findSourceNode == object->positionToNodeIdMap.end())
|
||||
continue;
|
||||
auto findObjectNode = object->nodeMap.find(findSourceNode->second);
|
||||
if (findObjectNode == object->nodeMap.end())
|
||||
continue;
|
||||
object->vertexColors[i] = findObjectNode->second.color;
|
||||
}
|
||||
|
||||
std::vector<std::vector<Vector3>> triangleVertexNormals;
|
||||
smoothNormal(object->vertices,
|
||||
|
@ -1247,7 +1266,8 @@ void MeshGenerator::generate()
|
|||
|
||||
const auto& componentCache = m_cacheContext->components[to_string(Uuid())];
|
||||
|
||||
m_object->sourceNodeMap = componentCache.sourceNodeMap;
|
||||
m_object->positionToNodeIdMap = componentCache.positionToNodeIdMap;
|
||||
m_object->nodeMap = componentCache.nodeMap;
|
||||
m_object->partTriangleUvs = componentCache.partTriangleUvs;
|
||||
|
||||
std::vector<Vector3> combinedVertices;
|
||||
|
|
|
@ -44,7 +44,8 @@ public:
|
|||
|
||||
struct GeneratedPart {
|
||||
std::vector<Vector3> vertices;
|
||||
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||
std::map<PositionKey, Uuid> positionToNodeIdMap;
|
||||
std::map<Uuid, ObjectNode> nodeMap;
|
||||
std::vector<std::vector<size_t>> faces;
|
||||
std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>> triangleUvs;
|
||||
Color color = Color(1.0, 1.0, 1.0);
|
||||
|
@ -57,7 +58,8 @@ public:
|
|||
vertices.clear();
|
||||
faces.clear();
|
||||
triangleUvs.clear();
|
||||
sourceNodeMap.clear();
|
||||
positionToNodeIdMap.clear();
|
||||
nodeMap.clear();
|
||||
color = Color(1.0, 1.0, 1.0);
|
||||
metalness = 0.0;
|
||||
roughness = 1.0;
|
||||
|
@ -72,7 +74,8 @@ public:
|
|||
std::unordered_map<Uuid, std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> partTriangleUvs;
|
||||
std::vector<std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> seamTriangleUvs;
|
||||
std::set<PositionKey> noneSeamVertices;
|
||||
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||
std::map<PositionKey, Uuid> positionToNodeIdMap;
|
||||
std::map<Uuid, ObjectNode> nodeMap;
|
||||
void reset()
|
||||
{
|
||||
mesh.reset();
|
||||
|
@ -80,7 +83,8 @@ public:
|
|||
partTriangleUvs.clear();
|
||||
seamTriangleUvs.clear();
|
||||
noneSeamVertices.clear();
|
||||
sourceNodeMap.clear();
|
||||
positionToNodeIdMap.clear();
|
||||
nodeMap.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue