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

fix(gltf): getting typed arrays for accessor #2691

Closed
wants to merge 1 commit into from

Conversation

mspivak-actionengine
Copy link
Collaborator

Implemented the getTypedArrayForAccessor function in get-typed-arrays.ts with the interface similar to getTypedArrayForBufferView and getTypedArrayForImageData.
Currently these functions are not being used in gltf-scenegraph.ts.
Later on, after deep investigation we will make a decision with regard to their possible usage in gltf-scenegraph.ts.

@mspivak-actionengine mspivak-actionengine marked this pull request as draft October 12, 2023 10:20
): TypedArray {
const gltfAccessor = typeof accessor === 'number' ? json.accessors?.[accessor] : accessor;
if (!gltfAccessor) {
throw new Error(`No Accessor ${accessor}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be very hard for end users to understand such an error message. Maybe mentioning glTF could give them a hint?

Suggested change
throw new Error(`No Accessor ${accessor}`);
throw new Error(`No glTF accessor ${accessor}`);

}
const bufferView = json.bufferViews?.[gltfAccessor.bufferView || 0];
if (!bufferView) {
throw new Error(`No Buffer View for Accessor ${bufferView}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
throw new Error(`No Buffer View for Accessor ${bufferView}`);
throw new Error(`No glTF buffer view for accessor ${bufferView}`);

* @returns {TypedArray} Typed array with type matching the type of data poited by the accessor.
*/
// eslint-disable-next-line complexity
export function getTypedArrayForAccessor(
Copy link
Collaborator

Choose a reason for hiding this comment

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

A function like this should really have a couple of test cases. It can be very painful to debug code when the error happens in a low-level utility like this.

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.

2 participants