How to get- / setMaterial / diffuseColor / Texture / Tiling & Offset in CC v2.11

How to get- / setMaterial / diffuseColor / Texture / Tiling & Offset in CC v2.11


I am now inside the Materials of CC 2.11. I added already Materials to my 3D Objects. But now, i need to :

  • swaping Mat_1 with Mat_2
  • define diffuseColor of Mat_1 (including alpha-value)
  • changing Texture of Mat_1
  • change Tiling / Offset of Mat_1

I didn´t found anything related to this (even inside the API). Especially because my question is not related to the well known 2D (Sprite), its related to the 3D Node + the new Material System. I guess its because of that. Does anybody has experience to that ? Or any Link / Tutorial to it. Would be great if someone could explain how to accomplish all the tasks i named above. Thanks.

So, i figured it out by myself. After few days of research. Anyways, here are my solutions:

  • swaping Mat_1 with Mat_2
    you have few ways to do it:
    1.) this.MESH_node.setMaterial(0, this.MY_MAT_archive_node); // if you have a node with Material put on it
    2.) this.MESH_node.setMaterial(0, this.MY_MAT_archive_node.getComponent(cc.MeshRenderer).getMaterial(1)); // takes Material from one node to another one
    3.) cc.loader.loadRes( “MATs/Ground_TEST”, cc.Material, (err, MAT_new) => { this.MESH_Bird.setMaterial(0, MAT_new);
    // // loading Material from …/resources/MATs/“Ground_TEST”

  • define diffuseColor of Mat_1 (including alpha-value)
    1.) this.MESH_node.getMaterial(0).setProperty(“diffuseColor”, cc.color(0, 0, 255, 100)); // if you need to set something in Material 2, 3, etc…just change number inside “getMaterial(0)” f.e. to “getMaterial(1)”

  • changing Texture of Mat_1
    1.) this.MESH_node.getMaterial(0).setProperty(“diffuseTexture”, this.TEX_test); // " this.TEX_test" it must be pre defined inside a script-variable, or inside a component
    2.) cc.loader.loadRes( “Textures/teeest.png”, cc.Texture2D, (err, TEX_new) => {
    this.TEX_node = TEX_new; // stores “TEX_new” into the “TEX_node”-VARIABLE
    }) // this loads stuff from the root-folder “resources”

  • change Tiling / Offset of Mat_1
    this.MESH_node.getMaterial(0).setProperty(“mainTiling”, cc.v2(2, 2)); // use cc.v2 for X, Y
    this.MESH_node.getMaterial(0).setProperty(“mainOffset”, cc.v2(0.2, 0.2)); // use cc.v2 for X, Y

I hope this can help someone, who is also searching for this :innocent:. Sadly it seems “tiling” texture2d with alpha doesn´t seems to work. Thats it …

Ehm, i also just want to mention that i am struggleing with the API documentation of CC. It seems like not everything is documented. I mean really ALL-functions , ALL-commands. If someone know, where to find ALL JS commands for CC, please let me know. Let the users know … thx :+1:


so you can’t find any document about material
and upgrade the material system in v2.1.2 was delayed to v2.1.3

Thx for info. I figured it out by myself. But good to hear they plan to put more love into it. In general i got the feeling the API isn´t that well documented. But maybe this get optimized with time.Do you know anything about the release date of v2.13 ?

i don’t know!