Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Allow setting arrays of materials in a mesh#189

Open
feritarou wants to merge 3 commits into
troisjs:masterfrom
mastoryberlin:master
Open

Allow setting arrays of materials in a mesh#189
feritarou wants to merge 3 commits into
troisjs:masterfrom
mastoryberlin:master

Conversation

@feritarou

Copy link
Copy Markdown

Made in reaction to #89

@klevron

klevron commented Apr 7, 2023

Copy link
Copy Markdown
Member

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

@feritarou

Copy link
Copy Markdown
Author

@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)

@klevron

klevron commented Apr 7, 2023

Copy link
Copy Markdown
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants