Пример #1
0
def placeCrowdAgents():
    """place crowd agents randomly"""

    global navMesh, sceneNP, crowdAgent
    for i in range(NUMAGENTS):
        # remove agent from nav mesh
        navMesh.remove_crowd_agent(NodePath.any_path(crowdAgent[i]))
        # set its random position
        randPos = getRandomPos(sceneNP)
        NodePath.any_path(crowdAgent[i]).set_pos(randPos)
        # re-add agent to nav mesh
        navMesh.add_crowd_agent(NodePath.any_path(crowdAgent[i]))
def placeCrowdAgent():
    """place crowd agent"""

    global navMesh, crowdAgent
    if navMesh == None or crowdAgent == None:
        return

    # get the collision entry, if any
    entry0 = getCollisionEntryFromCamera()
    if entry0:
        # remove agent from nav mesh
        navMesh.remove_crowd_agent(NodePath.any_path(crowdAgent))
        point = entry0.get_surface_point(NodePath())
        NodePath.any_path(crowdAgent).set_pos(point)
        # re-add agent to nav mesh
        navMesh.add_crowd_agent(NodePath.any_path(crowdAgent))
Пример #3
0
def writeToBamFileAndExit(fileName):
    """write scene to a file (and exit)"""
    
    OSSteerManager.get_global_ptr().write_to_bam_file(fileName)
    # # this is for testing explicit removal and destruction of all elements
    steerMgr = OSSteerManager.get_global_ptr()
    # remove steer vehicles from steer plug-ins
    for plugInTmp in steerMgr.get_steer_plug_ins():
        for vehicleTmp in plugInTmp:
            # remove vehicleTmp
            plugInTmp.remove_steer_vehicle(NodePath.any_path(vehicleTmp))
    # destroy steer vehicles
    for vehicleTmp in steerMgr.get_steer_vehicles():
        # destroy vehicleTmp
        steerMgr.destroy_steer_vehicle(NodePath.any_path(vehicleTmp))
    # destroy steer plug-ins
    for plugInTmp in steerMgr.get_steer_plug_ins():
        # destroy vehicleTmp
        steerMgr.destroy_steer_plug_in(NodePath.any_path(plugInTmp))
    # #
    #
    sys.exit(0)
def cycleQueries():
    """cycle over queries"""

    global query, navMesh, crowdAgent
    if (crowdAgent == None) or (navMesh == None):
        return

    crowdAgentNP = NodePath.any_path(crowdAgent)
    startPos, endPos = (crowdAgentNP.get_pos(), crowdAgent.get_move_target())
    if query == 0:
        print("get path find to follow and its cost:")
        print("\tfrom " + str(startPos) + " to " + str(endPos))
        areaPointList = navMesh.path_find_follow(startPos, endPos)
        for p in areaPointList:
            print("\t" + str(p))
        print("\tcost: " +
              str(navMesh.path_find_follow_cost(startPos, endPos)))
    elif query == 1:
        print("get path find to follow straight:")
        print("\tfrom " + str(startPos) + " to " + str(endPos))
        pointFlagList = navMesh.path_find_straight(startPos, endPos,
                                                   RNNavMesh.NONE_CROSSINGS)
        for pF in pointFlagList:
            pathFlag = None
            flag = pF.get_second()
            if flag == RNNavMesh.START:
                pathFlag = "START"
            elif flag == RNNavMesh.END:
                pathFlag = "END"
            elif flag == RNNavMesh.OFFMESH_CONNECTION:
                pathFlag = "OFFMESH_CONNECTION"
            print("\t" + str(pF.get_first()) + ", " + str(pathFlag))
    elif query == 2:
        print("check visibility:")
        print("\tfrom " + str(startPos) + " to " + str(endPos))
        hitPoint = navMesh.ray_cast(startPos, endPos)
        RES = ""
        if hitPoint != endPos:
            RES = "not "
        print("\thit " + str(hitPoint) + " : " + RES + "visible!")
    elif query == 3:
        print("get distance to wall:")
        print("\tfrom " + str(startPos))
        distance = navMesh.distance_to_wall(startPos)
        print("\t" + str(distance))
    else:
        pass
    query += 1
    query = query % 4
