Exemplo n.º 1
0
    /// <summary>
    /// Generates the patch mesh and assigns it to the MeshFilter of this GameObject.
    /// </summary>
    /// <param name="controlPoints"></param>
    /// <param name="width">Number of control points in x direction</param>
    /// <param name="height">Number of control points in y direction</param>
    public void UpdatePatchMesh(List <Vector3> controlPoints, int width, int height)
    {
        Mesh patchMesh = PatchMesh.GeneratePatchMesh(controlPoints, width, height, this.resolutionWidth, this.resolutionHeight);
        Mesh oldMesh   = this.GetComponent <MeshFilter>().sharedMesh;

        Destroy(oldMesh);
        this.GetComponent <MeshFilter>().mesh = patchMesh;
    }
        /// <summary>
        /// Generates the patch mesh and assigns it to the MeshFilter of this GameObject.
        /// </summary>
        /// <param name="controlPoints"></param>
        /// <param name="width">Number of control points in x direction</param>
        /// <param name="height">Number of control points in y direction</param>
        private void UpdatePatchMesh(List <Vector3> controlPoints, int width, int height)
        {
            if (height < 3 || width < 3 || controlPoints.Count / width != height)
            {
                Debug.LogWarning("The amount of control points is invalid! \n There must at least be 3x3 control points. Amount of control ponits must be a multiple of width.");
                SetMesh(null);
                return;
            }

            Mesh patchMesh = PatchMesh.GeneratePatchMesh(controlPoints, width, height, this.ResolutionWidth, this.ResolutionHeight);

            SetMesh(patchMesh);
        }