Skip to content
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

Add overrideMaterialFillMode property to Mesh #13688

Closed
wants to merge 4 commits into from

Conversation

MiikaH
Copy link
Contributor

@MiikaH MiikaH commented Mar 31, 2023

As discussed in forum thread here: https://forum.babylonjs.com/t/add-mesh-overridematerialfillmode/39475/

It seems to work fine for playground /#WX0F9G. The model has 2 meshes, each with bunch of instances, both share same material. The playground example changes overrideMaterialFillMode on the other mesh only.

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 31, 2023

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 31, 2023

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 31, 2023

@Popov72
Copy link
Contributor

Popov72 commented Mar 31, 2023

Thanks for the PR!

However, I wonder why you put getFillMode on the subMesh, when it is only related to the material and mesh?

To mimic what we have for alpha blending, with material.needAlphaBlending when we want the setting for the material only and material.needAlphaBlendingForMesh when we want to apply it to a specific mesh, I'd opt for Material.getFillModeForMesh in the implementation.

cc @sebavan to get his opinion.

Regarding:

it("No more than 144 clean properties on a mesh", () => {

I don't think you can change the 128 limit, I seem to remember that it's a limit in Chrome where things get much slower because the object is not stored/managed internally in the same way when the number of properties reaches that limit...

Instead of adding overrideMaterialFillMode as a direct property of Mesh, you should instead add it inside the _InternalMeshDataInfo structure: this structure was added to overcome the 128 property limitation.

@MiikaH
Copy link
Contributor Author

MiikaH commented Mar 31, 2023

However, I wonder why you put getFillMode on the subMesh, when it is only related to the material and mesh?

Because SubMesh seemed to be the only common factor between all use cases where fillMode is used.

Say, take a look at:

!!material && subMesh.getFillMode(material) === Constants.MATERIAL_TriangleStripDrawMode

Right now it is pretty short and clear: subMesh.getFillMode(material).
If that was changed to a material method like you suggested then it would be: material.getFillModeForMesh(subMesh.getRenderingMesh()) which is not only much longer but also can create confusion as to which mesh to use.

Instead of adding overrideMaterialFillMode as a direct property of Mesh, you should instead add it inside the _InternalMeshDataInfo structure: this structure was added to overcome the 128 property limitation.

Interesting. I'll take a look if I can figure that out.

@Popov72
Copy link
Contributor

Popov72 commented Mar 31, 2023

What bothers me is that conceptually, fillMode is not related to subMesh, so having the method in the subMesh class doesn't seem right...

Let's see what @sebavan thinks.

@MiikaH
Copy link
Contributor Author

MiikaH commented Mar 31, 2023

Yeah I understand. I was spending quite bit of time trying to think how to do it myself.

A plain function would require adding imports everywhere. Mesh or Material submethod requires calling SubMesh.getRenderingMesh() anyway in many cases so it kind of is tied to SubMesh anyway.

Anyway, how I ended up thinking of it is just a @internal helper function. Its not a getter or property tied to SubMesh itself. Just a helper function to get the required fillMode when dealing with SubMeshes. (Like all code parts that used fillMode were)

@MiikaH
Copy link
Contributor Author

MiikaH commented Mar 31, 2023

Pushed a fix for not using _InternalMeshDataInfo and restored the 128 test

@sebavan sebavan requested a review from Popov72 April 3, 2023 09:41
Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

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

As @Popov72 I would as well prefer the fill mode on the mesh rather than the submesh.

I would also remove the scene parameter from it as it is only used once in scene. so we prevent extra checks in all the other cases.

Looking more closely the override seems to only be needed in 4 places:

  1. in _bind
  2. in _processRendering
  3. collide
  4. and in the depth peeling

For the first 2 If it all belongs to the mesh like _bind and _processRendering does, it could be computed inside ? I wonder if it would make things simpler

@MiikaH
Copy link
Contributor Author

MiikaH commented Apr 3, 2023

For the first 2 If it all belongs to the mesh like _bind and _processRendering does, it could be computed inside ? I wonder if it would make things simpler

I already considered that but unfortunately I don't think that would work. If applied inside then:

  • It would be impossible for any part in code to override the fillMode for _bind or _processRendering, because the mesh override would be applied on top
  • And also it would then override the scene level option

@MiikaH
Copy link
Contributor Author

MiikaH commented Apr 3, 2023

I would also remove the scene parameter from it as it is only used once in scene. so we prevent extra checks in all the other cases.

Scene override is used by effectLayer._renderSubMesh() and mesh.render(), so yeah I suppose that is kind of redundant to centralize. Could make more sense if additional render paths that use it are added in future.

I'll go ahead and move the helper function to Mesh and remove that scene arument then.

@MiikaH
Copy link
Contributor Author

MiikaH commented Apr 3, 2023

Ok, did those changes now.

Looks like it gained couple extra .getRenderingMesh() calls. Personally I'm not sure if that is better if it always and only ever uses subMesh renderingMesh for the override anyway..

@sebavan
Copy link
Member

sebavan commented Apr 5, 2023

@MiikaH We gave this one more thoughts with @Popov72 earlier today and we think this could do it #13708 so instead of adding tons of feedback here I drafted it to discuss the difference before merging.

It is all your code just remapped a tiny bit without the part not related to the rendering (as we figured those info are really geometry based)

What do you think ?

@sebavan sebavan closed this Apr 6, 2023
@MiikaH MiikaH deleted the Mesh-overrideMaterialFillMode branch April 6, 2023 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants