three-stdlib icon indicating copy to clipboard operation
three-stdlib copied to clipboard

GLTFReference type out of date

Open funwithtriangles opened this issue 3 years ago • 0 comments

  • three version: 0.136.0
  • three-stdlib version: 2.6.4

Problem description:

The current GLTFReference type is out of date since version 2.6.4 where loaders were updated.

Relevant code:

const reference = parser.associations.get(object.material) 

if (reference?.materials) {
  // TS error: Property 'materials' does not exist on type 'GLTFReference'
  object.material = copiedMaterials[reference.materials]
  object.material.needsUpdate = true
}

Suggested solution:

I have fixed this temporarily like this:

interface GlTFMaterialReference {
  materials: number
}

const reference = parser.associations.get(object.material) as
        | GlTFMaterialReference
        | undefined

I think to handle this type properly in the library it will need something like generics because the type will change depending on what is passed to parser.associations.get

Extra notes

The type currently looks like this, which is now out of date:

// GLTFLoader.d.ts
export interface GLTFReference {
    type: 'materials' | 'nodes' | 'textures';
    index: number;
}

funwithtriangles avatar Jan 14 '22 10:01 funwithtriangles