Beispiel #1
0
def getAgentModelAnims():
    """load the agents' models and anims"""

    global app, agentNP, agentFile
    # get some models, with animations, to attach to crowd agents
    for i in range(NUMAGENTS):
        # get the model
        agentNP[i] = app.loader.load_model(agentFile[i])
        # set random scale (0.35 - 0.45)
        scale = 0.35 + 0.1 * random.uniform(0.0, 1.0)
        agentNP[i].set_scale(scale)
        # associate an anim with a given anim control
        tmpAnims = AnimControlCollection()
        agentAnimNP = [None, None]
        # first anim -> modelAnimCtls[i][0]
        agentAnimNP[0] = app.loader.load_model(agentAnimFiles[i][0])
        agentAnimNP[0].reparent_to(agentNP[i])
        auto_bind(agentNP[i].node(), tmpAnims)
        agentAnimCtls[i][0] = tmpAnims.get_anim(0)
        tmpAnims.clear_anims()
        agentAnimNP[0].detach_node()
        # second anim -> modelAnimCtls[i][1]
        agentAnimNP[1] = app.loader.load_model(agentAnimFiles[i][1])
        agentAnimNP[1].reparent_to(agentNP[i])
        auto_bind(agentNP[i].node(), tmpAnims)
        agentAnimCtls[i][1] = tmpAnims.get_anim(0)
        tmpAnims.clear_anims()
        agentAnimNP[1].detach_node()
        # reparent all node paths
        agentAnimNP[0].reparent_to(agentNP[i])
        agentAnimNP[1].reparent_to(agentNP[i])
Beispiel #2
0
def getVehicleModelAnims(meanScale, vehicleFileIdx, moveType, sceneNP, steerPlugIn, 
                           steerVehicles, vehicleAnimCtls, pos = None):
    """get a vehicle, model and animations"""
    
    global app, vehicleAnimFiles
    # get some models, with animations, to attach to vehicles
    # get the model
    vehicleNP = app.loader.load_model(vehicleFile[vehicleFileIdx])
    # set random scale
    scale = meanScale * (1 + 0.2 * (2 * random.uniform(0.0, 1.0) - 1))
    vehicleNP.set_scale(scale)
    # associate an anim with a given anim control
    tmpAnims = AnimControlCollection()
    vehicleAnimNP = [None, None]
    vehicleAnimCtls.append([None, None])
    if(len(vehicleAnimFiles[vehicleFileIdx][0]) != 0) and \
            (len(vehicleAnimFiles[vehicleFileIdx][1]) != 0):
        # first anim -> modelAnimCtls[i][0]
        vehicleAnimNP[0] = app.loader.load_model(vehicleAnimFiles[vehicleFileIdx][0])
        vehicleAnimNP[0].reparent_to(vehicleNP)
        auto_bind(vehicleNP.node(), tmpAnims, 
                  PartGroup.HMF_ok_part_extra |
                  PartGroup.HMF_ok_anim_extra |
                  PartGroup.HMF_ok_wrong_root_name)
        vehicleAnimCtls[-1][0] = tmpAnims.get_anim(0)
        tmpAnims.clear_anims()
        vehicleAnimNP[0].detach_node()
        # second anim -> modelAnimCtls[i][1]
        vehicleAnimNP[1] = app.loader.load_model(vehicleAnimFiles[vehicleFileIdx][1])
        vehicleAnimNP[1].reparent_to(vehicleNP)
        auto_bind(vehicleNP.node(), tmpAnims, 
                  PartGroup.HMF_ok_part_extra |
                  PartGroup.HMF_ok_anim_extra |
                  PartGroup.HMF_ok_wrong_root_name)
        vehicleAnimCtls[-1][1] = tmpAnims.get_anim(0)
        tmpAnims.clear_anims()
        vehicleAnimNP[1].detach_node()
        # reparent all node paths
        vehicleAnimNP[0].reparent_to(vehicleNP)
        vehicleAnimNP[1].reparent_to(vehicleNP)
    # set parameter for vehicle's move type (OPENSTEER or OPENSTEER_KINEMATIC)
    steerMgr = OSSteerManager.get_global_ptr()
    steerMgr.set_parameter_value(OSSteerManager.STEERVEHICLE, "mov_type",
            moveType)
    # create the steer vehicle (attached to the reference node)
    steerVehicleNP = steerMgr.create_steer_vehicle("vehicle" + str(len(steerVehicles)))
    steerVehicles.append(steerVehicleNP.node())
    randPos = pos
    if randPos == None:
        # set the position randomly
        randPos = getRandomPos(sceneNP)
    steerVehicleNP.set_pos(randPos)
    # attach some geometry (a model) to steer vehicle
    vehicleNP.reparent_to(steerVehicleNP)
    # add the steer vehicle to the plug-in
    steerPlugIn.add_steer_vehicle(steerVehicleNP)
def getPlayerModelAnims(name, scale, vehicleFileIdx, steerPlugIn, 
                           steerVehicles, vehicleAnimCtls, pos):
    """get the player, model and animations"""
    
    global app, vehicleAnimFiles
    # get some models, with animations, to attach to vehicles
    # get the model
    vehicleNP = app.loader.load_model(vehicleFile[vehicleFileIdx])
    # associate an anim with a given anim control
    tmpAnims = AnimControlCollection()
    vehicleAnimNP = [None, None]
    vehicleAnimCtls.append([None, None])
    if(len(vehicleAnimFiles[vehicleFileIdx][0]) != 0) and \
            (len(vehicleAnimFiles[vehicleFileIdx][1]) != 0):
        # first anim -> modelAnimCtls[i][0]
        vehicleAnimNP[0] = app.loader.load_model(vehicleAnimFiles[vehicleFileIdx][0])
        vehicleAnimNP[0].reparent_to(vehicleNP)
        auto_bind(vehicleNP.node(), tmpAnims, 
                  PartGroup.HMF_ok_part_extra |
                  PartGroup.HMF_ok_anim_extra |
                  PartGroup.HMF_ok_wrong_root_name)
        vehicleAnimCtls[-1][0] = tmpAnims.get_anim(0)
        tmpAnims.clear_anims()
        vehicleAnimNP[0].detach_node()
        # second anim -> modelAnimCtls[i][1]
        vehicleAnimNP[1] = app.loader.load_model(vehicleAnimFiles[vehicleFileIdx][1])
        vehicleAnimNP[1].reparent_to(vehicleNP)
        auto_bind(vehicleNP.node(), tmpAnims, 
                  PartGroup.HMF_ok_part_extra |
                  PartGroup.HMF_ok_anim_extra |
                  PartGroup.HMF_ok_wrong_root_name)
        vehicleAnimCtls[-1][1] = tmpAnims.get_anim(0)
        tmpAnims.clear_anims()
        vehicleAnimNP[1].detach_node()
        # reparent all node paths
        vehicleAnimNP[0].reparent_to(vehicleNP)
        vehicleAnimNP[1].reparent_to(vehicleNP)
    #
    steerMgr = OSSteerManager.get_global_ptr()
    # create the steer vehicle (attached to the reference node)
    # note: vehicle's move type is ignored
    steerVehicleNP = steerMgr.create_steer_vehicle("PlayerVehicle")
    steerVehicles.append(steerVehicleNP.node())
    # set the name
    steerVehicleNP.set_name(name)
    # set scale
    steerVehicleNP.set_scale(scale)
    # set the position
    steerVehicleNP.set_pos(pos)
    # attach some geometry (a model) to steer vehicle
    vehicleNP.reparent_to(steerVehicleNP)
    # add the steer vehicle to the plug-in
    steerPlugIn.add_steer_vehicle(steerVehicleNP)
    # return the steerVehicleNP
    return steerVehicleNP
Beispiel #4
0
def restoreAllScene():
    """restore all scene stuff  when read from bam file"""

    global navMesh, crowdAgent, sceneNP, agentAnimCtls
    # restore nav mesh: through nav mesh manager
    navMesh = RNNavMeshManager.get_global_ptr().get_nav_mesh(0)
    # restore sceneNP: through panda3d
    sceneNP = RNNavMeshManager.get_global_ptr().get_reference_node_path().find(
        "**/Owner")
    # reparent the reference node to render
    RNNavMeshManager.get_global_ptr().get_reference_node_path().reparent_to(
        app.render)

    # restore crowd agents
    for i in range(NUMAGENTS):
        # restore the crowd agent: through nav mesh manager
        crowdAgent[i] = RNNavMeshManager.get_global_ptr().get_crowd_agent(i)
        # restore animations
        tmpAnims = AnimControlCollection()
        auto_bind(crowdAgent[i], tmpAnims)
        for j in range(tmpAnims.get_num_anims()):
            agentAnimCtls[i][j] = tmpAnims.get_anim(j)
        ).find("**/SceneNP")
        # reparent the reference node to render
        OSSteerManager.get_global_ptr().get_reference_node_path().reparent_to(
            app.render)

        # restore steer vehicles
        NUMVEHICLES = OSSteerManager.get_global_ptr().get_num_steer_vehicles()
        tmpList = [None for i in range(NUMVEHICLES)]
        steerVehicles.extend(tmpList)
        vehicleAnimCtls.extend(tmpList)
        for i in range(NUMVEHICLES):
            # restore the steer vehicle: through steer manager
            steerVehicles[i] = OSSteerManager.get_global_ptr(
            ).get_steer_vehicle(i)
            # restore animations
            tmpAnims = AnimControlCollection()
            auto_bind(steerVehicles[i], tmpAnims)
            vehicleAnimCtls[i] = [None, None]
            for j in range(tmpAnims.get_num_anims()):
                vehicleAnimCtls[i][j] = tmpAnims.get_anim(j)

        # set creation parameters as strings before other plug-ins/vehicles creation
        print("\n" + "Current creation parameters:")
        setParametersBeforeCreation()

    # # first option: start the default update task for all plug-ins
#     steerMgr.start_default_update()

# # second option: start the custom update task for all plug-ins
    app.taskMgr.add(updatePlugIn,
                    "updatePlugIn",
from common import startFramework, toggleDebugFlag, toggleDebugDraw, mask, \
        loadTerrain, printCreationParameters, handleVehicleEvent, \
        changeVehicleMaxForce, changeVehicleMaxSpeed, getVehicleModelAnims, \
        animRateFactor, writeToBamFileAndExit, readFromBamFile, bamFileName, \
        getCollisionEntryFromCamera, obstacleFile, HandleObstacleData, \
        handleObstacles, HandleVehicleData, handleVehicles, loadTerrainLowPoly
import sys, random

# # specific data/functions declarations/definitions
sceneNP = None
vehicleAnimCtls = []
steerPlugIn = None
steerVehicles = []
#
flagNP = NodePath()
flagAnims = AnimControlCollection()


def setParametersBeforeCreation():
    """set parameters as strings before plug-ins/vehicles creation"""

    steerMgr = OSSteerManager.get_global_ptr()
    valueList = ValueList_string()
    # set plug-in type
    steerMgr.set_parameter_value(OSSteerManager.STEERPLUGIN, "plugin_type",
                                 "capture_the_flag")

    # set vehicle throwing events
    valueList.clear()
    valueList.add_value("avoid_obstacle@[email protected]")
    steerMgr.set_parameter_values(OSSteerManager.STEERVEHICLE, "thrown_events",