def toggleSetupCleanup():
    """toggle setup/cleanup"""

    global navMesh, app, setupCleanupFlag, toggleDebugFlag, firstSetup
    if setupCleanupFlag:
        # true: setup
        navMesh.set_owner_node_path(sceneNP)
        navMesh.setup()
        navMesh.enable_debug_drawing(app.camera)
        #
        if firstSetup:
            # first set initial position and target
            NodePath.any_path(crowdAgent).set_pos(LPoint3f(0.0, 15.0, 10.0))
            # then attach the crowd agent to the nav mesh
            navMesh.add_crowd_agent(NodePath.any_path(crowdAgent))
            crowdAgent.set_move_target(LPoint3f(0.0, 20.0, 10.0))
            NodePath.any_path(crowdAgent).show()
            firstSetup = False

        # show debug draw
        navMesh.toggle_debug_drawing(True)
        toggleDebugFlag = False
        # show areas
        for ref in list(areaRefs):
            points = navMesh.get_convex_volume_by_ref(ref)
            if points.get_num_values() == 0:
                print("Area's invalid ref: " + str(ref) + " ...removing")
                areaRefs.remove(ref)
                continue
            centroid = LPoint3f(0, 0, 0)
            for p in points:
                centroid += p
            centroid /= points.get_num_values()
            settings = navMesh.get_convex_volume_settings(centroid)

            if not (settings == navMesh.get_convex_volume_settings(ref)):
                print(
                    "assertion failed: settings == navMesh.get_convex_volume_settings(ref)"
                )

            print("Area n. " + str(areaRefs.index(ref)))
            print("\tref: " + str(settings.get_ref()) + " | "
                  "area: " + str(settings.get_area()) + " | "
                  "flags: " + str(settings.get_flags()))
        # show links
        for ref in list(linkRefs):
            points = navMesh.get_off_mesh_connection_by_ref(ref)
            if points.get_num_values() == 0:
                print("Link's invalid ref: " + str(ref) + " ...removing")
                linkRefs.remove(ref)
                continue
            settings = navMesh.get_off_mesh_connection_settings(points[0])

            if not (settings == navMesh.get_off_mesh_connection_settings(ref)):
                print(
                    "assertion failed: settings == navMesh.get_off_mesh_connection_settings(ref)"
                )

            print("Link n. " + str(linkRefs.index(ref)))
            print("\tref: " + str(settings.get_ref()) + " | "
                  "rad: " + str(settings.get_rad()) + " | "
                  "bidir: " + str(settings.get_bidir()) + " | "
                  "area: " + str(settings.get_area()) + " | "
                  "flags: " + str(settings.get_flags()))
    else:
        # false: cleanup
        navMesh.cleanup()
        areaPointList.clear()
        linkPointPair.clear()
        # now crowd agents and obstacles are detached
        # from navMesh's NodePath, so we need to
        # prevent them to disappear from the scene:
        # reparent to navMeshNP's parent (i.e. commonNP)
        for agent in navMesh:
            NodePath.any_path(agent).reparent_to(
                NodePath.any_path(navMesh).get_parent())

    setupCleanupFlag = not setupCleanupFlag
Пример #6
0
def handleVehicleEvent(name, vehicle):
    """handle vehicle's events"""
    
    vehicleNP = NodePath.any_path(vehicle)
    print ("got " + name + " event from '"+ vehicleNP.get_name() + "' at " + str(vehicleNP.get_pos()))
Пример #7
0
def handleCrowdAgentEvent(crowAgent):
    """handle crowd agent's events"""

    agent = NodePath.any_path(crowAgent)
    print("move-event - " + agent.get_name() + " - " + str(agent.get_pos()))