Start a new topic

Approach to delete polygons with nested children?

Greetings,


I want to explore removing the parent faces for sub-faced faces.  This is a structure that does not seem to export well from flt to gltf, as the parent remains but the children get removed in the exported file.  I am checking the export in blender 3.x.


In creator it would be no problem to remove level on the parent faces, but what would happen if I can do this in the API, do the children re-parent automatically or would they also get removed?  What approach can I use if I want to do this in the API instead of Creator?  I have python experience but not so much OF API.


If you know of a sample script that touches on this feel free to point it out, I am poring over the egstruct scripts.


Thanks!!


Shawn


Hi


The basic info that is needed to code this is:


  • Subfaces can be detected for any face by calling mgGetNestedChild( face )
  • Subfaces can be detached like any node using mgDetach(subface)
  • For any given subface, you can get the parent face using mgGetNestedParent (subface)
Given those, you can walk a database, find all subfaces as you walk and push them into a list
After walking, you can loop over that list of subfaces, detach them, then re-attach them to wherever you want. Typically to the parent of the face they were a nested child of.

Here is a script to do just that:

db = mgGetCurrentDb()

subfaces = []
def collectSubfaces (db, parent, rec, data):
   global subfaces
   if mgGetCode(rec) == fltPolygon:
      subf = mgGetNestedChild(rec)
      if subf != None:
         subfaces.append(subf)
   return MG_TRUE
   
mgWalk(db, collectSubfaces, None, None, 0)

for subface in subfaces:
   parentface = mgGetNestedParent(subface)
   targetparent = mgGetParent(parentface)
   mgDetach(subface)
   mgAttach(targetparent, subface)

 

Chris,


Thank you very much!  I will check it out!


Shawn

Chris,


Here's where I landed, it seems to do the job.  Thanks again!


 

db = mgGetCurrentDb()

parent_faces = []

def collectParentFaces(db, parent, rec, data):
    global parent_faces
    if mgGetCode(rec) == fltPolygon and mgGetNestedChild(rec) is not None:
        parent_faces.append(rec)
    return MG_TRUE

mgWalk(db, collectParentFaces, None, None, 0)

for parent_face in parent_faces:
    subface = mgGetNestedChild(parent_face)
    while subface is not None:
        parent = mgGetParent(parent_face)
        mgDetach(subface)
        mgAttach(parent, subface)
        subface = mgGetNestedChild(parent_face)

for parent_face in parent_faces:
    mgDelete(parent_face)

 

Great!

Ah I see. you wanted to delete the parent faces. I misunderstood and thought you just wanted to move subfaced children up. Glad it worked out.

Login to post a comment