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

feat: Make it easier work with the Mesh class [flame_3d] #3212

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

luanpotter
Copy link
Member

Description

Currently it is quite hard to operate with the Mesh class, because the list of surfaces is kept private.

I understand the concern with immutability, and the fact that the aabb must be recalculated when anything change.
Sadly I don't think Dart provides us with patterns to fully automate updating the aabb.
We need a way to update the meshes, so this is a compromise:

  • add a getter to an unmodifiable list
  • if the user updates the surfaces within, they are responsible for calling updateBounds
  • add methods to update or remove elements from the list, which automatically call updateBounds
  • this allow us to remove the silly "updateMaterial" methods that are used by Defend the Donut

This also adds an add method that takes a Surface object witch is extremely handy (even though it allows for post-modifications).

If we prefer to go a truly fully immutable route, we instead need helper methods to copy and recreate meshes with given set of changes. I am happy to take a stab at that option too.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm!

Comment on lines +17 to +21
mesh.updateSurfaces((surfaces) {
surfaces[0].material = StandardMaterial(
albedoTexture: crateTexture,
);
});
Copy link
Member Author

Choose a reason for hiding this comment

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

@wolfenrain I thought of adding this updateSurfaces method as well as a simpler alternative for people!

@luanpotter
Copy link
Member Author

@wolfenrain updated, please lmk what you think!

@luanpotter luanpotter merged commit 3091b12 into flame_3d Jul 9, 2024
2 of 8 checks passed
@luanpotter luanpotter deleted the luan.surface branch July 9, 2024 15:40
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.

None yet

3 participants