Skip to content

Model Entities: useOriginalPivot Property #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 10, 2021

Conversation

HifiExperiments
Copy link
Contributor

@HifiExperiments HifiExperiments commented Jan 2, 2021

implements #284 resolves #793

adds a new property to Model Entities: useOriginalPivot

defaults to false (current behavior), but adds option to toggle in new model dialog

caveat: in create, the bounding box of a selected entity is centered around the actual entity position, which is now offset from the model's position when useOriginalPivot is true. I actually like this, as it reflects that offset, but maybe others have different opinions

Test plan:

  • run this script: https://gist.github.com/HifiExperiments/7b3faa7919eed7a308c762ffe03d893f/raw/615f87b8315e433ac35b23e47a52ab6954e27f6b/PivotTest.js
  • first and third models have useOriginalPivot false, second and fourth are true. First and second models use natural dimensions, third and fourth use { 1, 1, 2 }
  • enable Developer -> Physics -> Show Bullet Collisions. green collision lines should match the 4 models
  • hover over the entities with your mouse. a small white sphere will appear when your mouse is over the entities. make sure it lines up with the models
  • press "o" to toggle through different registrationPoints for all of the models. note that they show the correct behavior, and that the physics and ray picking continue to work on all 4 models
  • verify the workflow of adding a model with/without "Use Original Pivot" via create, and that you can toggle it on a created model via the property window
  • run luci.js and use the Bounding Box section to confirm that the render bounds of each model is in the correct place, encompassing it regardless of pivot

@HifiExperiments HifiExperiments added docs Improvements or additions to documentation enhancement New feature or request question / review Further attention is requested packet version change will result in a protocol mismatch renderer Touches or changes rendering needs testing (QA) The PR is ready for testing needs CR (code review) labels Jan 2, 2021
@@ -248,9 +248,9 @@ private: \
* <em>Read-only.</em>
* @property {string} lodStatus - Description of the current LOD.
* <em>Read-only.</em>
* @property {string} numEntityUpdates - The number of entity updates that happened last frame.
* @property {number} numEntityUpdates - The number of entity updates that happened last frame.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this (and some below) is unrelated cleanup to silence some warnings and fixup this JSDoc

updateRenderItems = true;
model->scaleToFit();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to call scaleToFit here because we call simulate below which calls scaleToFit as necessary

@@ -452,7 +465,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
pointCollection[i][j] = scaleToFit * (pointCollection[i][j] + model->getOffset()) - registrationOffset;
}
}
shapeInfo.setParams(type, 0.5f * extents, getCompoundShapeURL());
shapeInfo.setParams(type, 0.5f * extents, getCompoundShapeURL() + model->getSnapModelToRegistrationPoint());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hack to make sure that the same model with/without useOriginalPivot know that they have slightly different physics shapes (the difference being the offset)

@@ -723,8 +723,10 @@ ShapeType RenderablePolyVoxEntityItem::getShapeType() const {
}

void RenderablePolyVoxEntityItem::setRegistrationPoint(const glm::vec3& value) {
if (value != _registrationPoint) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some cleanup below to make sure this stuff is all threadsafe and takes into account the pivot

@@ -302,6 +302,7 @@ class EntityItemProperties {
DEFINE_PROPERTY(PROP_RELAY_PARENT_JOINTS, RelayParentJoints, relayParentJoints, bool, ENTITY_ITEM_DEFAULT_RELAY_PARENT_JOINTS);
DEFINE_PROPERTY_REF(PROP_GROUP_CULLED, GroupCulled, groupCulled, bool, false);
DEFINE_PROPERTY_REF(PROP_BLENDSHAPE_COEFFICIENTS, BlendshapeCoefficients, blendshapeCoefficients, QString, "");
DEFINE_PROPERTY_REF(PROP_USE_ORIGINAL_PIVOT, UseOriginalPivot, useOriginalPivot, bool, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEFINE_PROPERTY_REF(PROP_USE_ORIGINAL_PIVOT, UseOriginalPivot, useOriginalPivot, bool, false);
DEFINE_PROPERTY_REF(PROP_USE_ORIGINAL_PIVOT, UseOriginalPivot, useOriginalPivot, bool, true);

If using the original pivot is the standard, we should probably respect that and encourage doing the same going forward. What you export from Blender should generally show up in the same fashion in-world if at all possible.

Though, is it set to false because all existing entities without this property will get populated with false (in order to prevent breakage?)

In that case, I guess it'll have to stay false, the Create app will have to set it to "true" by default, and then we'll have to plan to set the default value to true at some point further down the line...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the default needs to be false because of old content. I can change the default in the new model dialog to be true, but there’s no easy way to change the default in the future (without breaking lots of stuff).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the domain server not have a way to parse the entity tree and upgrade them to latest? Therefore if an old entity is parsed, set it to false, and then we can set it to true by default in all places for new entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a way to do this for domain content/backups, so a domain that’s upgrading to a new version could properly detect it, but there’s no way to do it for things like scripts that could be doing anything

@ctrlaltdavid ctrlaltdavid added the scripting api change Change is made in the scripting API label Jan 3, 2021
@HifiExperiments HifiExperiments added the rebuild rebuild through the GithubActions label Jan 4, 2021
@HifiExperiments HifiExperiments added rebuild rebuild through the GithubActions and removed rebuild rebuild through the GithubActions labels Jan 4, 2021
@Aitolda
Copy link
Collaborator

Aitolda commented Jan 9, 2021

Works as intended if you use when of the generated collisions types like basic, exact, etc.. BUT if you use something like Box or Sphere collision center will be the original position. Not necessarily a bug, but this might lead to some confusion. Not sure how we should address this. Maybe if the checkbox is ticked, it does some sort of "get center" from the mesh and puts the shape collision there.

EDIT: Compound shape has the same issue, even if using the same offset model. So originalpivot is not being respected on compound shapes.

Exact
Compound Shape
Box
Test Model

@HifiExperiments
Copy link
Contributor Author

@Aitolda thanks for catching that, I think it should be fixed in the latest commit, but of course windows builds are broken here too

@HifiExperiments HifiExperiments added rebuild rebuild through the GithubActions and removed rebuild rebuild through the GithubActions labels Jan 22, 2021
@HifiExperiments HifiExperiments added rebuild rebuild through the GithubActions and removed rebuild rebuild through the GithubActions labels Jan 22, 2021
@Aitolda
Copy link
Collaborator

Aitolda commented Jan 23, 2021

Pivot point of compound shapes still doesn't seem to be working, at least on the offset cube model I've been using.

  1. Load the Offset Cube
  2. Set shape type to compound
  3. paste the same model in the compound shape URL
  4. switch pivot type and test
  5. rinse and repeat

Offset Cube

@HifiExperiments
Copy link
Contributor Author

@Aitolda @digisomni ok hopefully NOW it's working 😛

@Aitolda
Copy link
Collaborator

Aitolda commented Feb 4, 2021

Still some major issues with using compound collisions, I see two problems potentially working together.

  1. on an fbx model (only) the compound collision hull is rotated on the wrong axis.
    glb
    fbx
  2. on both fbx and glb, if the model pivot point is moved away from 0,0,0 within a 3d application before exporting, the compound collision may be ignoring this offset while the main mesh respects it

I've attached several models which should help demonstrate the issues. Unfortunately html doesn't like my naming scheme so I will label them here. Note, in blender Z is up, and the coordinates in my naming scheme reflects this.

ArrowUp(0,0,0)Blender
ArrowUp(0,0,0).fbx
ArrowUp(0,0,0).glb

ArrowUp(-5,-5,0)Blender
ArrowUp(-5,-5,0).fbx
ArrowUp(-5,-5,0).glb

@Aitolda
Copy link
Collaborator

Aitolda commented Feb 4, 2021

Thinking about it more, I'm not sure respecting the 0,0,0 (as mentioned in the post above) is even desirable. it would make sense only if you were making complex environments most of the time, and I think a json exported is a better approach for this. Just want to clarify we're talking about the distance of the pivot point from zero in blender or 3dmax, not the pivot point itself, which is the whole point of this pr. In other words, I think with the exception of the wrong rotation on fbx, the compound shape is doing what it's supposed to, and it's the mesh that's incorrectly respecting the distance from 0

@Aitolda
Copy link
Collaborator

Aitolda commented Feb 5, 2021

Thinking about it more, I'm not sure respecting the 0,0,0 (as mentioned in the post above) is even desirable. it would make sense only if you were making complex environments most of the time, and I think a json exported is a better approach for this. Just want to clarify we're talking about the distance of the pivot point from zero in blender or 3dmax, not the pivot point itself, which is the whole point of this pr. In other words, I think with the exception of the wrong rotation on fbx, the compound shape is doing what it's supposed to, and it's the mesh that's incorrectly respecting the distance from 0

Regarding treating 0,0,0 in blender/Maya/3dMax export as the pivot point, after doing some digging around, it unfortunately looks like even Unreal and Unity have adopted this. I assume their is some reason, but I think it's one of those things in the grand scheme are actually more difficult on artists who want to bring in elaborate scenes, but perhaps we can tackle that issue by updating the blender plugin. Either way I think once the rotation issue is solved on fbx we should move forward as is for the time being.

@HifiExperiments
Copy link
Contributor Author

after a conversation with @Aitolda, he found that other engines also have problems with non-zero pivot points (https://forum.unity.com/threads/wrong-pivot-point-from-blender-to-unity.423176/). for now, we think it's ok to move forward with this, and if we fix it in the future, we can try to do so in a backwards-compatible way. after this is merged, I'll open an issue tracking that

@digisomni
Copy link
Member

Okeydokeseys!

@AleziaKurdis
Copy link
Contributor

Just tested this. (I have not read any of the comments in this thread yet)
Here are my impressions:

The feature works as expected. I tested it with fbx and glb

But where it hurts is about having this behavior as default value in the UI.
It looks like this with an ex-centric pivot:
image

I don't know how other tools deal with this but is the bounding box is clearly not design to support that.
This is also ruins a bit the "snap to surface" feature. Is there a way to figure where is the edge of the model anymore?
A lot of stuff are going to behave weirdly if we have this by default.

I think we should try to figure if honoring the original pivot is the mainstream usecase before decide if this needs to be the default option. What are the usecase where you need more the original pivot than a consistent central point?

In my example the pivot was largely outside. BI suspect that in many cases, people will just have it approximatively in the middle, but without being mathematically in the center. So they might get the bounding box offset in a significant number of cases.
I would have let this option for the case where it is intentional (not as default). This is my opinion.

In the create app (Create Model), the option is not persisted using a setting like what we have for "grabbable".
You can be sure that I will minimally plug such a setting in the future to not have this defaulted (minimally for my-self).
I see advantage for this feature for doors, or anything that we need an ex-centric pivot. Which is not the main usecase for me.

I tested the object as dynamic... here too, excentricity doesn't appears to be a main desired behavior.

To recap:

  • Feature is good
  • Set by Default in UI: Not sure about this. (I assume it is not by the api, because that could ruin scripts)
  • Set by Default in UI: create app behave weirdly which is not going to reflect stability for new comers.
  • A setting in create app would be a must. (Consider to log an issue for this)

@digisomni digisomni merged commit b826743 into vircadia:master Feb 10, 2021
@HifiExperiments HifiExperiments deleted the pivot branch February 10, 2021 06:37
@HifiExperiments
Copy link
Contributor Author

@AleziaKurdis like I said in the description, I actually think the bounding box thing in create is somewhat helpful, as it reflects the ACTUAL position of the entity, but I agree it’s another layer of complexity. I’m open to suggestions on how to fix this...we could expose the offset to create and draw two different boxes maybe?

snap to surface should still work, since it uses findRayIntersection, right? that should still work, even on pivoted models.

I agree the setting should be persistent!

Kalila wanted to get this in for the next release but I can sync with you to fix any bugs you find or make any improvements in a follow up

in general, I think this feature request is less about eccentricity for rotations and more about making building complex scenes easier for modelers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CR Approved At least one code reviewer has approved the PR. docs Improvements or additions to documentation enhancement New feature or request merge right before snip Do not merge these changes until the very end. needs testing (QA) The PR is ready for testing packet version change will result in a protocol mismatch question / review Further attention is requested rebuild rebuild through the GithubActions renderer Touches or changes rendering scripting api change Change is made in the scripting API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement/FeatureRequest: Optional preserve point of origin from models.
6 participants