Prefix internal attribute name with underline

master
huxingyi 2020-10-16 18:36:54 +09:30
parent 3233e7add0
commit 3cff6ad52a
3 changed files with 24 additions and 57 deletions

View File

@ -1165,7 +1165,7 @@ void Document::toSnapshot(Snapshot *snapshot, const std::set<QUuid> &limitNodeId
} }
if (!partIt.second.fillMeshLinkedId.isNull()) if (!partIt.second.fillMeshLinkedId.isNull())
part["fillMesh"] = partIt.second.fillMeshLinkedId.toString(); part["fillMesh"] = partIt.second.fillMeshLinkedId.toString();
part["dirty"] = partIt.second.dirty ? "true" : "false"; part["__dirty"] = partIt.second.dirty ? "true" : "false";
if (partIt.second.hasColor) if (partIt.second.hasColor)
part["color"] = partIt.second.color.name(QColor::HexArgb); part["color"] = partIt.second.color.name(QColor::HexArgb);
if (partIt.second.colorSolubilityAdjusted()) if (partIt.second.colorSolubilityAdjusted())
@ -1241,7 +1241,7 @@ void Document::toSnapshot(Snapshot *snapshot, const std::set<QUuid> &limitNodeId
component["name"] = componentIt.second.name; component["name"] = componentIt.second.name;
component["expanded"] = componentIt.second.expanded ? "true" : "false"; component["expanded"] = componentIt.second.expanded ? "true" : "false";
component["combineMode"] = CombineModeToString(componentIt.second.combineMode); component["combineMode"] = CombineModeToString(componentIt.second.combineMode);
component["dirty"] = componentIt.second.dirty ? "true" : "false"; component["__dirty"] = componentIt.second.dirty ? "true" : "false";
if (componentIt.second.smoothAllAdjusted()) if (componentIt.second.smoothAllAdjusted())
component["smoothAll"] = QString::number(componentIt.second.smoothAll); component["smoothAll"] = QString::number(componentIt.second.smoothAll);
if (componentIt.second.smoothSeamAdjusted()) if (componentIt.second.smoothSeamAdjusted())

View File

@ -122,7 +122,7 @@ bool MeshGenerator::checkIsPartDirty(const QString &partIdString)
qDebug() << "Find part failed:" << partIdString; qDebug() << "Find part failed:" << partIdString;
return false; return false;
} }
return isTrueValueString(valueOfKeyInMapOrEmpty(findPart->second, "dirty")); return isTrueValueString(valueOfKeyInMapOrEmpty(findPart->second, "__dirty"));
} }
bool MeshGenerator::checkIsPartDependencyDirty(const QString &partIdString) bool MeshGenerator::checkIsPartDependencyDirty(const QString &partIdString)
@ -168,7 +168,7 @@ bool MeshGenerator::checkIsComponentDirty(const QString &componentIdString)
component = &findComponent->second; component = &findComponent->second;
} }
if (isTrueValueString(valueOfKeyInMapOrEmpty(*component, "dirty"))) { if (isTrueValueString(valueOfKeyInMapOrEmpty(*component, "__dirty"))) {
isDirty = true; isDirty = true;
} }
@ -345,8 +345,9 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
bool isDisabled = isTrueValueString(valueOfKeyInMapOrEmpty(part, "disabled")); bool isDisabled = isTrueValueString(valueOfKeyInMapOrEmpty(part, "disabled"));
//bool xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(part, "xMirrored")); //bool xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(part, "xMirrored"));
bool _xFlip = isTrueValueString(valueOfKeyInMapOrEmpty(part, "_xFlip")); //bool _xFlip = isTrueValueString(valueOfKeyInMapOrEmpty(part, "_xFlip"));
QString _xMirroredFrom = valueOfKeyInMapOrEmpty(part, "_xMirroredFrom"); QString __mirroredByPartId = valueOfKeyInMapOrEmpty(part, "__mirroredByPartId");
QString __mirrorFromPartId = valueOfKeyInMapOrEmpty(part, "__mirrorFromPartId");
bool subdived = isTrueValueString(valueOfKeyInMapOrEmpty(part, "subdived")); bool subdived = isTrueValueString(valueOfKeyInMapOrEmpty(part, "subdived"));
bool rounded = isTrueValueString(valueOfKeyInMapOrEmpty(part, "rounded")); bool rounded = isTrueValueString(valueOfKeyInMapOrEmpty(part, "rounded"));
bool chamfered = isTrueValueString(valueOfKeyInMapOrEmpty(part, "chamfered")); bool chamfered = isTrueValueString(valueOfKeyInMapOrEmpty(part, "chamfered"));
@ -360,7 +361,7 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
auto target = PartTargetFromString(valueOfKeyInMapOrEmpty(part, "target").toUtf8().constData()); auto target = PartTargetFromString(valueOfKeyInMapOrEmpty(part, "target").toUtf8().constData());
auto base = PartBaseFromString(valueOfKeyInMapOrEmpty(part, "base").toUtf8().constData()); auto base = PartBaseFromString(valueOfKeyInMapOrEmpty(part, "base").toUtf8().constData());
QString searchPartIdString = _xMirroredFrom.isEmpty() ? partIdString : _xMirroredFrom; QString searchPartIdString = __mirrorFromPartId.isEmpty() ? partIdString : __mirrorFromPartId;
QString cutFaceString = valueOfKeyInMapOrEmpty(part, "cutFace"); QString cutFaceString = valueOfKeyInMapOrEmpty(part, "cutFace");
std::vector<QVector2D> cutTemplate; std::vector<QVector2D> cutTemplate;
@ -538,11 +539,13 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
outcomeNode.countershaded = countershaded; outcomeNode.countershaded = countershaded;
outcomeNode.colorSolubility = colorSolubility; outcomeNode.colorSolubility = colorSolubility;
outcomeNode.boneMark = nodeInfo.boneMark; outcomeNode.boneMark = nodeInfo.boneMark;
//outcomeNode.mirroredByPartId = mirroredPartId; if (!__mirroredByPartId.isEmpty())
outcomeNode.joined = partCache.joined; outcomeNode.mirroredByPartId = QUuid(__mirroredByPartId);
if (_xFlip) { if (!__mirrorFromPartId.isEmpty()) {
outcomeNode.mirrorFromPartId = QUuid(__mirrorFromPartId);
outcomeNode.origin.setX(-nodeInfo.position.x()); outcomeNode.origin.setX(-nodeInfo.position.x());
} }
outcomeNode.joined = partCache.joined;
partCache.outcomeNodes.push_back(outcomeNode); partCache.outcomeNodes.push_back(outcomeNode);
//if (xMirrored) { //if (xMirrored) {
// outcomeNode.partId = mirroredPartId; // outcomeNode.partId = mirroredPartId;
@ -670,7 +673,7 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
partCache.vertices = strokeMeshBuilder->generatedVertices(); partCache.vertices = strokeMeshBuilder->generatedVertices();
partCache.faces = strokeMeshBuilder->generatedFaces(); partCache.faces = strokeMeshBuilder->generatedFaces();
if (_xFlip) { if (!__mirrorFromPartId.isEmpty()) {
for (auto &it: partCache.vertices) for (auto &it: partCache.vertices)
it.setX(-it.x()); it.setX(-it.x());
for (auto &it: partCache.faces) for (auto &it: partCache.faces)
@ -700,7 +703,7 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
if (strokeMeshBuilder->buildBaseNormalsOnly()) { if (strokeMeshBuilder->buildBaseNormalsOnly()) {
buildSucceed = fillPartWithMesh(partCache, fillMeshFileId, buildSucceed = fillPartWithMesh(partCache, fillMeshFileId,
deformThickness, deformWidth, cutRotation, strokeMeshBuilder); deformThickness, deformWidth, cutRotation, strokeMeshBuilder);
if (_xFlip) { if (!__mirrorFromPartId.isEmpty()) {
for (auto &it: partCache.vertices) for (auto &it: partCache.vertices)
it.setX(-it.x()); it.setX(-it.x());
for (auto &it: partCache.faces) for (auto &it: partCache.faces)
@ -717,45 +720,7 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
if (buildSucceed) { if (buildSucceed) {
mesh = new MeshCombiner::Mesh(partCache.vertices, partCache.faces, false); mesh = new MeshCombiner::Mesh(partCache.vertices, partCache.faces, false);
if (!mesh->isNull()) { if (mesh->isNull()) {
//if (xMirrored) {
// std::vector<QVector3D> xMirroredVertices;
// std::vector<std::vector<size_t>> xMirroredFaces;
// makeXmirror(partCache.vertices, partCache.faces, &xMirroredVertices, &xMirroredFaces);
// for (size_t i = 0; i < xMirroredVertices.size(); ++i) {
// const auto &position = xMirroredVertices[i];
// size_t nodeIndex = 0;
// const auto &source = sourceNodeIndices[i];
// nodeIndex = strokeModifier->nodes()[source].originNodeIndex;
// const auto &nodeIdString = nodeIndexToIdStringMap[nodeIndex];
// partCache.outcomeNodeVertices.push_back({position, {mirroredPartIdString, nodeIdString}});
// }
// size_t xMirrorStart = partCache.vertices.size();
// for (const auto &vertex: xMirroredVertices)
// partCache.vertices.push_back(vertex);
// for (const auto &face: xMirroredFaces) {
// std::vector<size_t> newFace = face;
// for (auto &it: newFace)
// it += xMirrorStart;
// partCache.faces.push_back(newFace);
// }
// MeshCombiner::Mesh *newMesh = nullptr;
// MeshCombiner::Mesh *xMirroredMesh = new MeshCombiner::Mesh(xMirroredVertices, xMirroredFaces, false);
// if (!xMirroredMesh->isNull()) {
// newMesh = combineTwoMeshes(*mesh,
// *xMirroredMesh, MeshCombiner::Method::Union);
// }
// delete xMirroredMesh;
// if (newMesh && !newMesh->isNull()) {
// delete mesh;
// mesh = newMesh;
// } else {
// hasMeshError = true;
// qDebug() << "Xmirrored mesh generate failed";
// delete newMesh;
// }
//}
} else {
hasMeshError = true; hasMeshError = true;
qDebug() << "Mesh built is uncombinable"; qDebug() << "Mesh built is uncombinable";
} }
@ -1787,13 +1752,15 @@ void MeshGenerator::preprocessMirror()
//qDebug() << "Added part:" << newPartIdString << "by mirror from:" << mirroredPart["id"]; //qDebug() << "Added part:" << newPartIdString << "by mirror from:" << mirroredPart["id"];
mirroredPart["_xFlip"] = "true"; mirroredPart["__mirrorFromPartId"] = mirroredPart["id"];
mirroredPart["_xMirroredFrom"] = mirroredPart["id"];
mirroredPart["id"] = newPartIdString; mirroredPart["id"] = newPartIdString;
mirroredPart["dirty"] = "true"; mirroredPart["__dirty"] = "true";
newParts.push_back(mirroredPart); newParts.push_back(mirroredPart);
} }
for (const auto &it: partOldToNewMap)
m_snapshot->parts[it.second]["__mirroredByPartId"] = it.first;
std::map<QString, QString> parentMap; std::map<QString, QString> parentMap;
for (auto &componentIt: m_snapshot->components) { for (auto &componentIt: m_snapshot->components) {
for (const auto &childId: valueOfKeyInMapOrEmpty(componentIt.second, "children").split(",")) { for (const auto &childId: valueOfKeyInMapOrEmpty(componentIt.second, "children").split(",")) {
@ -1824,7 +1791,7 @@ void MeshGenerator::preprocessMirror()
//qDebug() << "Added component:" << newComponentIdString << "by mirror from:" << valueOfKeyInMapOrEmpty(componentIt.second, "id"); //qDebug() << "Added component:" << newComponentIdString << "by mirror from:" << valueOfKeyInMapOrEmpty(componentIt.second, "id");
mirroredComponent["linkData"] = findPart->second; mirroredComponent["linkData"] = findPart->second;
mirroredComponent["id"] = newComponentIdString; mirroredComponent["id"] = newComponentIdString;
mirroredComponent["dirty"] = "true"; mirroredComponent["__dirty"] = "true";
parentMap[newComponentIdString] = parentMap[valueOfKeyInMapOrEmpty(componentIt.second, "id")]; parentMap[newComponentIdString] = parentMap[valueOfKeyInMapOrEmpty(componentIt.second, "id")];
//qDebug() << "Update component:" << newComponentIdString << "parent to:" << parentMap[valueOfKeyInMapOrEmpty(componentIt.second, "id")]; //qDebug() << "Update component:" << newComponentIdString << "parent to:" << parentMap[valueOfKeyInMapOrEmpty(componentIt.second, "id")];
newComponents.push_back(mirroredComponent); newComponents.push_back(mirroredComponent);

View File

@ -17,7 +17,7 @@ static void saveSkeletonComponent(Snapshot *snapshot, QXmlStreamWriter *writer,
children = componentAttributeIterator->second; children = componentAttributeIterator->second;
continue; continue;
} }
if ("dirty" == componentAttributeIterator->first) if (componentAttributeIterator->first.startsWith("__"))
continue; continue;
writer->writeAttribute(componentAttributeIterator->first, componentAttributeIterator->second); writer->writeAttribute(componentAttributeIterator->first, componentAttributeIterator->second);
} }
@ -72,7 +72,7 @@ void saveSkeletonToXmlStream(Snapshot *snapshot, QXmlStreamWriter *writer)
std::map<QString, QString>::iterator partAttributeIterator; std::map<QString, QString>::iterator partAttributeIterator;
writer->writeStartElement("part"); writer->writeStartElement("part");
for (partAttributeIterator = partIterator->second.begin(); partAttributeIterator != partIterator->second.end(); partAttributeIterator++) { for (partAttributeIterator = partIterator->second.begin(); partAttributeIterator != partIterator->second.end(); partAttributeIterator++) {
if ("dirty" == partAttributeIterator->first) if (partAttributeIterator->first.startsWith("__"))
continue; continue;
writer->writeAttribute(partAttributeIterator->first, partAttributeIterator->second); writer->writeAttribute(partAttributeIterator->first, partAttributeIterator->second);
} }