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.

change material on mesh

See original GitHub issue

Is it possible to trigger an even that will change the material assignment of the mesh?

I want to swap a phong shader:

phongMaterial = [new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading }  )];

with this basic material:

basicMaterial = [new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors } ),new THREE.MeshBasicMaterial({color: 0xffffff, opacity: 1, wireframe: true} ) ]

when a certain event is triggered I switch using this code:

myMesh.materials = basicMaterial

and switching back:

myMesh.materials = phongMaterial

however when I switch from the phong to the basic the mesh just disappears (it comes back when I switch back)

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
alteredqcommented, Jan 10, 2012

Try this (there are no more multi-materials, also more complex material must be first one that gets rendered, if you use some vertex colors, they must be present / absent in both materials):

phongMaterial = new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading } );
basicMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff, opacity: 1, wireframe: true } );

myMesh.material = phongMaterial;

myMesh.material = basicMaterial;
0reactions
daphnawegnercommented, Jan 15, 2012

Thanks again! that fixed it ( I had the mesh.dynamic in there from the previous version)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Material Mesh - Unreal C++
In this tutorial we will change a static mesh's material on overlap. Create a new actor class and call it whatever you want,...
Read more >
How to change Material and its properties at runtime in Unity?
To change the material at runtime, add the following script to a gameObject with a Mesh Render component. using System.Collections;
Read more >
How do I change the MATERIAL of this mesh when i press T
So I have this. using UnityEngine; using System.Collections;. // Change renderer's material each changeInterval // seconds from the material ...
Read more >
Change material on repeating mesh. : r/unrealengine - Reddit
Create a material or material instance variable within your blueprint. Set it to editable. Then, in the construction script, set the mesh's material...
Read more >
Changing Materials on the Fly - Stellar Game Assets
Begin by creating a duplicate material for each material in the mesh renderer that you want to change. · Rename the duplicate to...
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