Exemplo n.º 1
0
    def loadLevelData(self, inputData):
        """
        processes the level asloaded from the file. it seperates the input data until the data for each tile is ready.
        """
        rigidNode = RigidBodyCombiner("LevelNode")
        levelNode = NodePath(rigidNode)

        #deleting whitespaces and seperating the content for each tile into a list.
        inputData = inputData.replace("\n", "").strip().replace(
            " ", "").lstrip("<").rstrip(">").split("><")

        for tileData in inputData:
            tile = self.loadTile(tileData)
            if tile != None:
                tile.reparentTo(levelNode)
                tile.setPos(self.getPosFromTile(tile))
                tile.setZ(
                    tile, 0.00000001
                )  # workaround for rigid body combiner so it does not assume the (0,0) tile as static
            else:
                print("ERROR, could not load tile with data: ", tileData)
        rigidNode.collect()
        inode = rigidNode.getInternalScene().node(
        )  # workaround for a boundingvolume issue with rigidbodycombiner
        inode.setBounds(OmniBoundingVolume())  # still workaround
        inode.setFinal(True)  # still workaround
        return levelNode
Exemplo n.º 2
0
    def _create_in_world(self):
        """
        Create NodePath and Geom node to perform both collision detection and render
        """
        self.lane_line_node_path = NodePath(
            RigidBodyCombiner(self._block_name + "_lane_line"))
        self.sidewalk_node_path = NodePath(
            RigidBodyCombiner(self._block_name + "_sidewalk"))
        self.lane_node_path = NodePath(
            RigidBodyCombiner(self._block_name + "_lane"))
        self.lane_vis_node_path = NodePath(
            RigidBodyCombiner(self._block_name + "_lane_vis"))
        graph = self.block_network.graph
        for _from, to_dict in graph.items():
            for _to, lanes in to_dict.items():
                self._add_lane_surface(_from, _to, lanes)
                for _id, l in enumerate(lanes):
                    line_color = l.line_color
                    self._add_lane(l, _id, line_color)
        self.lane_line_node_path.flattenStrong()
        self.lane_line_node_path.node().collect()

        self.sidewalk_node_path.flattenStrong()
        self.sidewalk_node_path.node().collect()
        self.sidewalk_node_path.hide(CamMask.ScreenshotCam)

        # only bodies reparent to this node
        self.lane_node_path.flattenStrong()
        self.lane_node_path.node().collect()

        self.lane_vis_node_path.flattenStrong()
        self.lane_vis_node_path.node().collect()
        self.lane_vis_node_path.hide(CamMask.DepthCam | CamMask.ScreenshotCam)

        self.node_path = NodePath(self._block_name)
        self.node_path.hide(CamMask.Shadow)

        self.sidewalk_node_path.reparentTo(self.node_path)
        self.lane_line_node_path.reparentTo(self.node_path)
        self.lane_node_path.reparentTo(self.node_path)
        self.lane_vis_node_path.reparentTo(self.node_path)

        self.bounding_box = self.block_network.get_bounding_box()
 def __init__(self, world, spawnNP):
     self.running = False
     self.world = world
     rbc = RigidBodyCombiner("rbc")
     self.rbcnp = NodePath(rbc)
     self.rbcnp.reparentTo(render)
     self.NrObjectToDrop = 10
     self.spawnNP = spawnNP
     self.objects = []
     self.model = loader.loadModel('models/box.egg')
     self.model.flattenLight()
     self.shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
Exemplo n.º 4
0
    def __init__(self):
        """Setup this world manager."""
        Logger.info("Initializing world manager...")

        self.terrain = None
        self.portals = []
        self.gates = []
        self.objects = []
        self.scenery = RigidBodyCombiner("scenery")
        self.scenery_np = render.attach_new_node(self.scenery)
        self.is_dirty = True

        base.task_mgr.add(self.run_logic)

        Logger.info("World manager initialized.")
Exemplo n.º 5
0
    def _render_chunk(self, chunk: Chunk):
        # Create the chunk hierarchy in the scene graph.
        c_new_chunk = chunk.chunk_center
        chunk_path = self.path.attachNewNode(
            "chunk.%s.%s.%s" %
            (c_new_chunk[0], c_new_chunk[1], c_new_chunk[2]))
        chunk_model = chunk_path.attachNewNode('model')
        rbc = RigidBodyCombiner('chunk')
        rbcnp = NodePath(rbc)
        rbcnp.reparentTo(chunk_model)

        # Offset the matrix from the origin to the center of the new relative chunk.
        relative_spiral_matrix = np.array(self.cubic_spiral)
        spiral_matrix = relative_spiral_matrix + np.repeat(
            [c_new_chunk], repeats=relative_spiral_matrix.shape[0], axis=0)

        for ii, c_sp in enumerate(spiral_matrix):
            # TODO: remove the terrain generation and put in a generator class.

            center = (256, 256)
            o_x, o_y = cube_to_offset(c_sp)
            current_noise = self.terrain_noise[center[0] + o_x][center[1] +
                                                                o_y]
            # TODO: noise times maximum height. work this out with the noise generation to make the jumps not drastic
            elevation = current_noise * 20
            terrain = None
            if -1.0 <= current_noise <= -0.5:
                terrain = WaterTerrain(elevation=elevation)
            elif -0.9 <= current_noise <= 0.6:
                percent = (current_noise + 0.9) / 1.5
                modulated_color = 0, 1 * percent, 0
                terrain = GrassTerrain(elevation=elevation,
                                       color=modulated_color)
            else:
                # Cliff are steeper than most terrain.
                elevation = elevation * 1.5
                terrain = CliffTerrain(elevation=elevation)

            c_rsp = relative_spiral_matrix[ii]
            loc = self.data_model.at_chunked(chunk.chunk_id, c_rsp)
            loc.major_terrain = terrain

            hex_loc = HexLocationComponent(chunk_path, loc, c_sp,
                                           self._hex_model)
            hex_loc.render(rbcnp, chunk_model)

        rbc.collect()
        return chunk_path
Exemplo n.º 6
0
def setupPandaApp(mesh):
    scene_members = getSceneMembers(mesh)

    p3dApp = ShowBase()
    nodePath = getBaseNodePath(render)

    rotateNode = GeomNode("rotater")
    rotatePath = nodePath.attachNewNode(rotateNode)
    matrix = numpy.identity(4)
    if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
        r = collada.scene.RotateTransform(0, 1, 0, 90)
        matrix = r.matrix
    elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
        r = collada.scene.RotateTransform(1, 0, 0, 90)
        matrix = r.matrix
    rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))

    rbc = RigidBodyCombiner('combiner')
    rbcPath = rotatePath.attachNewNode(rbc)

    for geom, renderstate, mat4 in scene_members:
        node = GeomNode("primitive")
        node.addGeom(geom)
        if renderstate is not None:
            node.setGeomState(0, renderstate)
        geomPath = rbcPath.attachNewNode(node)
        geomPath.setMat(mat4)

    rbc.collect()

    ensureCameraAt(nodePath, base.camera)
    base.disableMouse()
    attachLights(render)
    render.setShaderAuto()
    render.setTransparency(TransparencyAttrib.MDual, 1)

    return p3dApp