// Update is called once per frame void Update() { transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime); bool hit = false; Fix64Vec3 start = (Fix64Vec3)transform.position; Fix64Vec3 movement = (Fix64)castRange * (Fix64Vec3)transform.forward; Fix64 radius = (Fix64)sphereRadius; Fix64Vec3 end = start + movement; hit = Parallel3D.SphereCast(start, radius, movement, layerMask, ref hitInfo); if (hit) { castPoint = hitInfo.point; castNormal = hitInfo.normal; sphereHitPosition = start + hitInfo.fraction * movement; } else { castPoint = end; castNormal = Fix64Vec3.zero; sphereHitPosition = end; } }
void Update() { Fix64Vec3 center = (Fix64Vec3)transform.position; Fix64 radius = (Fix64)sphereRadius; Parallel3D.OverlapSphere(center, radius, layerMask, result); }
public static void CheckVolume(PNavMesh pNavMesh, int xStart, int xEnd, int zStart, int zEnd, int yStart, int yEnd, int scale, Action <int, int, int, int, int, int> callback) { PShapeOverlapResult3D result = new PShapeOverlapResult3D(); Fix64Vec3 size = pNavMesh.gridSize * (Fix64)scale; Fix64Vec3 toCenter = Fix64.half * size; int scaledXEnd = xEnd / scale; int scaledYEnd = yEnd / scale; int scaledZEnd = zEnd / scale; for (int x = xStart; x < scaledXEnd; x++) { for (int z = zStart; z < scaledZEnd; z++) { for (int y = yStart; y < scaledZEnd; y++) { int scaledX = x * scale; int scaledY = y * scale; int scaledZ = z * scale; Fix64Vec3 l; Fix64Vec3 u; pNavMesh.GetAABB(scaledX, scaledY, scaledZ, out l, out u); Fix64Vec3 center = l + toCenter; Fix64Quat rot = Fix64Quat.identity; Parallel3D.OverlapCube( center, rot, size.x, size.y, size.z, -1, result); if (result.count > 0) { callback(scaledX, scaledX + scale, scaledZ, scaledZ + scale, scaledY, scaledY + scale); } } } } }
// Update is called once per frame void Update() { transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime); PRaycastHit3D raycastHit3D; bool hit = false; Fix64Vec3 start = (Fix64Vec3)transform.position; Fix64Vec3 end = start + (Fix64)raycastLength * (Fix64Vec3)transform.right; hit = Parallel3D.RayCast(start, end, layerMask, out raycastHit3D); if (hit) { raycastPoint = raycastHit3D.point; raycastNormal = raycastHit3D.normal; } else { raycastPoint = end; } }
public static void Process(PNavMesh pNavMesh) { const int INDICE_COUNT = 1024; using (new SProfiler("Triangulation")) { int[] indices = new int[INDICE_COUNT]; int[] indiceCounts = new int[INDICE_COUNT]; Fix64Vec2[] verts = new Fix64Vec2[INDICE_COUNT]; int[] indexes = new int[INDICE_COUNT]; int index = 0; foreach (PNavIsland island in pNavMesh.islands) { //build island with island boundary if (island.boundaryEdgeLoopIndex < 0) { continue; } Debug.Log($"Generating Polygon graph for island={index}"); index++; PNavEdgeLoop boundary = island.edgeLoops[island.boundaryEdgeLoopIndex]; int boundaryCornersCount = PrepareCornerVerts(boundary, island, verts, indexes); PolyIsland polyIsland = Parallel3D.CreatePolyIsland(verts, indexes, boundaryCornersCount); //add other edgeloops as holes int edgeLoopIndex = -1; foreach (PNavEdgeLoop edgeLoop in island.edgeLoops) { edgeLoopIndex++; if (edgeLoopIndex == island.boundaryEdgeLoopIndex) { continue; } int holeCornersCount = PrepareCornerVerts(edgeLoop, island, verts, indexes); Parallel3D.AddHolePolyIsland(verts, indexes, holeCornersCount, polyIsland); } int polygonCount = 0; int totalIndicsCount = 0; bool ok = Parallel3D.TriangulatePolyIsland(indices, indiceCounts, ref polygonCount, ref totalIndicsCount, 2, polyIsland); int[] indicesCopy = new int[totalIndicsCount]; Array.Copy(indices, 0, indicesCopy, 0, totalIndicsCount); int[] indiceCountsCopy = new int[polygonCount]; Array.Copy(indiceCounts, 0, indiceCountsCopy, 0, polygonCount); island.indices = indicesCopy; island.indiceCountsOfPolygons = indiceCountsCopy; island.indicsCount = totalIndicsCount; island.polygonCount = polygonCount; Parallel3D.DestroyPolyIsland(polyIsland); } } }
public static void Process(PNavMesh pNavMesh) { ParallelRigidbody3D[] pRigidbody3Ds = GameObject.FindObjectsOfType <ParallelRigidbody3D>(); using (new SProfiler($"Insert static bodies")) { //insert static bodies foreach (ParallelRigidbody3D rigidbody3D in pRigidbody3Ds) { if (rigidbody3D.bodyType != BodyType.Static) { continue; } rigidbody3D.AddToWorldForPathFinding(); } } // make grid pNavMesh.xCount = (int)((pNavMesh.worldSize.x) / pNavMesh.gridSize.x); pNavMesh.yCount = (int)((pNavMesh.worldSize.y) / pNavMesh.gridSize.y); pNavMesh.zCount = (int)((pNavMesh.worldSize.z) / pNavMesh.gridSize.z); PNavColumn[,] columns = new PNavColumn[pNavMesh.xCount, pNavMesh.zCount]; for (int x = 0; x < columns.GetLength(0); x++) { for (int z = 0; z < columns.GetLength(1); z++) { PNavColumn column = new PNavColumn(); column.nodes = new PNavNode[pNavMesh.yCount]; column.type = ParallelNavColumnType.Empty; column.surfaceNodeIndexes = new int[1]; column.surfaceNodeIndexes[0] = -1; columns[x, z] = column; } } pNavMesh.columns = columns; using (new SProfiler($"CubeCast")) { int xStart1 = 0; int xEnd1 = columns.GetLength(0); int zStart1 = 0; int zEnd1 = columns.GetLength(1); int yStart1 = 0; int yEnd1 = pNavMesh.yCount; CubeCastInRange(pNavMesh, xStart1, xEnd1, zStart1, zEnd1, yStart1, yEnd1); /* * int scale2 = 5; * * CheckVolume(xStart1, xEnd1, zStart1, zEnd1, yStart1, yEnd1, scale1, (xS, xE, zS, zE, yS, yE) => * { * CubeCastInRange(xS, xE, zS, zE, yS, yE); * CheckVolume(xS, xE, zS, zE, yS, yE, scale2, (xS2, xE2, zS2, zE2, yS2, yE2) => * { * CubeCastInRange(xS2, xE2, zS2, zE2, yS2, yE2); * }); * * }); */ } Parallel3D.CleanUp(); }
public static void CubeCastInRange(PNavMesh pNavMesh, int xStart, int xEnd, int zStart, int zEnd, int yStart, int yEnd) { PShapeOverlapResult3D result = new PShapeOverlapResult3D(); if (xEnd > pNavMesh.xCount) { xEnd = pNavMesh.xCount; } if (zEnd > pNavMesh.zCount) { zEnd = pNavMesh.zCount; } if (yEnd > pNavMesh.yCount) { yEnd = pNavMesh.yCount; } Debug.Log("CubeCastInRange:" + " xStart=" + xStart + " xEnd=" + xEnd + " zStart=" + zStart + " zEnd=" + zEnd + " yStart=" + yStart + " yEnd=" + yEnd); for (int x = xStart; x < xEnd; x++) { for (int z = zStart; z < zEnd; z++) { PNavColumn column = pNavMesh.columns[x, z]; int surfaceIndex = -1; for (int y = yStart; y < yEnd; y++) { Fix64Vec3 l; Fix64Vec3 u; pNavMesh.GetAABB(x, y, z, out l, out u); Fix64Vec3 center = Fix64.half * (l + u); Fix64Quat rot = Fix64Quat.identity; Parallel3D.OverlapCube( center, rot, pNavMesh.gridSize.x, pNavMesh.gridSize.y, pNavMesh.gridSize.z, -1, result ); PNavNode node = new PNavNode(); node.lower = l; node.upper = u; node.objectCount = result.count; node.islandIndex = -1; node.point = new PNavPoint(x, z); if (result.count > 0 && y > surfaceIndex) { surfaceIndex = y; } column.nodes[y] = node; } column.surfaceNodeIndexes[0] = surfaceIndex; if (surfaceIndex >= 0) { column.type = ParallelNavColumnType.Walkable; } else { column.type = ParallelNavColumnType.Empty; } } } }