History

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

Models are still rescaled beforehand if thought to be in cm.

David Rowe committed 9 years ago

Commit c82ccec1 parent dbd00e31 file · +24 −6Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+24−6
@@ -5764,13 +5764,31 @@ void Application::addAssetToWorldCheckModelSize() { · 5763 unmodified lines
5764 const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f, 0.1f, 0.1f);5764 const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f, 0.1f, 0.1f);
5765 if (dimensions != DEFAULT_DIMENSIONS) {5765 if (dimensions != DEFAULT_DIMENSIONS) {
5766 // Entity has been auto-resized; adjust dimensions if it seems too big.5766 // Entity has been auto-resized; adjust dimensions if it seems too big.
5767 EntityItemProperties properties;5767 auto isResized = false;
5768 const float RESCALE_THRESHOLD = 10.0f; // Resize entities larger than this as the FBX is likely in cm or mm.5768
5769 // Entities with a dimension large than 10m are likely modelled in cm so scale to 1%.
5770 const float RESCALE_THRESHOLD = 10.0f;
5769 if (dimensions.x > RESCALE_THRESHOLD || dimensions.y > RESCALE_THRESHOLD || dimensions.z > RESCALE_THRESHOLD) {5771 if (dimensions.x > RESCALE_THRESHOLD || dimensions.y > RESCALE_THRESHOLD || dimensions.z > RESCALE_THRESHOLD) {
5770 auto dimensionsResized = dimensions * 0.01f;5772 auto previousDimensions = dimensions;
5771 properties.setDimensions(dimensionsResized);5773 dimensions *= 0.01f;
5772 qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << dimensions << " to "5774 qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
5773 << dimensionsResized;5775 isResized = true;
5776 }
5777
5778 // Scale model to have a maximum dimension of 1m
5779 const float MAXIMUM_DIMENSION = 1.0f;
5780 if (dimensions.x > MAXIMUM_DIMENSION || dimensions.y > MAXIMUM_DIMENSION || dimensions.z > MAXIMUM_DIMENSION) {
5781 auto previousDimensions = dimensions;
5782 auto scale = std::min(MAXIMUM_DIMENSION / dimensions.x, std::min(MAXIMUM_DIMENSION / dimensions.y,
5783 MAXIMUM_DIMENSION / dimensions.z));
5784 dimensions *= scale;
5785 qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
5786 isResized = true;
5787 }
5788
5789 EntityItemProperties properties;
5790 if (isResized) {
5791 properties.setDimensions(dimensions);
5774 } else {5792 } else {
5775 qInfo(interfaceapp) << "Asset" << name << "does not need to be auto-resized";5793 qInfo(interfaceapp) << "Asset" << name << "does not need to be auto-resized";
5776 }5794 }