kzhsw
December 30, 2024, 8:41am
1
Version: 7.42.0
Engine: webgl2
Steps to reproduce:
get a model here:
teapots_galore.zip (78.9 KB)
Display inspector
Find teapot
mesh
Check “Render vertex normals”
Expected:
Normals rendered at the position near each instance.
Actual:
It renders at the center of scene
sebavan
December 31, 2024, 12:21am
2
This is expected as the normals are only displayed for the root model of the thinInstances.
kzhsw
December 31, 2024, 12:40am
3
But why is it that big? On non instanced mesh it looks just ok.
sebavan
December 31, 2024, 6:24pm
4
This is probably related to the scale of the element
The scale depends on the bounding box of the mesh:
const normals = mesh.getVerticesData(VertexBuffer.NormalKind);
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
const color = Color3.White();
const bbox = mesh.getBoundingInfo();
const diag = bbox.maximum.subtractToRef(bbox.minimum, TmpVectors.Vector3[0]);
const size = diag.length() * 0.05;
const lines = [];
for (let i = 0; i < normals!.length; i += 3) {
const v1 = Vector3.FromArray(positions!, i);
const v2 = v1.add(Vector3.FromArray(normals!, i).scaleInPlace(size));
lines.push([v1, v2]);
}
As the bouding box of a mesh with thin instances encompasses all instances, the scale can be quite big. In this case, we should maybe calculate a scale for each instance separately and use the mean of these scales…
2 Likes
kzhsw
January 3, 2025, 1:49am
6
Or just use mesh.rawBoundingInfo/mesh._thinInstanceDataStorage.boundingVectors for root model, and render it instanced