public void EvaluateNormals(OutputMesh mesh, CPNGuide guide) { int N = guide.GetN(); if (N <= 0) { return; } bool doTangents = mesh.DoUseTangents(); bool doNormals = mesh.DoNormals(); if (doNormals) { float step = 1.0f / N; for (int j = 1; j < N; j++) { EvalAt(j * step, guide); Vector3 dev; Vector3 normal = EvalNormal(guide, out dev); int index = guide.GetIndex(j); mesh.SetNormal(index, normal.normalized); if (doTangents) { mesh.SetTangent(index, GetTangent(guide, dev, normal).normalized); } } if (doTangents) { for (int j = 0; j <= N; j += N) { EvalAt(j * step, guide); Vector3 dev = EvalDev(guide); int index = guide.GetIndex(j); Vector3 normal = mesh.GetNormal(index); mesh.SetTangent(index, GetTangent(guide, dev, normal).normalized); } } } }
int WriteVertices(OutputMesh mesh) { int numberOfVertices = subSet == null?curvedPolygonsNet.GetNumberOfVertices() : subSet.vertices.Length; Vector3[] vertices = curvedPolygonsNet.GetVertices(); Vector3[] normals = curvedPolygonsNet.GetNormals(); Vector3[] uvs = curvedPolygonsNet.GetUv(); Vector3[][] properties = curvedPolygonsNet.GetProperties3(); int countProperties = mesh.CountProperties(); //Vector3[] tangents = curvedPolygonsNet.GetTangents(); //bool doTangents = tangents != null; bool doUvs = uvs != null && mesh.DoUseUVs(); bool doNormals = normals != null && mesh.DoNormals(); for (int i = 0; i < numberOfVertices; i++) { int index = subSet == null ? i : subSet.vertices[i]; mesh.SetVertex(index, vertices[index]); if (doUvs) { mesh.SetUV(index, uvs[index]); } if (doNormals) { mesh.SetNormal(index, normals[index]); } for (int k = 0; k < countProperties; k++) { mesh.SetProperty3(index, k, properties[k][index]); } } return(numberOfVertices); }