Utilize Blender 2.8 to instantly open all kinds of 3D model files by double clicking them from Cinnamon / Nemo or similar. Bash, Python and some configuration for Linux Mint 19.3
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

blender_2.8_import_3dobjects.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import bpy
  5. file_loc = sys.argv[4] #0: blender 1: --python 2: path to script 3: -- 4: actual filepath
  6. print("Path: ", file_loc)
  7. for o in bpy.data.objects:
  8. if o.type == 'MESH':
  9. o.select_set(True)
  10. else:
  11. o.select_set(False)
  12. # call the operator only one initial time
  13. bpy.ops.object.delete()
  14. #check for filetype
  15. extension = file_loc.split(".")[-1]
  16. # BLENDER 2.8 3DS IMPORT NOT YET AVAILABLE
  17. #if(extension == "3ds" or extension == "3DS"):
  18. # imported_object = bpy.ops.import_scene.autodesk_3ds(filepath=file_loc)
  19. if(extension == "obj" or extension == "OBJ"):
  20. imported_object = bpy.ops.import_scene.obj(filepath=file_loc)
  21. if(extension == "fbx" or extension == "FBX"):
  22. imported_object = bpy.ops.import_scene.fbx(filepath=file_loc)
  23. if(extension == "gltf" or extension == "GLTF" or extension == "glb" or extension == "GLB"):
  24. imported_object = bpy.ops.import_scene.gltf(filepath=file_loc)
  25. if(extension == "ply" or extension == "PLY"):
  26. imported_object = bpy.ops.import_mesh.ply(filepath=file_loc)
  27. if(extension == "stl" or extension == "STL"):
  28. imported_object = bpy.ops.import_mesh.stl(filepath=file_loc)
  29. if(extension == "abc" or extension == "ABC"):
  30. imported_object = bpy.ops.wm.alembic_import(filepath=file_loc, as_background_job=False)
  31. if(extension == "dae" or extension == "DAE"):
  32. imported_object = bpy.ops.wm.collada_import(filepath=file_loc)
  33. if(extension == "x3d" or extension == "X3D" or extension == "wrl" or extension == "WRL"):
  34. imported_object = bpy.ops.import_scene.x3d(filepath=file_loc)
  35. if(extension == "bvh" or extension == "BVH"):
  36. imported_object = bpy.ops.import_anim.bvh(filepath=file_loc)
  37. if(extension == "mdl" or extension == "MDL"):
  38. file_name = os.path.basename(file_loc)
  39. imported_object = bpy.ops.import_mesh.mdl(filepath=file_loc, files=[{"name":file_name}])
  40. #zoom to object
  41. for area in bpy.context.screen.areas:
  42. if area.type == 'VIEW_3D':
  43. for region in area.regions:
  44. if region.type == 'WINDOW':
  45. override = {'area': area, 'region': region, 'edit_object': bpy.context.edit_object}
  46. bpy.ops.view3d.view_selected(override)
  47. #change view: zoom to object & hide overlays
  48. area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D')
  49. if(extension != "bvh" and extension != "BVH"):
  50. area.spaces[0].overlay.show_overlays = False
  51. area.spaces[0].shading.type = 'MATERIAL'
  52. #bpy.ops.view3d.camera_to_view_selected()
  53. #area.spaces[0].region_3d.view_perspective = 'CAMERA'