def AttachWheelToBody(self, wheel, parent, wheelPos): """ Attaches the wheel to the given parent using a 6DOF constraint """ # set the wheel positions relative to the robot in case the # chassis was moved by the builder script or manually in blender """ globalWheelPos=wheelPos+parent.worldPosition wheel.worldPosition=globalWheelPos """ result = parent.getVectTo(wheel) ## result is a unit vector (result[2]) and a length(result[0]) ## multiply them together to get the complete vector wheelPos = result[0] * result[2] logger.debug("Added wheel '%s' at ('%f','%f','%f')" % (wheel.name, wheelPos[0], wheelPos[1], wheelPos[2])) # create constraint to allow wheel to spin # For an explanation on the parameters, see: # http://www.tutorialsforblender3d.com/GameModule/ClassKX_PyConstraintBinding_1f.html joint = blenderapi.constraints().createConstraint( parent.getPhysicsId(), # get physics ID of the parent object wheel.getPhysicsId(), # get physics ID of the wheel object 12, # 6dof constraint wheelPos[0], wheelPos[1], wheelPos[2], # pivot position 0, 0, 0, # pivot axis 128) # flag, 128=disable collision between wheel and parent # no parameters are set on x axis to allow full rotation about it joint.setParam(4, 0.0, 0.0) # no rotation about Y axis - min=0, max=0 joint.setParam(5, 0.0, 0.0) # no rotation about Z axis - min=0, max=0 return joint # return a reference to the constraint
def AttachCasterWheelToBody(self, wheel, parent, wheelPos): """ Attaches a freely rotating wheel to the given parent using a 6DOF constraint. It can also rotate around the Z axis """ result = parent.getVectTo(wheel) ## result is a unit vector (result[2]) and a length(result[0]) ## multiply them together to get the complete vector wheelPos = result[0] * result[2] logger.debug("Added caster wheel '%s' at ('%f','%f','%f')" % (wheel.name, wheelPos[0], wheelPos[1], wheelPos[2])) # create constraint to allow wheel to spin joint = blenderapi.constraints().createConstraint( parent.getPhysicsId(), # get physics ID of the parent object wheel.getPhysicsId(), # get physics ID of the wheel object 12, # 6dof constraint wheelPos[0], wheelPos[1], wheelPos[2], # pivot position 0, 0, 0, # pivot axis 128) # flag, 128=disable collision between wheel and parent # no parameters are set on x and z axis to allow full rotation about it joint.setParam(4, 0.0, 0.0) # no rotation about Y axis - min=0, max=0 joint.setParam(5, 0.0, 0.0) # no rotation about Z axis - min=0, max=0 return joint # return a reference to the constraint
def attach_wheel_to_body(self, wheel, parent, wheel_pos): """ Attaches the wheel to the given parent using a 6DOF constraint Set the wheel positions relative to the robot in case the chassis was moved by the builder script or manually in blender """ result = parent.getVectTo(wheel) ## result is a unit vector (result[2]) and a length(result[0]) ## multiply them together to get the complete vector wheel_pos = result[0] * result[2] logger.debug("Added wheel '%s' at ('%f','%f','%f')" % (wheel.name, wheel_pos[0], wheel_pos[1], wheel_pos[2])) # create constraint to allow wheel to spin # For an explanation on the parameters, see: # http://www.tutorialsforblender3d.com/GameModule/ClassKX_PyConstraintBinding_1f.html joint = blenderapi.constraints().createConstraint( parent.getPhysicsId(), # get physics ID of the parent object wheel.getPhysicsId(), # get physics ID of the wheel object 12, # 6dof constraint wheel_pos[0], wheel_pos[1], wheel_pos[2], # pivot position 0,0,0, # pivot axis 128) # flag, 128=disable collision between wheel and parent # no parameters are set on x axis to allow full rotation about it joint.setParam(4, 0.0, 0.0) # no rotation about Y axis - min=0, max=0 joint.setParam(5, 0.0, 0.0) # no rotation about Z axis - min=0, max=0 return joint # return a reference to the constraint
def __init__(self, obj1, obj2, pos_pivot =[0.0, 0.0, 0.0], rot_pivot =[0.0, 0.0, 0.0], may_collide =False): """ Construct a 6DoF joint between obj1 and obj2. By default, all axis are locked and should be explicitly unlocked :param obj1: the first physical object to link :param obj2: the second physical object to link :param pos_pivot: the position of the pivot, relative to obj1 frame. Default to (0.0, 0.0, 0.0), i.e. obj1's center. :param rot_pivot: the rotation of the pivot frame, related to obj1 frame. Defaults to (0.0,0.0,0.0), ie aligned with obj1's orientation. :param bool may_collide: indicates if collisions should be enabled or not between the two linked rigid-bodies """ self._joint = blenderapi.constraints().createConstraint( obj1.getPhysicsId(), obj2.getPhysicsId(), 12, # 6DoF pos_pivot[0], pos_pivot[1], pos_pivot[2], rot_pivot[0], rot_pivot[1], rot_pivot[2], 0 if may_collide else 128) for i in range(0, 5): self._lock_axis(i)
def __init__(self, obj1, obj2, pos_pivot=[0.0, 0.0, 0.0], rot_pivot=[0.0, 0.0, 0.0], may_collide=False): """ Construct a 6DoF joint between obj1 and obj2. By default, all axis are locked and should be explicitly unlocked :param obj1: the first physical object to link :param obj2: the second physical object to link :param pos_pivot: the position of the pivot, relative to obj1 frame. Default to (0.0, 0.0, 0.0), i.e. obj1's center. :param rot_pivot: the rotation of the pivot frame, related to obj1 frame. Defaults to (0.0,0.0,0.0), ie aligned with obj1's orientation. :param bool may_collide: indicates if collisions should be enabled or not between the two linked rigid-bodies """ self._joint = blenderapi.constraints().createConstraint( obj1.getPhysicsId(), obj2.getPhysicsId(), 12, # 6DoF pos_pivot[0], pos_pivot[1], pos_pivot[2], rot_pivot[0], rot_pivot[1], rot_pivot[2], 0 if may_collide else 128) for i in range(0, 5): self._lock_axis(i)
def attach_wheel_to_body(self, wheel, parent): """ Attaches the wheel to the given parent using a 6DOF constraint Set the wheel positions relative to the robot in case the chassis was moved by the builder script or manually in blender """ # create constraint to allow wheel to spin # For an explanation on the parameters, see: # http://www.tutorialsforblender3d.com/GameModule/ClassKX_PyConstraintBinding_1f.html joint = blenderapi.constraints().createConstraint( wheel.getPhysicsId(), # get physics ID of the wheel object parent.getPhysicsId(), # get physics ID of the parent object 12, # 6dof constraint 0.0, 0.0, 0.0, # Pivot around the center of the wheel 0,0,0, # pivot axis 128) # flag, 128=disable collision between wheel and parent # no parameters are set on x axis to allow full rotation about it joint.setParam(3, 0.0, 0.0) # no rotation about X axis - min=0, max=0 joint.setParam(4, 0.0, 0.0) # no rotation about Y axis - min=0, max=0 return joint # return a reference to the constraint
def AttachCasterWheelToBody(self, wheel, parent, wheelPos): """ Attaches a freely rotating wheel to the given parent using a 6DOF constraint. It can also rotate around the Z axis """ result = parent.getVectTo(wheel); ## result is a unit vector (result[2]) and a length(result[0]) ## multiply them together to get the complete vector wheelPos=result[0]*result[2] logger.debug("Added caster wheel '%s' at ('%f','%f','%f')" %(wheel.name, wheelPos[0], wheelPos[1], wheelPos[2])) # create constraint to allow wheel to spin joint = blenderapi.constraints().createConstraint( parent.getPhysicsId(), # get physics ID of the parent object wheel.getPhysicsId(), # get physics ID of the wheel object 12, # 6dof constraint wheelPos[0], wheelPos[1], wheelPos[2], # pivot position 0,0,0, # pivot axis 128) # flag, 128=disable collision between wheel and parent # no parameters are set on x and z axis to allow full rotation about it joint.setParam(4,0.0,0.0) # no rotation about Y axis - min=0, max=0 return joint # return a reference to the constraint