Skip to content

Reinstate Model Instancing #417

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

two-one-five
Copy link
Contributor

@two-one-five two-one-five commented Jun 4, 2020

This reverts commit 86dbf3f, reversing
changes made to d69c895.

This was removed in PR#414 kasenvr/fix/revert-instancing-temporarily.

#412
#383

The above issues outlines the current problem with this PR. This PR will be merged to reinstate instancing once this bug is solved.

From HifiExperiments:

to be completely honest, I have no idea what the bulk of this PR does. I have limited understanding of the serializer code and all the transform stuff is so tangled and insane. for the most part, this PR should exactly match the original merge commit from sabrina, but with the additions outlined below

CORRECTION: The original reversal of changes was to 3592488, not d69c895.

…mporarily-1"

This reverts commit 86dbf3f, reversing
changes made to d69c895.
@two-one-five two-one-five added do not merge do not merge due to issues or pending updates renderer Touches or changes rendering labels Jun 4, 2020
@two-one-five two-one-five changed the title Reinstate Instancing Reinstate Model Instancing Jun 6, 2020
@Aitolda
Copy link
Collaborator

Aitolda commented Jul 19, 2020

Not sure I have any answers yet, but after doing some testing with the Pillar.fbx Alezia provided, it appears to import visually at the right size in scale, however in the create tools it's showing as exactly twice it's scale on the x and z axis within interface, while the Y axis (up/down) is acurate to scaled size in blender (which is the Z axis within blender). HOWEVER... in blender this axis is actually the ONLY part that is scaled. So... the non-scaled axis are showing up with incorrect dimensions, while the scaled dimension shows up correctly.

In Blender (2.83) note the scaling and length on the Z axis (Y within interface)
Blender

And note the Y-dimensions within the create menu in interface (again)
Interface

Both remain at 17.8, but the other two dimensions are doubled in interface. Again, they actually are showing up at the correct visual scale for me, just not in the create dimensions.

@two-one-five
Copy link
Contributor Author

Vegaslon noted these two commits may be of interest:
yozlet/interface@ecdca05
yozlet/interface@a70f0f2

glm::mat4_cast(combinedRotation) * joint.postTransform;
joint.transform = localTransform * joint.geometricOffset;
joint.globalTransform = hfmModel.offset * localTransform * joint.geometricOffset;
joint.globalTransformForChildren = hfmModel.offset * localTransform;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is basically the fix...when hifi did the instancing PR, they removed support for geometricOffset

I don't know if there's an analogous property in GLTF so for now this (globalTransformForChildren) is only used here so that each joint has the correct globalTransform (including geometricOffset), but it doesn't pass geometricOffset down to its children

Copy link
Collaborator

Choose a reason for hiding this comment

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

The top level object in glTF is the "scene". The scene has one or more "nodes". Each node may have a transform plus one or more meshes, and it can have other nodes as children (e.g., to form a skeleton).


data.setCauterized(cauterized);
data.setRenderWithZones(renderWithZones);
Copy link
Contributor

Choose a reason for hiding this comment

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

I had two merge conflicts when trying to update this PR to master, which reviewers should pay particular attention to. one was around this area, I think because of the renderWithZones stuff, which I have tried to preserve


if (indicesAccessorIdx > _file.accessors.size()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

another was in this file, I think because we added these bound checks

@HifiExperiments HifiExperiments added bugfix needs CR (code review) needs testing (QA) The PR is ready for testing rebuild rebuild through the GithubActions and removed do not merge do not merge due to issues or pending updates labels Aug 11, 2020
@two-one-five
Copy link
Contributor Author

While it will be good to review this fully, really all that needs to be considered is what HiFiExperiments added... the rest is stuff High Fidelity kinda added semi-finished but untested fully (how we caught this problem, but maybe they already knew about it and were intending to revisit it, according to the comments, in which case then it was fully considered and of course code-reviewed.)

I know we're dealing with limited resources, so it's my hope that we'll catch more issues in testing. :)

@Aitolda
Copy link
Collaborator

Aitolda commented Aug 14, 2020

Tested. Scale and position seems to be working as expected. I did notice that drawcalls don't seem to report accurately, however, after switching back to stable this does not seem to be specific to this PR.

@vegaslon
Copy link
Contributor

Understand why they removed model offset from this pr. If you are trying to instance a model having geometry offsets on it will cause all but one of the instanced models to be in the wrong place. We will just have to work around that when the times comes for someone try instancing in a scene.

@Aitolda
Copy link
Collaborator

Aitolda commented Aug 15, 2020

Understand why they removed model offset from this pr. If you are trying to instance a model having geometry offsets on it will cause all but one of the instanced models to be in the wrong place. We will just have to work around that when the times comes for someone try instancing in a scene.

You are still having this problem? I did not. I wonder what we may be doing differently.

@vegaslon
Copy link
Contributor

No do not have “this” problem as currently stated. I am just saying that may see “new bugs” in future.

@HifiExperiments
Copy link
Contributor

@vegaslon the old code (before the original PR removed it) worked by actually altering the underlying vertices of the meshes, which I assume would lead to the problem you mention. but with my new changes, the vertices stay unmodified, but the applied transform changes. I think this should fix the issue, but the only way to be sure would be to create a model with instanced parts and geometric offsets and test it

@AleziaKurdis
Copy link
Contributor

image

Still have the problem with this PR417 build.

image

image

@AleziaKurdis
Copy link
Contributor

There are links on those model in
#383
if you need this to investigate.

Copy link
Contributor

@daleglass daleglass left a comment

Choose a reason for hiding this comment

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

Overall this is way too much for me to properly get my head around it in any reasonable amount of time, but I can nitpick a bit and check for anything that jumps out to me.

@@ -121,8 +121,9 @@ bool CollisionPick::isLoaded() const {
bool CollisionPick::getShapeInfoReady(const CollisionRegion& pick) {
if (_mathPick.shouldComputeShapeInfo()) {
if (_cachedResource && _cachedResource->isLoaded()) {
computeShapeInfo(pick, *_mathPick.shapeInfo, _cachedResource);
_mathPick.loaded = true;
// TODO: Model CollisionPick support
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a "TODO" here. What does missing this part imply?

const int MAX_ALLOWED_MESH_COUNT = 1000;
if (numMeshes > MAX_ALLOWED_MESH_COUNT) {
// too many will cause the deadlock timer to throw...
const size_t MAX_VERTICES_PER_STATIC_MESH = 1e6;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be here? Maybe move it to the top?

Also, a million? Perhaps that is a bit much for some of the lower end hardware like the Quest? Perhaps this should even be configurable (even if not actually exposed anywhere yet) so that we can put some other limit for the Quest and such devices?

hfmModel.meshExtents.addPoint(transformedVertex);
}
}
// TODO: Fix skinning and remove this workaround which disables skinning
Copy link
Contributor

Choose a reason for hiding this comment

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

Another TODO here

@Aitolda
Copy link
Collaborator

Aitolda commented Dec 10, 2020

While I need to investigate further, older models that are scaling incorrectly when imported back into current blender 2.9x, resaved without changes, seam to stop having the issue.

@AleziaKurdis
Copy link
Contributor

While I need to investigate further, older models that are scaling incorrectly when imported back into current blender 2.9x, resaved without changes, seam to stop having the issue.

I suspected that. If this is the case, it might be a lot of rework, but I think we should go ahead.

@digisomni
Copy link
Member

We should investigate what the Hub looks like in this PR for example.

@digisomni digisomni added rebuild rebuild through the GithubActions and removed rebuild rebuild through the GithubActions labels Dec 12, 2020
@digisomni
Copy link
Member

Per @ctrlaltdavid: Can we find out the difference between the FBX's and insert a compatibility fix then to check to see if a model was exported with the older version and process that differently?

@ctrlaltdavid
Copy link
Collaborator

If we can get some example "broken before", "not broken before" and "broken before fixed after" models, it might be possible to see what differences there are in the FBX files.

@AleziaKurdis
Copy link
Contributor

Maybe this could help:

BROKEN:
http://metaverse.bashora.com/objects/ZEDHA/DOORFRAME.fbx
(16 May 2017)

http://metaverse.bashora.com/objects/ZEDHA/FENETRE.fbx
(8 May 2017)

http://metaverse.bashora.com/objects/WOTHAL/PILAR.fbx
(2018)

http://metaverse.bashora.com/objects/WOTHAL/PILAR_RE_EDITED_BL281.fbx
(Re-edited in Blender 2.81 (15 dec 2020), Materials get modified)
but with this version it has the same issue!

NOT BROKEN:
http://metaverse.bashora.com/objects/ZEDHA/Cafe.fbx
(15 May 2017)

http://metaverse.bashora.com/objects/WOTHAL/PILAR_RE_EDITED_BL281_WITH_APPLY.fbx
(Re-edited in Blender 2.81 (15 dec 2020), Materials get modified, AND I did Apply Location, Scale , Rotation)


I clearly suspect that it has to do with the "Apply: Location, Scale , Rotation"
A concept that I wasn't even know 18 months ago...

so depending if some objects has been rotate or scale in "Object Mode" in Blender, without have done "Apply"
these objects has the problem. (in the PR417 version)
But sometime, I was starting to work directly in "Edit Mode" in blender without have to play with it in "Object Mode",
then those model would have resisted.
Of course, all those model are render correctly in the release 2020.3.2 and are display broken in PR417.

@AleziaKurdis
Copy link
Contributor

Here, the "PILAX.blend" file with the scale (Z-UP)
image
In-word, the PILAR.fbx model is rescaled inside its bounding box with opposite proportions.
Those that had the scale of 1,1,1 are untouched. (As observed, being the opposite of them-self)

@AleziaKurdis
Copy link
Contributor

This is not a old model or old software issue, but clearly a bug.
I can now reproduce it with model created today with Blender 2.8.1

2020.3.2 - Demeter
ROTATE_ONLY_2020_3_2

PR 417
ROTATE_ONLY_PR417

Here's the step to reproduce in Blender (probably any version)

1- Open Blender

2- Clear the scene and add a mesh of type cube

3- in "Object Mode", select the cube and do R, Z, 45
(This rotate the Object of 45 degree on the Z axis (blender being Z-UP))

4- Switch to "Edit Mode"

5- Click A to select All

6- Do R, Z, -45
(This rotate the Object of -45 degree on the Z axis.)

7- you can add a material and save this.

8- Export as an FBX (you can use the Metaverse Plugin (Menithal), should not be the problem)

9- Import In-world...
Results:
With 2020.3.2, you should get a perfect cube that fits its bounding box when selected.

With PR417, you should get a long horizontal rectangular prism (Y axis being the longest side) and not fitting the bounding box that is a perfect cube.

Additional tests
The second test you see on the pictures (the blue cube)
is when you rotate only it in Object Mode. As you can see, the rotated model is rendered accordingly in it's bounding box, which make sense.

I made also additional test with the scale not being applied, and it's not that, the unique responsible is that double rotation that is badly computed at some point.

Here's the 3 test models:
http://metaverse.bashora.com/objects/broken417/BROKEN_CUBE_ROTATE_OBJECT_ONLY.fbx
http://metaverse.bashora.com/objects/broken417/BROKEN_CUBE_ROTATE_ONLY.fbx
http://metaverse.bashora.com/objects/broken417/GOOD_CUBE.fbx

@AleziaKurdis
Copy link
Contributor

Here How it looks inside the FBX of these 3 models:
image

image

image

image

@digisomni digisomni added help wanted Extra attention is needed and removed needs CR (code review) needs testing (QA) The PR is ready for testing labels Dec 19, 2020
@digisomni digisomni modified the milestones: 2020.3.3 Release, 2020.3.4 Release, 2021.1.0 Release Dec 21, 2020
@digisomni digisomni added the dormant This PR is on hold but has interest/use surrounding it. label Nov 6, 2021
@stale
Copy link

stale bot commented May 5, 2022

Hello! Is this still an issue?

@stale stale bot added the stale Issue / PR has not had activity label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix dormant This PR is on hold but has interest/use surrounding it. help wanted Extra attention is needed rebuild rebuild through the GithubActions renderer Touches or changes rendering stale Issue / PR has not had activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants