ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Red Vertex Color in CopperCube
person icon
okeoke
Registered User
Quote
2023-09-11 11:04:47

Ah, ok. I've read the original post. You were asking how the number is obtained, I see.

person icon
olprint
Registered User
Quote
2023-09-11 11:33:08

@okeoke now run:

var node = ccbGetSceneNodeFromName("box1");
var meshBufferCount = ccbGetSceneNodeMeshBufferCount(node);
for (var i=0; i<meshBufferCount; i++) {
var vertCountPerBuffer = ccbGetMeshBufferVertexCount(node, i);
for (var j=0; j<vertCountPerBuffer; j++) {
var color = ccbGetMeshBufferVertexColor(node, i, j);
print(color + " = " + color.toString(16));
}
}

person icon
olprint
Registered User
Quote
2023-09-11 11:37:50

It is red to the eyes, but will we actually get ff0000 when we use CopperCube's 'Scripting Window' (or our app's JavaScript)?

person icon
okeoke
Registered User
Quote
2023-09-11 12:47:00

You're missing alpha channel. Your result should be either FF0000FF for RGBA or FFFF0000 ARGB.
There is either an issue with data types, so it's translated incorrectly, or it's calculated differently.

But does it matter? If you want to apply different colors, you can get random ints. If you want to set colors in blender - you can also do that and they are propagated correctly.

I mean, if you want to understand how it works, you probably, need to understand which data type is used to store color in C++ and see if it translates to js engine properly. Or you can try exporting different vertex colors like black with 0 and 255 transparency, red with 0 and 255 transparency, and etc and see if you can see any system.

person icon
olprint
Registered User
Quote
2023-09-11 13:50:33

I kind of understand... I had a problem in the past with using fanciful int (like int32_t, uint_8 etc) while dealing with colors and color channels. Maybe I was not being consistent. I had to use plain int to solve those bugs.
Further: Blender doesn't support changing alpha value for vertex coloring. Also, CopperCube doesn't support that. I think I tried one other software.
color.toString(16) did not include alpha on my computer.
@Dieter and @Guest (a guest) gave codes that included alpha.

person icon
just_in_case
Moderator
Quote
2023-09-11 15:33:07

@oleprint, it will give you the red color as well, if you have the functions mentioned on my website then you will get to know that, by default the API
ccbGetMeshBufferVertexColor(node, meshbufferindex, vertexindex)
gives you a decimal color, which you need to convert into RGB values, you can use the functions from the website. or for ease of acess I am writing them again here.


// Fixing the Color Property type Parameter of action to get RGB value and clamp them between 0 and 1.
function RGB(decimalcolorcode)
{var color = (decimalcolorcode); // use the property type or put a decimal color value.
var Rr = (color & 0xff0000) >> 16; // get red color by bitwise operation
var Gg = (color & 0x00ff00) >> 8; // get green color by bitwise operation
var Bb = (color & 0x0000ff); // get blue color by bitwise operation
var RrGgBb = new vector3d(Rr,Gg,Bb);
var r = (Rr/255); // dividing red by 255 to clamp b/w 0-1
var g = (Gg/255); // dividing green by 255 to clamp b/w 0-1
var b = (Bb/255); // dividing blue by 255 to clamp b/w 0-1
var rgb = new vector3d (r,g,b); // final rgb value to use in the editor
return rgb;
}


you can use the above code to get the RBG values from the decimal color, it will give you the same color.

However this only works if you apply the vertex color inside the CopperCube editor, if you are importing the model for example from blender 3D, then you also need to multiply the RGB value with 4.0476, to get the actual value of the vertex color.

Hope this will solve the original question asked here, I thought that you just wanted to have vertex colored objects in your game.

person icon
Dieter
Guest
Quote
2023-09-11 15:33:12

Yeah, well first of all, there seems to be an inconsistency between webGL and other targets, in how to access vertex color by script in CC. If I remember correctly, these aren't supported at all, but one can use the respective copperlicht.js syntax instead, or a fork in the code, depending on platform.

I have just recently posted an EntityAlpha() function somewhere here (somebody asked for something to appear slowly). It works, but only with an older version of copperlicht.js.

There are blending modes for textures in the irrEditor window. One of the last ones in the menu is something like "use vertex alpha to blend in 2nd texture".

You can use this one without a second texture, effectively making the mesh alpha-transparent, based on vertex alpha.

One could do a fog this way that gets dense towards the ground, for example.

In terms of vertex color, CC uses 63 interally, not 255, so values higher than 63 are reseved for other purposes, it seems. However, B3D files normally contain RGB as 8 bit ints. I do remember I had quite a hard time to modd the export code, as for this particular blending mode there was some kind of strange behavior by CC, like reading them as signed 8 bit int values.

