mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 21:26:25 +02:00
Scale all imported Clara models to have max dimension of exactly 1m
This commit is contained in:
parent
349765ad74
commit
16418d52d2
1 changed files with 25 additions and 43 deletions
|
@ -5752,46 +5752,21 @@ void Application::addAssetToWorldCheckModelSize() {
|
||||||
auto dimensions = properties.getDimensions();
|
auto dimensions = properties.getDimensions();
|
||||||
|
|
||||||
const QString GRABBABLE_USER_DATA = "{\"grabbableKey\":{\"grabbable\":true}}";
|
const QString GRABBABLE_USER_DATA = "{\"grabbableKey\":{\"grabbable\":true}}";
|
||||||
|
bool doResize = false;
|
||||||
|
|
||||||
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.
|
|
||||||
auto isResized = false;
|
|
||||||
|
|
||||||
// Entities with a dimension large than 10m are likely modelled in cm so scale to 1%.
|
// Scale model so that its maximum is exactly specific size.
|
||||||
const float RESCALE_THRESHOLD = 10.0f;
|
|
||||||
if (dimensions.x > RESCALE_THRESHOLD || dimensions.y > RESCALE_THRESHOLD || dimensions.z > RESCALE_THRESHOLD) {
|
|
||||||
auto previousDimensions = dimensions;
|
|
||||||
dimensions *= 0.01f;
|
|
||||||
qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
|
|
||||||
isResized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scale model to have a maximum dimension of 1m
|
|
||||||
const float MAXIMUM_DIMENSION = 1.0f;
|
const float MAXIMUM_DIMENSION = 1.0f;
|
||||||
if (dimensions.x > MAXIMUM_DIMENSION || dimensions.y > MAXIMUM_DIMENSION || dimensions.z > MAXIMUM_DIMENSION) {
|
auto previousDimensions = dimensions;
|
||||||
auto previousDimensions = dimensions;
|
auto scale = std::min(MAXIMUM_DIMENSION / dimensions.x, std::min(MAXIMUM_DIMENSION / dimensions.y,
|
||||||
auto scale = std::min(MAXIMUM_DIMENSION / dimensions.x, std::min(MAXIMUM_DIMENSION / dimensions.y,
|
MAXIMUM_DIMENSION / dimensions.z));
|
||||||
MAXIMUM_DIMENSION / dimensions.z));
|
dimensions *= scale;
|
||||||
dimensions *= scale;
|
qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
|
||||||
qInfo(interfaceapp) << "Asset" << name << "auto-resized from" << previousDimensions << " to " << dimensions;
|
doResize = true;
|
||||||
isResized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItemProperties properties;
|
|
||||||
if (isResized) {
|
|
||||||
properties.setDimensions(dimensions);
|
|
||||||
} else {
|
|
||||||
qInfo(interfaceapp) << "Asset" << name << "does not need to be auto-resized";
|
|
||||||
}
|
|
||||||
properties.setVisible(true);
|
|
||||||
properties.setCollisionless(false);
|
|
||||||
properties.setUserData(GRABBABLE_USER_DATA);
|
|
||||||
properties.setLastEdited(usecTimestampNow());
|
|
||||||
entityScriptingInterface->editEntity(entityID, properties);
|
|
||||||
|
|
||||||
item = _addAssetToWorldResizeList.erase(item); // Finished with this entity.
|
|
||||||
|
|
||||||
|
item = _addAssetToWorldResizeList.erase(item); // Finished with this entity; advance to next.
|
||||||
} else {
|
} else {
|
||||||
// Increment count of checks done.
|
// Increment count of checks done.
|
||||||
_addAssetToWorldResizeList[entityID]++;
|
_addAssetToWorldResizeList[entityID]++;
|
||||||
|
@ -5800,21 +5775,28 @@ void Application::addAssetToWorldCheckModelSize() {
|
||||||
if (_addAssetToWorldResizeList[entityID] > CHECK_MODEL_SIZE_MAX_CHECKS) {
|
if (_addAssetToWorldResizeList[entityID] > CHECK_MODEL_SIZE_MAX_CHECKS) {
|
||||||
// Have done enough checks; model was either the default size or something's gone wrong.
|
// Have done enough checks; model was either the default size or something's gone wrong.
|
||||||
|
|
||||||
EntityItemProperties properties;
|
// Rescale all dimensions.
|
||||||
properties.setVisible(true);
|
const glm::vec3 UNIT_DIMENSIONS = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
properties.setCollisionless(false);
|
dimensions = UNIT_DIMENSIONS;
|
||||||
properties.setUserData(GRABBABLE_USER_DATA);
|
qInfo(interfaceapp) << "Asset" << name << "auto-resize timed out; resized to " << dimensions;
|
||||||
properties.setLastEdited(usecTimestampNow());
|
doResize = true;
|
||||||
entityScriptingInterface->editEntity(entityID, properties);
|
|
||||||
qInfo(interfaceapp) << "Asset" << name << "auto-resize timed out";
|
|
||||||
|
|
||||||
item = _addAssetToWorldResizeList.erase(item); // Finished with this entity.
|
|
||||||
|
|
||||||
|
item = _addAssetToWorldResizeList.erase(item); // Finished with this entity; advance to next.
|
||||||
} else {
|
} else {
|
||||||
// No action on this entity; advance to next.
|
// No action on this entity; advance to next.
|
||||||
++item;
|
++item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (doResize) {
|
||||||
|
EntityItemProperties properties;
|
||||||
|
properties.setDimensions(dimensions);
|
||||||
|
properties.setVisible(true);
|
||||||
|
properties.setCollisionless(false);
|
||||||
|
properties.setUserData(GRABBABLE_USER_DATA);
|
||||||
|
properties.setLastEdited(usecTimestampNow());
|
||||||
|
entityScriptingInterface->editEntity(entityID, properties);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop timer if nothing in list to check.
|
// Stop timer if nothing in list to check.
|
||||||
|
|
Loading…
Reference in a new issue