Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Based on some example scripts from this forum I've created the following "on-click-random-color" JS code. On a "click behaviour" it changes the vertex color to random RGB. This works fine as long its an *.exe publish. Does anyone know how to convert it that it works with WebGL too? I know the "ccbGetSceneNodeMeshBufferCount();" does not work on WebGL; any workaround idea? Thanks. var rndIntR = Math.floor(Math.random() * 255) + 1; var rndIntG = Math.floor(Math.random() * 255) + 1; var rndIntB = Math.floor(Math.random() * 255) + 1; //print(rndInt); var meshnode = ccbGetCurrentNode(); var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode); for (var i = 0; i < bufferCount; ++i) { var vertexcount = ccbGetMeshBufferVertexCount(meshnode, i); var rgb = "0x" + Math.random().toString(16).slice(2, 8); if (rgb) { var rgbStr = rgb.replace(" ", ""); var rgbArr = rgbStr.split(","); var r = rndIntR; var g = rndIntG; var b = rndIntB; for (var v = 0; v < vertexcount; ++v) { function rgbToHex(r, g, b) { return ( "0x" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) ); } var color = rgbToHex(parseInt(r), parseInt(g), parseInt(b)); ccbSetMeshBufferVertexColor( meshnode, i, v, parseInt(Number(color), 10) ); } } else { // Do nothing } } //var rndIntR = Math.floor(Math.random() * 255) + 1; //var rndIntG = Math.floor(Math.random() * 255) + 1; //var rndIntB = Math.floor(Math.random() * 255) + 1; //print(rndInt); //print("END"); |
||||
|
Why don't you use a shader to do that, instead of coloring it through the geometry editing tools. Shaders work for webGL, it is not hard to create an RGB color multiplying shader for WebGL. |
||||
|
Great Tipp - Thanks just_in_case. I will look into WebGL shaders. Is there a place for ccb shaders where i can get some examples to play with? |
||||
|
There is example in the CC documentation, also some of my shaders has webGL support. Like blend two textures together has support for webGL. Animate Texture Coord shader has support for webGL as well. If you want you can go through them. hope that helps :) |
||||
|
Awesome - will do that later. thanks |
|