As very often, when standards blur, experimentation can give answers, and it is rather a matter of setting up the experiment in no time, than to find the answer online. Because frankly I even don't remember exactly.

Actually, just for fun:

// parameters: node, alpha (0.0 to 1.0),dyn_lit

function EntityAlpha(node2,al,is_dyn_lit=0){
var node=node2.getMesh();
if(!node)alert("sum ting wong");
//var mes=node.GetMesh();
buf=node.GetMeshBuffers();
if(is_dyn_lit==1) {al*=4;}
al*=63;
if(al<0)al=0;
if(al>255)al=255;
al=al<<24; // bit-shifting alpha to the top byte.
var al_max=0x3e000000;
if(is_dyn_lit==1) {al_max=0xfe000000;}
for(i=0; i<buf.length;i++){
if(al>al_max){
if(is_dyn_lit==0) {buf[i].Mat.Type = CL3D.Material.EMT_SOLID;}
else {buf[i].Mat.Type = CL3D.Material.EMT_TRANSPARENT_ALPHA_CHANNEL_REF;} // this is used for dyn. lit plants and such
}
else{
buf[i].Mat.Type = CL3D.Material.EMT_TRANSPARENT_ALPHA_CHANNEL;
}
for(j=0; j<buf[i].Vertices.length;j++){
buf[i].Vertices[j].Color=(al | 0x3f3f3f);//0x3f3f3f);
}
buf[i].update(false,false);
}
}


There you see a lot of messy code to handle just 2 possible blending modes. If the mesh is lit dynamically, alpha is multiplied x 4.
Alpha may be no more than 0x3E000000, or if dyn-lit no more than 0xFE000000.

Then I mix this with a neutral 0x3F3F3F, which is basically 63,63,63, or CC-white. Could be anything, of course.

person icon
just_in_case
Moderator
Quote
2023-09-11 15:36:41

well i guess, We answered the thread at the same moment Dieter. hehehhe emoji icon_grin Yeah, vertex alpha works in CC as well, there is special material to use the vertex alpha in CC, one might need to change it. "Trans_vertex_alpha" material type in irredit/irrlicht properties.

person icon
Dieter
Guest
Quote
2023-09-11 15:50:12

Hey just_in_case, 4.0476 ? Why? :-)

person icon
okeoke
Registered User
Quote
2023-09-11 15:52:51

Blender also supports vertex alpha. You need to set up the material so it's transparent.

It's also easy to verify, if you export models with alpha set to 1 and 0 and compare number you receive by ccbGetMeshBufferVertexColor.

person icon
okeoke
Registered User
Quote
2023-09-11 15:55:39

I guess 4.0476 * 63 ~= 255:)

person icon
olprint
Registered User
Quote
2023-09-11 16:00:54

Thanks @just_in_case. Thanks @Dieter. Since I'm new to CopperCube, I barely know things about copperlicht.

Remember everyone: I'm no longer seeking for a solution.

person icon
just_in_case
Moderator
Quote
2023-09-11 17:17:07

@Dieter, remember when you have your Viking boat in your game disappearing I suggested you to use (63,63,63) as vertex color, to fix it. At that time I took myself why it happens and since then I knew that CC uses 4x of vertex color for some imported models, while it internally uses values upto 255. So if you apply the color using CC's internal vertex coloring mechanism, you will get 255 while for some imported models with vertex color you will get 63.

As @okeoke already provided answer 63 * 4.0476 ~= 255 , I suggested multiplying the result with this value, it will give the required color value for the imported model with vertex color.

@Olprint, Copperlicht is the webGL engine for CopperCube. Welcome to the community, hope you will create something good with the engine. There is a lot to explore in this engine.

person icon
olprint
Registered User
Quote
2023-09-11 17:42:11

Thanks for the explanation.
There is a lot to explore in this engine
True. I like it because it serves both low and high end computers.

person icon
Dieter
Guest
Quote
2023-09-13 21:26:49

@just_in_case

Yeah I already had a suspicion. Yet, I'd rather say:

(64*4)-1= 255.

All those cryptic floats must scare people lol. Like I use
57.29577951 a lot, and people go like "yeah right, totally intuitive" ^^ - the secret math spells of the CC vets.

I still don't understand exactly why it uses 63 instead of 255. Sure when you set it to say 127,127,127, the mesh becomes way too bright.

Could use this for baked shading, like Phong shading, or for a part of the triangles of a lightmap (triangles without shadow edges on them).


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |