Thu, 06 Nov 2014 13:51:09 +0200
- argh
src/ldDocument.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.cc | file | annotate | diff | comparison | revisions | |
src/mainWindow.cc | file | annotate | diff | comparison | revisions |
--- a/src/ldDocument.cc Wed Nov 05 17:48:11 2014 +0200 +++ b/src/ldDocument.cc Thu Nov 06 13:51:09 2014 +0200 @@ -1373,6 +1373,8 @@ // ----------------------------------------------------------------------------- LDObjectList LDDocument::inlineContents (bool deep, bool renderinline) { + sweepBFC(); + // Possibly substitute with logoed studs: // stud.dat -> stud-logo.dat // stud2.dat -> stud-logo2.dat @@ -1387,41 +1389,42 @@ return g_logoedStud2->inlineContents (deep, renderinline); } - LDObjectList objs, objcache; - bool invertnext = false; + LDObjectList objs; + QList<LDSubfilePtr> subfiles; for (LDObjectPtr obj : objects()) { - // Handle invertnext - if (obj->type() == OBJ_BFC - and obj.staticCast<LDBFC>()->statement() == BFCStatement::InvertNext) - { - invertnext = true; - continue; - } - // Skip those without scemantic meaning if (not obj->isScemantic()) continue; - + // Got another sub-file reference, inline it if we're deep-inlining. If not, // just add it into the objects normally. Yay, recursion! if (deep == true and obj->type() == OBJ_Subfile) - { - for (LDObjectPtr otherobj : obj.staticCast<LDSubfile>()->inlineContents (deep, renderinline)) - { - if (invertnext) - otherobj->setBlockWinding (Winding (int (otherobj->blockWinding()) ^ 1)); - - objs << otherobj; - } - - invertnext = false; - } + subfiles << obj.staticCast<LDSubfile>(); else objs << obj->createCopy(); } + // Perform deep inlining + while (not subfiles.isEmpty()) + { + QList<LDSubfilePtr> subfiles2; + + for (LDSubfilePtr& ref : subfiles) + { + for (LDObjectPtr obj : ref->inlineContents (false, renderinline)) + { + if (obj->type() == OBJ_Subfile) + subfiles2 << obj.staticCast<LDSubfile>(); + else + objs << obj; + } + } + + subfiles = subfiles2; + } + return objs; } @@ -1641,10 +1644,12 @@ if (invertnext) { + print ("sweepBFC: applying invertnext on %1\n", obj->id()); invertWinding (objwinding); invertnext = false; } + print ("sweepBFC: winding of %1 -> %2\n", obj->id(), int (objwinding)); obj->setBlockWinding (objwinding); } }
--- a/src/ldObject.cc Wed Nov 05 17:48:11 2014 +0200 +++ b/src/ldObject.cc Thu Nov 06 13:51:09 2014 +0200 @@ -387,6 +387,9 @@ // ----------------------------------------------------------------------------- LDObjectList LDSubfile::inlineContents (bool deep, bool render) { + fileInfo()->sweepBFC(); + bool isInverted = ((blockWinding() == Winding::CW) + or (transform().getDeterminant() < 0)); LDObjectList objs = fileInfo()->inlineContents (deep, render); // Transform the objects @@ -395,6 +398,12 @@ // Set the parent now so we know what inlined the object. obj->setParent (self()); TransformObject (obj, transform(), position(), color()); + + // Adjust winding + if (blockWinding() == Winding::None) + obj->setBlockWinding (Winding::None); + elif (isInverted) + obj->setBlockWinding (Winding (int (obj->blockWinding()) ^ 1)); } return objs; @@ -426,19 +435,18 @@ return data; } +/* +0 BFC CERTIFY CCW +1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud2a.dat +*/ + // ============================================================================= // QList<LDPolygon> LDSubfile::inlinePolygons() { - bool isInverted (false); - LDBFCPtr bfc (previous().dynamicCast<LDBFC>()); - - if ((bfc != null and bfc->statement() == BFCStatement::InvertNext) - or transform().getDeterminant() < 0) - { - isInverted = true; - } - + fileInfo()->sweepBFC(); + bool isInverted = ((blockWinding() == Winding::CW) + or (transform().getDeterminant() < 0)); QList<LDPolygon> data = fileInfo()->inlinePolygons(); for (LDPolygon& entry : data) @@ -446,12 +454,15 @@ for (int i = 0; i < entry.numVertices(); ++i) entry.vertices[i].transform (transform(), position()); - if (blockWinding() == Winding::None) + // Adjust winding + if (entry.winding == Winding::None) entry.winding = Winding::None; + //obj->setBlockWinding (Winding::None); elif (isInverted) invertWinding (entry.winding); + //obj->setBlockWinding (Winding (int (obj->blockWinding()) ^ 1)); } - + return data; }
--- a/src/mainWindow.cc Wed Nov 05 17:48:11 2014 +0200 +++ b/src/mainWindow.cc Thu Nov 06 13:51:09 2014 +0200 @@ -403,6 +403,10 @@ } } +#ifdef DEBUG + descr.prepend (format ("[%1] ", obj->id())); +#endif + QListWidgetItem* item = new QListWidgetItem (descr); item->setIcon (GetIcon (obj->typeName()));