Esempio n. 1
0
        /// <summary>
        /// Voxelizes the triangles from the provided <see cref="ChunkyTriMesh"/> into the
        /// heightfield.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The chunks that are voxelized is controled by the bounds parameters.
        /// </para>
        /// </remarks>
        /// <param name="context">The build context.</param>
        /// <param name="mesh">The mesh.</param>
        /// <param name="boundsMin">The minimum bounds for the mesh query.</param>
        /// <param name="boundsMax">The maximum bounds for the mesh query.</param>
        /// <param name="flagMergeThreshold">
        /// The distance where the walkable flag is favored over the non-walkable flag.
        /// [Limit: >= 0] [Normal: 1]
        /// </param>
        /// <returns>True if the operation was successful.</returns>
        public bool AddTriangles(BuildContext context, ChunkyTriMesh mesh
                                 , Vector3 boundsMin, Vector3 boundsMax
                                 , int flagMergeThreshold)
        {
            if (IsDisposed || mesh == null || mesh.IsDisposed)
            {
                return(false);
            }

            List <ChunkyTriMeshNode> nodeList = new List <ChunkyTriMeshNode>();

            int triCount = mesh.GetChunks(boundsMin.x, boundsMin.z
                                          , boundsMax.x, boundsMax.z
                                          , nodeList);

            if (triCount == 0)
            {
                return(true);
            }

            return(HeightfieldEx.nmhfRasterizeNodes(context.root
                                                    , mesh.verts
                                                    , mesh.tris
                                                    , mesh.areas
                                                    , nodeList.ToArray()
                                                    , nodeList.Count
                                                    , root
                                                    , flagMergeThreshold));
        }
Esempio n. 2
0
        private void UpdateSubdivide()
        {
            mIter = 0;
            while (mStack.Count > 0 && mIter < mNodeIterations)
            {
                Subdivide c = mStack.Peek().Build(buildData);

                if (c == null)
                {
                    // Finished.
                    buildData.Return(mStack.Pop());
                }
                else
                {
                    // New sub-divide.
                    mStack.Push(c);
                }

                mIter++;
            }

            if (mStack.Count == 0)
            {
                mMesh = new ChunkyTriMesh(mVerts
                                          , mVertCount
                                          , buildData.tris
                                          , buildData.areas
                                          , mTriCount
                                          , buildData.nodes
                                          , buildData.curNode);

                buildData.Reset();  // Release references.

                mState = BuildState.Complete;
            }
        }
 internal InputGeometry(ChunkyTriMesh mesh, Vector3 boundsMin, Vector3 boundsMax)
 {
     mBoundsMin = boundsMin;
     mBoundsMax = boundsMax;
     mMesh = mesh;
 }
Esempio n. 4
0
        /// <summary>
        /// Voxelizes the triangles from the provided <see cref="ChunkyTriMesh"/> into the 
        /// heightfield.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The chunks that are voxelized is controled by the bounds parameters.
        /// </para>
        /// </remarks>
        /// <param name="context">The build context.</param>
        /// <param name="mesh">The mesh.</param>
        /// <param name="boundsMin">The minimum bounds for the mesh query.</param>
        /// <param name="boundsMax">The maximum bounds for the mesh query.</param>
        /// <param name="flagMergeThreshold">
        /// The distance where the walkable flag is favored over the non-walkable flag. 
        /// [Limit: >= 0] [Normal: 1]
        /// </param>
        /// <returns>True if the operation was successful.</returns>
        public bool AddTriangles(BuildContext context, ChunkyTriMesh mesh
            , Vector3 boundsMin, Vector3 boundsMax
            , int flagMergeThreshold)
        {
            if (IsDisposed || mesh == null || mesh.IsDisposed)
                return false;

            List<ChunkyTriMeshNode> nodeList = new List<ChunkyTriMeshNode>();
            
            int triCount =  mesh.GetChunks(boundsMin.x, boundsMin.z
                , boundsMax.x, boundsMax.z
                , nodeList);

            if (triCount == 0)
                return true;

            return HeightfieldEx.nmhfRasterizeNodes(context.root
                , mesh.verts
                , mesh.tris
                , mesh.areas
                , nodeList.ToArray()
                , nodeList.Count
                , root
                , flagMergeThreshold);
        }