# blender -b -P region_dbg.py -- in.glb out.glb "cond1;cond2"   (x,y,z world, rest pose)
import bpy, sys
a=sys.argv[sys.argv.index("--")+1:]; conds=a[2].split(";")
bpy.ops.wm.read_factory_settings(use_empty=True); bpy.ops.import_scene.gltf(filepath=a[0])
for o in list(bpy.context.scene.objects):
    if o.type=="MESH" and o.name.startswith("Ico"): bpy.data.objects.remove(o)
for o in bpy.context.scene.objects:
    if o.type=="ARMATURE": o.data.pose_position="REST"
bpy.context.view_layer.update()
o=[x for x in bpy.context.scene.objects if x.type=="MESH"][0]; mw=o.matrix_world
m=bpy.data.materials.new("hl"); m.use_nodes=True; m.node_tree.nodes["Principled BSDF"].inputs[0].default_value=(0,1,1,1)
o.data.materials.append(m); mi=len(o.data.materials)-1; n=0
for p in o.data.polygons:
    c=mw@p.center
    if all(eval(k,{"x":c.x,"y":c.y,"z":c.z,"abs":abs}) for k in conds): p.material_index=mi; n+=1
print("HL",n)
bpy.ops.export_scene.gltf(filepath=a[1],export_format="GLB",export_animations=False)
