Exemple #1
0
            /// <inheritdoc/>
            public void Execute(int index)
            {
                NodeTransform nt = nodesTransforms[index];

                // start a bit before the node just in case there's an obstacle overlapping a bit
                Vector3 center = nt.Pos - nt.Up * 0.1f;

                // nodes are squares and we don't plan to change it
                float   halfWidth   = NodeHalfSize * settings.boxNodePercentage;
                float   halfDepth   = halfWidth;
                Vector3 halfExtents = new Vector3(halfWidth, 0.01f, halfDepth);

                commands[index] = new BoxcastCommand(center, halfExtents, nt.GetRotation(), nt.Up, settings.maxCharacterHeight, settings.mask);
            }
Exemple #2
0
            /// <inheritdoc/>
            public void Execute(int index)
            {
                NodeTransform nt = nodesTransforms[index];

                // start a bit before the node just in case there's an obstacle overlapping a bit
                Vector3 center = (Vector3)(nt.pos - nt.up * 0.1f);

                // nodes are squares and we don't plan to change it
                float   halfWidth   = NodeHalfSize * boxNodePercentage;
                Vector3 halfExtents = new Vector3(halfWidth, 0.01f, halfWidth);

                commands[index] = new BoxcastCommand(center, halfExtents, (Quaternion)nt.GetRotation(), (Vector3)nt.up, maxCharacterHeight, mask);
            }
Exemple #3
0
        /// <summary>
        /// Adds the nodes debugging.
        /// </summary>
        public void RecalculateDebug()
        {
            DisposeDebugNativeDatastructures();
            int numNodes = gridDepth * gridWidth;

            // prepare the job that calculates the vertices for the neighbor connection lines
            int arrayLength = numNodes * NodeNeighbors * 2;

            connectionsMeshVertices = new NativeArray <Vector3>(arrayLength, Allocator.Persistent);
            connectionsMeshIndices  = new NativeArray <int>(arrayLength, Allocator.Persistent);

            CalculateConnectionMeshJob calcConnectionsMeshJob = new CalculateConnectionMeshJob(NodeNeighbors, nodesTransforms, nodesNeighbors, connectionsMeshVertices, connectionsMeshIndices);
            JobHandle calcConnectionMeshHandle = calcConnectionsMeshJob.Schedule(numNodes, 8);

            // do other required stuff before calling complete so we have actual parallelism
            MeshRenderer mr = Utils.GetOrAddComponent <MeshRenderer>(transform, out bool createdRenderer);

            mr.shadowCastingMode    = ShadowCastingMode.Off;
            mr.sharedMaterial       = nodeConnectionsMaterial;
            mr.lightProbeUsage      = LightProbeUsage.Off;
            mr.reflectionProbeUsage = ReflectionProbeUsage.Off;
            mr.enabled = showNodesConnections;

            MeshFilter filter = Utils.GetOrAddComponent <MeshFilter>(transform, out bool createdFilter);

            filter.sharedMesh = connectionsMesh;

            // the nodes themselves
            nodeBatcher.Clear();

            if (showNodes)
            {
                for (int i = 0; i < numNodes; i++)
                {
                    NodeTransform nt       = nodesTransforms[i];
                    NodeType      nodeType = nodesTypes[i];

                    Color32 c;

                    if (nodeType == NodeType.Invalid)
                    {
                        c = invalidNodeColor;
                    }
                    else if (nodeType == NodeType.OccupiedByObstacle)
                    {
                        c = nonWalkableNodeColor;
                    }
                    else
                    {
                        c = walkableNodeColor;
                    }

                    Vector3   pos = nt.Pos + (nt.Up * NodeVisualNormalOffset);
                    Matrix4x4 trs = Matrix4x4.TRS(pos, nt.GetRotation(), Vector3.one);

                    // batch each node quad debug
                    nodeBatcher.AddItem(c, trs);
                }
            }

            calcConnectionMeshHandle.Complete();

            // set the mesh using the results of the job
            connectionsMesh.SetVertices(calcConnectionsMeshJob.vertices);
            connectionsMesh.SetIndices(calcConnectionsMeshJob.indices, MeshTopology.Lines, 0);
        }