def createInertials(link, empty=False, preserve_children=False): """Creates inertial representations for visual and collision objects in link. :param link: The link you want to create the inertial for. :type link: bpy_types.Object :param empty: If set to True the new inertial object will contain no information. :type empty: bool :param preserve_children: If set to False already existent inertial objects will be deleted. :type preserve_children: bool """ # viscols = getInertiaRelevantObjects(link) # clean existing data if not preserve_children: oldinertials = selectionUtils.getImmediateChildren(link, ['inertial']) else: try: oldinertials = [bpy.data.objects['inertial_' + link.name]] except KeyError: oldinertials = None if oldinertials: selectionUtils.selectObjects(oldinertials, clear=True, active=0) bpy.ops.object.delete() if not preserve_children: for obj in viscols: if not empty: mass = obj['mass'] if 'mass' in obj else None geometry = robotdictionary.deriveGeometry(obj) if mass is not None: if geometry['type'] == 'mesh': selectionUtils.selectObjects([obj]) bpy.context.scene.objects.active = obj inert = calculateMeshInertia(obj.data, mass) #print('mesh:', inert) #print('ellipsoid:', calculateEllipsoidInertia(mass, geometry['size'])) #print('box:', calculateBoxInertia(mass, geometry['size'])) else: inert = calculateInertia(mass, geometry) if inert is not None: inertial = createInertial(obj) inertial['mass'] = mass inertial['inertia'] = inert else: createInertial(obj) # compose inertial object for link if not empty: mass, com, inert = fuseInertiaData( selectionUtils.getImmediateChildren(link, ['inertial'])) if mass and com and inert: inertial = createInertial(link) com_translate = mathutils.Matrix.Translation(com) inertial.matrix_local = com_translate bpy.ops.transform.translate(value=( 0, 0, 0 )) # FIXME: this is a trick to force Blender to apply matrix_local inertial['inertial/mass'] = mass inertial['inertial/inertia'] = inertiaMatrixToList(inert) else: createInertial(link)
def createInertials(link, empty=False, preserve_children=False): """Creates inertial representations for visual and collision objects in link. :param link: The link you want to create the inertial for. :type link: bpy_types.Object :param empty: If set to True the new inertial object will contain no information. :type empty: bool :param preserve_children: If set to False already existent inertial objects will be deleted. :type preserve_children: bool """ # viscols = getInertiaRelevantObjects(link) # clean existing data if not preserve_children: oldinertials = selectionUtils.getImmediateChildren(link, ['inertial']) else: try: oldinertials = [bpy.data.objects['inertial_'+link.name]] except KeyError: oldinertials = None if oldinertials: selectionUtils.selectObjects(oldinertials, clear=True, active=0) bpy.ops.object.delete() if not preserve_children: for obj in viscols: if not empty: mass = obj['mass'] if 'mass' in obj else None geometry = robotdictionary.deriveGeometry(obj) if mass is not None: if geometry['type'] == 'mesh': selectionUtils.selectObjects([obj]) bpy.context.scene.objects.active = obj inert = calculateMeshInertia(obj.data, mass) #print('mesh:', inert) #print('ellipsoid:', calculateEllipsoidInertia(mass, geometry['size'])) #print('box:', calculateBoxInertia(mass, geometry['size'])) else: inert = calculateInertia(mass, geometry) if inert is not None: inertial = createInertial(obj) inertial['mass'] = mass inertial['inertia'] = inert else: createInertial(obj) # compose inertial object for link if not empty: mass, com, inert = fuseInertiaData(selectionUtils.getImmediateChildren(link, ['inertial'])) if mass and com and inert: inertial = createInertial(link) com_translate = mathutils.Matrix.Translation(com) inertial.matrix_local = com_translate bpy.ops.transform.translate(value=(0, 0, 0)) # FIXME: this is a trick to force Blender to apply matrix_local inertial['inertial/mass'] = mass inertial['inertial/inertia'] = inertiaMatrixToList(inert) else: createInertial(link)
def createInertials(link, empty=False, preserve_children=False): # create inertial representations for visual and collision objects in link viscols = getInertiaRelevantObjects(link) # clean existing data if not preserve_children: oldinertials = selectionUtils.getImmediateChildren(link, ['inertial']) else: try: oldinertials = [bpy.data.objects['inertial_'+link.name]] except KeyError: oldinertials = None if oldinertials: selectionUtils.selectObjects(oldinertials, clear=True, active=0) bpy.ops.object.delete() if not preserve_children: for obj in viscols: if not empty: mass = obj['mass'] if 'mass' in obj else None geometry = robotdictionary.deriveGeometry(obj) if mass is not None: inert = calculateInertia(mass, geometry) if inert is not None: inertial = createInertial(obj) inertial['mass'] = mass inertial['inertia'] = inert else: createInertial(obj) # compose inertial object for link if not empty: mass, com, inert = fuseInertiaData(selectionUtils.getImmediateChildren(link, ['inertial'])) if mass and com and inert: inertial = createInertial(link) com_translate = mathutils.Matrix.Translation(com) inertial.matrix_local = com_translate bpy.ops.transform.translate(value=(0, 0, 0)) # FIXME: this is a trick to force Blender to apply matrix_local inertial['inertial/mass'] = mass inertial['inertial/inertia'] = inertiaMatrixToList(inert) else: createInertial(link)