Black model when inverting axis - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9) +--- Thread: Black model when inverting axis (/showthread.php?tid=4278) Black model when inverting axis - MSMess - 09-01-2021 Hello, 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 ? Thank you RE: Black model when inverting axis - abenedik - 09-01-2021 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). RE: Black model when inverting axis - MSMess - 09-02-2021 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;                     }                 }             }); RE: Black model when inverting axis - abenedik - 09-03-2021 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.