Beispiel #1
0
    def execute(self, context):
        """This function executes the operator and creates a link.

        :param context: The blender context this operator works with.
        :type context: Blender context.
        :return: Blender result.
        """
        if self.type == '3D cursor':
            links.createLink(self.size)
        else:
            for obj in bpy.context.selected_objects:
                tmpnamepartindices = [int(p) for p in self.namepartindices.split()]
                links.deriveLinkfromObject(obj, scale=self.size, parenting=self.parenting, parentobjects=self.parentobject,
                                     namepartindices=tmpnamepartindices, separator=self.separator,
                                     prefix=self.prefix)
        return {'FINISHED'}
Beispiel #2
0
 def execute(self, context):
     if self.bakeObj == "None":
         return {"FINISHED"}
     with open(os.path.join(os.path.dirname(defs.__file__), "RobotLib.yml"), "r") as f:
         robot_lib = yaml.load(f.read())
     root = links.createLink(1.0, name=self.robName + "::" + self.bakeObj)
     root["modelname"] = self.bakeObj
     root["entityname"] = self.robName
     root["isInstance"] = True
     bpy.ops.import_mesh.stl(filepath=os.path.join(robot_lib[self.bakeObj], "bake.stl"))
     bpy.ops.view3d.snap_selected_to_cursor(use_offset=False)
     obj = context.active_object
     obj.name = self.robName + "::visual"
     obj.phobostype = "visual"
     selectionUtils.selectObjects([root, obj], clear=True, active=0)
     bpy.ops.object.parent_set(type='BONE_RELATIVE')
     return {"FINISHED"}
Beispiel #3
0
 def execute(self, context):
     if self.bakeObj == "None":
         return {"FINISHED"}
     with open(os.path.join(os.path.dirname(defs.__file__), "RobotLib.yml"),
               "r") as f:
         robot_lib = yaml.load(f.read())
     root = links.createLink(1.0, name=self.robName + "::" + self.bakeObj)
     root["modelname"] = self.bakeObj
     root["entity/name"] = self.robName
     root["isInstance"] = True
     bpy.ops.import_mesh.stl(
         filepath=os.path.join(robot_lib[self.bakeObj], "bake.stl"))
     bpy.ops.view3d.snap_selected_to_cursor(use_offset=False)
     obj = context.active_object
     obj.name = self.robName + "::visual"
     obj.phobostype = "visual"
     sUtils.selectObjects([root, obj], clear=True, active=0)
     bpy.ops.object.parent_set(type='BONE_RELATIVE')
     return {"FINISHED"}
Beispiel #4
0
 def execute(self, context):
     # create a dictionary holding the sensor definition
     sensor = {'name': self.sensor_name,
               'type': self.custom_type if self.sensor_type == 'Custom' else self.sensor_type,
               'props': {}
               }
     parent = context.active_object
     for key in defs.sensorProperties[self.sensor_type]:
         if type(defs.sensorProperties[self.sensor_type][key]) == type(True):
             value = getattr(self, key)
             sensor['props'][key] = '$true' if value else '$false'
         else:
             sensor['props'][key] = getattr(self, key)
     # type-specific settings
     if sensor['type'] in ['CameraSensor', 'ScanningSonar', 'RaySensor',
                           'MultiLevelLaserRangeFinder', 'RotatingRaySensor']:
         if self.add_link:
             link = links.createLink(scale=0.1, position=context.active_object.matrix_world.to_translation(),
                                     name='link_' + self.sensor_name)
             sensorObj = sensors.createSensor(sensor, link.name, link.matrix_world)
         else:
             sensorObj = sensors.createSensor(sensor, context.active_object.name, context.active_object.matrix_world)
         if self.add_link:
             selectionUtils.selectObjects([parent, link], clear=True, active=0)
             bpy.ops.object.parent_set(type='BONE_RELATIVE')
             selectionUtils.selectObjects([link, sensorObj], clear=True, active=0)
             bpy.ops.object.parent_set(type='BONE_RELATIVE')
         sensors.cameraRotLock(sensorObj)
     elif sensor['type'] in ['Joint6DOF']:
         sensors.createSensor(sensor, context.active_object, context.active_object.matrix_world)
     elif 'Node' in sensor['type']:
         sensors.createSensor(sensor, [obj for obj in context.selected_objects if obj.phobostype == 'collision'],
                      mathutils.Matrix.Translation(context.scene.cursor_location))
     elif 'Motor' in sensor['type'] or 'Joint' in sensor['type']:
         sensors.createSensor(sensor, [obj for obj in context.selected_objects if obj.phobostype == 'link'],
                      mathutils.Matrix.Translation(context.scene.cursor_location))
     return {'FINISHED'}