1
$\begingroup$

I created two blender scripts :

  • a MeshCleaner : that cleans the meshes for my glb file
  • a HierarchyCleaner : that cleans the hierarchy for my glb files

To clean the code , i added an IOHandler for reading and writing glb files so i can reuse the IOHandler in both the MeshCleaner and the HierarchyCleaner . When running one of the scripts i run blender in the background

  • MeshCleaner.py
import bpy
from .IOHandler import import_gltf_file , export_gltf_file , read_filename

def remove_default_cube ():
    objs = bpy.data.objects
    objs.remove(objs["Cube"], do_unlink=True)
    
def clean_heavy_gltf_file(filename):
    import_gltf_file(filename)
    export_gltf_file(filename)

if __name__=="__main__":
    remove_default_cube()
    filename = read_filename()
    clean_heavy_gltf_file(filename)

  • HierarchyCleaner.py
import bpy
from IOHandler import import_gltf_file , export_gltf_file , read_filename
from MeshCleaner import remove_default_cube

def clean_hierarchy():
    objs = bpy.data.objects
    nodes=objs.values()
    print(nodes)
    for node in nodes :
        if(len(node.children)==0):
            node.name=node.data.name
    
def correct_file(filename):
    import_gltf_file(filename)
    remove_default_cube()
    clean_hierarchy()
    export_gltf_file(filename)


if __name__=="__main__":
    correct_file()
  • IOHandler.py:
import bpy
import sys

def import_gltf_file(filename):
    bpy.ops.import_scene.gltf(filepath = filename)

def export_gltf_file(filename):
    bpy.ops.export_scene.gltf(filepath = filename)

def read_filename():
    filename=sys.argv[4]
    return filename

I run the code using sh scripts running :

GLB_FILE=$1 ;

blender --background --python HierarchyCleaner.py $GLB_FILE ;

or

GLB_FILE=$1 ;

blender --background --python MeshCleaner.py $GLB_FILE ;

when trying to run the code i have an ImportError stating that there is no such module as IOHandler . all the scripts are within the same directory .

Is there a way to make this work and ?

$\endgroup$
0

0

Browse other questions tagged .