Jump to content

getFaceColor at pick Point


Pryme8
 Share

Recommended Posts

http://www.babylonjs-playground.com/#YSZ7YV#29

I feel like I am doing this wrong...
 

    getVertexColor = function(pick){
        var indices = pick.pickedMesh.getIndices();
        var vdc = pick.pickedMesh.getVertexBuffer(BABYLON.VertexBuffer.ColorKind);
        //console.log(vdc, indices);
        var p1,p2,p3;
        p1 = indices[(pick.faceId*3)];
        //p2 = indices[(pick.faceId*3)+1];
       //p3 = indices[(pick.faceId*3)+2];
        var pc = new BABYLON.Vector3(vdc._buffer._data[p1],vdc._buffer._data[p1+1],vdc._buffer._data[p1+2]);
        shader.setVector3("selectedChannel", pc);
    };  

I want to get the Color Vertex Data at point of click.

Link to comment
Share on other sites

I am not sure what should be the result, but one thing for sure -  p1 will not be enough. you will need p2 and p3.

also, highly recommended not to use native js events in the playground (you have canvas.addEventListener). those functions will not be unregistered if you press run again, and will actually run N times (N being the number of times you pressed run + 1). you can use scene.onPointerMove instead.

Link to comment
Share on other sites

Hmm so I need to average the color information of the three points then to get the face color then?  That might make it so when a face is on the border to anouther color, that I get a different response then what anticipated because it will blend those points.

http://www.babylonjs-playground.com/#YSZ7YV#33

>_< yeah this is not working.

Link to comment
Share on other sites

We have three basic channels;

  • Red: r=1, g=0, b=0
  • Green: r=0, g=1, b=0
  • Blue: r=0, g=0, b=1

Some faces though have less intense, R, G or B as these are intended to be areas that can have their texture altered.

Looking through the PG, I'm not sure though how this could be accomplished. My intention originally was that each of the separately selectable vertices could be 'detached' from the mesh to make a new one... but I suspect this may be tons of work which I want to avoid. I am thinking with my Blender head on.

Link to comment
Share on other sites

It would be possible but would add tons more script.  This is working off the assumption that there will ever only be 3 channels, you are effectively making it an infinite amount by doing that.
 

17 minutes ago, babbleon said:

I am thinking with my Blender head on.

Ideally you would just split the mesh up before exporting it, and then this shader would be way way simpler.
I know you said that would mess with your workflow, but honestly should make thing easier for you.  Just select the faces on the model you want to be a separate modifiable section split it out and then add all the parts to a null object/parent.  That would honestly be faster then assigning vertex colors and would be way way more robust.

Then when we import the model, we assign new instances of the shader to each of the submeshs/regions.  It will make your and my life way easier and should accomplish what you really want. 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...