mirror of
https://github.com/lubosz/overte.git
synced 2025-06-04 17:10:22 +02:00
Cleanup ObjBaker and remove setPropertiesList
This commit is contained in:
parent
dd2d3d97b4
commit
6050b4d85c
1 changed files with 117 additions and 120 deletions
|
@ -129,7 +129,6 @@ void OBJBaker::handleOBJNetworkReply() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OBJBaker::bakeOBJ() {
|
void OBJBaker::bakeOBJ() {
|
||||||
// Read the OBJ file
|
// Read the OBJ file
|
||||||
QFile objFile(_originalModelFilePath);
|
QFile objFile(_originalModelFilePath);
|
||||||
|
@ -188,9 +187,16 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
// Setting the tree hierarchy: GlobalSettings -> Properties70 -> P -> Properties
|
// Setting the tree hierarchy: GlobalSettings -> Properties70 -> P -> Properties
|
||||||
FBXNode properties70Node;
|
FBXNode properties70Node;
|
||||||
properties70Node.name = PROPERTIES70_NODE_NAME;
|
properties70Node.name = PROPERTIES70_NODE_NAME;
|
||||||
|
|
||||||
FBXNode pNode;
|
FBXNode pNode;
|
||||||
pNode.name = P_NODE_NAME;
|
{
|
||||||
setNodeProperties(pNode);
|
pNode.name = P_NODE_NAME;
|
||||||
|
pNode.properties.append({
|
||||||
|
"UnitScaleFactor", "double", "Number", "",
|
||||||
|
UNIT_SCALE_FACTOR
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
properties70Node.children = { pNode };
|
properties70Node.children = { pNode };
|
||||||
globalSettingsNode.children = { properties70Node };
|
globalSettingsNode.children = { properties70Node };
|
||||||
|
|
||||||
|
@ -200,7 +206,14 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
// Generating Object node's child - Geometry node
|
// Generating Object node's child - Geometry node
|
||||||
FBXNode geometryNode;
|
FBXNode geometryNode;
|
||||||
geometryNode.name = GEOMETRY_NODE_NAME;
|
geometryNode.name = GEOMETRY_NODE_NAME;
|
||||||
setNodeProperties(geometryNode);
|
{
|
||||||
|
_geometryID = _nodeID;
|
||||||
|
geometryNode.properties = {
|
||||||
|
_nodeID++,
|
||||||
|
GEOMETRY_NODE_NAME,
|
||||||
|
MESH
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Compress the mesh information and store in dracoNode
|
// Compress the mesh information and store in dracoNode
|
||||||
bool hasDeformers = false; // No concept of deformers for an OBJ
|
bool hasDeformers = false; // No concept of deformers for an OBJ
|
||||||
|
@ -211,7 +224,14 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
// Generating Object node's child - Model node
|
// Generating Object node's child - Model node
|
||||||
FBXNode modelNode;
|
FBXNode modelNode;
|
||||||
modelNode.name = MODEL_NODE_NAME;
|
modelNode.name = MODEL_NODE_NAME;
|
||||||
setNodeProperties(modelNode);
|
{
|
||||||
|
_modelID = _nodeID++;
|
||||||
|
modelNode.properties = {
|
||||||
|
_nodeID,
|
||||||
|
MODEL_NODE_NAME,
|
||||||
|
MESH
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
_objectNode.children = { geometryNode, modelNode };
|
_objectNode.children = { geometryNode, modelNode };
|
||||||
|
|
||||||
|
@ -222,7 +242,7 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
materialNode.name = MATERIAL_NODE_NAME;
|
materialNode.name = MATERIAL_NODE_NAME;
|
||||||
if (geometry.materials.size() == 1) {
|
if (geometry.materials.size() == 1) {
|
||||||
// case when no material information is provided, OBJReader considers it as a single default material
|
// case when no material information is provided, OBJReader considers it as a single default material
|
||||||
foreach(QString materialID, geometry.materials.keys()) {
|
for (auto& materialID : geometry.materials.keys()) {
|
||||||
setMaterialNodeProperties(materialNode, materialID, geometry);
|
setMaterialNodeProperties(materialNode, materialID, geometry);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,7 +254,8 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
|
|
||||||
// Generating Texture Node
|
// Generating Texture Node
|
||||||
// iterate through mesh parts and process the associated textures
|
// iterate through mesh parts and process the associated textures
|
||||||
for (int i = 0; i < meshParts.size(); i++) {
|
auto size = meshParts.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
QString material = meshParts[i].materialID;
|
QString material = meshParts[i].materialID;
|
||||||
FBXMaterial currentMaterial = geometry.materials[material];
|
FBXMaterial currentMaterial = geometry.materials[material];
|
||||||
if (!currentMaterial.albedoTexture.filename.isEmpty() || !currentMaterial.specularTexture.filename.isEmpty()) {
|
if (!currentMaterial.albedoTexture.filename.isEmpty() || !currentMaterial.specularTexture.filename.isEmpty()) {
|
||||||
|
@ -242,20 +263,24 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
_mapTextureMaterial.push_back(QPair<qlonglong, int>(_textureID, i));
|
_mapTextureMaterial.push_back(QPair<qlonglong, int>(_textureID, i));
|
||||||
|
|
||||||
FBXNode textureNode;
|
FBXNode textureNode;
|
||||||
textureNode.name = TEXTURE_NODE_NAME;
|
{
|
||||||
QVariant textureProperty(_nodeID++);
|
textureNode.name = TEXTURE_NODE_NAME;
|
||||||
textureNode.properties = { textureProperty };
|
textureNode.properties = { _nodeID++ };
|
||||||
|
}
|
||||||
|
|
||||||
// Texture node child - TextureName node
|
// Texture node child - TextureName node
|
||||||
FBXNode textureNameNode;
|
FBXNode textureNameNode;
|
||||||
textureNameNode.name = TEXTURENAME_NODE_NAME;
|
{
|
||||||
QByteArray propertyString = (!currentMaterial.albedoTexture.filename.isEmpty()) ? "Kd" : "Ka";
|
textureNameNode.name = TEXTURENAME_NODE_NAME;
|
||||||
textureProperty = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
QByteArray propertyString = (!currentMaterial.albedoTexture.filename.isEmpty()) ? "Kd" : "Ka";
|
||||||
textureNameNode.properties = { textureProperty };
|
textureNameNode.properties = { propertyString };
|
||||||
|
}
|
||||||
|
|
||||||
// Texture node child - Relative Filename node
|
// Texture node child - Relative Filename node
|
||||||
FBXNode relativeFilenameNode;
|
FBXNode relativeFilenameNode;
|
||||||
relativeFilenameNode.name = RELATIVEFILENAME_NODE_NAME;
|
{
|
||||||
|
relativeFilenameNode.name = RELATIVEFILENAME_NODE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray textureFileName = (!currentMaterial.albedoTexture.filename.isEmpty()) ? currentMaterial.albedoTexture.filename : currentMaterial.specularTexture.filename;
|
QByteArray textureFileName = (!currentMaterial.albedoTexture.filename.isEmpty()) ? currentMaterial.albedoTexture.filename : currentMaterial.specularTexture.filename;
|
||||||
|
|
||||||
|
@ -266,13 +291,11 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
|
|
||||||
// Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node
|
// Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node
|
||||||
QByteArray* textureFile = this->compressTexture(textureFileName, textureContentTypeCallback);
|
QByteArray* textureFile = this->compressTexture(textureFileName, textureContentTypeCallback);
|
||||||
if (textureFile) {
|
if (!textureFile) {
|
||||||
textureProperty = QVariant::fromValue(QByteArray(textureFile->data(), (int)textureFile->size()));
|
|
||||||
} else {
|
|
||||||
// Baking failed return
|
// Baking failed return
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
relativeFilenameNode.properties = { textureProperty };
|
relativeFilenameNode.properties = { *textureFile };
|
||||||
|
|
||||||
textureNode.children = { textureNameNode, relativeFilenameNode };
|
textureNode.children = { textureNameNode, relativeFilenameNode };
|
||||||
|
|
||||||
|
@ -287,23 +310,36 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
// connect Geometry to Model
|
// connect Geometry to Model
|
||||||
FBXNode cNode;
|
FBXNode cNode;
|
||||||
cNode.name = C_NODE_NAME;
|
cNode.name = C_NODE_NAME;
|
||||||
QByteArray propertyString(CONNECTIONS_NODE_PROPERTY);
|
|
||||||
QVariant property0 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
cNode.properties = {
|
||||||
qlonglong childID = _geometryID;
|
CONNECTIONS_NODE_PROPERTY,
|
||||||
QVariant property1(childID);
|
_geometryID,
|
||||||
qlonglong parentID = _modelID;
|
_modelID
|
||||||
QVariant property2(parentID);
|
};
|
||||||
cNode.properties = { property0, property1, property2 };
|
|
||||||
connectionsNode.children = { cNode };
|
connectionsNode.children = { cNode };
|
||||||
|
|
||||||
// connect all materials to model
|
// connect all materials to model
|
||||||
for (int i = 0; i < geometry.materials.size(); i++) {
|
for (auto& materialID : _materialIDs) {
|
||||||
FBXNode cNode1;
|
FBXNode cNode1;
|
||||||
cNode1.name = C_NODE_NAME;
|
cNode1.name = C_NODE_NAME;
|
||||||
property0 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
cNode1.properties = {
|
||||||
property1 = _materialIDs[i];
|
CONNECTIONS_NODE_PROPERTY,
|
||||||
property2 = _modelID;
|
materialID,
|
||||||
cNode1.properties = { property0, property1, property2 };
|
_modelID
|
||||||
|
};
|
||||||
|
connectionsNode.children.append(cNode1);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < geometry.materials.size(); i++) {
|
||||||
|
continue;
|
||||||
|
FBXNode cNode1;
|
||||||
|
cNode1.name = C_NODE_NAME;
|
||||||
|
cNode1.properties = {
|
||||||
|
CONNECTIONS_NODE_PROPERTY,
|
||||||
|
_materialIDs[i],
|
||||||
|
_modelID
|
||||||
|
};
|
||||||
|
|
||||||
connectionsNode.children.append(cNode1);
|
connectionsNode.children.append(cNode1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,25 +348,25 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
for (size_t i = 0; i < mapSize; i++) {
|
for (size_t i = 0; i < mapSize; i++) {
|
||||||
FBXNode cNode2;
|
FBXNode cNode2;
|
||||||
cNode2.name = C_NODE_NAME;
|
cNode2.name = C_NODE_NAME;
|
||||||
propertyString = CONNECTIONS_NODE_PROPERTY_1;
|
auto& texMat = _mapTextureMaterial[i];
|
||||||
property0 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
cNode2.properties = {
|
||||||
property1 = _mapTextureMaterial[i].first;
|
CONNECTIONS_NODE_PROPERTY_1,
|
||||||
int matID = _mapTextureMaterial[i].second;
|
texMat.first,
|
||||||
property2 = _materialIDs[matID];
|
_materialIDs[texMat.second],
|
||||||
propertyString = "AmbientFactor";
|
"AmbientFactor"
|
||||||
QVariant property3 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
};
|
||||||
cNode2.properties = { property0, property1, property2, property3 };
|
|
||||||
connectionsNode.children.append(cNode2);
|
connectionsNode.children.append(cNode2);
|
||||||
|
|
||||||
FBXNode cNode3;
|
FBXNode cNode3;
|
||||||
cNode3.name = C_NODE_NAME;
|
cNode3.name = C_NODE_NAME;
|
||||||
propertyString = CONNECTIONS_NODE_PROPERTY_1;
|
cNode3.properties = {
|
||||||
property0 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
CONNECTIONS_NODE_PROPERTY_1,
|
||||||
property1 = _mapTextureMaterial[i].first;
|
texMat.first,
|
||||||
property2 = _materialIDs[matID];
|
_materialIDs[texMat.second],
|
||||||
propertyString = "DiffuseColor";
|
"DiffuseColor"
|
||||||
property3 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
};
|
||||||
cNode3.properties = { property0, property1, property2, property3 };
|
|
||||||
connectionsNode.children.append(cNode3);
|
connectionsNode.children.append(cNode3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,44 +374,15 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
rootNode.children = { globalSettingsNode, _objectNode, connectionsNode };
|
rootNode.children = { globalSettingsNode, _objectNode, connectionsNode };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set properties for P Node and Sub-Object nodes
|
|
||||||
void OBJBaker::setNodeProperties(FBXNode& parentNode) {
|
|
||||||
if (parentNode.name == P_NODE_NAME) {
|
|
||||||
std::vector<QByteArray> stringProperties { "UnitScaleFactor", "double", "Number", "" };
|
|
||||||
std::vector<double> numericProperties { UNIT_SCALE_FACTOR };
|
|
||||||
|
|
||||||
setPropertiesList(stringProperties, numericProperties, parentNode.properties);
|
|
||||||
} else if (parentNode.name == GEOMETRY_NODE_NAME) {
|
|
||||||
_geometryID = _nodeID;
|
|
||||||
QVariant property0(_nodeID++);
|
|
||||||
QByteArray propertyString(GEOMETRY_NODE_NAME);
|
|
||||||
QVariant property1 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
|
||||||
propertyString = MESH;
|
|
||||||
QVariant property2 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
|
||||||
|
|
||||||
parentNode.properties = { property0, property1, property2 };
|
|
||||||
} else if (parentNode.name == MODEL_NODE_NAME) {
|
|
||||||
_modelID = _nodeID;
|
|
||||||
QVariant property0(_nodeID++);
|
|
||||||
QByteArray propertyString(MODEL_NODE_NAME);
|
|
||||||
QVariant property1 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
|
||||||
propertyString = MESH;
|
|
||||||
QVariant property2 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
|
||||||
|
|
||||||
parentNode.properties = { property0, property1, property2 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set properties for material nodes
|
// Set properties for material nodes
|
||||||
void OBJBaker::setMaterialNodeProperties(FBXNode& materialNode, QString material, FBXGeometry& geometry) {
|
void OBJBaker::setMaterialNodeProperties(FBXNode& materialNode, QString material, FBXGeometry& geometry) {
|
||||||
_materialIDs.push_back(_nodeID);
|
auto materialID = _nodeID++;
|
||||||
QVariant property0(_nodeID++);
|
_materialIDs.push_back(materialID);
|
||||||
QByteArray propertyString(material.toLatin1());
|
materialNode.properties = {
|
||||||
QVariant property1 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
materialID,
|
||||||
propertyString = MESH;
|
material,
|
||||||
QVariant property2 = QVariant::fromValue(QByteArray(propertyString.data(), (int)propertyString.size()));
|
MESH
|
||||||
|
};
|
||||||
materialNode.properties = { property0, property1, property2 };
|
|
||||||
|
|
||||||
FBXMaterial currentMaterial = geometry.materials[material];
|
FBXMaterial currentMaterial = geometry.materials[material];
|
||||||
|
|
||||||
|
@ -385,57 +392,47 @@ void OBJBaker::setMaterialNodeProperties(FBXNode& materialNode, QString material
|
||||||
|
|
||||||
// Set diffuseColor
|
// Set diffuseColor
|
||||||
FBXNode pNodeDiffuseColor;
|
FBXNode pNodeDiffuseColor;
|
||||||
pNodeDiffuseColor.name = P_NODE_NAME;
|
{
|
||||||
|
pNodeDiffuseColor.name = P_NODE_NAME;
|
||||||
std::vector<QByteArray> stringProperties { "DiffuseColor", "Color", "", "A" };
|
pNodeDiffuseColor.properties.append({
|
||||||
std::vector<double> numericProperties { currentMaterial.diffuseColor[0], currentMaterial.diffuseColor[1], currentMaterial.diffuseColor[2] };
|
"DiffuseColor", "Color", "", "A",
|
||||||
setPropertiesList(stringProperties, numericProperties, pNodeDiffuseColor.properties);
|
currentMaterial.diffuseColor[0], currentMaterial.diffuseColor[1], currentMaterial.diffuseColor[2]
|
||||||
|
});
|
||||||
|
}
|
||||||
properties70Node.children.append(pNodeDiffuseColor);
|
properties70Node.children.append(pNodeDiffuseColor);
|
||||||
|
|
||||||
// Set specularColor
|
// Set specularColor
|
||||||
FBXNode pNodeSpecularColor;
|
FBXNode pNodeSpecularColor;
|
||||||
pNodeSpecularColor.name = P_NODE_NAME;
|
{
|
||||||
|
pNodeSpecularColor.name = P_NODE_NAME;
|
||||||
stringProperties = { "SpecularColor", "Color", "", "A" };
|
pNodeSpecularColor.properties.append({
|
||||||
numericProperties = { currentMaterial.specularColor[0], currentMaterial.specularColor[1], currentMaterial.specularColor[2] };
|
"SpecularColor", "Color", "", "A",
|
||||||
setPropertiesList(stringProperties, numericProperties, pNodeSpecularColor.properties);
|
currentMaterial.specularColor[0], currentMaterial.specularColor[1], currentMaterial.specularColor[2]
|
||||||
|
});
|
||||||
|
}
|
||||||
properties70Node.children.append(pNodeSpecularColor);
|
properties70Node.children.append(pNodeSpecularColor);
|
||||||
|
|
||||||
// Set Shininess
|
// Set Shininess
|
||||||
FBXNode pNodeShininess;
|
FBXNode pNodeShininess;
|
||||||
pNodeShininess.name = P_NODE_NAME;
|
{
|
||||||
|
pNodeShininess.name = P_NODE_NAME;
|
||||||
stringProperties = { "Shininess", "Number", "", "A" };
|
pNodeShininess.properties.append({
|
||||||
numericProperties = { currentMaterial.shininess };
|
"Shininess", "Number", "", "A",
|
||||||
setPropertiesList(stringProperties, numericProperties, pNodeShininess.properties);
|
currentMaterial.shininess
|
||||||
|
});
|
||||||
|
}
|
||||||
properties70Node.children.append(pNodeShininess);
|
properties70Node.children.append(pNodeShininess);
|
||||||
|
|
||||||
// Set Opacity
|
// Set Opacity
|
||||||
FBXNode pNodeOpacity;
|
FBXNode pNodeOpacity;
|
||||||
pNodeOpacity.name = P_NODE_NAME;
|
{
|
||||||
|
pNodeOpacity.name = P_NODE_NAME;
|
||||||
stringProperties = { "Opacity", "Number", "", "A" };
|
pNodeOpacity.properties.append({
|
||||||
numericProperties = { currentMaterial.opacity };
|
"Opacity", "Number", "", "A",
|
||||||
setPropertiesList(stringProperties, numericProperties, pNodeOpacity.properties);
|
currentMaterial.opacity
|
||||||
|
});
|
||||||
|
}
|
||||||
properties70Node.children.append(pNodeOpacity);
|
properties70Node.children.append(pNodeOpacity);
|
||||||
|
|
||||||
materialNode.children.append(properties70Node);
|
materialNode.children.append(properties70Node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bundle various String and numerical type properties into a single QVariantList
|
|
||||||
template<typename N>
|
|
||||||
void OBJBaker::setPropertiesList(std::vector<QByteArray>& stringProperties, std::vector<N>& numericProperties, QVariantList& propertiesList) {
|
|
||||||
foreach(auto stringProperty, stringProperties) {
|
|
||||||
auto propertyValue = QVariant::fromValue(QByteArray(stringProperty.data(), (int)stringProperty.size()));
|
|
||||||
propertiesList.append(propertyValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(auto numericProperty, numericProperties) {
|
|
||||||
QVariant propertyValue(numericProperty);
|
|
||||||
propertiesList.append(propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue