Rescale models if necessary to have their largest dimension be 1m

Models are still rescaled beforehand if thought to be in cm.
This commit is contained in:
David Rowe 2016-12-15 12:25:56 +13:00 committed by Seth Alves
parent d2468b63fe
commit a63beedff4

View file

@ -5815,13 +5815,31 @@ void Application::addAssetToWorldCheckModelSize() {
const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f, 0.1f, 0.1f); const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f, 0.1f, 0.1f);
if (dimensions != DEFAULT_DIMENSIONS) { if (dimensions != DEFAULT_DIMENSIONS) {
// Entity has been auto-resized; adjust dimensions if it seems too big. // Entity has been auto-resized; adjust dimensions if it seems too big.
EntityItemProperties properties; auto isResized = false;
const float RESCALE_THRESHOLD = 10.0f; // Resize entities larger than this as the FBX is likely in cm or mm.
// Entities with a dimension large than 10m are likely modelled in cm so scale to 1%.
const float RESCALE_THRESHOLD = 10.0f;
if (dimensions.x > RESCALE_THRESHOLD || dimensions.y > RESCALE_THRESHOLD || dimensions.z > RESCALE_THRESHOLD) { if (dimensions.x > RESCALE_THRESHOLD || dimensions.y > RESCALE_THRESHOLD || dimensions.z > RESCALE_THRESHOLD) {
auto dimensionsResized = dimensions * 0.01f; auto previousDimensions = dimensions;
properties.setDimensions(dimensionsResized); dimensions *= 0.01f;
qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << dimensions << " to " qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
<< dimensionsResized; isResized = true;
}
// Scale model to have a maximum dimension of 1m
const float MAXIMUM_DIMENSION = 1.0f;
if (dimensions.x > MAXIMUM_DIMENSION || dimensions.y > MAXIMUM_DIMENSION || dimensions.z > MAXIMUM_DIMENSION) {
auto previousDimensions = dimensions;
auto scale = std::min(MAXIMUM_DIMENSION / dimensions.x, std::min(MAXIMUM_DIMENSION / dimensions.y,
MAXIMUM_DIMENSION / dimensions.z));
dimensions *= scale;
qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
isResized = true;
}
EntityItemProperties properties;
if (isResized) {
properties.setDimensions(dimensions);
} else { } else {
qInfo(interfaceapp) << "Asset" << name << "does not need to be auto-resized"; qInfo(interfaceapp) << "Asset" << name << "does not need to be auto-resized";
} }