NavMeshGenerator::NavMeshGenerator(rcContext* ctx) : 
	m_ctx(ctx),
	m_keepInterResults(true),
	m_totalBuildTimeMs(0),
	m_solid(0),
	m_chf(0),
	m_cset(0),
	m_pmesh(0),
	m_dmesh(0),
	m_navMesh(0)
{
	m_cellSize = 0.3f;
	m_cellHeight = 0.2f;
	m_agentHeight = 2.0f;
	m_agentRadius = 0.6f;
	m_agentMaxClimb = 0.9f;
	m_agentMaxSlope = 45.0f;
	m_regionMinSize = 8;
	m_regionMergeSize = 20;
	m_edgeMaxLen = 12.0f;
	m_edgeMaxError = 1.3f;
	m_vertsPerPoly = 6.0f;
	m_detailSampleDist = 6.0f;
	m_detailSampleMaxError = 1.0f;

	m_partitionType = 0; //SAMPLE_PARTITION_WATERSHED;
	m_navQuery = dtAllocNavMeshQuery();
	m_crowd = dtAllocCrowd();
}
Exemple #2
0
	void NavMesh::InitMesh()
	{
		// common setting
		m_cellSize = 0.3f;
		m_cellHeight = 0.2f;
		m_agentHeight = 2.0f;
		m_agentRadius = 0.6f;
		m_agentMaxClimb = 0.9f;
		m_agentMaxSlope = 45.0f;
		m_regionMinSize = 8;
		m_regionMergeSize = 20;
		m_edgeMaxLen = 12.0f;
		m_edgeMaxError = 1.3f;
		m_vertsPerPoly = 6.0f;
		m_detailSampleDist = 6.0f;
		m_detailSampleMaxError = 1.0f;
		//
		m_geom = 0;
		m_navMesh = 0;
		m_navQuery = dtAllocNavMeshQuery();
		m_crowd = dtAllocCrowd();
		m_tileCache = 0;
		m_maxTiles = 0;
		m_maxPolysPerTile = 0;
		m_tileSize = 48;
		m_talloc = new LinearAllocator(32000);
		m_tcomp = new FastLZCompressor;
		m_tmproc = new MeshProcess;
	}
Exemple #3
0
Sample::Sample() :
	m_geom(0),
	m_navMesh(0),
	m_navQuery(0),
	m_crowd(0),
	m_ctx(0)
{
	resetCommonSettings();
	m_navQuery = dtAllocNavMeshQuery();
	m_crowd = dtAllocCrowd();

}
Exemple #4
0
Sample::Sample() :
	m_geom(0),
	m_navMesh(0),
	m_navQuery(0),
	m_crowd(0),
	m_navMeshDrawFlags(DU_DRAWNAVMESH_OFFMESHCONS|DU_DRAWNAVMESH_CLOSEDLIST),
	m_tool(0),
	m_ctx(0)
{
	resetCommonSettings();
	m_navQuery = dtAllocNavMeshQuery();
	m_crowd = dtAllocCrowd();
}
Exemple #5
0
Sample::Sample() :
	m_geom(0),
	m_navMesh(0),
	m_navQuery(0),
	m_crowd(0),
	m_navMeshDrawFlags(DU_DRAWNAVMESH_OFFMESHCONS|DU_DRAWNAVMESH_CLOSEDLIST),
	m_tool(0),
	m_ctx(0)
{
	resetCommonSettings();
	m_navQuery = dtAllocNavMeshQuery();
	m_crowd = dtAllocCrowd();

	for (int i = 0; i < MAX_TOOLS; i++)
		m_toolStates[i] = 0;
}
void UCrowdManager::CreateCrowdManager()
{
	ARecastNavMesh* RecastNavData = Cast<ARecastNavMesh>(MyNavData);
	FPImplRecastNavMesh* PImplNavMesh = RecastNavData ? RecastNavData->RecastNavMeshImpl : NULL;
	dtNavMesh* NavMeshPtr = PImplNavMesh ? PImplNavMesh->GetRecastMesh() : NULL;

	if (NavMeshPtr)
	{
		DetourCrowd = dtAllocCrowd();
	}
		
	if (DetourCrowd)
	{
		DetourCrowd->init(MaxAgents, MaxAgentRadius, NavMeshPtr);
		DetourCrowd->setAgentCheckInterval(NavmeshCheckInterval);
		DetourCrowd->setSingleAreaVisibilityOptimization(bSingleAreaVisibilityOptimization);
		DetourCrowd->setPruneStartedOffmeshConnections(bPruneStartedOffmeshConnections);
		DetourCrowd->setEarlyReachTestOptimization(bEarlyReachTestOptimization);

		DetourCrowd->initAvoidance(MaxAvoidedAgents, MaxAvoidedWalls, FMath::Max(SamplingPatterns.Num(), 1));

		for (int32 Idx = 0; Idx < SamplingPatterns.Num(); Idx++)
		{
			const FCrowdAvoidanceSamplingPattern& Info = SamplingPatterns[Idx];
			if (Info.Angles.Num() > 0 && Info.Angles.Num() == Info.Radii.Num())
			{
				DetourCrowd->setObstacleAvoidancePattern(Idx, Info.Angles.GetData(), Info.Radii.GetData(), Info.Angles.Num());
			}
		}

		UpdateAvoidanceConfig();

		AgentFlags.Reset();
		AgentFlags.AddZeroed(MaxAgents);

		for (auto It = ActiveAgents.CreateIterator(); It; ++It)
		{
			AddAgent(It.Key(), It.Value());
		}
	}
}
OgreDetourCrowd::OgreDetourCrowd(OgreRecast *recast)
    : m_crowd(0),
    m_recast(recast),
    m_targetRef(0),
    m_activeAgents(0)
{
    m_crowd = dtAllocCrowd();
    if(!m_crowd)
        Ogre::LogManager::getSingletonPtr()->logMessage("Error: Could not allocate crowd instance.");


    // Set default agent parameters
    m_anticipateTurns = true;
    m_optimizeVis = true;
    m_optimizeTopo = true;
    m_obstacleAvoidance = true;
    m_separation = false;

    m_obstacleAvoidanceType = 3.0f;
    m_separationWeight = 2.0f;


    memset(m_trails, 0, sizeof(m_trails));

    m_vod = dtAllocObstacleAvoidanceDebugData();
    m_vod->init(2048);

    memset(&m_agentDebug, 0, sizeof(m_agentDebug));
    m_agentDebug.idx = -1;
    m_agentDebug.vod = m_vod;



    dtNavMesh* nav = recast->m_navMesh;
    dtCrowd* crowd = m_crowd;
            if (nav && crowd && crowd->getAgentCount() == 0)
            {
                    crowd->init(MAX_AGENTS, m_recast->getAgentRadius(), nav);

                    // Make polygons with 'disabled' flag invalid.
                    crowd->getEditableFilter()->setExcludeFlags(SAMPLE_POLYFLAGS_DISABLED);


                    // Create different avoidance settings presets. The crowd object can store multiple, identified by an index number.
                    // Setup local avoidance params to different qualities.
                    dtObstacleAvoidanceParams params;
                    // Use mostly default settings, copy from dtCrowd.
                    memcpy(&params, crowd->getObstacleAvoidanceParams(0), sizeof(dtObstacleAvoidanceParams));

                    // Low (11)
                    params.velBias = 0.5f;
                    params.adaptiveDivs = 5;
                    params.adaptiveRings = 2;
                    params.adaptiveDepth = 1;
                    crowd->setObstacleAvoidanceParams(0, &params);

                    // Medium (22)
                    params.velBias = 0.5f;
                    params.adaptiveDivs = 5;
                    params.adaptiveRings = 2;
                    params.adaptiveDepth = 2;
                    crowd->setObstacleAvoidanceParams(1, &params);

                    // Good (45)
                    params.velBias = 0.5f;
                    params.adaptiveDivs = 7;
                    params.adaptiveRings = 2;
                    params.adaptiveDepth = 3;
                    crowd->setObstacleAvoidanceParams(2, &params);

                    // High (66)
                    params.velBias = 0.5f;
                    params.adaptiveDivs = 7;
                    params.adaptiveRings = 3;
                    params.adaptiveDepth = 3;

                    crowd->setObstacleAvoidanceParams(3, &params);
            }
}
Exemple #8
0
bool NavMesh::loadNavMeshFile()
{
    auto data = FileUtils::getInstance()->getDataFromFile(_navFilePath);
    if (data.isNull()) return false;

    // Read header.
    unsigned int offset = 0;
    TileCacheSetHeader header = *((TileCacheSetHeader*)(data.getBytes() + offset));
    offset += sizeof(TileCacheSetHeader);
    if (header.magic != TILECACHESET_MAGIC)
    {
        return false;
    }
    if (header.version != TILECACHESET_VERSION)
    {
        return false;
    }

    _navMesh = dtAllocNavMesh();
    if (!_navMesh)
    {
        return false;
    }
    dtStatus status = _navMesh->init(&header.meshParams);
    if (dtStatusFailed(status))
    {
        return false;
    }

    _tileCache = dtAllocTileCache();
    if (!_tileCache)
    {
        return false;
    }

    _allocator = new LinearAllocator(32000);
    _compressor = new FastLZCompressor;
    _meshProcess = new MeshProcess(_geomData);
    status = _tileCache->init(&header.cacheParams, _allocator, _compressor, _meshProcess);

    if (dtStatusFailed(status))
    {
        return false;
    }

    // Read tiles.
    for (int i = 0; i < header.numTiles; ++i)
    {
        TileCacheTileHeader tileHeader = *((TileCacheTileHeader*)(data.getBytes() + offset));
        offset += sizeof(TileCacheTileHeader);
        if (!tileHeader.tileRef || !tileHeader.dataSize)
            break;

        unsigned char* tileData = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
        if (!tileData) break;
        memcpy(tileData, (data.getBytes() + offset), tileHeader.dataSize);
        offset += tileHeader.dataSize;

        dtCompressedTileRef tile = 0;
        _tileCache->addTile(tileData, tileHeader.dataSize, DT_COMPRESSEDTILE_FREE_DATA, &tile);

        if (tile)
            _tileCache->buildNavMeshTile(tile, _navMesh);
    }

    //create crowed
    _crowed = dtAllocCrowd();
    _crowed->init(MAX_AGENTS, header.cacheParams.walkableRadius, _navMesh);

    //create NavMeshQuery
    _navMeshQuery = dtAllocNavMeshQuery();
    _navMeshQuery->init(_navMesh, 2048);

    _agentList.assign(MAX_AGENTS, nullptr);
    _obstacleList.assign(header.cacheParams.maxObstacles, nullptr);
    //duDebugDrawNavMesh(&_debugDraw, *_navMesh, DU_DRAWNAVMESH_OFFMESHCONS);
    return true;
}