[gltf2-exporter] Adding FB_ngon_encoding support
parent
3880cd225c
commit
8e589221d7
|
@ -1108,6 +1108,7 @@ public:
|
||||||
bool KHR_materials_clearcoat;
|
bool KHR_materials_clearcoat;
|
||||||
bool KHR_materials_transmission;
|
bool KHR_materials_transmission;
|
||||||
bool KHR_draco_mesh_compression;
|
bool KHR_draco_mesh_compression;
|
||||||
|
bool FB_ngon_encoding;
|
||||||
} extensionsUsed;
|
} extensionsUsed;
|
||||||
|
|
||||||
//! Keeps info about the required extensions
|
//! Keeps info about the required extensions
|
||||||
|
|
|
@ -507,6 +507,19 @@ namespace glTF2 {
|
||||||
Mesh::Primitive& p = m.primitives[i];
|
Mesh::Primitive& p = m.primitives[i];
|
||||||
Value prim;
|
Value prim;
|
||||||
prim.SetObject();
|
prim.SetObject();
|
||||||
|
|
||||||
|
// Extensions
|
||||||
|
{
|
||||||
|
Value exts;
|
||||||
|
exts.SetObject();
|
||||||
|
|
||||||
|
Value FB_ngon_encoding;
|
||||||
|
FB_ngon_encoding.SetObject();
|
||||||
|
|
||||||
|
exts.AddMember(StringRef("FB_ngon_encoding"), FB_ngon_encoding, w.mAl);
|
||||||
|
prim.AddMember("extensions", exts, w.mAl);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
prim.AddMember("mode", Value(int(p.mode)).Move(), w.mAl);
|
prim.AddMember("mode", Value(int(p.mode)).Move(), w.mAl);
|
||||||
|
|
||||||
|
@ -874,6 +887,10 @@ namespace glTF2 {
|
||||||
if (this->mAsset.extensionsUsed.KHR_materials_transmission) {
|
if (this->mAsset.extensionsUsed.KHR_materials_transmission) {
|
||||||
exts.PushBack(StringRef("KHR_materials_transmission"), mAl);
|
exts.PushBack(StringRef("KHR_materials_transmission"), mAl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->mAsset.extensionsUsed.FB_ngon_encoding) {
|
||||||
|
exts.PushBack(StringRef("FB_ngon_encoding"), mAl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exts.Empty())
|
if (!exts.Empty())
|
||||||
|
|
|
@ -97,6 +97,9 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai
|
||||||
|
|
||||||
mAsset.reset( new Asset( pIOSystem ) );
|
mAsset.reset( new Asset( pIOSystem ) );
|
||||||
|
|
||||||
|
// Always on as our triangulation process is aware of this type of encoding
|
||||||
|
mAsset->extensionsUsed.FB_ngon_encoding = true;
|
||||||
|
|
||||||
if (isBinary) {
|
if (isBinary) {
|
||||||
mAsset->SetAsBinary();
|
mAsset->SetAsBinary();
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,10 +217,21 @@ bool TriangulateProcess::TriangulateMesh( aiMesh* pMesh)
|
||||||
// if it's a simple point,line or triangle: just copy it
|
// if it's a simple point,line or triangle: just copy it
|
||||||
if( face.mNumIndices <= 3)
|
if( face.mNumIndices <= 3)
|
||||||
{
|
{
|
||||||
|
// ngon encoding: making sure that triangles are not recognized as false ngons.
|
||||||
|
// To do so, we make sure the first indice is not the same as previous triangle emitted.
|
||||||
|
unsigned int prev_first_indice = (unsigned int)-1;
|
||||||
|
if (curOut != out) prev_first_indice = (curOut - 1)->mIndices[0];
|
||||||
|
|
||||||
aiFace& nface = *curOut++;
|
aiFace& nface = *curOut++;
|
||||||
nface.mNumIndices = face.mNumIndices;
|
nface.mNumIndices = face.mNumIndices;
|
||||||
nface.mIndices = face.mIndices;
|
nface.mIndices = face.mIndices;
|
||||||
|
|
||||||
|
if (nface.mIndices[0] == prev_first_indice) {
|
||||||
|
// rotate indices to avoid ngon encoding false ngons
|
||||||
|
std::swap(nface.mIndices[0], nface.mIndices[2]);
|
||||||
|
std::swap(nface.mIndices[1], nface.mIndices[2]);
|
||||||
|
}
|
||||||
|
|
||||||
face.mIndices = nullptr;
|
face.mIndices = nullptr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue