Skip to content

[RFC] Should BufferAttribute.array be TypedArray instead of ArrayLike? #35

@joshuaellis

Description

@joshuaellis

Problem description:

Documented as BufferAttributes only being able to be given a TypedArray, but when you call attribute.array the return type is ArrayLike instead of a version of TypedArray – https://threejs.org/docs/#api/en/core/BufferAttribute

this becomes a problem in code like estimateBytesUsed in BufferGeometryUtils:

export function estimateBytesUsed(geometry: BufferGeometry) {
  let mem = 0
  for (let name in geometry.attributes) {
    const attr = geometry.getAttribute(name)
    mem += attr.count * attr.itemSize * (attr.array as TypedArray).BYTES_PER_ELEMENT // you have to typecase to get BYTES_PER_ELEMENT because it's not on ArrayLike
  }

  const indices = geometry.getIndex()
  mem += indices ? indices.count * indices.itemSize * (indices.array as TypedArray).BYTES_PER_ELEMENT : 0
  return mem
}

Suggested solution:

Could we use a generic to detect the type of TypedArray passed to the Attribute so that type is returned when we call attribute.array?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcurrent releaseissues to do with the current release of Threerequest for commentsDiscussion about changes to the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions