Loaded assets vertical position

Hi,

I am loading some assets and find that some assets are positioned vertically above the ground (like SheenChair.glb), but some are positioned vertically below the ground (like BoomBox.gltf), even though they all having Y = 0.

Question: is there a way to detect which asset are properly placed above the ground and detect those are below the ground?

Thanks.

finally I am using getMinMax to calculate the min. if the min.y is negative, I assume that it is below ground.

note: getMinMax function taken from https://www.babylonjs-playground.com/#QHMT1#18

function getMinMax(mesh, computeWorldMatrix=true) { //my getMinMax wrapper
	var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
	var max = new BABYLON.Vector3(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);
	_getMinMax(mesh, min, max, computeWorldMatrix);
	return {"min":min,"max":max};
}
function _getMinMax(mesh, min, max, computeWorldMatrix) { //original getMinMax
	if (computeWorldMatrix) {
		mesh.computeWorldMatrix(true);
	}
	
	var bi = mesh.getBoundingInfo();
	var minimum = bi.boundingBox.minimumWorld;
	var maximum = bi.boundingBox.maximumWorld;
	
	if (minimum.x < min.x) {
		min.x = minimum.x;
	}
	if (minimum.y < min.y) {
		min.y = minimum.y;
	}
	if (minimum.z < min.z) {
		min.z = minimum.z;
	}

	if (maximum.x > max.x) {
		max.x = maximum.x;
	}
	if (maximum.y > max.y) {
		max.y = maximum.y;
	}
	if (maximum.z > max.z) {
		max.z = maximum.z;
	}
	
	var children = mesh.getChildMeshes();
	
	for (var i = 0; i < children.length; i++){
		getMinMax(children[i], min, max, computeWorldMatrix);
	}
}
2 Likes

There is a helper function on all babylon nodes called getHierarchyBoundingVectors to compute this if needed :slight_smile:

Thanks. I will check it out.