def reset(self): namelist = [ 'Ground', 'Conveyor', 'Finger', 'Block', 'Scrambled Block', 'Not Rewardable', 'Teleport Me' ] for child in render.getChildren(): for test in namelist: if child.node().name == test: self.world.remove(child.node()) child.removeNode() break # Plane self.plane_shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.plane_node = BulletRigidBodyNode('Ground') self.plane_node.addShape(self.plane_shape) self.plane_np = self.render.attachNewNode(self.plane_node) self.plane_np.setPos(0.0, 0.0, -1.0) self.world.attachRigidBody(self.plane_node) # Conveyor self.conv_node = BulletRigidBodyNode('Conveyor') self.conv_node.setFriction(1.0) self.conv_np = self.render.attachNewNode(self.conv_node) self.conv_shape = BulletBoxShape(Vec3(100.0, 1.0, 0.05)) self.conv_node.setMass(1000.0) self.conv_np.setPos(-95.0, 0.0, 0.1) self.conv_node.addShape(self.conv_shape) self.world.attachRigidBody(self.conv_node) self.model = loader.loadModel('assets/conv.egg') self.model.flattenLight() self.model.reparentTo(self.conv_np) # Finger self.finger_node = BulletRigidBodyNode('Finger') self.finger_node.setFriction(1.0) self.finger_np = self.render.attachNewNode(self.finger_node) self.finger_shape = BulletCylinderShape(0.1, 0.25, ZUp) self.finger_node.setMass(0) self.finger_np.setPos(1.8, 0.0, 0.24 + 0.0254 * 3.5) self.finger_node.addShape(self.finger_shape) self.world.attachRigidBody(self.finger_node) self.model = loader.loadModel('assets/finger.egg') self.model.flattenLight() self.model.reparentTo(self.finger_np) self.blocks = [] for block_num in range(15): new_block = self.spawn_block(Vec3(18, 0, (0.2 * block_num) + 2.0)) self.blocks.append(new_block) self.have_scramble = False self.penalty_applied = False self.spawnned = False self.score = 10 self.teleport_cooled_down = True self.fps = 20 self.framecount = 0 return self.step(1)[0]
def __init__(self): PhysicsNodePath.__init__(self, 'can') self.shapeGroup = BitMask32.allOn() sph = BulletCylinderShape(0.5, 1.2, ZUp) rbnode = BulletRigidBodyNode('can_body') rbnode.setMass(10.0) rbnode.addShape(sph) rbnode.setCcdMotionThreshold(1e-7) rbnode.setCcdSweptSphereRadius(0.5) self.mdl = loader.loadModel("phase_5/models/props/can.bam") self.mdl.setScale(11.0) self.mdl.setZ(-0.55) self.mdl.reparentTo(self) self.mdl.showThrough(CIGlobals.ShadowCameraBitmask) self.setupPhysics(rbnode) #self.makeShadow(0.2) self.reparentTo(render) self.setPos(base.localAvatar.getPos(render)) self.setQuat(base.localAvatar.getQuat(render)) dir = self.getQuat(render).xform(Vec3.forward()) amp = 10 self.node().setLinearVelocity(dir * amp)
def circle_region_detection(engine: EngineCore, position: Tuple, radius: float, detection_group: int, height=10, in_static_world=False): """ :param engine: BaseEngine class :param position: position in PGDrive :param radius: radius of the region to be detected :param detection_group: which group to detect :param height: the detect will be executed from this height to 0 :param in_static_world: execute detection in static world :return: detection result """ region_detect_start = panda_position(position, z=height) region_detect_end = panda_position(position, z=-1) tsFrom = TransformState.makePos(region_detect_start) tsTo = TransformState.makePos(region_detect_end) shape = BulletCylinderShape(radius, 5, ZUp) penetration = 0.0 physics_world = engine.physics_world.dynamic_world if not in_static_world else engine.physics_world.static_world result = physics_world.sweep_test_closest(shape, tsFrom, tsTo, detection_group, penetration) return result
def throwBall(self, size, camP, camH): self.ballNP.removeNode() pos = self.playerObj.getPosition() pNP = self.playerObj.getNodePath() px = plypos.getX() py = plypos.getY() pz = plypos.getZ() size = self.ballModel.getScale().getX() self.ballShape = BulletCylinderShape(size, size * 1.7, ZUp) self.ballRBody = BulletRigidBodyNode() self.ballRBody.setMass(1) self.ballRBody.addShape(self.ballShape) rbNP = self.worldObj.attachNewNode(self.ballRBody) ph = self.playerObj.getRotation() self.ballModel.setPos(0, 0, 0) dx = -sin(ph * DEG_TO_RAD) * size * 3 dy = cos(ph * DEG_TO_RAD) * size * 3 self.ballModel.reparentTo(rbNP) rbNP.setPos(px + dx, py + dy, pz) self.worldBullet.attachRigidBody(self.ballRBody) self.setRolling(False) self.rolledOnce = True self.ballExists = True xFactor = -sin(camH * DEG_TO_RAD) * cos(camP * DEG_TO_RAD) yFactor = cos(camH * DEG_TO_RAD) * cos(camP * DEG_TO_RAD) zFactor = sin(camP * DEG_TO_RAD) defUpFrc = 200 defXYFrc = 500 self.applyForce( Vec3(defXYFrc * xFactor, defXYFrc * yFactor, defUpFrc * zFactor))
def getPhysBody(self): shape = BulletCylinderShape(0.3925, 1.4, ZUp) body = BulletRigidBodyNode('tntBody') body.addShape(shape) body.setKinematic(True) body.setCcdMotionThreshold(1e-7) body.setCcdSweptSphereRadius(0.3925) return body
def __init__(self, world: BulletWorld, entity: Entity, radius=0.5, height=1, mass=0, rotation=[None, None, None]): super().__init__(world, entity, BulletCylinderShape(radius, height, 1), 'cylinder', rotation, mass)
def getPhysBody(self): shape = BulletCylinderShape(0.3925, 1.4, ZUp) body = BulletRigidBodyNode('tntBody') body.addShape(shape) body.setCcdMotionThreshold(1e-7) body.setCcdSweptSphereRadius(0.3925) body.setKinematic(False) body.setMass(5.0) body.setAngularDamping(0.3) body.setLinearDamping(0.8) return body
def create_solid(self): walker_capsule = BulletGhostNode(self.name + "_walker_cap") self.walker_capsule_shape = BulletCylinderShape(.7, .2, YUp) walker_bullet_np = self.actor.attach_new_node(walker_capsule) walker_bullet_np.node().add_shape(self.walker_capsule_shape) walker_bullet_np.node().set_kinematic(True) walker_bullet_np.set_pos(0,1.5,0) walker_bullet_np.wrt_reparent_to(self.actor) self.world.physics.attach_ghost(walker_capsule) walker_bullet_np.node().setIntoCollideMask(GHOST_COLLIDE_BIT) return None
def __init__(self, num_lasers: int = 240, distance: float = 50, enable_show=False): super(Lidar, self).__init__(num_lasers, distance, enable_show) self.origin.hide(CamMask.RgbCam | CamMask.Shadow | CamMask.Shadow | CamMask.DepthCam) self.mask = CollisionGroup.Vehicle | CollisionGroup.InvisibleWall | CollisionGroup.TrafficObject # lidar can calculate the detector mask by itself self.angle_delta = 360 / num_lasers if num_lasers > 0 else None self.broad_detector = NodePath(BulletGhostNode("detector_mask")) self.broad_detector.node().addShape(BulletCylinderShape(self.BROAD_PHASE_EXTRA_DIST + distance, 5)) self.broad_detector.node().setIntoCollideMask(CollisionGroup.LidarBroadDetector) self.broad_detector.node().setStatic(True) engine = get_engine() engine.physics_world.static_world.attach(self.broad_detector.node()) self.enable_mask = True if not engine.global_config["_disable_detector_mask"] else False
def __emitShell(self): def __shellThink(shell, task): if task.time > 3.0: base.physicsWorld.remove(shell.node()) shell.removeNode() return task.done if not hasattr(task, 'didHitNoise'): task.didHitNoise = False if not task.didHitNoise: contact = base.physicsWorld.contactTest(shell.node()) if contact.getNumContacts() > 0: task.didHitNoise = True hitNoise = base.loadSfxOnNode( self.ShellContactSoundPath.format( random.randint(*self.ShellContactSoundRange)), shell) hitNoise.play() return task.cont from panda3d.bullet import BulletCylinderShape, BulletRigidBodyNode, ZUp scale = 0.75 shape = BulletCylinderShape(0.07 * scale, 0.47 * scale, ZUp) rbnode = BulletRigidBodyNode('shellrbnode') rbnode.setMass(1.0) rbnode.addShape(shape) rbnode.setCcdMotionThreshold(1e-7) rbnode.setCcdSweptSphereRadius(0.1) rbnp = render.attachNewNode(rbnode) mdl = loader.loadModel(self.ShellPath) mdl.reparentTo(rbnp) mdl.setScale(0.3 * scale, 0.7 * scale, 0.3 * scale) mdl.setP(90) mdl.setTransparency(True, 1) rbnp.setPos(camera, (1, 2, -0.5)) rbnp.setHpr(camera, (0, -90, 0)) localEjectDir = Vec3(1, 0, 0.3) rbnode.applyCentralImpulse( camera.getQuat(render).xform(localEjectDir) * 7) base.physicsWorld.attach(rbnode) taskMgr.add(__shellThink, 'shellThink', extraArgs=[rbnp], appendTask=True)
def addMultiCylinderRB(self,rads,centT1,centT2,**kw): inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode("Cylinder")) inodenp.node().setMass(1.0) centT1 = ingr.positions[0]#ingr.transformPoints(jtrans, rotMat, ingr.positions[0]) centT2 = ingr.positions2[0]#ingr.transformPoints(jtrans, rotMat, ingr.positions2[0]) for radc, p1, p2 in zip(rads, centT1, centT2): length, mat = helper.getTubePropertiesMatrix(p1,p2) pMat = self.pandaMatrice(mat) # d = numpy.array(p1) - numpy.array(p2) # s = numpy.sum(d*d) shape = BulletCylinderShape(radc, length,1)#math.sqrt(s), 1)# { XUp = 0, YUp = 1, ZUp = 2 } or LVector3f const half_extents inodenp.node().addShape(shape, TransformState.makeMat(pMat))# self.setRB(inodenp,**kw) inodenp.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(inodenp.node()) return inodenp
def getPhysBody(self): bsph = BulletSphereShape(0.6) bcy = BulletCylinderShape(0.25, 0.35, ZUp) body = BulletRigidBodyNode('tntBody') body.addShape( bsph, TransformState.makePosHpr((0.05, 0, 0.43), (86.597, 24.5539, 98.1435))) body.addShape( bcy, TransformState.makePosHpr((0.05, 0.655, 0.35), (86.597, 24.5539, 98.1435))) body.setKinematic(True) body.setCcdMotionThreshold(1e-7) body.setCcdSweptSphereRadius(0.6) return body
def announceGenerate(self): DistributedEntity.announceGenerate(self) DistributedNode.announceGenerate(self) self.build() # Build collisions self.collSphere = BulletCylinderShape(self.radius, self.height, ZUp) self.collNode = BulletRigidBodyNode(self.uniqueName('barrelSphere')) self.collNode.setKinematic(True) self.collNode.addShape(self.collSphere, TransformState.makePos(Point3(0, 0, self.height / 2))) self.collNode.setIntoCollideMask(WallGroup) self.collNodePath = self.attachNewNode(self.collNode) base.physicsWorld.attach(self.collNodePath.node()) self.accept('enter' + self.collNodePath.getName(), self.__handleCollision) self.reparentTo(render)
def __init__(self, lane, lane_index: LaneIndex, position: Sequence[float], heading: float = 0.): super(TrafficCone, self).__init__(lane, lane_index, position, heading) self.body_node = ObjectNode(self.NAME) self.body_node.addShape(BulletCylinderShape(self.RADIUS, self.HEIGHT)) self.node_path: NodePath = NodePath(self.body_node) self.node_path.setPos(panda_position(self.position, self.HEIGHT / 2)) self.dynamic_nodes.append(self.body_node) self.node_path.setH(panda_heading(self.heading)) if self.render: model = self.loader.loadModel( AssetLoader.file_path("models", "traffic_cone", "scene.gltf")) model.setScale(0.02) model.setPos(0, 0, -self.HEIGHT / 2) model.reparentTo(self.node_path)
def __init__(self, lane, longitude: float, lateral: float, static: bool = False, random_seed=None): super(TrafficCone, self).__init__(lane, longitude, lateral, random_seed) self.add_body(BaseRigidBodyNode(self.name, self.NAME)) self.body.addShape(BulletCylinderShape(self.RADIUS, self.HEIGHT)) self.body.setIntoCollideMask(self.COLLISION_GROUP) self.origin.setPos(panda_position(self.position, self.HEIGHT / 2)) self.origin.setH(panda_heading(self.heading)) if self.render: model = self.loader.loadModel( AssetLoader.file_path("models", "traffic_cone", "scene.gltf")) model.setScale(0.02) model.setPos(0, 0, -self.HEIGHT / 2) model.reparentTo(self.origin) self.set_static(static)
def __init__(self, x, y, z, id): self.health = 100 radius = .15 height = 1 shape = BulletCylinderShape(radius, height, ZUp) self.playerNode = BulletCharacterControllerNode(shape, 0.4, str(id)) self.playerNode.setMaxJumpHeight(2.0) self.playerNode.setJumpSpeed(4.0) self.playerNP = base.render.attachNewNode(self.playerNode) self.playerNP.setPos(x, y, z) self.playerModel = Actor('models/soldier.egg', {"idle": "models/soldier_ani_idle.egg", "walk": "models/soldier_ani_walk.egg", "pistol": "models/soldier_ani_pistol.egg", "death": "models/soldier_ani_death.egg",}) self.playerModel.makeSubpart("legs", ["mixamorig:LeftUpLeg", "mixamorig:RightUpLeg"]) self.playerModel.makeSubpart("hips", ["mixamorig:Hips"], ["mixamorig:LeftUpLeg", "mixamorig:RightUpLeg", "mixamorig:Spine"]) self.playerModel.makeSubpart("upperBody", ["mixamorig:Spine"]) self.playerModel.pose("idle", 0, partName="hips") self.playerModel.setH(90) self.playerModel.setScale(.06) self.playerModel.setZ(-.45) self.playerModel.flattenLight() # self.playerModel.setLightOff()self.playerSpine self.playerModel.reparentTo(self.playerNP) self.playerSpine = self.playerModel.controlJoint(None, 'modelRoot', 'mixamorig:Spine') self.hand = self.playerModel.exposeJoint(None, 'modelRoot', 'mixamorig:RightHand') self.spineExpose = self.playerModel.exposeJoint(None, 'modelRoot', 'mixamorig:Spine') self.playerSpine.setH(-7) # player weapon self.weapon = Ak47(self.hand) # player animation self.xSpeed = 0 self.ySpeed = 0 self.animation = Animation(self) self.model = NodePath("MySpineNode")
def dropBall(self): self.ballNP.removeNode() pos = self.playerObj.getPosition() pNP = self.playerObj.getNodePath() px = pos.getX() py = pos.getY() pz = pos.getZ() size = self.ballModel.getScale().getX() self.ballShape = BulletCylinderShape(size, size * 1.7, ZUp) self.ballRBody = BulletRigidBodyNode() self.ballRBody.setMass(0) self.ballRBody.addShape(self.ballShape) rbNP = self.worldObj.attachNewNode(self.ballRBody) ph = self.playerObj.getRotation() self.ballModel.setPos(0, 0, 0) dx = -sin(ph * DEG_TO_RAD) * size * 3 dy = cos(ph * DEG_TO_RAD) * size * 3 self.ballModel.reparentTo(rbNP) rbNP.setPos(px + dx, py + dy, pz) self.worldBullet.attachRigidBody(self.ballRBody) self.setRolling(False) self.rolledOnce = True self.ballExists = True print(self.rolledOnce)
def setup(self): self.targetAlt = r.randrange(100,300) self.Valves = np.array([0.15,0.2,0.15]) self.EngObs = self.vulcain.predict_data_point(np.array(self.Valves).reshape(1,-1)) if self.VISUALIZE is True: self.worldNP = self.render.attachNewNode('World') else: self.root = NodePath(PandaNode("world root")) self.worldNP = self.root.attachNewNode('World') self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.80665)) # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) self.debugNP.show() self.world.setDebugNode(self.debugNP.node()) # self.debugNP.showTightBounds() # self.debugNP.showBounds() # Ground (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.groundNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) self.groundNP.node().addShape(shape) self.groundNP.setPos(0, 0, 0) self.groundNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.groundNP.node()) # Rocket shape = BulletCylinderShape(self.radius, self.length, ZUp) self.rocketNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Cylinder')) self.rocketNP.node().setMass(27200 * self.scale) self.rocketNP.node().addShape(shape) #self.rocketNP.setPos(20,20,250) self.rocketNP.setPos(20, 20, r.randrange(100, 300)+200) #self.rocketNP.setPos(r.randrange(-self.lateralError, self.lateralError, 1), r.randrange(-self.lateralError, self.lateralError, 1), self.height) # self.rocketNP.setPos(0, 0, self.length*10) self.rocketNP.setCollideMask(BitMask32.allOn()) # self.rocketNP.node().setCollisionResponse(0) self.rocketNP.node().notifyCollisions(True) self.world.attachRigidBody(self.rocketNP.node()) for i in range(4): leg = BulletCylinderShape(0.1 * self.radius, 0.5 * self.length, XUp) self.rocketNP.node().addShape(leg, TransformState.makePosHpr( Vec3(6 * self.radius * math.cos(i * math.pi / 2), 6 * self.radius * math.sin(i * math.pi / 2), -0.6 * self.length), Vec3(i * 90, 0, 30))) shape = BulletConeShape(0.75 * self.radius, 0.5 * self.radius, ZUp) self.rocketNP.node().addShape(shape, TransformState.makePosHpr(Vec3(0, 0, -1 / 2 * self.length), Vec3(0, 0, 0))) # Fuel self.fuelRadius = 0.9 * self.radius shape = BulletCylinderShape(self.fuelRadius, 0.01 * self.length, ZUp) self.fuelNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Cone')) self.fuelNP.node().setMass(self.fuelMass_full * self.fuelMass_init) self.fuelNP.node().addShape(shape) self.fuelNP.setPos(0, 0, self.rocketNP.getPos().getZ() - self.length * 0.5 * (1 - self.fuelMass_init)) self.fuelNP.setCollideMask(BitMask32.allOn()) self.fuelNP.node().setCollisionResponse(0) self.world.attachRigidBody(self.fuelNP.node()) frameA = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 90)) frameB = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 90)) self.fuelSlider = BulletSliderConstraint(self.rocketNP.node(), self.fuelNP.node(), frameA, frameB, 1) self.fuelSlider.setTargetLinearMotorVelocity(0) self.fuelSlider.setDebugDrawSize(2.0) self.fuelSlider.set_lower_linear_limit(0) self.fuelSlider.set_upper_linear_limit(0) self.world.attachConstraint(self.fuelSlider) self.npThrustForce = LineNodePath(self.rocketNP, 'Thrust', thickness=4, colorVec=Vec4(1, 0.5, 0, 1)) self.npDragForce = LineNodePath(self.rocketNP, 'Drag', thickness=4, colorVec=Vec4(1, 0, 0, 1)) self.npLiftForce = LineNodePath(self.rocketNP, 'Lift', thickness=4, colorVec=Vec4(0, 0, 1, 1)) self.npFuelState = LineNodePath(self.fuelNP, 'Fuel', thickness=20, colorVec=Vec4(0, 1, 0, 1)) self.rocketCSLon = self.radius ** 2 * math.pi self.rocketCSLat = self.length * 2 * self.radius if self.VISUALIZE is True: self.terrain = loader.loadModel("LZGrid2.egg") self.terrain.setScale(10) self.terrain.reparentTo(self.render) self.terrain.setColor(Vec4(0.1, 0.2, 0.1, 1)) self.toggleTexture() #self.fuelNP.setPos(0, 0, self.rocketNP.getPos().getZ() - self.length * 0.4 * (1 - self.fuelMass_init)) for i in range(5): self.world.doPhysics(self.dt, 5, 1.0 / 180.0) self.fuelSlider.set_lower_linear_limit(-self.length * 0.5 * (1 - self.fuelMass_init)) self.fuelSlider.set_upper_linear_limit(self.length * 0.5 * (1 - self.fuelMass_init)) for i in range(100): self.world.doPhysics(self.dt, 5, 1.0 / 180.0) self.rocketNP.node().applyForce(Vec3(0,0,300000), Vec3(0, 0, 0))
def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.show() self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) #self.debugNP.showTightBounds() #self.debugNP.showBounds() self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Ground (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.groundNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Ground')) self.groundNP.node().addShape(shape) self.groundNP.setPos(0, 0, -2) self.groundNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.groundNP.node()) #Rocket shape = BulletCylinderShape(0.2 * self.scale, 2 * self.scale, ZUp) self.rocketNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Cylinder')) self.rocketNP.node().setMass(3.0) self.rocketNP.node().addShape(shape) self.rocketNP.setPos(0, 0, 2 * self.scale) self.rocketNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.rocketNP.node()) for i in range(4): leg = BulletCylinderShape(0.02 * self.scale, 1 * self.scale, XUp) self.rocketNP.node().addShape( leg, TransformState.makePosHpr( Vec3(0.6 * self.scale * math.cos(i * math.pi / 2), 0.6 * self.scale * math.sin(i * math.pi / 2), -1.2 * self.scale), Vec3(i * 90, 0, 30))) shape = BulletConeShape(0.15 * self.scale, 0.3 * self.scale, ZUp) self.rocketNozzle = self.worldNP.attachNewNode( BulletRigidBodyNode('Cone')) self.rocketNozzle.node().setMass(1) self.rocketNozzle.node().addShape(shape) self.rocketNozzle.setPos(0, 0, 0.8 * self.scale) self.rocketNozzle.setCollideMask(BitMask32.allOn()) self.rocketNozzle.node().setCollisionResponse(0) self.world.attachRigidBody(self.rocketNozzle.node()) frameA = TransformState.makePosHpr(Point3(0, 0, -1 * self.scale), Vec3(0, 0, 90)) frameB = TransformState.makePosHpr(Point3(0, 0, 0.2 * self.scale), Vec3(0, 0, 90)) self.cone = BulletConeTwistConstraint(self.rocketNP.node(), self.rocketNozzle.node(), frameA, frameB) self.cone.enableMotor(1) #self.cone.setMaxMotorImpulse(2) #self.cone.setDamping(1000) self.cone.setDebugDrawSize(2.0) self.cone.setLimit(20, 20, 0, softness=1.0, bias=1.0, relaxation=10.0) self.world.attachConstraint(self.cone) self.npThrustForce = LineNodePath(self.render, 'Thrust', thickness=4, colorVec=VBase4(1, 0.5, 0, 1))
def reset(self): namelist = ['Ground', 'Conveyor', 'Finger', 'Block', 'Scrambled Block', 'Not Rewardable', 'Teleport Me'] for child in self.render.getChildren(): for test in namelist: if child.node().name == test: self.world.remove(child.node()) child.removeNode() break # Plane self.plane_shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.plane_node = BulletRigidBodyNode('Ground') self.plane_node.addShape(self.plane_shape) self.plane_np = self.render.attachNewNode(self.plane_node) self.plane_np.setPos(0.0, 0.0, -1.0) self.world.attachRigidBody(self.plane_node) # Conveyor self.conv_node = BulletRigidBodyNode('Conveyor') self.conv_node.setFriction(1.0) self.conv_np = self.render.attachNewNode(self.conv_node) self.conv_shape = BulletBoxShape(Vec3(100.0, 1.0, 0.05)) self.conv_node.setMass(1000.0) self.conv_np.setPos(-95.0, 0.0, 0.1) self.conv_node.addShape(self.conv_shape) self.world.attachRigidBody(self.conv_node) self.model = loader.loadModel('assets/conv.egg') self.model.flattenLight() self.model.reparentTo(self.conv_np) # Finger self.finger_node = BulletRigidBodyNode('Finger') self.finger_node.setFriction(1.0) self.finger_np = self.render.attachNewNode(self.finger_node) self.finger_shape = BulletCylinderShape(0.1, 0.25, ZUp) self.finger_node.setMass(0) self.finger_np.setPos(1.8, 0.0, 0.24 + 0.0254*3.5) self.finger_node.addShape(self.finger_shape) self.world.attachRigidBody(self.finger_node) self.model = loader.loadModel('assets/finger.egg') self.model.flattenLight() self.model.reparentTo(self.finger_np) self.blocks = [] for block_num in range(15): new_block = self.spawn_block(Vec3(28, random.uniform(-3, 3), (0.2 * block_num) + 2.0), 2, random.choice([4, 4, 6]), random.choice([10, 11, 12, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 23, 24])) # new_block = self.spawn_block(Vec3(18, 0, (0.2 * block_num) + 2.0), # 2, 4, 24) self.blocks.append(new_block) self.finger_speed_mps = 0.0 self.penalty_applied = False self.teleport_cooled_down = True self.fps = 20 self.framecount = 0 self.last_teleport_time = 0.0 self.time_to_teleport = False return self.step(1)[0]
def construct(self): # Drone name = str(np.random.randint(1, 10000)) self.drone = BulletRigidBodyNode('Box') self.drone.setMass(1.0) #collision model shape2 = BulletBoxShape(Vec3(0.6, 1.2, 1.45)) self.drone.addShape(shape2, TransformState.makePos(Point3(0.3, 0.1, -0.1))) shape4 = BulletCylinderShape(1, 0.5, ZUp) self.drone.addShape(shape4, TransformState.makePos(Point3(0.3, -3.0, 1.0))) self.drone.addShape(shape4, TransformState.makePos(Point3(0.3, 3, 1.0))) self.drone.addShape(shape4, TransformState.makePos(Point3(3.3, 0.1, 1.0))) self.drone.addShape(shape4, TransformState.makePos(Point3(-2.7, 0.1, 1.0))) shape5 = BulletBoxShape(Vec3(0.5, 3, 0.2)) self.drone.addShape(shape5, TransformState.makePos(Point3(0.3, 0, 1.0))) shape6 = BulletBoxShape(Vec3(3, 0.5, 0.2)) self.drone.addShape(shape6, TransformState.makePos(Point3(0.3, 0, 1.0))) # Drone body self.body = render.attachNewNode(self.drone) self.body.setPos(self.initialPos[0], self.initialPos[1], self.initialPos[2]) model = loader.loadModel('../models/drone.gltf') model.setHpr(0, 90, 0) model.flattenLight() model.reparentTo(self.body) #ISSUE here, has to be attached manually #world.attachRigidBody(self.drone) # blades blade = loader.loadModel("../models/blade.gltf") blade.reparentTo(self.body) blade.setHpr(0, 90, 0) blade.setPos(Vec3(0.3, -3.0, 1.1)) rotation_interval = blade.hprInterval(0.2, Vec3(180, 90, 0)) rotation_interval.loop() placeholder = self.body.attachNewNode("blade-placeholder") placeholder.setPos(Vec3(0, 6.1, 0)) blade.instanceTo(placeholder) placeholder = self.body.attachNewNode("blade-placeholder") placeholder.setPos(Vec3(3.05, 3.0, 0)) blade.instanceTo(placeholder) placeholder = self.body.attachNewNode("blade-placeholder") placeholder.setPos(Vec3(-3.05, 3.0, 0)) blade.instanceTo(placeholder) #under light self.plight2 = PointLight('plight') self.plight2.setColor((0.9, 0.1, 0.1, 1)) plnp = self.body.attachNewNode(self.plight2) plnp.setPos(0, 0, -1) self.body.setLight(plnp) #over light plight3 = PointLight('plight') plight3.setColor((0.9, 0.8, 0.8, 1)) plnp = self.body.attachNewNode(plight3) plnp.setPos(0, 0, 2) self.body.setLight(plnp)
def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.show() self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Plane (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 0) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) np.node().addShape(shape) np.setPos(0, 0, -1) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # Box (dynamic) shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5)) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(0, 0, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) self.boxNP = np # For applying force & torque #np.node().notifyCollisions(True) #self.accept('bullet-contact-added', self.doAdded) #self.accept('bullet-contact-destroyed', self.doRemoved) # Sphere (dynamic) shape = BulletSphereShape(0.6) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(-4, 0, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # Cone (dynamic) shape = BulletConeShape(0.6, 1.2, ZUp) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Cone')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(4, 0, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # Capsule (dynamic) shape = BulletCapsuleShape(0.5, 1.0, ZUp) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Capsule')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(0, 4, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # Cyliner (dynamic) shape = BulletCylinderShape(0.7, 1.5, ZUp) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Cylinder')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(4, 4, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # Convex (dynamic) shape = BulletConvexHullShape() shape.addPoint(Point3(1, 1, 2)) shape.addPoint(Point3(0, 0, 0)) shape.addPoint(Point3(2, 0, 0)) shape.addPoint(Point3(0, 2, 0)) shape.addPoint(Point3(2, 2, 0)) # Another way to create the convex hull shape: #shape = BulletConvexHullShape() #shape.addArray([ # Point3(1, 1, 2), # Point3(0, 0, 0), # Point3(2, 0, 0), # Point3(0, 2, 0), # Point3(2, 2, 0), #]) # Yet another way to create the convex hull shape: #geom = loader.loadModel('models/box.egg')\ # .findAllMatches('**/+GeomNode')\ # .getPath(0)\ # .node()\ # .getGeom(0) #shape = BulletConvexHullShape() #shape.addGeom(geom) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Convex')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(-4, 4, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # Mesh (static) p0 = Point3(-10, -10, 0) p1 = Point3(-10, 10, 0) p2 = Point3(10, -10, 0) p3 = Point3(10, 10, 0) mesh = BulletTriangleMesh() mesh.addTriangle(p0, p1, p2) mesh.addTriangle(p1, p2, p3) shape = BulletTriangleMeshShape(mesh, dynamic=False) # Another way to create the triangle mesh shape: #geom = loader.loadModel('models/box.egg')\ # .findAllMatches('**/+GeomNode')\ # .getPath(0)\ # .node()\ # .getGeom(0) #mesh = BulletTriangleMesh() #mesh.addGeom(geom) #shape = BulletTriangleMeshShape(mesh, dynamic=False) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh')) np.node().addShape(shape) np.setPos(0, 0, 0.1) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # MutiSphere points = [Point3(-1, 0, 0), Point3(0, 0, 0), Point3(1, 0, 0)] radii = [.4, .8, .6] shape = BulletMultiSphereShape(points, radii) np = self.worldNP.attachNewNode(BulletRigidBodyNode('MultiSphere')) np.node().setMass(1.0) np.node().addShape(shape) np.setPos(8, 0, 4) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node())
def setupItems(self): #############Items######################################## self.iteamsModelsList = [0] * 50 self.iteamsNodesList = [0] * 50 self.iteamsNpsList = [0] * 50 self.index = 0 for i in range(5): x = 4 + i y = -20 + i t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(x, y, 104) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(x, y, 104) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 for i in range(5): x = -4 + i y = -42 + i t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(x, y, 106) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(x, y, 106) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 for i in range(5): x = -25 + i y = -42 + i t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(x, y, 106) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(x, y, 106) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 for i in range(5): x = -25 + i y = -64 + i t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(x, y, 106) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(x, y, 106) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 for i in range(5): x = -22 y = -120 - (i * 10) t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(x, y, 108) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(x, y, 108) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(self.Cylinder1.getX(), self.Cylinder1.getY(), self.Cylinder1.getZ() + 2) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(self.Cylinder1.getX(), self.Cylinder1.getY(), self.Cylinder1.getZ() + 2) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(self.Cylinder2.getX(), self.Cylinder2.getY(), self.Cylinder2.getZ() + 2) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(self.Cylinder2.getX(), self.Cylinder2.getY(), self.Cylinder2.getZ() + 2) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 t1 = loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(self.Cylinder3.getX(), self.Cylinder3.getY(), self.Cylinder3.getZ() + 2) t1.setHpr(0, 90, 0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(self.Cylinder3.getX(), self.Cylinder3.getY(), self.Cylinder3.getZ() + 2) npt1.setHpr(0, 90, 0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1
def __addCylinder(self, body, model, pos=(0,0,0), hpr=(0,0,0), scale=(1,1,1) ): size = self.getSize(model) shape = BulletCylinderShape(max(size.x,size.y)/2, size.z, ZUp) body.addShape( shape, TransformState.makePosHprScale(pos,hpr,scale) )
def setup(self): #World self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) #Ground shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.ground = BulletRigidBodyNode('Ground') self.ground.addShape(shape) self.groundNp = render.attachNewNode(self.ground) self.groundNp.setPos(0, 0, 0) self.groundNp.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.ground) #build self.shape1 = BulletBoxShape(Vec3(8, 8, 0.75)) self.node1 = BulletRigidBodyNode('Box1') self.node1.setMass(0) self.node1.addShape(self.shape1) self.np1 = render.attachNewNode(self.node1) self.np1.setPos(0, 0, 100) self.np1.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node1) self.box1 = loader.loadModel("models/box/box1") self.box1.reparentTo(render) self.box1.setScale(10, 10, 0.2) self.box1.setPos(0, 0, 100) self.shape2 = BulletBoxShape(Vec3(8, 8, 0.75)) self.node2 = BulletRigidBodyNode('Box2') self.node2.setMass(0) self.node2.addShape(self.shape2) self.np2 = render.attachNewNode(self.node2) self.np2.setPos(5, -22, 102) self.np2.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node2) self.box2 = loader.loadModel("models/box/box1") self.box2.reparentTo(render) self.box2.setScale(10, 10, 0.2) self.box2.setPos(5, -22, 102) self.shape3 = BulletBoxShape(Vec3(8, 8, 0.75)) self.node3 = BulletRigidBodyNode('Box3') self.node3.setMass(0) self.node3.addShape(self.shape3) self.np3 = render.attachNewNode(self.node3) self.np3.setPos(-5, -44, 104) self.np3.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node3) self.box3 = loader.loadModel("models/box/box1") self.box3.reparentTo(render) self.box3.setScale(10, 10, 0.2) self.box3.setPos(-5, -44, 104) self.shape4 = BulletBoxShape(Vec3(8, 8, 0.75)) self.node4 = BulletRigidBodyNode('Box4') self.node4.setMass(0) self.node4.addShape(self.shape4) self.np4 = render.attachNewNode(self.node4) self.np4.setPos(-27, -44, 104) self.np4.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node4) self.box4 = loader.loadModel("models/box/box1") self.box4.reparentTo(render) self.box4.setScale(10, 10, 0.2) self.box4.setPos(-27, -44, 104) self.shape5 = BulletBoxShape(Vec3(8, 8, 0.75)) self.node5 = BulletRigidBodyNode('Box5') self.node5.setMass(0) self.node5.addShape(self.shape5) self.np5 = render.attachNewNode(self.node5) self.np5.setPos(-27, -66, 104) self.np5.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node5) self.box5 = loader.loadModel("models/box/box1") self.box5.reparentTo(render) self.box5.setScale(10, 10, 0.2) self.box5.setPos(-27, -66, 104) self.box6 = loader.loadModel("models/box/box1") self.box6.reparentTo(render) self.box6.setScale(10, 87, 0.2) self.box6.setPos(-22, -150, 106) self.shape6 = BulletBoxShape(Vec3(8, 70, 0.75)) self.node6 = BulletRigidBodyNode('Box6') self.node6.setMass(0) self.node6.addShape(self.shape6) self.np6 = render.attachNewNode(self.node6) self.np6.setPos(-22, -150, 106) self.np6.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node6) blocks_tex6 = loader.loadTexture("models/blocks_tex6.jpg") self.Cylinder1 = loader.loadModel("models/Cylinder/Cylinder") self.Cylinder1.reparentTo(render) self.Cylinder1.setScale(8, 8, 0.2) self.Cylinder1.setPos(-22, -230, 108) self.Cylinder1.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape16 = BulletCylinderShape(radius, height, ZUp) self.node16 = BulletRigidBodyNode('Cylinder1') self.node16.setMass(0) self.node16.addShape(shape16) self.np16 = render.attachNewNode(self.node16) self.np16.setPos(-22, -230, 108) self.np16.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node16) self.Cylinder2 = loader.loadModel("models/Cylinder/Cylinder") self.Cylinder2.reparentTo(render) self.Cylinder2.setScale(8, 8, 0.2) self.Cylinder2.setPos(-15, -250, 110) self.Cylinder2.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape17 = BulletCylinderShape(radius, height, ZUp) self.node17 = BulletRigidBodyNode('Cylinder2') self.node17.setMass(0) self.node17.addShape(shape17) self.np17 = render.attachNewNode(self.node17) self.np17.setPos(-15, -250, 110) self.np17.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node17) self.Cylinder3 = loader.loadModel("models/Cylinder/Cylinder") self.Cylinder3.reparentTo(render) self.Cylinder3.setScale(8, 8, 0.2) self.Cylinder3.setPos(-25, -270, 112) self.Cylinder3.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape18 = BulletCylinderShape(radius, height, ZUp) self.node18 = BulletRigidBodyNode('Cylinder3') self.node18.setMass(0) self.node18.addShape(shape18) self.np18 = render.attachNewNode(self.node18) self.np18.setPos(-25, -270, 112) self.np18.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node18) self.Cylinder4 = loader.loadModel("models/Cylinder/Cylinder") self.Cylinder4.reparentTo(render) self.Cylinder4.setScale(8, 8, 0.2) self.Cylinder4.setPos(-30, -290, 114) self.Cylinder4.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape19 = BulletCylinderShape(radius, height, ZUp) self.node19 = BulletRigidBodyNode('Cylinder4') self.node19.setMass(0) self.node19.addShape(shape19) self.np19 = render.attachNewNode(self.node19) self.np19.setPos(-30, -290, 114) self.np19.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node19) self.fire = loader.loadModel("models/stop_sign/stop_sign") self.fire.setScale(0.01) self.fire.reparentTo(render) self.fire.setPos(-30, -290, 114 + 6) self.shape7 = BulletBoxShape(Vec3(8, 8, 0.75)) self.node7 = BulletRigidBodyNode('Box7') self.node7.setMass(0) self.node7.addShape(self.shape7) self.np7 = render.attachNewNode(self.node7) self.np7.setPos(0, 0, 200) self.np7.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node7) self.box7 = loader.loadModel("models/box/box1") self.box7.reparentTo(render) self.box7.setScale(10, 10, 0.2) self.box7.setPos(0, 0, 200) #setup the items to be collected self.setupItems() self.setupEndPoint()
def __init__(self) : ShowBase.__init__(self) #--------------------- MUSIC mySound = base.loader.loadSfx(musicPath + "mus_reunited.ogg") mySound.play() #--------------------- WORLD self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) ## --------------------- DEBUG # debugNode = BulletDebugNode('Debug') # debugNode.showWireframe(True) # debugNode.showConstraints(True) # debugNode.showBoundingBoxes(False) # debugNode.showNormals(False) # debugNP = render.attachNewNode(debugNode) # debugNP.show() # # debugNode.showWireframe(True) # self.world.setDebugNode(debugNP.node()) #--------------------- GRASS shape = BulletPlaneShape(Vec3(0, 0, 1), 0) # creo la forma geometrica (normale, distanza) node = BulletRigidBodyNode('Ground') # creo il rigidbody per il terreno node.addShape(shape) # link tra il rigidbody e la forma geometrica np = render.attachNewNode(node) np.setPos(0, 0, -0.5) #-1.5 cm = CardMaker('card') # crea una carta bianca a cui appiccicare la texture cm.setFrame(-20, 20, -20, 20) grass = self.render.attachNewNode(cm.generate()) # attacca il nodo FLOOR pattern = self.loader.loadTexture(imagePath + 'grass3.jpg') # handler per la texture ts = TextureStage('ts') grass.setP(270) grass.setTexScale(ts, 3, 3) grass.setTexture(ts, pattern) # appiccica la texture al modello grass.reparentTo(np) # collega la texture dell'erba al nodo fisico self.world.attachRigidBody(node) # solo i nodi attaccati al world vengono considerati nella simulazione #--------------------- CRASH (MY MODEL) self.actor = Actor("models/MyCrash1/MyCrash1.egg", {"walk":"./models/MyCrash1/CrashWalk.egg","launch":"./models/MyCrash1/CrashLaunch.egg"}) self.actor.reparentTo(np) # reparent the model to render self.actor.setScale(1, 1, 1) # apply scale to model self.actor.setPos(3, -10, 0) # apply position to model #--------------------- CAMERA base.cam.setPos(self.actor.getX(), self.actor.getY() - 18, self.actor.getZ() + 4) base.cam.lookAt(self.actor.getX(), self.actor.getY(), self.actor.getZ() + 2) #--------------------- TABLE shape = BulletBoxShape(Vec3(4.8, 1.45, 0.15)) node = BulletRigidBodyNode('Box') node.addShape(shape) np = render.attachNewNode(node) np.setPos(5, 3, 0.8 - 0.5) self.table = Object(self, "CafeTableLong/CafeTableLong", 0.01, 0.01, 0.01, 0, 0, 0, 0, 0, -0.15, np) self.world.attachRigidBody(node) #--------------------- ARMCHAIR shape = BulletBoxShape(Vec3(1.35, 1.5, 2)) #2 node = BulletRigidBodyNode('Box') node.addShape(shape) node.setMass(5) np = render.attachNewNode(node) np.setPos(12, 3, 1.5) self.chair = Object(self, "ArmChair/ArmChair", 0.0013, 0.0013, 0.0013, 100, 0, 0, 0, 0, -1.5, np) self.world.attachRigidBody(node) #--------------------- OBJECTS TO HIT # cake shape = BulletCylinderShape(0.56, 0.5, 2) node = BulletRigidBodyNode('Cylinder') node.setMass(2) node.addShape(shape) np = render.attachNewNode(node) np.setPos(5, 3, 0.62) self.cake = Object(self, "Cake/Cake", 0.008, 0.008, 0.009, 0, 0, 0, 0, 0, -0.25, np) self.world.attachRigidBody(node) #teapot shape = BulletBoxShape(Vec3(0.65, 0.3, 0.8)) # creo la forma geometrica (normale, distanza) node = BulletRigidBodyNode('Box') # creo il rigidbody per il terreno node.setMass(2) node.addShape(shape) # link tra il rigidbody e la forma geometrica np = render.attachNewNode(node) np.setPos(3, 3, 1.2) self.tea = Object(self, "Teapot/Teapot", 1, 1, 1, 90, 0, 0, 0, 0, -0.83, np) self.world.attachRigidBody(node) #mug shape = BulletCylinderShape(0.2, 0.5, 2) node = BulletRigidBodyNode('Cylinder') node.setMass(2) node.addShape(shape) np = render.attachNewNode(node) np.setPos(6, 3, 1.2 - 0.54) self.mug = Object(self, "cup/cup", 0.02, 0.02, 0.02, 0, 0, 0, 0, 0.2, -0.1, np) self.world.attachRigidBody(node) #creamer shape = BulletBoxShape(Vec3(0.5, 0.3, 0.5)) node = BulletRigidBodyNode('Box') node.setMass(2) node.addShape(shape) np = render.attachNewNode(node) np.setPos(8, 3.2, 1.1 - 0.2) self.creamer = Object(self, "creamer/creamer", 1, 1, 1, -90, 0, 0, 0.1, 0, -0.5, np) self.world.attachRigidBody(node) #mint shape = BulletCylinderShape(0.25, 0.2, 2) node = BulletRigidBodyNode('Cylinder') node.setMass(1) node.addShape(shape) np = render.attachNewNode(node) np.setPos(1.8, 3.2, 1.2 - 0.65) self.mint = Object(self, "Mint/Mint", 3, 3, 3, 0, 0, 0, 0, 0, 0, np) self.world.attachRigidBody(node) #--------------------- TASK and FUNCTIONS Decoration(self) self.lightUp() HandleArrows(self, 8, 12, -8, -31) Shoot(self) HandleCharacter(self, 8, 12, -8, -31) taskMgr.add(self.update, 'update')
conv_node.setFriction(1.0) conv_np = render.attachNewNode(conv_node) conv_shape = BulletBoxShape(Vec3(100.0, 1.0, 0.05)) conv_node.setMass(1000.0) conv_np.setPos(-95.0, 0.0, 0.1) conv_node.addShape(conv_shape) world.attachRigidBody(conv_node) model = loader.loadModel('assets/conv.egg') model.flattenLight() model.reparentTo(conv_np) # Finger finger_node = BulletRigidBodyNode('Finger') finger_node.setFriction(1.0) finger_np = render.attachNewNode(finger_node) finger_shape = BulletCylinderShape(0.1, 0.25, ZUp) finger_node.setMass(0) finger_np.setPos(1.8, 0.0, 0.24 + 0.0254 * 3.5) finger_node.addShape(finger_shape) world.attachRigidBody(finger_node) model = loader.loadModel('assets/finger.egg') model.flattenLight() model.reparentTo(finger_np) # Spotlight light = Spotlight('light') light.setColor((0.9, 0.9, 0.9, 1)) lightNP = render.attachNewNode(light) # This light is facing backwards, towards the camera. lightNP.setHpr(180, -20, 0) lightNP.setPos(0, 10, 10)
def setupItems(self): #############Items######################################## self.iteamsModelsList = [0] * 50 self.iteamsNodesList = [0] * 50 self.iteamsNpsList = [0] * 50 self.index = 0 n6 = 0 for i in range(10): t1= loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(-325,925-(n6*1.2),n6+2) t1.setHpr(0,90,0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(-325, 925-(n6*1.2), n6+2) npt1.setHpr(0,90,0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 n6 += 2 self.index += 1 n7 = 20 for i in range(5): t1= loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(-325,880-n7,n6+2) t1.setHpr(0,90,0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(-325, 880-n7, n6+2) npt1.setHpr(0,90,0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 n7 += 20 self.index += 1 t1= loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(self.Cylinder1.getX(),self.Cylinder1.getY(),n6+2) t1.setHpr(0,90,0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(self.Cylinder1.getX(),self.Cylinder1.getY(),n6+2) npt1.setHpr(0,90,0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 t1= loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(self.Cylinder2.getX(),self.Cylinder2.getY(),n6+2) t1.setHpr(0,90,0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(self.Cylinder2.getX(),self.Cylinder2.getY(),n6+2) npt1.setHpr(0,90,0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 t1= loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(self.Cylinder3.getX(),self.Cylinder3.getY(),n6+2) t1.setHpr(0,90,0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(self.Cylinder3.getX(),self.Cylinder3.getY(),n6+2) npt1.setHpr(0,90,0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 self.index += 1 n6 = 0 for i in range(30): x = random.randint(-50, 50) y = random.randint(-50, 50) t1= loader.loadModel("models/Torus/Torus") t1.reparentTo(render) t1.setScale(.6) t1.setPos(x,y,2) t1.setHpr(0,90,0) radius = .8 height = .5 shape19 = BulletCylinderShape(radius, height, ZUp) nodet1 = BulletGhostNode('t1') nodet1.addShape(shape19) npt1 = render.attachNewNode(nodet1) npt1.setPos(x, y, 2) npt1.setHpr(0,90,0) npt1.setCollideMask(BitMask32.allOn()) self.world.attachGhost(nodet1) self.iteamsModelsList[self.index] = t1 self.iteamsNodesList[self.index] = nodet1 self.iteamsNpsList[self.index] = npt1 n6 += 2 self.index += 1
def setup(self): #World self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) #Ground shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.ground = BulletRigidBodyNode('Ground') self.ground.addShape(shape) self.groundNp = render.attachNewNode(self.ground) self.groundNp.setPos(0, 0, 0) self.groundNp.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.ground) #BoxPyramid1 self.pyramid1 = loader.loadModel("models/pyramid/Pyramid") self.pyramid1.reparentTo(render) self.pyramid1.setScale(.5) self.pyramid1.setPos(0,-400,0) mesh = BulletTriangleMesh() for geomNP in self.pyramid1.findAllMatches('**/+GeomNode'): geomNode = geomNP.node() ts = geomNP.getTransform(self.pyramid1) for geom in geomNode.getGeoms(): mesh.addGeom(geom, ts) shape2 = BulletTriangleMeshShape(mesh, dynamic=False) self.node = BulletRigidBodyNode('BoxPyramid1') self.node.setMass(0) self.node.addShape(shape2) self.np = render.attachNewNode(self.node) self.np.setPos(0, -400, 0) self.np.setScale(1.65) self.np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node) #BoxPyramid2 self.pyramid2 = loader.loadModel("models/pyramid/Pyramid") self.pyramid2.reparentTo(render) self.pyramid2.setScale(.25) self.pyramid2.setPos(180,-400,0) mesh2 = BulletTriangleMesh() for geomNP in self.pyramid2.findAllMatches('**/+GeomNode'): geomNode = geomNP.node() ts = geomNP.getTransform(self.pyramid2) for geom in geomNode.getGeoms(): mesh2.addGeom(geom, ts) shape3 = BulletTriangleMeshShape(mesh2, dynamic=False) self.node3 = BulletRigidBodyNode('BoxPyramid2') self.node3.setMass(0) self.node3.addShape(shape3) self.np3 = render.attachNewNode(self.node3) self.np3.setPos(180, -400, 0) self.np3.setScale(0.85) self.np3.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node3) #BoxPyramid3 self.pyramid3 = loader.loadModel("models/pyramid/Pyramid") self.pyramid3.reparentTo(render) self.pyramid3.setScale(.25) self.pyramid3.setPos(-180,-400,0) mesh3 = BulletTriangleMesh() for geomNP in self.pyramid3.findAllMatches('**/+GeomNode'): geomNode = geomNP.node() ts = geomNP.getTransform(self.pyramid3) for geom in geomNode.getGeoms(): mesh3.addGeom(geom, ts) shape4 = BulletTriangleMeshShape(mesh2, dynamic=False) self.node4 = BulletRigidBodyNode('BoxPyramid3') self.node4.setMass(0) self.node4.addShape(shape4) self.np4 = render.attachNewNode(self.node4) self.np4.setPos(-180, -400, 0) self.np4.setScale(0.85) self.np4.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node4) #BoxSphinx self.sphinx = loader.loadModel("models/sphinx/Sphinx") self.sphinx.reparentTo(render) self.sphinx.setScale(.08) self.sphinx.setPos(100,-50,20) shape5 = BulletBoxShape(Vec3(18, 55, 30)) self.node5 = BulletRigidBodyNode('BoxSphinx') self.node5.setMass(0) self.node5.addShape(shape5) self.np5 = render.attachNewNode(self.node5) self.np5.setPos(100, -50, 10) self.np5.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node5) #start blocks_tex6 = loader.loadTexture("models/blocks_tex6.jpg") self.box1= loader.loadModel("models/box/box3") self.box1.reparentTo(render) self.box1.setScale(10,400,10) self.box1.setPos(-300,850,0) shape8 = BulletBoxShape(Vec3(8, 315, 13.5)) self.node8 = BulletRigidBodyNode('Box1') self.node8.setMass(0) self.node8.addShape(shape8) self.np8 = render.attachNewNode(self.node8) self.np8.setPos(-300, 850, 10) self.np8.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node8) self.box2= loader.loadModel("models/box/box3") self.box2.reparentTo(render) self.box2.setScale(10,400,10) self.box2.setPos(-350,850,0) shape9 = BulletBoxShape(Vec3(8, 315, 13.5)) self.node9 = BulletRigidBodyNode('Box2') self.node9.setMass(0) self.node9.addShape(shape9) self.np9 = render.attachNewNode(self.node9) self.np9.setPos(-350, 850, 10) self.np9.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node9) self.box3= loader.loadModel("models/box/box4") self.box3.reparentTo(render) self.box3.setScale(40,10,10) self.box3.setPos(-325,543,0) shape10 = BulletBoxShape(Vec3(30, 8, 13.5)) self.node10 = BulletRigidBodyNode('Box3') self.node10.setMass(0) self.node10.addShape(shape10) self.np10 = render.attachNewNode(self.node10) self.np10.setPos(-325, 543, 10) self.np10.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node10) self.box4= loader.loadModel("models/box/box4") self.box4.reparentTo(render) self.box4.setScale(40,10,10) self.box4.setPos(-325,1157,0) shape11 = BulletBoxShape(Vec3(30, 8, 13.5)) self.node11 = BulletRigidBodyNode('Box4') self.node11.setMass(0) self.node11.addShape(shape11) self.np11 = render.attachNewNode(self.node11) self.np11.setPos(-325, 1157, 10) self.np11.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node11) #Stars 1 self.stairsList = [0] * 10 self.stairsListNp = [0] * 10 n5 = 0 for i in range(10): n5 += 2 self.stairsList[i]= loader.loadModel("models/box/box1") self.stairsList[i].reparentTo(render) self.stairsList[i].setScale(1.3) self.stairsList[i].setPos(-325,925-(n5*1.2),n5) self.stairsList[i].setHpr(0,0,90) shape6 = BulletBoxShape(Vec3(3.2, 1.1, 1.1)) node6 = BulletRigidBodyNode('Box5 '+str(i)) node6.setMass(0) node6.addShape(shape6) self.stairsListNp[i] = render.attachNewNode(node6) self.stairsListNp[i].setPos(-325, 925-(n5*1.2), n5) self.stairsListNp[i].setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(node6) self.n5Upstairs = n5 self.box6= loader.loadModel("models/box/box1") self.box6.reparentTo(render) self.box6.setScale(10,87,0.2) self.box6.setPos(-325,829,n5) self.shape12 = BulletBoxShape(Vec3(8, 70, 0.75)) self.node12 = BulletRigidBodyNode('Box6') self.node12.setMass(0) self.node12.addShape(self.shape12) self.np12 = render.attachNewNode(self.node12) self.np12.setPos(-325, 829, n5) self.np12.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node12) self.box7= loader.loadModel("models/box/box2") self.box7.reparentTo(render) self.box7.setScale(5,12,0.25) self.box7.setPos(-325,749,n5) shape13 = BulletBoxShape(Vec3(4, 10, 0.8)) self.node13 = BulletRigidBodyNode('Box7') self.node13.setMass(0) self.node13.addShape(shape13) self.np13 = render.attachNewNode(self.node13) self.np13.setPos(-325, 749, n5) self.np13.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node13) box7Interval1 = self.box7.posInterval(3.3, Point3(-325, 749, n5+5), startPos=Point3(-325, 749, n5-5)) np13Interval1 = self.np13.posInterval(3, Point3(-325, 749, n5+5), startPos=Point3(-325, 749, n5-5)) box7Interval2 = self.box7.posInterval(3.3, Point3(-325, 749, n5-5), startPos=Point3(-325, 749, n5+5)) np13Interval2 = self.np13.posInterval(3, Point3(-325, 749, n5-5), startPos=Point3(-325, 749, n5+5)) self.box7Pace = Sequence(Parallel(box7Interval1,np13Interval1), Parallel(box7Interval2,np13Interval2), name="box7Pace") self.box7Pace.loop() self.box8= loader.loadModel("models/box/box2") self.box8.reparentTo(render) self.box8.setScale(5,12,0.25) self.box8.setPos(-325,725,n5) shape14 = BulletBoxShape(Vec3(4, 10, 0.8)) node14 = BulletRigidBodyNode('Box8') node14.setMass(0) node14.addShape(shape14) self.np14 = render.attachNewNode(node14) self.np14.setPos(-325, 725, n5) self.np14.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(node14) box8Interval1 = self.box8.posInterval(3.3, Point3(-325, 725, n5-5), startPos=Point3(-325, 725, n5+5)) np14Interval1 = self.np14.posInterval(3, Point3(-325, 725, n5-5), startPos=Point3(-325, 725, n5+5)) box8Interval2 = self.box8.posInterval(3.3, Point3(-325, 725, n5+5), startPos=Point3(-325, 725, n5-5)) np14Interval2 = self.np14.posInterval(3, Point3(-325, 725, n5+5), startPos=Point3(-325, 725, n5-5)) self.box8Pace = Sequence(Parallel(box8Interval1,np14Interval1), Parallel(box8Interval2,np14Interval2), name="box8Pace") self.box8Pace.loop() self.Cylinder1= loader.loadModel("models/Cylinder/Cylinder") self.Cylinder1.reparentTo(render) self.Cylinder1.setScale(8,8,0.2) self.Cylinder1.setPos(-322,700,n5) self.Cylinder1.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape16 = BulletCylinderShape(radius, height, ZUp) self.node16 = BulletRigidBodyNode('Cylinder1') self.node16.setMass(0) self.node16.addShape(shape16) self.np16 = render.attachNewNode(self.node16) self.np16.setPos(-322, 700, n5) self.np16.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node16) self.Cylinder2= loader.loadModel("models/Cylinder/Cylinder") self.Cylinder2.reparentTo(render) self.Cylinder2.setScale(8,8,0.2) self.Cylinder2.setPos(-327,680,n5) self.Cylinder2.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape17 = BulletCylinderShape(radius, height, ZUp) self.node17 = BulletRigidBodyNode('Cylinder2') self.node17.setMass(0) self.node17.addShape(shape17) self.np17 = render.attachNewNode(self.node17) self.np17.setPos(-327, 680, n5) self.np17.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node17) self.Cylinder3= loader.loadModel("models/Cylinder/Cylinder") self.Cylinder3.reparentTo(render) self.Cylinder3.setScale(8,8,0.2) self.Cylinder3.setPos(-322,660,n5) self.Cylinder3.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape18 = BulletCylinderShape(radius, height, ZUp) self.node18 = BulletRigidBodyNode('Cylinder3') self.node18.setMass(0) self.node18.addShape(shape18) self.np18 = render.attachNewNode(self.node18) self.np18.setPos(-322, 660, n5) self.np18.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node18) self.Cylinder4= loader.loadModel("models/Cylinder/Cylinder") self.Cylinder4.reparentTo(render) self.Cylinder4.setScale(8,8,0.2) self.Cylinder4.setPos(-327,640,n5) self.Cylinder4.setTexture(blocks_tex6, 1) radius = 8 height = 1 shape19 = BulletCylinderShape(radius, height, ZUp) self.node19 = BulletRigidBodyNode('Cylinder4') self.node19.setMass(0) self.node19.addShape(shape19) self.np19 = render.attachNewNode(self.node19) self.np19.setPos(-327, 640, n5) self.np19.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.node19) self.fire= loader.loadModel("models/stop_sign/stop_sign") self.fire.setScale(0.01) self.fire.reparentTo(render) self.fire.setPos(-327,640,n5+5) #setup the items to be collected self.setupItems() self.setupEndPoint()
def setup(self): #self.targetAlt = r.randrange(100,300) self.Valves = np.array([0.15, 0.2, 0.15]) self.EngObs = self.vulcain.predict_data_point( np.array(self.Valves).reshape(1, -1)) if self.VISUALIZE is True: self.worldNP = self.render.attachNewNode('World') else: self.root = NodePath(PandaNode("world root")) self.worldNP = self.root.attachNewNode('World') self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.80665)) # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.node().showWireframe(True) self.debugNP.node().showConstraints(True) self.debugNP.node().showBoundingBoxes(False) self.debugNP.node().showNormals(True) self.debugNP.show() self.world.setDebugNode(self.debugNP.node()) # self.debugNP.showTightBounds() # self.debugNP.showBounds() # Ground (static) shape = BulletPlaneShape(Vec3(0, 0, 1), 1) self.groundNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Ground')) self.groundNP.node().addShape(shape) self.groundNP.setPos(0, 0, 0) self.groundNP.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(self.groundNP.node()) # Rocket shape = BulletCylinderShape(self.radius, self.length, ZUp) self.rocketNP = self.worldNP.attachNewNode( BulletRigidBodyNode('Cylinder')) self.rocketNP.node().setMass(self.drymass + self.fuelAmount_LH2 + self.fuelAmount_LOX) self.rocketNP.node().addShape(shape) #self.rocketNP.setPos(20,20,250) self.rocketNP.setPos(r.randrange(-200, 200), 20, 350) #r.randrange(300, 500)) #self.rocketNP.setPos(r.randrange(-self.lateralError, self.lateralError, 1), r.randrange(-self.lateralError, self.lateralError, 1), self.height) # self.rocketNP.setPos(0, 0, self.length*10) self.rocketNP.setCollideMask(BitMask32.allOn()) # self.rocketNP.node().setCollisionResponse(0) self.rocketNP.node().notifyCollisions(True) self.world.attachRigidBody(self.rocketNP.node()) for i in range(4): leg = BulletCylinderShape(0.1 * self.radius, 0.5 * self.length, XUp) self.rocketNP.node().addShape( leg, TransformState.makePosHpr( Vec3(6 * self.radius * math.cos(i * math.pi / 2), 6 * self.radius * math.sin(i * math.pi / 2), -0.6 * self.length), Vec3(i * 90, 0, 30))) shape = BulletConeShape(0.75 * self.radius, 0.5 * self.radius, ZUp) self.rocketNP.node().addShape( shape, TransformState.makePosHpr(Vec3(0, 0, -1 / 2 * self.length), Vec3(0, 0, 0))) self.npThrustForce = LineNodePath(self.rocketNP, 'Thrust', thickness=4, colorVec=Vec4(1, 0.5, 0, 1)) self.npDragForce = LineNodePath(self.rocketNP, 'Drag', thickness=4, colorVec=Vec4(1, 0, 0, 1)) self.npLiftForce = LineNodePath(self.rocketNP, 'Lift', thickness=4, colorVec=Vec4(0, 0, 1, 1)) self.rocketCSLon = self.radius**2 * math.pi self.rocketCSLat = self.length * 2 * self.radius if self.VISUALIZE is True: self.terrain = loader.loadModel("../LZGrid2.egg") self.terrain.setScale(10) self.terrain.reparentTo(self.render) self.terrain.setColor(Vec4(0.1, 0.2, 0.1, 1)) self.toggleTexture()