Three.js - Change Material on Runtime

后端 未结 1 921
长情又很酷
长情又很酷 2021-02-05 03:00

I have some .js files exported from Blender and load them with THREE.JSONLoader();

my callback:

var callback   = function( geometry ) { crea         


        
相关标签:
1条回答
  • 2021-02-05 03:39

    As you create a new material for each mesh I assume you only want to change the color of one mesh and not of all in the inArr array, and you probably need some sort of select for that. But changing the color of the material alone is quite easy:

    var onKeyDown = function(event) {
      if (event.keyCode == 67) { // when 'c' is pressed
        object.material.color.setHex(0xff0000); // there is also setHSV and setRGB
      }
    };
    document.addEventListener('keydown', onKeyDown, false);
    

    object is the mesh you want to change. Key codes can be found here: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

    0 讨论(0)
提交回复
热议问题