Exemple #1
0
 def execute(self, context):
     startLog(self)
     global sensors
     global motors
     location = bpy.context.scene.cursor_location
     objects = []
     controllers = []
     for obj in bpy.context.selected_objects:
         if obj.phobostype == "controller":
             controllers.append(obj)
         else:
             objects.append(obj)
     if len(controllers) <= 0:
         blenderUtils.createPrimitive(self.controller_name, "sphere", self.controller_scale, defs.layerTypes["sensor"], "phobos_controller", location)
         bpy.context.scene.objects.active.phobostype = "controller"
         bpy.context.scene.objects.active.name = self.controller_name
         controllers.append(bpy.context.scene.objects.active)
     #empty index list so enable robotupdate of controller
     for ctrl in controllers:
         ctrl['controller/sensors'] = sorted(sensors, key=str.lower)
         ctrl['controller/motors'] = sorted(motors, key=str.lower)
         ctrl['controller/rate'] = self.controller_rate
     print("Added joints/motors to (new) controller(s).")
     #for prop in defs.controllerProperties[self.controller_type]:
     #    for ctrl in controllers:
     #        ctrl[prop] = defs.controllerProperties[prop]
     endLog()
     return {'FINISHED'}
Exemple #2
0
 def execute(self, context):
     startLog(self)
     root = sUtils.getRoot(context.selected_objects[0])
     model, objectlist = robotdictionary.buildModelDictionary(root)
     exporter.export(model, objectlist)
     endLog()
     return {'FINISHED'}
Exemple #3
0
 def execute(self, context):
     startLog(self)
     objlist = context.selected_objects
     if self.complete:
         roots = list(
             set([sUtils.getRoot(obj) for obj in context.selected_objects]))
         if None in roots:
             roots.remove(None)
         objlist = [
             elem
             for sublist in [sUtils.getChildren(root) for root in roots]
             for elem in sublist
         ]
     objnames = [o.name for o in bpy.data.objects]
     for obj in objlist:
         if "::" in obj.name:
             if nUtils.namesAreExplicit({obj.name.split("::")[-1]},
                                        objnames):
                 nUtils.removeNamespace(obj)
             else:
                 log(
                     "Cannot remove namespace from " + obj.name +
                     ". Name wouldn't be explicit", "ERROR")
         else:
             nUtils.addNamespace(obj)
     endLog()
     return {'FINISHED'}
Exemple #4
0
 def execute(self, context):
     startLog(self)
     location = bpy.context.scene.cursor_location
     objects = []
     controllers = []
     for obj in bpy.context.selected_objects:
         if obj.phobostype == "controller":
             controllers.append(obj)
         else:
             objects.append(obj)
     if len(controllers) <= 0:
         blenderUtils.createPrimitive("controller", "sphere", self.controller_scale, defs.layerTypes["sensor"], "controller", location)
         bpy.context.scene.objects.active.phobostype = "controller"
         bpy.context.scene.objects.active.name = "controller"
         controllers.append(bpy.context.scene.objects.active)
     #empty index list so enable robotupdate of controller
     for ctrl in controllers:
         for key in ctrl.keys():
             if key.find("index") >= 0:
                 del ctrl[key]
                 log("Deleting " + str(key) + " in " + ctrl.name, "INFO")
         i = 1
         for obj in objects:
             if obj.phobostype == "link":
                 ctrl["index"+(str(i) if i >= 10 else "0"+str(i))] = namingUtils.getObjectName(obj)
                 i += 1
     log("Added joints to (new) controller(s).", "INFO")
     #for prop in defs.controllerProperties[self.controller_type]:
     #    for ctrl in controllers:
     #        ctrl[prop] = defs.controllerProperties[prop]
     endLog()
     return {'FINISHED'}
Exemple #5
0
 def execute(self, context):
     startLog(self)
     global sensors
     global motors
     location = bpy.context.scene.cursor_location
     objects = []
     controllers = []
     for obj in bpy.context.selected_objects:
         if obj.phobostype == "controller":
             controllers.append(obj)
         else:
             objects.append(obj)
     if len(controllers) <= 0:
         blenderUtils.createPrimitive(self.controller_name, "sphere",
                                      self.controller_scale,
                                      defs.layerTypes["sensor"],
                                      "phobos_controller", location)
         bpy.context.scene.objects.active.phobostype = "controller"
         bpy.context.scene.objects.active.name = self.controller_name
         controllers.append(bpy.context.scene.objects.active)
     #empty index list so enable robotupdate of controller
     for ctrl in controllers:
         ctrl['controller/sensors'] = sorted(sensors, key=str.lower)
         ctrl['controller/motors'] = sorted(motors, key=str.lower)
         ctrl['controller/rate'] = self.controller_rate
     print("Added joints/motors to (new) controller(s).")
     #for prop in defs.controllerProperties[self.controller_type]:
     #    for ctrl in controllers:
     #        ctrl[prop] = defs.controllerProperties[prop]
     endLog()
     return {'FINISHED'}
Exemple #6
0
    def execute(self, context):
        startLog(self)
        selectionUtils.selectByName(self.errorObj)
        for message in defs.checkMessages[self.errorObj]:
            log(message, 'INFO')
        endLog()

        return {'FINISHED'}
Exemple #7
0
 def execute(self, context):
     startLog(self)
     self.distance, self.distVector = generalUtils.distance(
         bpy.context.selected_objects)
     log("distance: " + str(self.distance) + ", " + str(self.distVector),
         "INFO")
     endLog()
     return {'FINISHED'}
Exemple #8
0
    def execute(self, context):
        startLog(self)
        selectionUtils.selectByName(self.errorObj)
        for message in defs.checkMessages[self.errorObj]:
            log(message, 'INFO')
        endLog()

        return {'FINISHED'}
Exemple #9
0
 def execute(self, context):
     startLog(self)
     root = selectionUtils.getRoot(bpy.context.active_object)
     if root == None:
         log("Could not set modelname due to missing root link. No name was set.", "ERROR")
         return {'FINISHED'}
     root["modelname"] = self.modelname
     endLog()
     return {'FINISHED'}
Exemple #10
0
 def execute(self, context):
     startLog(self)
     for obj in bpy.context.selected_objects:
         if obj.phobostype == 'collision' or obj.phobostype == 'visual':
             obj['geometry/type'] = self.geomType
         else:
             log("The object '" + obj.name + "' is no collision or visual")
     endLog()
     return {'FINISHED'}
Exemple #11
0
 def execute(self, context):
     startLog(self)
     file = self.filepath.split("/")[-1]
     if self.filepath.endswith(".bake"):
         zipF = zipfile.ZipFile(self.filepath, mode="r")
         zipF.extractall(path=os.path.join(self.libpath, file.split(".")[0]))
     else:
         log("This is no robot bake!", "ERROR")
     endLog()
     return {"FINISHED"}
Exemple #12
0
 def execute(self, context):
     startLog(self)
     root = sUtils.getRoot(context.selected_objects[0])
     if root.phobostype != 'link':
         log("Selection includes objects not parented to any model root, please adapt selection.", "ERROR", "ExportModelOperator")
     else:
         model, objectlist = robotdictionary.buildModelDictionary(root)
         exporter.export(model, objectlist)
         endLog()
     return {'FINISHED'}
Exemple #13
0
 def execute(self, context):
     startLog(self)
     root = sUtils.getRoot(context.active_object)
     if root == None:
         log(
             "Could not set modelname due to missing root link. No name was set.",
             "ERROR")
         return {'FINISHED'}
     root["modelname"] = self.modelname
     endLog()
     return {'FINISHED'}
Exemple #14
0
 def execute(self, context):
     startLog(self)
     root = sUtils.getRoot(context.selected_objects[0])
     if root.phobostype != 'link':
         log(
             "Selection includes objects not parented to any model root, please adapt selection.",
             "ERROR", "ExportModelOperator")
     else:
         model, objectlist = robotdictionary.buildModelDictionary(root)
         exporter.export(model, objectlist)
         endLog()
     return {'FINISHED'}
Exemple #15
0
 def execute(self, context):
     startLog(self)
     roots = set()
     for obj in bpy.context.selected_objects:
         roots.add(getRoot(obj))
     if len(roots) > 0:
         selectObjects(list(roots), True)
         bpy.context.scene.objects.active = list(roots)[0]
     else:
         # bpy.ops.error.message('INVOKE_DEFAULT', type="ERROR", message="Couldn't find any root object.")
         log("Couldn't find any root object.", "ERROR")
     endLog()
     return {'FINISHED'}
Exemple #16
0
    def execute(self, context):

        startLog(self)
        messages = {}
        dic = robotdictionary.buildRobotDictionary()
        validator.check_dict(dic, defs.dictConstraints, messages)
        defs.checkMessages = messages if len(list(messages.keys())) > 0 else {"NoObject": []}
        for entry in messages:
            log("Errors in object " + entry + ":", 'INFO')
            for error in messages[entry]:
                log(error, 'INFO')
        endLog()
        return {'FINISHED'}
Exemple #17
0
 def execute(self, context):
     startLog(self)
     roots = set()
     for obj in bpy.context.selected_objects:
         roots.add(selectionUtils.getRoot(obj))
     if len(roots) > 0:
         selectionUtils.selectObjects(list(roots), True)
         bpy.context.scene.objects.active = list(roots)[0]
     else:
         # bpy.ops.error.message('INVOKE_DEFAULT', type="ERROR", message="Couldn't find any root object.")
         log("Couldn't find any root object.", "ERROR")
     endLog()
     return {'FINISHED'}
Exemple #18
0
    def execute(self, context):

        startLog(self)
        messages = {}
        root = sUtils.getRoot(context.selected_objects[0])
        model, objectlist = robotdictionary.buildModelDictionary(root)
        validator.check_dict(model, defs.dictConstraints, messages)
        defs.checkMessages = messages if len(list(messages.keys())) > 0 else {"NoObject": []}
        for entry in messages:
            log("Errors in object " + entry + ":", 'INFO')
            for error in messages[entry]:
                log(error, 'INFO')
        endLog()
        return {'FINISHED'}
Exemple #19
0
 def execute(self, context):
     startLog(self)
     for obj in context.selected_objects:
         try:
             phobosType = obj.phobostype
             if phobosType != 'controller' and phobosType != 'undefined':
                 layers = 20 * [False]
                 layers[defs.layerTypes[phobosType]] = True
                 obj.layers = layers
             if phobosType == 'undefined':
                 log("The phobostype of the object '" + obj.name + "' is undefined")
         except AttributeError:
             log("The object '" + obj.name + "' has no phobostype", "ERROR")  # Handle this as error or warning?
     endLog()
     return {'FINISHED'}
Exemple #20
0
 def execute(self, context):
     startLog(self)
     objs = context.selected_objects
     root = sUtils.getRoot(context.selected_objects[0])
     model = robotdictionary.buildModelDictionary(root)
     sUtils.selectObjects(objs)
     if bpy.data.worlds[0].relativePath:
         outpath = exporter.securepath(os.path.expanduser(os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path)))
     else:
         outpath = exporter.securepath(os.path.expanduser(bpy.data.worlds[0].path))
     exporter.bakeModel(objs, outpath, model["modelname"])
     with open(os.path.join(outpath, "info.bake"), "w") as f:
         f.write(yaml.dump({"name": model["modelname"]}))
     endLog()
     return {'FINISHED'}
Exemple #21
0
    def execute(self, context):

        startLog(self)
        messages = {}
        dic = robotdictionary.buildRobotDictionary()
        validator.check_dict(dic, defs.dictConstraints, messages)
        defs.checkMessages = messages if len(list(messages.keys())) > 0 else {
            "NoObject": []
        }
        for entry in messages:
            log("Errors in object " + entry + ":", 'INFO')
            for error in messages[entry]:
                log(error, 'INFO')
        endLog()
        return {'FINISHED'}
Exemple #22
0
 def execute(self, context):
     startLog(self)
     for obj in context.selected_objects:
         if self.find in obj and self.replace != '':
             if self.replace in obj:
                 # print("### Error: property", self.replace, "already present in object", obj.name)
                 log("Property '" + self.replace + "' already present in object '" + obj.name + "'", "ERROR")
                 if self.overwrite:
                     log("Replace property, because overwrite option was set")
                     obj[self.replace] = obj[self.find]
                     del obj[self.find]
             else:
                 obj[self.replace] = obj[self.find]
                 del obj[self.find]
     endLog()
     return {'FINISHED'}
Exemple #23
0
    def execute(self, context):
        """Executes the operator and unifies the selected objects meshes

        :param context: The blender context to work with
        :return: Blender result
        """
        startLog(self)
        messages = {}
        dic = robotdictionary.buildRobotDictionary()
        validator.check_dict(dic, defs.dictConstraints, messages)
        defs.checkMessages = messages if len(list(messages.keys())) > 0 else {"NoObject": []}
        for entry in messages:
            log("Errors in object " + entry + ":", 'INFO')
            for error in messages[entry]:
                log(error, 'INFO')
        endLog()
        return {'FINISHED'}
Exemple #24
0
 def execute(self, context):
     startLog(self)
     objs = context.selected_objects
     robot = robotdictionary.buildRobotDictionary()
     selectionUtils.selectObjects(objs)
     outpath = ""
     if bpy.data.worlds[0].relativePath:
         outpath = exporter.securepath(os.path.expanduser(os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path)))
     else:
         outpath = exporter.securepath(os.path.expanduser(bpy.data.worlds[0].path))
     #expPath = os.path.join(outpath, robot["modelname"] + "_bake")
     #exporter.export(path=expPath, robotmodel=robot)
     exporter.bakeModel(objs, outpath, robot["modelname"])
     with open(os.path.join(outpath, "info.bake"), "w") as f:
         f.write(yaml.dump({"name": robot["modelname"]}))
     endLog()
     return {'FINISHED'}
Exemple #25
0
 def execute(self, context):
     startLog(self)
     objlist = context.selected_objects
     if self.complete:
         roots = list(set([selectionUtils.getRoot(obj) for obj in context.selected_objects]))
         if None in roots:
             roots.remove(None)
         objlist = [elem for sublist in [selectionUtils.getChildren(root) for root in roots] for elem in sublist]
     objnames = [o.name for o in bpy.data.objects]
     for obj in objlist:
         if "::" in obj.name:
             if namingUtils.namesAreExplicit({obj.name.split("::")[-1]}, objnames):
                 namingUtils.removeNamespace(obj)
             else:
                 log("Cannot remove namespace from " + obj.name + ". Name wouldn't be explicit", "ERROR")
         else:
             namingUtils.addNamespace(obj)
     endLog()
     return {'FINISHED'}
Exemple #26
0
 def execute(self, context):
     startLog(self)
     objs = context.selected_objects
     root = sUtils.getRoot(context.selected_objects[0])
     model = robotdictionary.buildModelDictionary(root)
     sUtils.selectObjects(objs)
     if bpy.data.worlds[0].relativePath:
         outpath = exporter.securepath(
             os.path.expanduser(
                 os.path.join(bpy.path.abspath("//"),
                              bpy.data.worlds[0].path)))
     else:
         outpath = exporter.securepath(
             os.path.expanduser(bpy.data.worlds[0].path))
     exporter.bakeModel(objs, outpath, model["modelname"])
     with open(os.path.join(outpath, "info.bake"), "w") as f:
         f.write(yaml.dump({"name": model["modelname"]}))
     endLog()
     return {'FINISHED'}
Exemple #27
0
 def execute(self, context):
     startLog(self)
     libPath = os.path.join(os.path.dirname(defs.__file__), "RobotLib.yml")
     path, file = os.path.split(self.filepath)
     if file.endswith(".bake"):
         with open(self.filepath, "r") as f:
             info = yaml.load(f.read())
         if not os.path.isfile(libPath):
             open(libPath, "a").close()
         with open(libPath, "r+") as f:
             robot_lib = yaml.load(f.read())
             robot_lib = robot_lib if robot_lib is not None else {}
             robot_lib[info["name"]] = path
             f.seek(0)
             f.write(yaml.dump(robot_lib))
             f.truncate()
     else:
         log("This is no robot bake!", "ERROR")
     endLog()
     return {"FINISHED"}
Exemple #28
0
 def execute(self, context):
     startLog(self)
     libPath = os.path.join(os.path.dirname(defs.__file__), "RobotLib.yml")
     path, file = os.path.split(self.filepath)
     if file.endswith(".bake"):
         with open(self.filepath, "r") as f:
             info = yaml.load(f.read())
         if not os.path.isfile(libPath):
             open(libPath, "a").close()
         with open(libPath, "r+") as f:
             robot_lib = yaml.load(f.read())
             robot_lib = robot_lib if robot_lib is not None else {}
             robot_lib[info["name"]] = path
             f.seek(0)
             f.write(yaml.dump(robot_lib))
             f.truncate()
     else:
         log("This is no robot bake!", "ERROR")
     endLog()
     return {"FINISHED"}
Exemple #29
0
 def execute(self, context):
     startLog(self)
     objs = context.selected_objects
     robot = robotdictionary.buildRobotDictionary()
     selectionUtils.selectObjects(objs)
     outpath = ""
     if bpy.data.worlds[0].relativePath:
         outpath = exporter.securepath(
             os.path.expanduser(
                 os.path.join(bpy.path.abspath("//"),
                              bpy.data.worlds[0].path)))
     else:
         outpath = exporter.securepath(
             os.path.expanduser(bpy.data.worlds[0].path))
     #expPath = os.path.join(outpath, robot["modelname"] + "_bake")
     #exporter.export(path=expPath, robotmodel=robot)
     exporter.bakeModel(objs, outpath, robot["modelname"])
     with open(os.path.join(outpath, "info.bake"), "w") as f:
         f.write(yaml.dump({"name": robot["modelname"]}))
     endLog()
     return {'FINISHED'}
Exemple #30
0
    def execute(self, context):
        """Executes the operator and unifies the selected objects meshes

        :param context: The blender context to work with
        :return: Blender result
        """
        startLog(self)
        objects = context.selected_objects
        source = context.active_object
        sMProp = 'geometry/' + defs.reservedProperties['SHAREDMESH']
        newName = source.name if self.meshName == "" else self.meshName
        log(source.name, "INFO")
        for obj in objects:
            if 'phobostype' in obj and obj.phobostype in ("visual", "collision") and obj != source:
                log("Setting data for: " + obj.name, "INFO")
                obj.data = source.data
                obj[sMProp] = newName
        if sMProp in source: del obj[sMProp]
        source['geometry/filename'] = newName
        log("Successfully shared the meshes for selected objects!", "INFO")
        endLog()
        return {'FINISHED'}
Exemple #31
0
 def execute(self, context):
     startLog(self)
     objs = context.selected_objects
     robot = robotdictionary.buildRobotDictionary()
     selectionUtils.selectObjects(objs)
     tmpdir = tempfile.gettempdir()
     expPath = os.path.join(tmpdir, robot["modelname"] + "_bake")
     exporter.export(path=expPath, robotmodel=robot)
     exporter.bakeModel(objs, expPath, robot["modelname"])
     zipfilename = os.path.join(tmpdir, robot["modelname"] + ".bake")
     file = zipfile.ZipFile(zipfilename, mode="w")
     for filename in os.listdir(expPath):
         file.write(os.path.join(expPath, filename), arcname=filename)
     file.close()
     shutil.rmtree(expPath)
     outpath = ""
     if bpy.data.worlds[0].relativePath:
         outpath = exporter.securepath(os.path.expanduser(os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path)))
     else:
         outpath = exporter.securepath(os.path.expanduser(bpy.data.worlds[0].path))
     shutil.copy(zipfilename, outpath)
     endLog()
     return {'FINISHED'}
Exemple #32
0
 def execute(self, context):
     startLog(self)
     for obj in bpy.context.selected_objects:
         if obj.phobostype in ['visual', 'collision', 'inertial']:
             try:
                 oldmass = obj['mass']
             except KeyError:
                 log("The object '" + obj.name + "' has no mass")
                 oldmass = None
             if self.userbmass:
                 try:
                     obj['mass'] = obj.rigid_body.mass
                 except AttributeError:
                     obj['mass'] = 0.001
                     # print("### Error: object has no rigid body properties.")
                     log("The object '" + obj.name + "' has no rigid body properties. Set mass to 0.001", "ERROR")
             else:
                 obj['mass'] = self.mass
             if obj['mass'] != oldmass:
                 t = datetime.now()
                 obj['masschanged'] = t.isoformat()
     endLog()
     return {'FINISHED'}
Exemple #33
0
 def execute(self, context):
     startLog(self)
     location = bpy.context.scene.cursor_location
     objects = []
     controllers = []
     for obj in bpy.context.selected_objects:
         if obj.phobostype == "controller":
             controllers.append(obj)
         else:
             objects.append(obj)
     if len(controllers) <= 0:
         blenderUtils.createPrimitive("controller", "sphere",
                                      self.controller_scale,
                                      defs.layerTypes["sensor"],
                                      "controller", location)
         bpy.context.scene.objects.active.phobostype = "controller"
         bpy.context.scene.objects.active.name = "controller"
         controllers.append(bpy.context.scene.objects.active)
     #empty index list so enable robotupdate of controller
     for ctrl in controllers:
         for key in ctrl.keys():
             if key.find("index") >= 0:
                 del ctrl[key]
                 log("Deleting " + str(key) + " in " + ctrl.name, "INFO")
         i = 1
         for obj in objects:
             if obj.phobostype == "link":
                 ctrl["index" + (str(i) if i >= 10 else "0" +
                                 str(i))] = namingUtils.getObjectName(obj)
                 i += 1
     log("Added joints to (new) controller(s).", "INFO")
     #for prop in defs.controllerProperties[self.controller_type]:
     #    for ctrl in controllers:
     #        ctrl[prop] = defs.controllerProperties[prop]
     endLog()
     return {'FINISHED'}
Exemple #34
0
 def execute(self, context):
     startLog(self)
     ob = context.active_object
     textfilename = ob.name + datetime.now().strftime("%Y%m%d_%H:%M")
     variablename = ob.name.translate({ord(c): "_" for c in "!@#$%^&*()[]{};:,./<>?\|`~-=+"}) \
                    + "_data"
     tmpdict = dict(ob.items())
     for key in tmpdict:
         if hasattr(tmpdict[key], 'to_list'):  # transform Blender id_arrays into lists
             tmpdict[key] = list(tmpdict[key])
     contents = [variablename + ' = """',
                 yaml.dump(blenderUtils.cleanObjectProperties(tmpdict),
                           default_flow_style=False) + '"""\n',
                 "# ------- Hit 'Run Script' to save your changes --------",
                 "import yaml", "import bpy",
                 "tmpdata = yaml.load(" + variablename + ")",
                 "for key, value in tmpdata.items():",
                 "    bpy.context.active_object[key] = value",
                 "bpy.ops.text.unlink()"
                 ]
     blenderUtils.createNewTextfile(textfilename, '\n'.join(contents))
     blenderUtils.openScriptInEditor(textfilename)
     endLog()
     return {'FINISHED'}
Exemple #35
0
 def execute(self, context):
     startLog(self)
     exporter.exportSMURFsScene()
     endLog()
     return {'FINISHED'}
Exemple #36
0
 def execute(self, context):
     startLog(self)
     mass = generalUtils.calculateSum(bpy.context.selected_objects, 'mass')
     log("The calculated mass is: " + str(mass), "INFO")
     endLog()
     return {'FINISHED'}
Exemple #37
0
    def execute(self, context):
        """Executes this blender operator and creates collision objects for the selected bodies.

        :param context: The blender context this function should work with.

        :return: set -- the blender specific return set.

        """

        startLog(self)
        visuals = []
        for obj in bpy.context.selected_objects:
            if obj.phobostype == "visual":
                visuals.append(obj)
            obj.select = False

        if not visuals:
            # bpy.ops.error.message('INVOKE_DEFAULT', type="CreateCollisions Error", message="Not enough bodies selected.")
            log("Not enough bodies selected.", "ERROR")
            return {'CANCELLED'}
        for vis in visuals:
            nameparts = vis.name.split('_')
            if nameparts[0] == 'visual':
                nameparts[0] = 'collision'
            collname = '_'.join(nameparts)
            materialname = vis.data.materials[0].name if len(vis.data.materials) > 0 else "None"
            bBox = vis.bound_box
            center = generalUtils.calcBoundingBoxCenter(bBox)
            rotation = mathutils.Matrix.Identity(4)
            size = list(vis.dimensions)
            if self.property_colltype in ['cylinder', 'capsule']:
                axes = ('X', 'Y', 'Z')
                long_side = axes[size.index(max(size))]
                # xyequal = (size[0] - size[1])
                length = max(size)
                radii = [s for s in size if s != length]
                radius = max(radii) / 2 if radii != [] else length / 2
                size = (radius, length)
                if long_side == 'X':
                    rotation = mathutils.Matrix.Rotation(math.pi / 2, 4, 'Y')
                elif long_side == 'Y':
                    rotation = mathutils.Matrix.Rotation(math.pi / 2, 4, 'X')
                    # FIXME: apply rotation for moved cylinder object?
            elif self.property_colltype == 'sphere':
                size = max(size) / 2
            rotation_euler = (vis.matrix_world * rotation).to_euler()
            center = vis.matrix_world.to_translation() + vis.matrix_world.to_quaternion() * center
            if self.property_colltype != 'capsule':
                ob = blenderUtils.createPrimitive(collname, self.property_colltype, size,
                                             defs.layerTypes['collision'], materialname, center,
                                             rotation_euler)
            elif self.property_colltype == 'capsule':
                length = max(length - 2 * radius, 0.001)  # prevent length from turning negative
                size = (radius, length)
                zshift = length / 2
                ob = blenderUtils.createPrimitive(collname, 'cylinder', size,
                                             defs.layerTypes['collision'], materialname, center,
                                             rotation_euler)
                sph1 = blenderUtils.createPrimitive('tmpsph1', 'sphere', radius,
                                               defs.layerTypes['collision'], materialname,
                                               center + rotation * mathutils.Vector((0, 0, zshift)),
                                               rotation_euler)
                sph2 = blenderUtils.createPrimitive('tmpsph2', 'sphere', radius,
                                               defs.layerTypes['collision'], materialname,
                                               center - rotation * mathutils.Vector((0, 0, zshift)),
                                               rotation_euler)
                selectionUtils.selectObjects([ob, sph1, sph2], True, 0)
                bpy.ops.object.join()
                ob['length'] = length
                ob['radius'] = radius
            elif self.property_colltype == 'mesh':
                pass
                # TODO: copy mesh!!
            ob.phobostype = 'collision'
            ob['geometry/type'] = self.property_colltype
            if vis.parent:
                ob.select = True
                bpy.ops.object.transform_apply(scale=True)
                vis.parent.select = True
                bpy.context.scene.objects.active = vis.parent
                bpy.ops.object.parent_set(type='BONE_RELATIVE')
                # ob.parent_type = vis.parent_type
                # ob.parent_bone = vis.parent_bone
        endLog()
        return {'FINISHED'}
Exemple #38
0
 def execute(self, context):
     startLog(self)
     self.distance, self.distVector = generalUtils.distance(bpy.context.selected_objects)
     log("distance: " + str(self.distance) + ", " + str(self.distVector), "INFO")
     endLog()
     return {'FINISHED'}
Exemple #39
0
 def execute(self, context):
     startLog(self)
     mass = generalUtils.calculateSum(bpy.context.selected_objects, 'mass')
     log("The calculated mass is: " + str(mass), "INFO")
     endLog()
     return {'FINISHED'}
Exemple #40
0
 def execute(self, context):
     startLog(self)
     exporter.export()
     endLog()
     return {'FINISHED'}