trois icon indicating copy to clipboard operation
trois copied to clipboard

Allow setting arrays of materials in a mesh

Open feritarou opened this issue 2 years ago • 3 comments

Made in reaction to #89

feritarou avatar Apr 06 '23 17:04 feritarou

Thanks, can you revert chore: build package so the PR is just about Mesh.ts

klevron avatar Apr 07 '23 06:04 klevron

@klevron Sure, just did so (wasn't sure how long it would take you to note/merge this PR but I needed that change urgently so I just built my fork without thinking - sorry for that)

feritarou avatar Apr 07 '23 07:04 feritarou

Thanks

setMaterial won't be called with an array of materials : https://github.com/troisjs/trois/blob/master/src/materials/Material.ts#L50

I think it should be :

setMaterial(material: Material) {
  if (Array.isArray(this.material)) {
    this.material.push(material)
  } else {
    if (this.material) {
      this.material = [this.material, material]
    } else {
      this.material = material
    }
  }
  if (this.mesh) this.mesh.material = material
}

But there should be some HMR problem, I don't have time to test for the moment.

klevron avatar Apr 07 '23 11:04 klevron