Support for scale property on model overlays

If "scale" property is present but "dimensions" are not, the model is NOT scale to fit.
And the scale of the model's natural dimensions will be affected by the scale properties.

If only the "dimensions" property is present, the model will "scale to fit" the dimensions.

If both properties are present, the model still be "scale to fit" but the dimension will be scaled by the scale factor.

For example:

If a model is loaded that is 2cm tall, is loaded with no "dimensions" or "scale" properties.
It will be displayed as 2cm tall.

    {"scale": 2}

The above properties will result in a model that is 4cm tall.

    {"dimensions": 1}

This will result in a model that is 1cm tall.

    {"scale": 2, "dimensions" 2}

Will result in a model that is 2cm tall.
This commit is contained in:
Anthony Thibault 2016-07-13 07:32:05 -07:00 committed by Anthony J. Thibault
parent e0739dcc9c
commit 1d77cec125
5 changed files with 60 additions and 36 deletions

View file

@ -19,8 +19,7 @@ QString const ModelOverlay::TYPE = "model";
ModelOverlay::ModelOverlay()
: _model(std::make_shared<Model>(std::make_shared<Rig>())),
_modelTextures(QVariantMap()),
_updateModel(false)
_modelTextures(QVariantMap())
{
_model->init();
_isLoaded = false;
@ -44,7 +43,11 @@ void ModelOverlay::update(float deltatime) {
if (_updateModel) {
_updateModel = false;
_model->setSnapModelToCenter(true);
_model->setScaleToFit(true, getDimensions());
if (_scaleToFit) {
_model->setScaleToFit(true, getScale() * getDimensions());
} else {
_model->setScale(getScale());
}
_model->setRotation(getRotation());
_model->setTranslation(getPosition());
_model->setURL(_url);
@ -84,16 +87,33 @@ void ModelOverlay::render(RenderArgs* args) {
}
void ModelOverlay::setProperties(const QVariantMap& properties) {
auto position = getPosition();
auto rotation = getRotation();
auto origPosition = getPosition();
auto origRotation = getRotation();
auto origDimensions = getDimensions();
auto origScale = getScale();
Volume3DOverlay::setProperties(properties);
Base3DOverlay::setProperties(properties);
if (position != getPosition() || rotation != getRotation()) {
_updateModel = true;
auto scale = properties["scale"];
if (scale.isValid()) {
setScale(vec3FromVariant(scale));
}
auto dimensions = properties["dimensions"];
if (dimensions.isValid()) {
_scaleToFit = true;
setDimensions(vec3FromVariant(dimensions));
} else if (scale.isValid()) {
// if "scale" property is set but "dimentions" is not.
// do NOT scale to fit.
if (scale.isValid()) {
_scaleToFit = false;
}
}
if (origPosition != getPosition() || origRotation != getRotation() || origDimensions != getDimensions() || origScale != getScale()) {
_updateModel = true;
}
auto urlValue = properties["url"];
if (urlValue.isValid() && urlValue.canConvert<QString>()) {
@ -123,8 +143,11 @@ QVariant ModelOverlay::getProperty(const QString& property) {
if (property == "url") {
return _url.toString();
}
if (property == "dimensions" || property == "scale" || property == "size") {
return vec3toVariant(_model->getScaleToFitDimensions());
if (property == "dimensions" || property == "size") {
return vec3toVariant(getDimensions());
}
if (property == "scale") {
return vec3toVariant(getScale());
}
if (property == "textures") {
if (_modelTextures.size() > 0) {

View file

@ -45,7 +45,8 @@ private:
QVariantMap _modelTextures;
QUrl _url;
bool _updateModel;
bool _updateModel = { false };
bool _scaleToFit = { false };
};
#endif // hifi_ModelOverlay_h

View file

@ -31,7 +31,7 @@ void Volume3DOverlay::setProperties(const QVariantMap& properties) {
auto dimensions = properties["dimensions"];
// if "dimensions" property was not there, check to see if they included aliases: scale
// if "dimensions" property was not there, check to see if they included aliases: scale, size
if (!dimensions.isValid()) {
dimensions = properties["scale"];
if (!dimensions.isValid()) {