c-frame / aframe-physics-system

community-maintained fork of n5ro's aframe-physics-system
https://c-frame.github.io/aframe-physics-system/
MIT License
42 stars 11 forks source link

Handle the case where mesh2shape returns null #41

Closed Elettrotecnica closed 1 year ago

Elettrotecnica commented 1 year ago

This can happen, for instance, when a gltf-model has not finished loading, hence a bounding box cannot be calculated. We try again after the object3D has been set in this case, the same as when "shape" is missing.

diarmidmackenzie commented 1 year ago

Are you able to make this change to remove the parentheses, then I'll merge? Thank you.

Elettrotecnica commented 1 year ago

Hi! I am not sure I understand what should be changed, if you refer to this line:

({ shape, offset, orientation } = shapeInfo);

the round parentheses are syntax. One can do without only when the variable is being declared. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#syntax

I was personally not familiar with this syntax and found out the hard way :-)

diarmidmackenzie commented 1 year ago

Ok, my error. Thanks for clarifying, and for the link.

Parentheses are required, because in the absence of a const, let or var, the opening brace for the destructuring assignment will be parsed as an opening brace of a new code block.

Including the parentheses allows the destructing assignment to work correctly.