def __init__(self, x, y, z, mass=1, scale=1, draw_as_cylinder=False, color=Color.blue, overdraw_length=1, overdraw_radius=1, flat_shading=False): if draw_as_cylinder: if y is max(x, y, z): radius = (x + z) / 4 * overdraw_radius self.shape = Primitives.getCylinder( 90, radius, y / (radius * 2) * overdraw_length) if z is max(x, y, z): radius = (x + y) / 4 * overdraw_radius self.shape = Primitives.getCylinder( 90, radius, z / (radius * 2) * overdraw_length) self.shape.rotateX(math.pi / 2) self.shape.rotateMesh() else: self.shape = createBox(x / 2.0 * scale, y / 2.0 * scale, z / 2.0 * scale) if flat_shading: self.shape.shadingMode = Object3D.SHADING_FAKED_FLAT colorname = 'box%d' % id(self) TextureManager.getInstance().addTexture(colorname, Texture(1, 1, color)) self.shape.setTexture(colorname) self.shape.build() shape = BoxShape(Vector3f(x / 2.0, y / 2.0, z / 2.0)) inertia = Vector3f(0, 0, 0) shape.calculateLocalInertia(mass, inertia) t = Transform() t.setIdentity() ms = DefaultMotionState(t) rb = RigidBodyConstructionInfo(mass, ms, shape, inertia) self.physics = RigidBody(rb)