def __init__(self, filename, texture, scale=1.0, mass=1, overdraw_scale=1.0): if not TextureManager.getInstance().containsTexture(texture): TextureManager.getInstance().addTexture(texture, Texture(texture)) if (filename, scale) not in MD2._shapes: shape = Loader.loadMD2(filename, scale) shape.rotateAxis(SimpleVector(1, 0, 0), math.pi/2) shape.rotateAxis(SimpleVector(0, 0, 1), -math.pi/2) shape.rotateMesh() shape.rotationMatrix = Matrix() MD2._shapes[(filename, scale)] = shape # self.shape = MD2._shapes[(filename, scale)].cloneObject() self.shape = Object3D(MD2._shapes[(filename, scale)], False) self.shape.build() self.shape.setTexture(texture) minx, maxx, miny, maxy, minz, maxz = self.shape.mesh.boundingBox shape = BoxShape(Vector3f((maxx - minx) / overdraw_scale / 2.0, (maxy - miny) / overdraw_scale / 2.0, (maxz - minz) / 2.0)) t = Transform() t.setIdentity() t.origin.x = (maxx + minx) / 2 t.origin.y = (maxy + miny) / 2 t.origin.z = (maxz + minz) / 2 ms = DefaultMotionState(t) inertia = Vector3f(0, 0, 0) shape.calculateLocalInertia(mass, inertia) rb = RigidBodyConstructionInfo(mass, ms, shape, inertia) self.physics = RigidBody(rb) self.shape.setOrigin(SimpleVector(-(maxx + minx) / 2, -(maxy + miny) / 2, -(maxz + minz) / 2))
def __init__(self, r, mass=1, color=Color.red): colorname = 'sphere_%d' % id(self) self.shape = Primitives.getSphere(r) TextureManager.getInstance().addTexture( colorname, Texture(1, 1, color)) self.shape.setTexture(colorname) self.shape.build() shape = BoxShape(Vector3f(r / 2.0, r / 2.0, r / 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)
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)