Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Programming and Scripting
Random vertex color
Author Text

Guest
Guest
Quote
2022-06-14 01:38:18

I've been messing with making prefabs of simple geometry for use in CC. Basically copying the contents of Unity primitive "blockout" kits for fun and learning. I'm not texturing them because that's not needed for a "blockout/greybox" or whatnot. I like to just slam the vertex-painted shapes together before merging the meshes into one and exporting to another program for texturing. If you're not doing this, I recommend you give it a try. It helps to deconstruct complex objects into simple colored shapes. Least that is what I've found out. That said, one thing I do not like is picking out the vertex color for my shapes. It's tedious when adding a lot of shapes to pick out colors. So to reduce those extra clicks I wrote a little editor plugin to do it for me, and that is what I want to share.



// CopperCube editor plugin that applies a random vertex color to a mesh

function randomVertexColor() {
var meshnode = editorGetSelectedSceneNode();

var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode);

function getColor() {

return color = "0x" + Math.random().toString(16).slice(2, 8);
}

getColor();

if (bufferCount == 0)

alert('The selected node has no 3D geometry.');

else {
for (var i = 0; i < bufferCount; ++i) {
var vertexcount = ccbGetMeshBufferVertexCount(meshnode, i);

for (var v = 0; v < vertexcount; ++v) {
ccbSetMeshBufferVertexColor(meshnode, i, v, parseInt(Number(color), 10));
}
}
}
}

editorRegisterMenuEntry("randomVertexColor()", "Apply random vertex color\tCtrl+P");



Just copy this code to a text file, save it as "randomVertexColor.js", and put it into you plugins folder. Next time you launch your CC you will be able to press Ctrl + P to apply a random vertex color to your geometry nodes. You can even hold down the keys to watch it run through a bunch of colors. Note: you can change the key combinations by simply replacing this line:

editorRegisterMenuEntry("randomVertexColor()", "Apply random vertex color\tCtrl+P");

to something like:

editorRegisterMenuEntry("randomVertexColor()", "Apply random vertex color\tCtrl+L");

It will now work with the Ctrl + L next time you open CC or reload the plugins. I recommend looking on Just_In_Case's website for his "Keyboard Shortcuts" plugin to see what other keyboard shortcuts are valid. Here it is, just open and look down at the bottom to see all the combinations you can use:

https://neophyte.cf/ccb_plugin_k...

You are free to do anything you want with this code. I release it to the community. If you do make something else with it, I would personally like to see it posted here for everyone. Maybe your way of doing it is superior than mine. I'm still new to programming but CC has greatly helped me learn and feel comfortable with JS. Cheers, guys.


just_in_case
Moderator
Quote
2022-06-14 06:51:24

Thanks a lot for sharing the plugin :) I also have an extension on my PC that allows you to change vertex color during the runtime of the game, I haven't added any ability to change the color to a random color but to a specific color. Maybe I can add the random color ability to the extension so that we can change vertex color during runtime. I created this extension for Helix Jump Demo of mine but never had time to use it or work on that project again.
If you don't have any issues, would you allow me to put your plugin on Neophyte.cf with proper attribution and a link back to your contact email address or website ?


Guest
Guest
Quote
2022-06-14 07:15:53

Hey Just_In_Case! I consider Neophyte.cf as part of the CC community, so you're free to post the code on your website. I don't need any credit since I released it to the community. Truth is I'd be happy to have it on your website since more people will likely see it. I searched the forum here for something like it and didn't find anything, so I decided to work on it and post it here. I'm happy just knowing I contributed something. I've learned a lot from your YouTube videos and website. Appreciate all you do. Cheers.


just_in_case
Moderator
Quote
2022-06-14 15:56:25

Thanks, uploaded it as a plugin asset on neophyte.cf here:-
https://neophyte.cf/ccb_plugin_r...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (you are not logged in)


Text:

 

  

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


   






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