mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:13:29 +02:00
implement snap to center in model
This commit is contained in:
parent
bb6444f5a9
commit
293963c546
3 changed files with 46 additions and 7 deletions
|
@ -35,10 +35,9 @@ var originalProperties = {
|
||||||
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/birarda/birarda_head.fbx",
|
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/birarda/birarda_head.fbx",
|
||||||
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/pug.fbx",
|
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/pug.fbx",
|
||||||
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/newInvader16x16-large-purple.svo",
|
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/newInvader16x16-large-purple.svo",
|
||||||
//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/mino_full.fst",
|
|
||||||
modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/minotaur/mino_full.fbx",
|
modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/minotaur/mino_full.fbx",
|
||||||
|
|
||||||
//modelRotation: rotation
|
modelRotation: rotation
|
||||||
};
|
};
|
||||||
|
|
||||||
var positionDelta = { x: 0, y: 0, z: 0 };
|
var positionDelta = { x: 0, y: 0, z: 0 };
|
||||||
|
|
|
@ -37,6 +37,8 @@ Model::Model(QObject* parent) :
|
||||||
_scaleToFit(false),
|
_scaleToFit(false),
|
||||||
_scaleToFitLargestDimension(0.0f),
|
_scaleToFitLargestDimension(0.0f),
|
||||||
_scaledToFit(false),
|
_scaledToFit(false),
|
||||||
|
_snapModelToCenter(false),
|
||||||
|
_snappedToCenter(false),
|
||||||
_shapesAreDirty(true),
|
_shapesAreDirty(true),
|
||||||
_boundingRadius(0.f),
|
_boundingRadius(0.f),
|
||||||
_boundingShape(),
|
_boundingShape(),
|
||||||
|
@ -63,6 +65,13 @@ Model::SkinLocations Model::_skinNormalMapLocations;
|
||||||
Model::SkinLocations Model::_skinShadowLocations;
|
Model::SkinLocations Model::_skinShadowLocations;
|
||||||
|
|
||||||
void Model::setScale(const glm::vec3& scale) {
|
void Model::setScale(const glm::vec3& scale) {
|
||||||
|
setScaleInternal(scale);
|
||||||
|
// if anyone sets scale manually, then we are no longer scaled to fit
|
||||||
|
_scaleToFit = false;
|
||||||
|
_scaledToFit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::setScaleInternal(const glm::vec3& scale) {
|
||||||
float scaleLength = glm::length(_scale);
|
float scaleLength = glm::length(_scale);
|
||||||
float relativeDeltaScale = glm::length(_scale - scale) / scaleLength;
|
float relativeDeltaScale = glm::length(_scale - scale) / scaleLength;
|
||||||
|
|
||||||
|
@ -798,7 +807,7 @@ void Model::setScaleToFit(bool scaleToFit, float largestDimension) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::checkScaleToFit() {
|
void Model::scaleToFit() {
|
||||||
Extents modelMeshExtents = getMeshExtents();
|
Extents modelMeshExtents = getMeshExtents();
|
||||||
|
|
||||||
// size is our "target size in world space"
|
// size is our "target size in world space"
|
||||||
|
@ -807,16 +816,34 @@ void Model::checkScaleToFit() {
|
||||||
float maxDimension = glm::max(glm::max(dimensions.x, dimensions.y), dimensions.z);
|
float maxDimension = glm::max(glm::max(dimensions.x, dimensions.y), dimensions.z);
|
||||||
float maxScale = _scaleToFitLargestDimension / maxDimension;
|
float maxScale = _scaleToFitLargestDimension / maxDimension;
|
||||||
glm::vec3 scale(maxScale, maxScale, maxScale);
|
glm::vec3 scale(maxScale, maxScale, maxScale);
|
||||||
setScale(scale);
|
setScaleInternal(scale);
|
||||||
_scaledToFit = true;
|
_scaledToFit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::setSnapModelToCenter(bool snapModelToCenter) {
|
||||||
|
if (_snapModelToCenter != snapModelToCenter) {
|
||||||
|
_snapModelToCenter = snapModelToCenter;
|
||||||
|
_snappedToCenter = false; // force re-centering
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::snapToCenter() {
|
||||||
|
Extents modelMeshExtents = getUnscaledMeshExtents();
|
||||||
|
glm::vec3 halfDimensions = (modelMeshExtents.maximum - modelMeshExtents.minimum) * 0.5f;
|
||||||
|
glm::vec3 offset = -modelMeshExtents.minimum - halfDimensions;
|
||||||
|
_offset = offset;
|
||||||
|
_snappedToCenter = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Model::simulate(float deltaTime, bool fullUpdate) {
|
void Model::simulate(float deltaTime, bool fullUpdate) {
|
||||||
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit);
|
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit);
|
||||||
if (isActive() && fullUpdate) {
|
if (isActive() && fullUpdate) {
|
||||||
// check for scale to fit
|
// check for scale to fit
|
||||||
if (_scaleToFit && !_scaledToFit) {
|
if (_scaleToFit && !_scaledToFit) {
|
||||||
checkScaleToFit();
|
scaleToFit();
|
||||||
|
}
|
||||||
|
if (_snapModelToCenter && !_snappedToCenter) {
|
||||||
|
snapToCenter();
|
||||||
}
|
}
|
||||||
simulateInternal(deltaTime);
|
simulateInternal(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,19 @@ public:
|
||||||
void setRotation(const glm::quat& rotation) { _rotation = rotation; }
|
void setRotation(const glm::quat& rotation) { _rotation = rotation; }
|
||||||
const glm::quat& getRotation() const { return _rotation; }
|
const glm::quat& getRotation() const { return _rotation; }
|
||||||
|
|
||||||
|
/// enables/disables scale to fit behavior, the model will be automatically scaled to the specified largest dimension
|
||||||
void setScaleToFit(bool scaleToFit, float largestDimension = 0.0f);
|
void setScaleToFit(bool scaleToFit, float largestDimension = 0.0f);
|
||||||
|
bool getScaleToFit() const { return _scaleToFit; } /// is scale to fit enabled
|
||||||
|
bool getIsScaledToFit() const { return _scaledToFit; } /// is model scaled to fit
|
||||||
|
bool getScaleToFitDimension() const { return _scaleToFitLargestDimension; } /// the dimension model is scaled to
|
||||||
|
|
||||||
|
void setSnapModelToCenter(bool snapModelToCenter);
|
||||||
|
bool getSnapModelToCenter() { return _snapModelToCenter; }
|
||||||
|
|
||||||
void setScale(const glm::vec3& scale);
|
void setScale(const glm::vec3& scale);
|
||||||
const glm::vec3& getScale() const { return _scale; }
|
const glm::vec3& getScale() const { return _scale; }
|
||||||
|
|
||||||
void setOffset(const glm::vec3& offset) { _offset = offset; }
|
void setOffset(const glm::vec3& offset) { _offset = offset; _snapModelToCenter = false; _snappedToCenter = false; }
|
||||||
const glm::vec3& getOffset() const { return _offset; }
|
const glm::vec3& getOffset() const { return _offset; }
|
||||||
|
|
||||||
void setPupilDilation(float dilation) { _pupilDilation = dilation; }
|
void setPupilDilation(float dilation) { _pupilDilation = dilation; }
|
||||||
|
@ -215,6 +223,9 @@ protected:
|
||||||
float _scaleToFitLargestDimension; /// this is the dimension that scale to fit will use
|
float _scaleToFitLargestDimension; /// this is the dimension that scale to fit will use
|
||||||
bool _scaledToFit; /// have we scaled to fit
|
bool _scaledToFit; /// have we scaled to fit
|
||||||
|
|
||||||
|
bool _snapModelToCenter; /// is the model's offset automatically adjusted to center around 0,0,0 in model space
|
||||||
|
bool _snappedToCenter;
|
||||||
|
|
||||||
class JointState {
|
class JointState {
|
||||||
public:
|
public:
|
||||||
glm::vec3 translation; // translation relative to parent
|
glm::vec3 translation; // translation relative to parent
|
||||||
|
@ -241,7 +252,9 @@ protected:
|
||||||
// returns 'true' if needs fullUpdate after geometry change
|
// returns 'true' if needs fullUpdate after geometry change
|
||||||
bool updateGeometry();
|
bool updateGeometry();
|
||||||
|
|
||||||
void checkScaleToFit();
|
void setScaleInternal(const glm::vec3& scale);
|
||||||
|
void scaleToFit();
|
||||||
|
void snapToCenter();
|
||||||
|
|
||||||
void simulateInternal(float deltaTime);
|
void simulateInternal(float deltaTime);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue