Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions blenderSimplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_args():
bpy.ops.object.select_all(action='DESELECT')

# selection
bpy.data.objects['Camera'].select = True
bpy.data.objects['Camera'].select_set(True)

# remove it
bpy.ops.object.delete()
Expand All @@ -61,15 +61,15 @@ def get_args():
# select objects by type
for o in bpy.data.objects:
if o.type == 'MESH':
o.select = True
o.select_set(True)
else:
o.select = False
o.select_set(False)

# call the operator once
bpy.ops.object.delete()

print('\n Beginning the process of Decimation using Blender Python API ...')
bpy.ops.import_scene.obj(filepath=input_model)
bpy.ops.wm.obj_import(filepath=input_model)
print('\n Obj file imported successfully ...')
modifierName='DecimateMod'

Expand All @@ -83,14 +83,14 @@ def get_args():
print("{} meshes".format(len(meshes)))

for i, obj in enumerate(meshes):
bpy.context.scene.objects.active = obj
bpy.context.view_layer.objects.active = obj
print("{}/{} meshes, name: {}".format(i, len(meshes), obj.name))
print("{} has {} verts, {} edges, {} polys".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons)))
modifier = obj.modifiers.new(modifierName,'DECIMATE')
modifier.ratio = decimateRatio
modifier.use_collapse_triangulate = True
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modifierName)
bpy.ops.object.modifier_apply(modifier=modifierName)
print("{} has {} verts, {} edges, {} polys after decimation".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons)))

bpy.ops.export_scene.obj(filepath=output_model)
bpy.ops.wm.obj_export(filepath=output_model)
print('\n Process of Decimation Finished ...')
14 changes: 7 additions & 7 deletions blenderSimplifyNumFaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_args():
bpy.ops.object.select_all(action='DESELECT')

# selection
bpy.data.objects['Camera'].select = True
bpy.data.objects['Camera'].select_set(True)

# remove it
bpy.ops.object.delete()
Expand All @@ -63,15 +63,15 @@ def get_args():
# select objects by type
for o in bpy.data.objects:
if o.type == 'MESH':
o.select = True
o.select_set(True)
else:
o.select = False
o.select_set(False)

# call the operator once
bpy.ops.object.delete()

print('\nImporting the input 3D model, please wait.......')
bpy.ops.import_scene.obj(filepath=input_model)
bpy.ops.wm.obj_import(filepath=input_model)
print('\nObj file imported successfully ...')


Expand Down Expand Up @@ -123,16 +123,16 @@ def get_args():
print("{} meshes".format(len(meshes)))

for i, obj in enumerate(meshes):
bpy.context.scene.objects.active = obj
bpy.context.view_layer.objects.active = obj
print("{}/{} meshes, name: {}".format(i, len(meshes), obj.name))
print("{} has {} verts, {} edges, {} polys".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons)))
modifier = obj.modifiers.new(modifierName,'DECIMATE')
modifier.ratio = decimateRatio
modifier.use_collapse_triangulate = True
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modifierName)
bpy.ops.object.modifier_apply(modifier=modifierName)
print("{} has {} verts, {} edges, {} polys after decimation".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons)))

bpy.ops.export_scene.obj(filepath=str(nameOfFolder) + "/" + output_model)
bpy.ops.wm.obj_export(filepath=str(nameOfFolder) + "/" + output_model)
print('\nProcess of Decimation Finished ...')
print('\nOutput Mesh is stored in corresponding folder ...')

Expand Down
14 changes: 7 additions & 7 deletions blenderSimplifyV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_args():
bpy.ops.object.select_all(action='DESELECT')

# selection
bpy.data.objects['Camera'].select = True
bpy.data.objects['Camera'].select_set(True)

# remove it
bpy.ops.object.delete()
Expand All @@ -64,15 +64,15 @@ def get_args():
# select objects by type
for o in bpy.data.objects:
if o.type == 'MESH':
o.select = True
o.select_set(True)
else:
o.select = False
o.select_set(False)

# call the operator once
bpy.ops.object.delete()

print('\nImporting the input 3D model, please wait.......')
bpy.ops.import_scene.obj(filepath=input_model)
bpy.ops.wm.obj_import(filepath=input_model)
print('\nObj file imported successfully ...')

#Creating a folder named as the Number of faces: named '150000'
Expand All @@ -96,16 +96,16 @@ def get_args():
print("{} meshes".format(len(meshes)))

for i, obj in enumerate(meshes):
bpy.context.scene.objects.active = obj
bpy.context.view_layer.objects.active = obj
print("{}/{} meshes, name: {}".format(i, len(meshes), obj.name))
print("{} has {} verts, {} edges, {} polys".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons)))
modifier = obj.modifiers.new(modifierName,'DECIMATE')
modifier.ratio = decimateRatio
modifier.use_collapse_triangulate = True
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modifierName)
bpy.ops.object.modifier_apply(modifier=modifierName)
print("{} has {} verts, {} edges, {} polys after decimation".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons)))

bpy.ops.export_scene.obj(filepath=str(nameOfFolder) + "%/" + output_model)
bpy.ops.wm.obj_export(filepath=str(nameOfFolder) + "%/" + output_model)
print('\nProcess of Decimation Finished ...')
print('\nOutput Mesh is stored in corresponding folder ...')

Expand Down