We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

CHANGE vertex paint rgb values?

Home Forums Puzzles CHANGE vertex paint rgb values?

Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
    Posts
  • #26102
    GLiFTeK
    Customer

    hi
    is there a way from within puzzles or JS to change the vertex paint rgb values of an object? just say.. for ease.. ALL of the vetexes change from 1,0,0 to 0,0,1 ?

    thanks

    #26131

    Hi, you can do it in JS as follows:

    
    // myObj is the object to change vertex colors for
    var vertColor = myObj.geometry.attributes.color;
    for (var i = 0; i < vertColor.count; i++) {
        vertColor.setXYZ(i, 0, 0, 1);
    }
    vertColor.needsUpdate = true;
    

    Co-founder and lead developer at Soft8Soft.

    #26158
    GLiFTeK
    Customer

    awesome! thanks! …
    is there any way in there to designate the vertex color map NAME that would/should be created?

    if i previously made a vet map default one “Col” should that name access that data?

    #26169
    GLiFTeK
    Customer

    Is there something else i should be doing with the “myObj” var (or whatever i choose to call it) .. before i put in the code? i’m using it as a call js…

    so when i click on the object it’s rgb goes 100% blue.

    ie:

    same as you put but added input rgbChanger..

            // myObj is the object to change vertex colors for
            app.ExternalInterface.setVertexPaintRGB2 = function(rgbChanger) {
                var myObj = rgbChanger;
                var vertColor = myObj.geometry.attributes.color;
                for (var i = 0; i < vertColor.count; i++) {
                    vertColor.setXYZ(i, 0, 0, 1);
                }
                vertColor.needsUpdate = true;
            }

    i have an onlick of the object and a var w the object’s value is plugged into the input rbChanger in the JScall.

    Getting error:
    ReferenceError: myObj is not defined
    TypeError: myObj.geometry is undefined

    i also did a simplified version with just the object actually named myObj and no changes to the code, same thing.

    do i have to initialize myobj var in a script tag in the html before all this loads?

    #26191

    if i previously made a vet map default one “Col” should that name access that data?

    Yes, you can access a particular vertex color layer by its name. The names are stored in an object’s material. It’s a bit inconvenient, but you can access them like this:

    
    // obtain an attribute name for a vertex color layer named 'Col'
    var attrName = myObj.material.nodeVCAliases['Col'];
    if (attrName !== undefined) {
        var vertColor = myObj.geometry.attributes[attrName];
        // changing colors, etc...
    }
    

    Is there something else i should be doing with the “myObj” var (or whatever i choose to call it) .. before i put in the code? i’m using it as a call js…

    It depends on what is in the “rgbChanger” variable, which “setVertexPaintRGB2” receives. If it’s an object, e.g. the object that was clicked on, or some object from the object selector puzzle:
    js_call.png

    then it needs something like this:

    
    var myObj = app.scene.getObjectByName(rgbChanger);
    

    instead of var myObj = rgbChanger;

    Attachments:
    You must be logged in to view attached files.

    Co-founder and lead developer at Soft8Soft.

    #26194
    GLiFTeK
    Customer
    #26264
    Xen Wildman
    Customer

    What would the whole script look like if you were setting a vertex colour for a picked object in a vertex colour index called KeyCol? Say I want to do another and call it something else?

    Edit: I’d also like user to specify a colour to change to.

    Edit2: Would this puzzle work or is it better to set variable and the external js will pick it up? There are two vertex colors: KeyCol and Legend

    #26293

    Edit2: Would this puzzle work or is it better to set variable and the external js will pick it up? There are two vertex colors: KeyCol and Legend

    Yes, such puzzle would work. But if you have multiple vertex colors then I’d suggest to specify a color name as a parameter:
    setVertexColor.png

    so, you can just call it twice for KeyCol and Legend separately.

    Here’s an example app: vertex_colors.zip. When you click on an object, it calls a js function defined in the vertex_colors.js file to modify the specified vertex color layer.

    Btw, you can also use a node material with RGB nodes instead of vertex colors. Those nodes can be controlled via the Materials->set color puzzle.

    Attachments:
    You must be logged in to view attached files.

    Co-founder and lead developer at Soft8Soft.

    #26296
    Xen Wildman
    Customer

    Thanks so much for the project that I can dissect. Based on your conversation with Gliftek, this is as far as I got but the objects were turning black. I think I understand now.

            app.ExternalInterface.setKeyCol = function(changeObject, changeColor) {
                var myObj = app.scene.getObjectByName(changeObject);
                var setcolor = changeColor;
                var attrName = myObj.material.nodeVCAliases['Keys'];
                if (attrName !== undefined) {
                var vertColor = myObj.geometry.attributes[attrName];
                }
                for (var i = 0; i < vertColor.count; i++) {
                    vertColor.setXYZ(i, 'setColor');
                }
                vertColor.needsUpdate = true;
            }
    #26318
    GLiFTeK
    Customer

    Yeah, not to in any way say you don’t know what you’re doing, but just to clarify if you might be trying to use rgb vertex colors for actual color… Use what Ivan just said with rgb node values.

    But if you’re not…then check it out…

    I’m using rgb vertex colors as a sort of “masking” where I can use one material across a multitude of objects to show different images on each object dependent on their vertex color values.

    I’ve got a seriously complex (yet efficient) node network going on that I’ll post here to share, if that interests you.

    P.s. also, if this helps…the same thing can be done across multiple objects if you give them all uniquely named uv maps, join them all into ONE object, then so all the uv’s are combined in the joined object, THEN, separate all the objects again, as they all hold all the UV’s … And can be successfully referenced in the material that they all share, using the uv’s with math(multiply) nodes to distinguish (mask/unmask) which image nodes (or ANY node)… Is allowed to display on the designated SPECIFIC object out of the multitude of objects that share the ONE material.

    Will make more sense when you see the project file(s).

    This is pretty much a hack for the new ish UDIM uv’s that allow many more channels of data blender 2.83 put it in, though verge is not supporting yet

    :good:

    #26361
    GLiFTeK
    Customer

    here is that project with the sRGB to RGB formula node network linked in a zip.

    3

    note: the html file “as is”, works as intended, fading out each cube as to it’s rgb blue value (.3, .6 , or .9 in this example).
    BUT.. when i export any of the blend file versions.. i wont get that same result. so i don’t know if it’s something i left out when i left off the project, or something that the new verge / blender versions have changed.

    in any case..
    It’s been AWHILE since i left off on this project.. and i am now picking it apart to use in my project now, so i’ll post any clarifications i find.

    but it’s there for you to toy with and see what i mean.

    ( i had a very detailed version of this working perfectly at one time.. many of the modules linked together using the range of .12, .13, .14 etc.. trying to get that back) ..

    ps.s. if i wrote RGBA it’s a typo i meant sRGB

    #26367
    Xen Wildman
    Customer

    Thanks for the reply Gliftek. No offense taken, I’ve been doing computer graphics for many years but you’re right this (WebGL) is new to me. I did solve the RGB thing, I’m not sure how efficient it is but it works.

    I am using vertex color to drive color so that the user can choose to color each element separately. I don’t think that would be very efficient with materials.

    Edit: In Blender that was Gamma 2.2. Changed here to test.

    #26370
    Xen Wildman
    Customer

    Here’s a link to the current working project:

    https://tinyurl.com/y9mxeeke

    Edit: Click on the sphere’s to set the values, then click the keys to change them.

    #26374
    GLiFTeK
    Customer

    Here’s a link to the current working project:
    https://tinyurl.com/y9mxeeke
    Edit: Click on the sphere’s to set the values, then click the keys to change them.

    that is pretty tight man. kudos!
    yeah i wouldn’t be able to find it.. but there’s a huge stackoverflow convo where i’m discussing the formula with people, and one guy is adamant about the gamma node instead of the math power node, (which i had used before unsuccessfully) .. then showing him the network i used, he re-missed and said yeah.. that! .. but that was about 6-7 months ago so i’m thinking the new gamma node is probably more suited to the hack, no? .. seems you have it rocking smoothly!

    also thanks for sharing your results, that’s some clever puzzle networking.
    i’ll def find them useful! :good:

    EDIT: wait.. no i thought from what you said there was a new version of the gamma node.. but no that’s the SETTING (2.4 i had) of the gamma i was using before. k i’m looping back on myself here.

    #26375
    Xen Wildman
    Customer

    It’s not all perfect yet as I have to account for the fact that the environment color and spot light is going to influence the result. I’m totally open to playing with your solution as well and appreciate you sharing. :good:

Viewing 15 posts - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.