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 helper method to compute the maximum bounding boxes for an array of meshes #15045

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bghgary
Copy link
Contributor

@bghgary bghgary commented Apr 29, 2024

No description provided.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 29, 2024

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 Apr 29, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 29, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 29, 2024

Visualization tests for WebGPU (Experimental)
Important - these might fail sporadically. This is an optional test.

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/15045/merge/testResults/webgpuplaywright/index.html

* @param animationStep An optional animation step value indicating the amount to iterate while computing bounding boxes
* @returns An array of bounding boxes corresponding to the input meshes, animation group, and animation step values
*/
export function computeMaxBoundingBoxes(meshes: Array<AbstractMesh>, animationGroup?: AnimationGroup, animationStep = 1 / 6): Array<BoundingBox> {
Copy link
Member

Choose a reason for hiding this comment

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

Should it not be used in CreateDefaultCamera ?

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'm not sure. This is an expensive operation.

* @param animationStep An optional animation step value indicating the amount to iterate while computing bounding boxes
* @returns An array of bounding boxes corresponding to the input meshes, animation group, and animation step values
*/
export function computeMaxBoundingBoxes(meshes: Array<AbstractMesh>, animationGroup?: AnimationGroup, animationStep = 1 / 6): Array<BoundingBox> {
Copy link
Member

Choose a reason for hiding this comment

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

The meshes array is not intended to be mutated, yes? Should it a be a DeepImmutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea.

* @param animationStep An optional animation step value indicating the amount to iterate while computing bounding boxes
* @returns An array of bounding boxes corresponding to the input meshes, animation group, and animation step values
*/
export function computeMaxBoundingBoxes(meshes: Array<AbstractMesh>, animationGroup?: AnimationGroup, animationStep = 1 / 6): Array<BoundingBox> {
Copy link
Member

Choose a reason for hiding this comment

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

If no animationGroup is provided, then no animationStep should be provided, correct? Would it be worth it to reflect this in the API, either with classic overloads or named tuples?

Suggested change
export function computeMaxBoundingBoxes(meshes: Array<AbstractMesh>, animationGroup?: AnimationGroup, animationStep = 1 / 6): Array<BoundingBox> {
export function computeMaxBoundingBoxes(...args: [meshes: Array<AbstractMesh>] | [meshes: Array<AbstractMesh>, animationGroup: AnimationGroup] | [meshes: Array<AbstractMesh>, animationGroup: AnimationGroup, animationStep: number]): Array<BoundingBox> {

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 personally don't think this is worth the effort. It makes the code more difficult to read.

I considered using a options arguments instead of individual arguments but decided against it also.

No strong preference though.

Copy link
Member

Choose a reason for hiding this comment

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

Personally I would prefer an options object using discriminated unions to make it super clear that it is not valid to provide an animationStep without providing an animationGroup. I think this kind of API design just helps ppl understand how to use it, but your call.

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 think requiring that animationStep not be passed in when animationGroup is not present is harder to use. Most of the time, the user doesn't know if there is going to be an animationGroup or not.

if (animationGroup) {
const step = animationGroup.getLength() * animationStep;

for (let frame = animationGroup.from; frame < animationGroup.to; frame += step) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be frame <= animationGroup.to, as the to frame is inclusive.


for (let frame = animationGroup.from; frame < animationGroup.to; frame += step) {
// Must increment the render id such that world matrices are recomputed.
animationGroup.scene.incrementRenderId();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You could pass true to computeWorldMatrix() instead.

@@ -0,0 +1,62 @@
import { AnimationGroup } from "../Animations/animationGroup";
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
import { AnimationGroup } from "../Animations/animationGroup";
import type { AnimationGroup } from "../Animations/animationGroup";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants