Adding Normals in OBJ exports
This commit is contained in:
parent
cc46acf10e
commit
b77188e35c
|
@ -1955,6 +1955,21 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const
|
||||||
}
|
}
|
||||||
seq.next(true); // allow to cancel
|
seq.next(true); // allow to cancel
|
||||||
}
|
}
|
||||||
|
// Export normals
|
||||||
|
MeshFacetIterator clIter(_rclMesh), clEnd(_rclMesh);
|
||||||
|
const MeshGeomFacet* pclFacet;
|
||||||
|
|
||||||
|
clIter.Begin();
|
||||||
|
clEnd.End();
|
||||||
|
|
||||||
|
while (clIter < clEnd) {
|
||||||
|
pclFacet = &(*clIter);
|
||||||
|
out << "vn " << pclFacet->GetNormal().x << " "
|
||||||
|
<< pclFacet->GetNormal().y << " "
|
||||||
|
<< pclFacet->GetNormal().z << std::endl;
|
||||||
|
++clIter;
|
||||||
|
seq.next(true); // allow to cancel
|
||||||
|
}
|
||||||
|
|
||||||
if (_groups.empty()) {
|
if (_groups.empty()) {
|
||||||
if (exportColorPerFace) {
|
if (exportColorPerFace) {
|
||||||
|
@ -1967,6 +1982,7 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const
|
||||||
|
|
||||||
std::size_t index = 0;
|
std::size_t index = 0;
|
||||||
App::Color prev;
|
App::Color prev;
|
||||||
|
int faceIdx = 1;
|
||||||
const std::vector<App::Color>& Kd = _material->diffuseColor;
|
const std::vector<App::Color>& Kd = _material->diffuseColor;
|
||||||
for (MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it, index++) {
|
for (MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it, index++) {
|
||||||
if (index == 0 || prev != Kd[index]) {
|
if (index == 0 || prev != Kd[index]) {
|
||||||
|
@ -1976,25 +1992,27 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const
|
||||||
out << "usemtl material_" << (c_it - colors.begin()) << std::endl;
|
out << "usemtl material_" << (c_it - colors.begin()) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << "f " << it->_aulPoints[0]+1 << " "
|
out << "f " << it->_aulPoints[0]+1 << "//" << faceIdx << " "
|
||||||
<< it->_aulPoints[1]+1 << " "
|
<< it->_aulPoints[1]+1 << "//" << faceIdx << " "
|
||||||
<< it->_aulPoints[2]+1 << std::endl;
|
<< it->_aulPoints[2]+1 << "//" << faceIdx << std::endl;
|
||||||
seq.next(true); // allow to cancel
|
seq.next(true); // allow to cancel
|
||||||
|
faceIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// facet indices (no texture and normal indices)
|
// facet indices (no texture and normal indices)
|
||||||
|
std::size_t faceIdx = 1;
|
||||||
for (MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it) {
|
for (MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it) {
|
||||||
out << "f " << it->_aulPoints[0]+1 << " "
|
out << "f " << it->_aulPoints[0]+1 << "//" << faceIdx << " "
|
||||||
<< it->_aulPoints[1]+1 << " "
|
<< it->_aulPoints[1]+1 << "//" << faceIdx << " "
|
||||||
<< it->_aulPoints[2]+1 << std::endl;
|
<< it->_aulPoints[2]+1 << "//" << faceIdx << std::endl;
|
||||||
seq.next(true); // allow to cancel
|
seq.next(true); // allow to cancel
|
||||||
|
faceIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (exportColorPerFace) {
|
if (exportColorPerFace) {
|
||||||
|
|
||||||
// make sure to use the 'usemtl' statement as less often as possible
|
// make sure to use the 'usemtl' statement as less often as possible
|
||||||
std::vector<App::Color> colors = _material->diffuseColor;
|
std::vector<App::Color> colors = _material->diffuseColor;
|
||||||
std::sort(colors.begin(), colors.end(), Color_Less());
|
std::sort(colors.begin(), colors.end(), Color_Less());
|
||||||
|
@ -2017,9 +2035,9 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "f " << f._aulPoints[0]+1 << " "
|
out << "f " << f._aulPoints[0]+1 << "//" << *it + 1 << " "
|
||||||
<< f._aulPoints[1]+1 << " "
|
<< f._aulPoints[1]+1 << "//" << *it + 1 << " "
|
||||||
<< f._aulPoints[2]+1 << std::endl;
|
<< f._aulPoints[2]+1 << "//" << *it + 1 << std::endl;
|
||||||
seq.next(true); // allow to cancel
|
seq.next(true); // allow to cancel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2029,9 +2047,9 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const
|
||||||
out << "g " << Base::Tools::escapedUnicodeFromUtf8(gt->name.c_str()) << std::endl;
|
out << "g " << Base::Tools::escapedUnicodeFromUtf8(gt->name.c_str()) << std::endl;
|
||||||
for (std::vector<unsigned long>::const_iterator it = gt->indices.begin(); it != gt->indices.end(); ++it) {
|
for (std::vector<unsigned long>::const_iterator it = gt->indices.begin(); it != gt->indices.end(); ++it) {
|
||||||
const MeshFacet& f = rFacets[*it];
|
const MeshFacet& f = rFacets[*it];
|
||||||
out << "f " << f._aulPoints[0]+1 << " "
|
out << "f " << f._aulPoints[0]+1 << "//" << *it + 1 << " "
|
||||||
<< f._aulPoints[1]+1 << " "
|
<< f._aulPoints[1]+1 << "//" << *it + 1 << " "
|
||||||
<< f._aulPoints[2]+1 << std::endl;
|
<< f._aulPoints[2]+1 << "//" << *it + 1 << std::endl;
|
||||||
seq.next(true); // allow to cancel
|
seq.next(true); // allow to cancel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user