2
$\begingroup$

I have a textured 3D mesh. I want to deduce a 3D mesh without texture, but with an RGB vector color on each node of this 3D mesh. The colors have to be picked from the initial texture. Is there a way to do this ? My question isn't related to art work. It's related to 3D mesh processing.

Thanks

$\endgroup$
3
  • 1
    $\begingroup$ To put it another way, you want to write code to "bake" the texture into vertex colors, so that the vertex colors approximate the original texture? $\endgroup$ Commented Dec 22, 2017 at 19:04
  • $\begingroup$ I've reopened your question now that you've clarified it a little, but to make sure you're not disappointed later, I'll say now: if you're looking for an existing piece of software that you can run your mesh through, we won't be able to help. If you're looking for an algorithm that you can use to write some software, we might be able to help. $\endgroup$
    – Dan Hulme
    Commented Dec 23, 2017 at 9:39
  • $\begingroup$ @DanHulme YEs, I was looking for an algorithm $\endgroup$
    – javier
    Commented Dec 26, 2017 at 21:00

1 Answer 1

1
$\begingroup$

You can sample the texture in your vertex shader and set the color appropriately. You don't say what system you're using, but for something like an OpenGL vertex shader, it would look something like this (this is a little old school, so it may need updating for modern GL) :

uniform sampler2DRect texture;
varying vec4 color;
void main ()
{
    color  = texture2DRect(texture, gl_MultiTexCoord0.xy);

    vec4    newVertex   = vec4(gl_Vertex.xyz, 1.0);

    gl_Position = gl_ModelViewProjectionMatrix * newVertex;
}

Your fragment shader would then just set the color of the fragment to the interpolated color coming from the vertex shader. Something like this:

varying vec4 color;
void main()
{
    gl_FragColor = color;
}
$\endgroup$
3
  • $\begingroup$ Thank you for your response. Since I never worked with openGl, I would need some clarifications about your code. The parameter texture that you've passed to the texture2DRect function is the 2D image associated to texture right ? Can you please give a more complet code having the lines for reading the 3D textured mesh, transferring the color texture to 3D vertices, and saving it to a .ply file ? $\endgroup$
    – javier
    Commented Dec 26, 2017 at 21:03
  • 1
    $\begingroup$ That's beyond the scope of an answer here, I'm afraid. I suggest you look up a modern beginning OpenGL tutorial. Once you've learned how to put geometry on the screen and add a texture to it, it's pretty much the same for a 3D texture. For 3D Textures you'll use a sampler3D instead of a sampler2DRect and call texture3D() instead of texture2DRect(). Good luck! $\endgroup$ Commented Dec 26, 2017 at 21:53
  • $\begingroup$ @javier What you're requesting is not an algorithm, it's an entire application. We have a finite amount of space in our answers, so it's best to keep your question limited to something specific. Loading a 3D mesh and save a .ply file are totally different problems and we can't possibly answer that without knowing more about the original format and what specific problems you're having with your mesh loading code. You should post separate questions once you've tried to load / save a mesh if you still need help. $\endgroup$
    – Dan
    Commented Dec 27, 2017 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.