Black model when inverting axis MSMess Junior Member Posts: 3 Threads: 2 Joined: Aug 2021 Reputation: 0 09-01-2021, 02:22 PM 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 Find Reply abenedik Administrator Posts: 661 Threads: 8 Joined: Sep 2009 Reputation: 10 09-01-2021, 04:31 PM 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). Andrej Benedik Find Reply MSMess Junior Member Posts: 3 Threads: 2 Joined: Aug 2021 Reputation: 0 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;                     }                 }             }); Find Reply abenedik Administrator Posts: 661 Threads: 8 Joined: Sep 2009 Reputation: 10 09-03-2021, 12:07 PM 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. Andrej Benedik Find Reply

Forum Jump:

 Users browsing this thread: 1 Guest(s)