I am transforming a ModelVisual3D using a matrix. If I try to invert an axis e.g. for x multiply the top row values with -1, all the Models3D turn black. There seems to be a problem with the lightning calculation I just don't know where.
Inverting the model normals kinda fixes the lightning but then naturally has the surfaces in the wrong direction.
The lightning is the ShowCameraLight from the TargetPositionCamera.
Any ideas how to fix it ?
Multiplying x by -1 inverts the orientation of the triangles.
This would require to invert the orientation of triangles - this could be done by swapping two triangle indices, for example if TriangleIndices are: 0 1 2 2 3 4 (two triangles with positions: first: 0 1 2, second: 2 3 4); to invert triangle orientation just swap two inices: 1 0 2 3 2 4 (first triangle 1 0 2; second: 3 2 4).
An easier option is to assign your material to BackMaterial instead of Material - BackMaterial is used to render back-facing triangles (a standard way to "debug" meshes is to set Material to green DiffuseMaterial and BackMaterial to red DiffuseMaterial - this shows which triangles need to be inverted).
09-02-2021, 07:53 AM
(This post was last modified: 09-02-2021, 08:19 AM by MSMess.)
Thank you! Works great.
Here the code I used to fix it:
ModelIterator.IterateGeometryModel3DObjects(MyModel, null, delegate (GeometryModel3D geometryModel3D, Transform3D transform3D)
var meshGeometry3D = (MeshGeometry3D)geometryModel3D.Geometry;
for (int i = 0; i < meshGeometry3D.TriangleIndices.Count; i++)
if ((i % 3) == 0)
int temp = meshGeometry3D.TriangleIndices[i];
meshGeometry3D.TriangleIndices[i] = meshGeometry3D.TriangleIndices[i + 1];
meshGeometry3D.TriangleIndices[i + 1] = temp;
Great idea to use ModelIterator.IterateGeometryModel3DObjects to invert the orientation of triangles in the meshGeometry3D.TriangleIndices.
One small comment: you can use "i+=3" instead of "i++" and remove the "if ((i % 3) == 0)" then.
Thank you for sharing the code for the solution.