コード例 #1
0
        /// <summary>Copies the contents of the generated mesh to a [UnityEngine.Mesh](https://docs.unity3d.com/ScriptReference/Mesh.html).</summary>
        /// <param name="mesh">The mesh to copy the <see cref="Chisel.Core.GeneratedMeshContents"/> into</param>
        /// <remarks><code>
        /// MeshDescription meshDescription = ... ;
        /// GeneratedMeshContents contents = tree.GetGeneratedMesh(meshDescription);
        /// UnityEngine.Mesh unityMesh = new UnityEngine.Mesh();
        /// contents.CopyTo(unityMesh);
        /// </code>
        /// See the [Create Unity Meshes](~/documentation/createUnityMesh.md) article for more information.
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="mesh"/> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when <paramref name="mesh"/> is invalid. This can happen when the mesh has already been destroyed.</exception>
        public void CopyTo(UnityEngine.Mesh mesh)
        {
            if (object.ReferenceEquals(mesh, null))
            {
                throw new ArgumentNullException("mesh");
            }
            if (!mesh)
            {
                throw new ArgumentException("mesh", "mesh is not valid, it might have already been destroyed");
            }

            if (description.vertexCount < 3 ||
                description.indexCount < 3)
            {
                mesh.Clear();
                return;
            }

            mesh.SetVertices(positions);
            if (normals.IsCreated)
            {
                mesh.SetNormals(normals);
            }
            if (tangents.IsCreated)
            {
                mesh.SetTangents(tangents);
            }
            if (uv0.IsCreated)
            {
                mesh.SetUVs(0, uv0);
            }

            mesh.SetTriangles(indices.ToArray(), 0, false);
            mesh.bounds = bounds;
        }
コード例 #2
0
        private void ApplyNormals()
        {
            var normals = GetNormals();

            if (normals != null)
            {
                unityNormals.Clear();

                for (int i = 0; i < normals.Length; ++i)
                {
                    unityNormals.Add(normals[i]);
                }

                unityMesh.SetNormals(unityNormals);
            }
        }