Exemplo n.º 1
0
        /// <summary>
        /// Creates a builder.
        /// </summary>
        /// <remarks>
        /// <para>
        /// No validation is performed and the builder will use the parameters directly
        /// during the build.
        /// </para>
        /// <para>
        /// Builders created using this method are not guarenteed to produce a usable result.
        /// </para>
        /// <para>
        /// It is the responsibility of the caller to ensure thread safely if
        /// <paramref name="isThreadSafe"/> is set to true.
        /// </para>
        /// <para>
        /// <b>Warning:</b> If walkable slope if greather than zero then the builder will
        /// apply <see cref="NMGen.ClearUnwalkableTriangles"/> directly to the areas parameter.
        /// </para>
        /// </remarks>
        /// <param name="mesh">The triangle mesh to use for the build.</param>
        /// <param name="areas">The triangle areas. (Null not permitted.)</param>
        /// <param name="walkableSlope">The walkable slope.
        /// (See <see cref="NMGenParams.WalkableSlope"/>)</param>
        /// <param name="isThreadSafe">True if the builder can run safely on its own thread.</param>
        /// <returns>A builder, or null on error.</returns>
        public static InputGeometryBuilder UnsafeCreate(TriangleMesh mesh
                                                        , byte[] areas
                                                        , float walkableSlope
                                                        , bool isThreadSafe)
        {
            if (mesh == null || areas == null || mesh.triCount < 0)
            {
                return(null);
            }

            walkableSlope = System.Math.Min(NMGen.MaxAllowedSlope, walkableSlope);

            if (walkableSlope > 0)
            {
                BuildContext context = new BuildContext();
                if (!NMGen.ClearUnwalkableTriangles(context, mesh, walkableSlope, areas))
                {
                    return(null);
                }
            }

            ChunkyTriMeshBuilder builder = ChunkyTriMeshBuilder.Create(mesh, areas, 32768);

            if (builder == null)
            {
                return(null);
            }

            Vector3 bmin;
            Vector3 bmax;

            mesh.GetBounds(out bmin, out bmax);

            return(new InputGeometryBuilder(builder, bmin, bmax, isThreadSafe));
        }
Exemplo n.º 2
0
 private InputGeometryBuilder(ChunkyTriMeshBuilder builder
                              , Vector3 boundsMin
                              , Vector3 boundsMax
                              , bool isThreadSafe)
 {
     mBuilder      = builder;
     mBoundsMin    = boundsMin;
     mBoundsMax    = boundsMax;
     mIsThreadSafe = isThreadSafe;
 }
 private InputGeometryBuilder(ChunkyTriMeshBuilder builder
     , Vector3 boundsMin
     , Vector3 boundsMax
     , bool isThreadSafe)
 {
     mBuilder = builder;
     mBoundsMin = boundsMin;
     mBoundsMax = boundsMax;
     mIsThreadSafe = isThreadSafe;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Performs the build in a single step.
        /// </summary>
        public void BuildAll()
        {
            if (mBuilder == null)
            {
                return;
            }

            mBuilder.BuildAll();

            mGeom    = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Performs a single build step.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method must be called repeatedly until it resturns false in order
        /// to complete the build. (Useful in GUI environments.)
        /// </para>
        /// </remarks>
        /// <returns>
        /// True if the build is still underway and another call is required. False
        /// if the build is finished.
        /// </returns>
        public bool Build()
        {
            if (mBuilder == null)
            {
                return(false);
            }

            if (mBuilder.Build())
            {
                return(true);
            }

            mGeom    = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;

            return(false);
        }
        /// <summary>
        /// Performs the build in a single step.
        /// </summary>
        public void BuildAll()
        {
            if (mBuilder == null)
                return;

            mBuilder.BuildAll();

            mGeom = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;
        }
        /// <summary>
        /// Performs a single build step.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method must be called repeatedly until it resturns false in order
        /// to complete the build. (Useful in GUI environments.)
        /// </para>
        /// </remarks>
        /// <returns>
        /// True if the build is still underway and another call is required. False
        /// if the build is finished.
        /// </returns>
        public bool Build()
        {
            if (mBuilder == null)
                return false;

            if (mBuilder.Build())
                return true;

            mGeom = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;

            return false;
        }