From af74a7c795a790c212257568971d0af60079ce1a Mon Sep 17 00:00:00 2001 From: Brian Q Date: Mon, 7 Dec 2020 19:10:14 +1400 Subject: [PATCH 1/4] Update __init__.py Add Export Selected Only preferences to plugin ui --- __init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 892cbf7..3793390 100755 --- a/__init__.py +++ b/__init__.py @@ -49,6 +49,7 @@ class ExportBullet(bpy.types.Operator, ExportHelper): out_hulls = bpy.props.BoolProperty(name="Include Convex Hulls data", description="Export Convex Hulls shape points", default = True) out_meshes = bpy.props.BoolProperty( name="Include Mesh Shapes data", description="Export Mesh Shape as Triaangle mesh (indices and vertices)", default = True) + out_selected = bpy.props.BoolProperty( name="Export Selected Only", description="Only export selected objects", default = True) filename_ext = ".json" filter_glob = StringProperty( @@ -60,7 +61,7 @@ class ExportBullet(bpy.types.Operator, ExportHelper): def execute(self, context): from . import export_bullet - export_bullet.save(context, self.properties.filepath, self.out_hulls, self.out_meshes) + export_bullet.save(context, self.properties.filepath, self.out_hulls, self.out_meshes, self.out_selected) return {'FINISHED'} def draw(self, context): @@ -69,7 +70,7 @@ def draw(self, context): col.label(text="Options") col.prop(self, "out_hulls") col.prop(self, "out_meshes") - + col.prop(self, "out_selected") def menu_func_import(self, context): From 210adae41c6a66d5bd00460d4f6a2288cf7fe17f Mon Sep 17 00:00:00 2001 From: Brian Q Date: Mon, 7 Dec 2020 19:14:31 +1400 Subject: [PATCH 2/4] Add option to Export only selected objects --- export_bullet.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/export_bullet.py b/export_bullet.py index 9c1d721..96ba488 100755 --- a/export_bullet.py +++ b/export_bullet.py @@ -18,7 +18,7 @@ def getOffsetFromAToB(a, b): tOffset.z = tOffset.z / sa.z return tOffset, rOffset -def save(context, path, out_hulls, out_meshes): +def save(context, path, out_hulls, out_meshes, out_selected): jsonObject = {} scene = context.scene @@ -28,8 +28,13 @@ def save(context, path, out_hulls, out_meshes): jsonObject["convex_hulls"] = [] jsonObject["meshes"] = [] - for obj in scene.objects: - + if out_selected == True: + obj_loop = context.selected_objects + else: + obj_loop = scene.objects + + for obj in obj_loop: + if obj.rigid_body is not None: transform = obj.matrix_world @@ -62,7 +67,7 @@ def save(context, path, out_hulls, out_meshes): if out_hulls == True and obj.rigid_body.collision_shape == 'CONVEX_HULL': save_hull = True for i in jsonObject["convex_hulls"]: - if (i["hull_name"] == obj.data.name) : + if (i["hull_name"] == obj.data.name) : save_hull = False if (save_hull == True) : hullObject = {} @@ -76,7 +81,7 @@ def save(context, path, out_hulls, out_meshes): if out_meshes == True and obj.rigid_body.collision_shape == 'MESH': save_mesh = True for i in jsonObject["meshes"]: - if (i["mesh_name"] == obj.data.name) : + if (i["mesh_name"] == obj.data.name) : save_mesh = False if (save_mesh == True) : meshObject = {} @@ -124,7 +129,7 @@ def save(context, path, out_hulls, out_meshes): tOffset, rOffset = getOffsetFromAToB(object2, obj) rigidBodyConstraintObject["translation_offset_b"] = tOffset[0:3] rigidBodyConstraintObject["rotation_offset_b"] = rOffset[0:4] - + if constraintType == 'HINGE': rigidBodyConstraintObject["use_limit_ang_z"] = obj.rigid_body_constraint.use_limit_ang_z rigidBodyConstraintObject["limit_ang_z_lower"] = obj.rigid_body_constraint.limit_ang_z_lower @@ -178,11 +183,10 @@ def save(context, path, out_hulls, out_meshes): rigidBodyConstraintObject["use_spring_ang_z"] = obj.rigid_body_constraint.use_spring_ang_z rigidBodyConstraintObject["spring_stiffness_ang_z"] = obj.rigid_body_constraint.spring_stiffness_ang_z rigidBodyConstraintObject["spring_damping_ang_z"] = obj.rigid_body_constraint.spring_damping_ang_z - + jsonObject["constraints"].append(rigidBodyConstraintObject) jsonText = json.dumps(jsonObject) f = open(path, 'w') f.write(jsonText) f.close() - From 0909331a654f9507a7d96469df097c127bb9c4b4 Mon Sep 17 00:00:00 2001 From: Brian Q Date: Mon, 7 Dec 2020 19:18:32 +1400 Subject: [PATCH 3/4] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4c45d8..fd90854 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,7 @@ Before exporting the physical scene, you should - rotate object in [edit mode](https://docs.blender.org/manual/en/dev/modeling/meshes/introduction.html#edit-mode) to align the [bound box](https://docs.blender.org/manual/en/dev/editors/3dview/properties/shading.html#viewport-shading) - [set the origin](https://docs.blender.org/manual/en/dev/editors/3dview/object/origin.html#set-origin) of geometry to it's [bounds center](https://docs.blender.org/manual/en/dev/editors/3dview/object/editing/transform/control/pivot_point/bounding_box_center.html?highlight=bounding%20box) -- [apply scale](https://docs.blender.org/manual/en/dev/editors/3dview/object/editing/transform/clear_apply.html?highlight=apply%20object%20transformations#apply) to object data \ No newline at end of file +- [apply scale](https://docs.blender.org/manual/en/dev/editors/3dview/object/editing/transform/clear_apply.html?highlight=apply%20object%20transformations#apply) to object data + +Update Dec-2020 +- Added option to Export only selected objects From 68a264e0f288bd9db9f32d7b4ba739127597e488 Mon Sep 17 00:00:00 2001 From: Brian Q Date: Mon, 7 Dec 2020 19:29:48 +1400 Subject: [PATCH 4/4] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index fd90854..097ac94 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,9 @@ Before exporting the physical scene, you should Update Dec-2020 - Added option to Export only selected objects + +Install +- In the Blender program folder, navigate to [[2.8x\scripts\addons\]] +- Create a folder in 'addons' and name it something like "io_bullet_blender_exporter" (no spaces, hyphens) +- Copy all the files in this project to the folder +- Start Blender, open Preferences > Add-ons enable "Bullet json format"