cleanup + create

This commit is contained in:
HifiExperiments 2021-01-01 23:42:06 -08:00
parent 002271a4cc
commit 20e0c24163
7 changed files with 19 additions and 19 deletions

View file

@ -227,12 +227,12 @@ EntityItemProperties RenderableModelEntityItem::getProperties(const EntityProper
glm::vec3 RenderableModelEntityItem::getPivot() const {
auto model = getModel();
auto raycastOffset = EntityItem::getPivot();
auto pivot = EntityItem::getPivot();
if (!model || !model->isLoaded() || !_useOriginalPivot) {
return raycastOffset;
return pivot;
}
return raycastOffset + model->getOriginalOffset();
return pivot + model->getOriginalOffset();
}
bool RenderableModelEntityItem::supportsDetailedIntersection() const {

View file

@ -1628,16 +1628,16 @@ AACube EntityItem::getMaximumAACube(bool& success) const {
_recalcMaxAACube = false;
// we want to compute the furthestExtent that an entity can extend out from its "position"
// to do this we compute the max of these two vec3s: registration and 1-registration
// and then scale by dimensions
glm::vec3 offset = getScaledDimensions() * getRegistrationPoint() + getPivot();
glm::vec3 maxExtents = glm::max(offset, glm::vec3(1.0f) - offset);
// and then scale by dimensions and add the absolute value of the pivot
glm::vec3 registrationPoint = getRegistrationPoint();
glm::vec3 maxExtents = getScaledDimensions() * glm::max(registrationPoint, glm::vec3(1.0f) - registrationPoint);
// there exists a sphere that contains maxExtents for all rotations
float radius = glm::length(maxExtents);
// put a cube around the sphere
// TODO? replace _maxAACube with _boundingSphereRadius
glm::vec3 minimumCorner = centerOfRotation - glm::vec3(radius, radius, radius);
glm::vec3 minimumCorner = (centerOfRotation + getPivot()) - glm::vec3(radius, radius, radius);
_maxAACube = AACube(minimumCorner, radius * 2.0f);
}
} else {

View file

@ -104,7 +104,7 @@ bool HFMModel::convexHullContains(const glm::vec3& point) const {
auto checkEachPrimitive = [=](HFMMesh& mesh, QVector<int> indices, int primitiveSize) -> bool {
// Check whether the point is "behind" all the primitives.
// But first must transform from model-frame into mesh-frame
glm::vec3 transformedPoint = glm::vec3(glm::inverse(mesh.modelTransform) * glm::vec4(point, 1.0f));
glm::vec3 transformedPoint = glm::vec3(glm::inverse(offset * mesh.modelTransform) * glm::vec4(point, 1.0f));
int verticesSize = mesh.vertices.size();
for (int j = 0;
j < indices.size() - 2; // -2 in case the vertices aren't the right size -- we access j + 2 below

View file

@ -151,7 +151,6 @@ void Model::setOffset(const glm::vec3& offset) {
// if someone manually sets our offset, then we are no longer snapped to center
_snapModelToRegistrationPoint = false;
_snappedToRegistrationPoint = false;
_needsTransformUpdate = true;
}
void Model::calculateTextureInfo() {
@ -384,9 +383,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
if (_snapModelToRegistrationPoint || _forceOffset) {
meshToWorldMatrix = meshToWorldMatrix * (glm::scale(_scale) * glm::translate(_offset));
} else {
Extents unscaledExtents = getUnscaledMeshExtents();
glm::vec3 unscaledDimensions = unscaledExtents.maximum - unscaledExtents.minimum;
meshToWorldMatrix = meshToWorldMatrix * (glm::scale(_scale) * glm::translate(unscaledDimensions * (0.5f - _registrationPoint)));
meshToWorldMatrix = meshToWorldMatrix * (glm::scale(_scale) * glm::translate(getNaturalDimensions() * (0.5f - _registrationPoint)));
}
glm::mat4 worldToMeshMatrix = glm::inverse(meshToWorldMatrix);
@ -550,9 +547,7 @@ bool Model::findParabolaIntersectionAgainstSubMeshes(const glm::vec3& origin, co
if (_snapModelToRegistrationPoint || _forceOffset) {
meshToWorldMatrix = meshToWorldMatrix * (glm::scale(_scale) * glm::translate(_offset));
} else {
Extents unscaledExtents = getUnscaledMeshExtents();
glm::vec3 unscaledDimensions = unscaledExtents.maximum - unscaledExtents.minimum;
meshToWorldMatrix = meshToWorldMatrix * (glm::scale(_scale) * glm::translate(unscaledDimensions * (0.5f - _registrationPoint)));
meshToWorldMatrix = meshToWorldMatrix * (glm::scale(_scale) * glm::translate(getNaturalDimensions() * (0.5f - _registrationPoint)));
}
glm::mat4 worldToMeshMatrix = glm::inverse(meshToWorldMatrix);
@ -1418,7 +1413,6 @@ void Model::setSnapModelToRegistrationPoint(bool snapModelToRegistrationPoint, c
_snapModelToRegistrationPoint = snapModelToRegistrationPoint;
_registrationPoint = clampedRegistrationPoint;
_snappedToRegistrationPoint = false; // force re-centering
_needsTransformUpdate = true;
}
}
@ -1446,7 +1440,7 @@ void Model::setUseDualQuaternionSkinning(bool value) {
void Model::simulate(float deltaTime, bool fullUpdate) {
DETAILED_PROFILE_RANGE(simulation_detail, __FUNCTION__);
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit)
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint) || _needsTransformUpdate;
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint);
if (isLoaded() && fullUpdate) {
onInvalidate();
@ -1462,7 +1456,6 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
glm::mat4 parentTransform = glm::scale(_scale) * ((_snapModelToRegistrationPoint || _forceOffset) ?
glm::translate(_offset) : glm::translate(getNaturalDimensions() * (0.5f - _registrationPoint)));
updateRig(deltaTime, parentTransform);
_needsTransformUpdate = false;
}
}

View file

@ -413,7 +413,6 @@ protected:
bool _snapModelToRegistrationPoint; /// is the model's offset automatically adjusted to a registration point in model space
bool _snappedToRegistrationPoint; /// are we currently snapped to a registration point
glm::vec3 _registrationPoint { glm::vec3(0.5f) }; /// the point in model space our center is snapped to
bool _needsTransformUpdate { false };
bool _forceOffset { false };
std::vector<MeshState> _meshStates;

View file

@ -601,6 +601,9 @@
"groupCulled": {
"tooltip": "If false, individual pieces of the entity may be culled by the render engine. If true, either the entire entity will be culled, or it won't at all."
},
"useOriginalPivot": {
"tooltip": "If false, the model will be centered based on its content, ignoring any offset in the model itself. If true, the model will respect its original offset."
},
"webColor": {
"tooltip": "The tint of the web entity."
},

View file

@ -614,6 +614,11 @@ const GROUPS = [
propertyID: "compoundShapeURL",
hideIfCertified: true,
},
{
label: "Use Original Pivot",
type: "bool",
propertyID: "useOriginalPivot",
},
{
label: "Animation",
type: "string",