Open stlemme opened 10 years ago
Custom vertex shaders that calculate the vertex position different from the standard model (gl_Position = modelViewProjectionMatrix * vec4(position, 1.0)
) lead to wrong bounding box calculations and break culling etc. For these cases (and cases where the bounding box changes per frame and the author want to avoid recalculation), the user can annotate a bounding box:
<mesh type="triangles">
<float3 name="boundingBox">-5 -5 -5 5 5 5</float3>
</mesh>`
This needs to be an entry of the mesh. The first tuple is the minimum vector, the second tuple the maximum of the axis-aligned bounding box in object-space.
However, since this does not work in the provided example, there is an issue in the calculation of the culling.
Since it is the "axis-aligned bounding box in object-space", it is clear that it will not work in the intended way, because the bbox should be constant in eye space.
The above commit adds a new method to mesh, model and group nodes: node.setWorldSpaceBoundingBox. This method takes an XML3DBox as argument, which replaces the automatically generated bounding box for this node.
This bounding box is NOT cached anywhere, so any change that causes the node's world space bounding box to be re-calculated will overwrite the user defined bounding box. This can happen, for example, if mesh data changes or if the world space bounding box of a child node changes (in the case of group and model nodes). We also need to create some unit tests for this new functionality. For these reasons I'm leaving the issue open for now.
Using custom shaders (in particular custom vertex shaders) that use the model-view matrix in an unusual fashion (i.e. skyboxes ignore the translation part) leads to wrong culling behavior. "Da würd wat falsch berechned."