Last active
July 13, 2023 13:29
-
-
Save mariusud/6d880a2809475e03db51ad909dcd0fc5 to your computer and use it in GitHub Desktop.
Convert off to obj files in batch using blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Slight modification of https://gist.github.com/AngryLoki/3800594 | |
# Converts Object File Format (OFF) files to OBJ files in batch | |
# Allows the usage of OFF files in Gazebo Ignition | |
# blender --background --python3.7 off2obj.py -- input_dir output_dir i.e. blender --background --python off2obj.py -- off_meshes/ ./obj_meshes/ | |
# Tested with Blender 2.82 and OFF Add-on https://github.com/3Descape/blender-off-addon/tree/patch-1 | |
# Sizes all objects down to 10,10,10 | |
import os | |
import sys | |
import glob | |
import bpy | |
import time | |
scale = 0.01 | |
if len(sys.argv) != 7: | |
print("Must provide input and output path") | |
else: | |
for infile in glob.glob(os.path.join(sys.argv[5], '*.off')): | |
override = bpy.context.copy() | |
override['selected_objects'] = list(bpy.context.scene.objects) | |
bpy.ops.object.delete(override) | |
obj = bpy.ops.import_mesh.off(filepath=infile) | |
bpy.ops.transform.resize(value=(scale,scale,scale)) | |
bpy.context.view_layer.update() | |
for ob in bpy.data.objects: | |
x,y,z = ob.dimensions | |
ob.scale = (10/x,10/y,10/z) | |
bpy.context.view_layer.update() | |
outfilename = os.path.splitext(os.path.split(infile)[1])[0] + ".dae" | |
bpy.ops.wm.collada_export(filepath=os.path.join(sys.argv[6], outfilename)) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment