fix the error: ArgumentNullException: Texture entry face cannot be null. Parameter name:…
- User
fix the error: ArgumentNullException: Texture entry face cannot be null. Parameter name: teFace. In the C# script for Unity below.
public void TransformTexCoords(List vertices, OMVVector3 center, Primitive.TextureEntryFace teFace, OMVVector3 primScale) { // Check if teFace is null to prevent NullReferenceException if (teFace == null) { throw new ArgumentNullException(nameof(teFace), "Texture entry face cannot be null."); }
// Compute trig stuff up front float cosineAngle = (float)Math.Cos(teFace.Rotation); float sinAngle = (float)Math.Sin(teFace.Rotation); for (int ii = 0; ii < vertices.Count; ii++) { // Tex coord comes to us as a number between zero and one // Transform about the center of the texture Vertex vert = vertices[ii]; // Apply planar transforms to the UV first if applicable if (teFace.TexMapType == MappingType.Planar) { OMVVector3 binormal; float d = OMVVector3.Dot(vert.Normal, OMVVector3.UnitX); if (d >= 0.5f || d <= -0.5f) { binormal = OMVVector3.UnitY; if (vert.Normal.X < 0f) binormal *= -1; } else { binormal = OMVVector3.UnitX; if (vert.Normal.Y > 0f) binormal *= -1; } OMVVector3 tangent = binormal % vert.Normal; OMVVector3 scaledPos = vert.Position * primScale; vert.TexCoord.X = 1f + (OMVVector3.Dot(binormal, scaledPos) * 2f - 0.5f); vert.TexCoord.Y = -(OMVVector3.Dot(tangent, scaledPos) * 2f - 0.5f); } float repeatU = teFace.RepeatU; float repeatV = teFace.RepeatV; float tX = vert.TexCoord.X - 0.5f; float tY = vert.TexCoord.Y - 0.5f; vert.TexCoord.X = (tX * cosineAngle + tY * sinAngle) * repeatU + teFace.OffsetU + 0.5f; vert.TexCoord.Y = (-tX * sinAngle + tY * cosineAngle) * repeatV + teFace.OffsetV + 0.5f; vertices[ii] = vert; }}
- Assistant
The error
ArgumentNullException: Texture entry face cannot be null. Parameter name: teFaceindicates that theteFaceargument being passed to theTransformTexCoordsmethod is null, which is not allowed since the method requires a validPrimitive.TextureEntryFaceobject.