First results:
I took the file Babylon.js-master/src/Rendering/edgesRenderer.ts and made a few line changes - very crude.
I simply took the camera position minus the midpoint of each edge as one vector (normalised) and then calculated dot products of this with the face normals either side of the edge under consideration. I commented out the “sharpness” (epsilon) test and instead checked if the dot products were of opposite polarity indicating one front facing and one back facing - if so then draw the edge otherwise do not.
The next thing was to get the triangle faces to be the same colour as the background so that they can occlude edges in the depth test but do so in a way that makes it look as if they are not there and we are simply seeing the background.
I did not achieve this in the code - instead I was playing around with Babylon Inspector and clicked on Scene in the left hand filter panel and rendering mode in the right hand panel. I then selected the fog mode option to linear and set the colour for the fog to the same value as I have for clear colour this had the desired effect although I have not yet read the doc on “fog”. I have not investigated yet but it is interesting that fog seems to have the desired effect. If I had not chanced upon this the pictures would show a ‘solid’ white (shaded) material where you would expect bone and I would have had to contrast this by setting the lines currently shown in white to a contrasting colour like red.
One of the ribs shown is dense with lines - this mesh is a bit odd I need to check it out, probably some badly set normals - I am ignoring that for now - its the mesh at fault I know that, it always looks a little odd in shaded mode as well.
The downside of this method is that the hidden line removal “effect” is not dynamic ( judging by observed results only, it looks as if ) the code in edgesRenderer.ts is called only once and does not update when the view direction changes. This makes a lot of sense since sharp edges are not defined by view direction and so need calculating only once - but the conditions for hidden line removal are very much dependent on view direction since we draw only lines (edges) that lie between front and back facing faces and that will of course change as the view direction changes.
Its actually what I would call hybrid behavior because of course the occluding property of triangles is recalculated when the view changes - its part and parcel of ordinary shading.
The actual result obtained thus far might be loosely described as follows.
-
Silhouette edges ( between front and back facing faces ) are calculated once and stored as a mesh, they are visible from any view but are not recalculated and so stay in position with respect to their “owner” triangles - just as if we had drawn the silhouette edges onto the model.
-
Silhouette edges are correctly occluded (for the most part) when the model is viewed from different angles but the silhouette edges themselves are no longer correct for that view, we should have selected a different set, discarded the old line mesh and made up a new one.
Here we see the same model from the back - occlusion is working correctly but the actual curves being occluded (or not occluded as may be the case) are not correct for this view, they were calculated when the model was first rendered from the view position indicated by the first two pictures.
Thoughts to self / others
-
Are the hidden line removed drawings worth pursuing? they are a bit “bitty” will probably look best on very refined (high density) meshes - might look better with tweaks etc. The third picture should be ignored of course when judging quality.
-
Why does fog work so effectively? Simply not investigated yet. A guess would be that fog processing occurs after lines and triangles are drawn, fog perhaps ignores wire meshes and so just obscures the triangles but crucially by that stage the triangles have done their job of obscuring parts of wire edges. This does suggest that there is an opportunity within the code and GPU phases to get a cheap “now I am done with triangles so just obscure them (with whatever functionality is used for the fog feature) but allow edges not occluded by triangles show through”. My fog is very thick since the scale of my model is around 1000 and my camera is at a distance of something like 5000 - more than likely the bones didn’t make it through the fog - perfect !
-
How easy would it be to get the code to throw away the edge line mesh it has created for an “old” view and recalculate the same for a new view? ie something short of the sophistication of real time animation with hidden line removal but at least something that could respond to a “refresh” command from the user or simply trigger when a camera moves or similar.
-
In my case I had to set the line width to 300, I can see in the code that the number supplied is divided by a factor of 50 - my models are large in the Babylon space (1000 units tall) numbers seem sensible but I have not looked at this side of things carefully - just cranked the number up enough to get a decent result.