/// <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; }
private void ApplyTangents() { var tangents = GetTangents(); if (tangents != null) { unityTangents.Clear(); for (int i = 0; i < tangents.Length; ++i) { unityTangents.Add(tangents[i]); } unityMesh.SetTangents(unityTangents); } }