コード例 #1
0
ファイル: MeshSourceMap.cs プロジェクト: taotao111/ainav
 public MeshSourceMap(NavMeshBuildSettings buildSettings)
 {
     BuildSettings     = buildSettings;
     TileSources       = new NativeMultiHashMap <int2, int>(256, Allocator.Persistent);
     IdIndex           = new NativeHashMap <int, MeshSource>(256, Allocator.Persistent);
     CustomIdToIdIndex = new NativeHashMap <int, int>(256, Allocator.Persistent);
 }
コード例 #2
0
ファイル: AiNavTests.cs プロジェクト: taotao111/ainav
        public unsafe void TestSourceMap()
        {
            GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            Mesh       mesh       = gameObject.GetComponent <MeshFilter>().sharedMesh;

            Object.DestroyImmediate(gameObject);

            var sharedData = MeshSourceData.Create(mesh);

            MeshSourceMap map          = new MeshSourceMap(NavMeshBuildSettings.Default());
            float4x4      localToWorld = float4x4.TRS(default, default, new float3(40f, 40f, 40f));
コード例 #3
0
        /// <summary>
        /// Calculates X-Z span for a navigation mesh tile. The Y-axis will span from <see cref="float.MinValue"/> to <see cref="float.MaxValue"/>
        /// </summary>
        public static DtBoundingBox CalculateTileBoundingBox(NavMeshBuildSettings settings, int2 tileCoord)
        {
            float  tcs     = settings.TileSize * settings.CellSize;
            float2 tileMin = new float2(tileCoord.x * tcs, tileCoord.y * tcs);
            float2 tileMax = tileMin + new float2(tcs);

            DtBoundingBox boundingBox = default;

            boundingBox.min.x = tileMin.x;
            boundingBox.min.z = tileMin.y;
            boundingBox.max.x = tileMax.x;
            boundingBox.max.z = tileMax.y;
            boundingBox.min.y = float.MinValue;
            boundingBox.max.y = float.MaxValue;

            return(boundingBox);
        }
コード例 #4
0
ファイル: NativeBuildUtitls.cs プロジェクト: taotao111/ainav
        public static NativeList <int2> GetOverlappingTiles(NavMeshBuildSettings settings, DtBoundingBox boundingBox)
        {
            NativeList <int2> ret   = new NativeList <int2>(Allocator.Temp);
            float             tcs   = settings.TileSize * settings.CellSize;
            float2            start = boundingBox.min.xz / tcs;
            float2            end   = boundingBox.max.xz / tcs;

            int2 startTile = new int2(
                (int)Math.Floor(start.x),
                (int)Math.Floor(start.y));
            int2 endTile = new int2(
                (int)Math.Ceiling(end.x),
                (int)Math.Ceiling(end.y));

            for (int y = startTile.y; y < endTile.y; y++)
            {
                for (int x = startTile.x; x < endTile.x; x++)
                {
                    ret.Add(new int2(x, y));
                }
            }
            return(ret);
        }
コード例 #5
0
 public void SetDefaultSettings()
 {
     BuildSettings = NavMeshBuildSettings.Default();
     AgentSettings = NavAgentSettings.Default();
 }
コード例 #6
0
ファイル: NavMeshBuilder.cs プロジェクト: taotao111/ainav
 public NavMeshBuilder(NavMeshBuildSettings buildSettings, NavAgentSettings agentSettings)
 {
     BuildSettings = buildSettings;
     AgentSettings = agentSettings;
 }
コード例 #7
0
ファイル: NavMeshBuilder.cs プロジェクト: taotao111/ainav
        private unsafe int BuildTile(int2 tileCoordinate, NavMeshBuildSettings buildSettings, NavAgentSettings agentSettings,
                                     NavMeshBuildInput buildInput, long buildTimeStamp, out NavMeshTile meshTile)
        {
            meshTile = null;

            if (buildInput.AreasLength != buildInput.IndicesLength / 3)
            {
                return(-1001);
            }

            if (buildInput.VerticesLength <= 0 || buildInput.IndicesLength <= 0)
            {
                return(-1000);
            }

            DtBoundingBox tileBoundingBox = NavMeshBuildUtils.CalculateTileBoundingBox(buildSettings, tileCoordinate);

            NavMeshBuildUtils.SnapBoundingBoxToCellHeight(buildSettings, ref tileBoundingBox);

            tileBoundingBox.min.y = HeightBounds.min.y;
            tileBoundingBox.max.y = HeightBounds.max.y;

            IntPtr builder = Navigation.NavMesh.CreateBuilder();

            DtBuildSettings internalBuildSettings = new DtBuildSettings
            {
                // Tile settings
                BoundingBox  = tileBoundingBox,
                TilePosition = tileCoordinate,
                TileSize     = buildSettings.TileSize,

                // General build settings
                CellHeight           = buildSettings.CellHeight,
                CellSize             = buildSettings.CellSize,
                RegionMinArea        = buildSettings.MinRegionArea,
                RegionMergeArea      = buildSettings.RegionMergeArea,
                EdgeMaxLen           = buildSettings.MaxEdgeLen,
                EdgeMaxError         = buildSettings.MaxEdgeError,
                DetailSampleDist     = buildSettings.DetailSamplingDistance,
                DetailSampleMaxError = buildSettings.MaxDetailSamplingError,

                // Agent settings
                AgentHeight   = agentSettings.Height,
                AgentRadius   = agentSettings.Radius,
                AgentMaxClimb = agentSettings.MaxClimb,
                AgentMaxSlope = agentSettings.MaxSlope
            };

            Navigation.NavMesh.SetSettings(builder, new IntPtr(&internalBuildSettings));

            IntPtr buildResultPtr = Navigation.NavMesh.Build2(builder, buildInput.Vertices, buildInput.VerticesLength, buildInput.Indices, buildInput.IndicesLength, buildInput.Areas);

            DtGeneratedData *generatedDataPtr = (DtGeneratedData *)buildResultPtr;

            if (generatedDataPtr->Success && generatedDataPtr->NavmeshDataLength > 0)
            {
                meshTile = new NavMeshTile();

                // Copy the generated navigationMesh data
                meshTile.Data = new byte[generatedDataPtr->NavmeshDataLength + sizeof(long)];
                Marshal.Copy(generatedDataPtr->NavmeshData, meshTile.Data, 0, generatedDataPtr->NavmeshDataLength);

                // Append time stamp
                byte[] timeStamp = BitConverter.GetBytes(buildTimeStamp);
                for (int i = 0; i < timeStamp.Length; i++)
                {
                    meshTile.Data[meshTile.Data.Length - sizeof(long) + i] = timeStamp[i];
                }
            }

            int error = generatedDataPtr->Error;

            Navigation.NavMesh.DestroyBuilder(builder);

            return(error);
        }
コード例 #8
0
 /// <summary>
 /// Snaps a <see cref="DtBoundingBox"/>'s height according to the given <see cref="NavMeshBuildSettings"/>
 /// </summary>
 /// <param name="settings">The build settings</param>
 /// <param name="boundingBox">Reference to the bounding box to snap</param>
 public static void SnapBoundingBoxToCellHeight(NavMeshBuildSettings settings, ref DtBoundingBox boundingBox)
 {
     // Snap Y to tile height to avoid height differences between tiles
     boundingBox.min.y = (float)Math.Floor(boundingBox.min.y / settings.CellHeight) * settings.CellHeight;
     boundingBox.max.y = (float)Math.Ceiling(boundingBox.max.y / settings.CellHeight) * settings.CellHeight;
 }
コード例 #9
0
 public NavMeshBuilderSettings(int id, NavMeshBuildSettings buildSettings, NavAgentSettings agentSettings)
 {
     Id            = id;
     BuildSettings = buildSettings;
     AgentSettings = agentSettings;
 }