question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Helper to deal with multi-materials

See original GitHub issue
Description of the problem

I am currently merging meshes with different materials which result in a single mesh with material property being an array.

Then I had to update all my code base in order to support this, and I feel like repeating myself a LOT !

That’s why I think it might be cool to have something to help us dealing with that.

I don’t think forcing material to be an array is a good move because of the memory overhead it will add.

I am thinking on a stuff more like this:

forEachMaterial(callback) {
  if (Array.isArray(this.material)) {
     for( var i =0; l = this.material.length; i < l; i++ ){
        callback(this.material[i]);
    }
  } else {
     callback(this.material);
  }
}

Like this on my side I could replace

if (Array.isArray(mesh.material)) {
     for( var i =0; l = this.material.length; i < l; i++ ){
        material[i].opacity = 0.5;
    }
} else {
  material.opacity = 0.5;
}

By

mesh.forEachMaterial(function(material) {
  material.opacity = 0.5;
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Jun 20, 2018

I am currently merging meshes with different materials which result in a single mesh with material property being an array.

Why not merge only meshes that share a single material? Only one material can be rendered in a draw call, so if you have N materials, you will have N draw calls anyway – and maybe many more than that if your merged faces are not properly sorted.

0reactions
WestLangleycommented, Jun 20, 2018

@moroine I think that makes sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi Material - V-Ray for SketchUp - Chaos Help
The Multi Material is used when a proxy is created. ... Instead, the V-Ray texture helper map is always displayed in the SketchUp...
Read more >
Elite Dangerous Odyssey Materials Helper - Frontier Forums
Ability to create multiple wishlists and a suggested shortest travel path to craft them; Ability to simulate bartender trading while taking the ...
Read more >
Tutorial for Elite Dangerous Odyssey Materials Helper - v1.90
In this video I go through how to download, install and use Elite Dangerous Odyssey Materials Helper (v1.90), which is an incredibly useful ......
Read more >
Material Handler Job Description [Updated for 2023] - Indeed
A Material Handler, or Warehouse Associate, handles, moves and stores various non-hazardous and hazardous materials within a warehouse. Their main duties ...
Read more >
What Does A Material Controller Do: Job Description, Duties ...
A material controller coordinates the movement of materials between departments. This position's duties include creating records of materials' movements in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found