mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-29 03:38:46 +02:00
Merge pull request #8238 from hyperlogic/bug-fix/jumbo-fish
Support for scale property on model overlays
This commit is contained in:
commit
e18d664204
5 changed files with 58 additions and 36 deletions
|
@ -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,31 @@ 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.
|
||||
_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 +141,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) {
|
||||
|
|
|
@ -45,7 +45,8 @@ private:
|
|||
QVariantMap _modelTextures;
|
||||
|
||||
QUrl _url;
|
||||
bool _updateModel;
|
||||
bool _updateModel = { false };
|
||||
bool _scaleToFit = { false };
|
||||
};
|
||||
|
||||
#endif // hifi_ModelOverlay_h
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue