PDA

View Full Version : Need ideas on how to "spray paint" object



cthulhu666
09-05-2002, 12:39 AM
Hi

I'm writing a program that's supposed to simulate and display objects that are spray painted by a robot. Ideas that can be used to make a play/pause/play backwards player would be highly appreciated.

I've thought about how to apply the "paint" and I've come up with the following ideas:
1. Use colored lights and then try to "store the lighting"
2. Some sort of raytracing (?)
3. Do it manually and only use OpenGL to display it.

Any ideas, comments and the like very welcome.

Thanks in advance.

Cthulhu

Pa3PyX
09-05-2002, 01:03 AM
glEnable(GL_LOGIC_OP);
glLogicOp(GL_XOR);

With this (provided you are using color index mode, not RGBA), when you draw a pixel, it will first be XOR'ed to whatever is in the frame buffer at that position. Thus, if you draw a pixel with a clear background, it will be drawn as usual (any number XOR 0 == that same number). When you draw that pixel again in that position, it will vanish (any number XOR self == 0). Should work if you are doing something simple, like drawing lines that do not cross and rectangles that do not overlap. If you do have overlapping images drawn, then it gets tricky, especially if the overlapping images are opaque...

Or - hey - how about just setting all your colors to background color and drawing everything backwards? Should work so long as you don't have any textures, lighting, direct rasterization and the likes, and even then in some cases - if your background is clear...

[This message has been edited by Pa3PyX (edited 09-05-2002).]

cthulhu666
09-05-2002, 01:21 AM
Originally posted by Pa3PyX:
glEnable(GL_LOGIC_OP);
glLogicOp(GL_XOR);

With this (provided you are using color index mode, not RGBA), when you draw a pixel, it will first be XOR'ed to whatever is in the frame buffer at that position. Thus, if you draw a pixel with a clear background, it will be drawn as usual (any number XOR 0 == that same number). When you draw that pixel again in that position, it will vanish (any number XOR self == 0). Should work if you are doing something simple, like drawing lines that do not cross and rectangles that do not overlap. If you do have overlapping images drawn, then it gets tricky, especially if the overlapping images are opaque...

Or - hey - how about just setting all your colors to background color and drawing everything backwards? Should work so long as you don't have any textures, lighting, direct rasterization and the likes, and even then in some cases - if your background is clear...

[This message has been edited by Pa3PyX (edited 09-05-2002).]

Thanks for the quick reply http://www.opengl.org/discussion_boards/ubb/smile.gif

I'm afraid that the first approach is unusable, since I need the "paint" to be applied to the object, so that it can be rotated and viewed from different angles.

And I'm afraid I don't really understand your 2nd approach?!?

[This message has been edited by cthulhu666 (edited 09-05-2002).]

Gavin
09-05-2002, 06:26 AM
hmmm, texture map it maybe. you can reveal/move the spray painted texture map across your object. The texture could be like a spray paint ramp if you see what I mean...

harsman
09-05-2002, 06:56 AM
Here are some ideas:

* Detect which vertices are within the sprays cone of influence and colour those. With smooth shading and a densely tesselated model it should look pretty good.

* Render the spray colour to the texture using an alpha blended quad with a gaussian (blob like) texture. This requires you to find the texcoords of the point where the colour hits, but that should be doable.

cthulhu666
09-05-2002, 07:26 AM
Thank you both for your replies http://www.opengl.org/discussion_boards/ubb/smile.gif

To specify the purpose of my program a little further:
It's supposed to reveal badly painted spots on an object when painted by a robot. Therefore I need to visualize the thickness of the paint all over the object. The program is meant to be a player whit the painting being showed as an animation (preferrebly in realtime).

Originally posted by Gavin:
hmmm, texture map it maybe. you can reveal/move the spray painted texture map across your object. The texture could be like a spray paint ramp if you see what I mean...
I'm not sure I can follow you: reveal/move the texture map?

Won't that only show the area currently being painted?

Originally posted by harsman:
Here are some ideas:

* Detect which vertices are within the sprays cone of influence and colour those. With smooth shading and a densely tesselated model it should look pretty good.

* Render the spray colour to the texture using an alpha blended quad with a gaussian (blob like) texture. This requires you to find the texcoords of the point where the colour hits, but that should be doable.
Detecting the vertices within the spray cone is very similar to collision detection, which is a somewhat difficult problem, especially with many vertices. The thought of this approach has crossed my mind, but I was hoping that openGL maybe could do all the "hard" work for me http://www.opengl.org/discussion_boards/ubb/wink.gif

I have also thought about something very similar to your 2nd approach, but how would you calculate the tex coords? Is there a way to transform object coords to tex coords? And how can I compensate for curved objects?

I hope to hear from you both again (and many others) http://www.opengl.org/discussion_boards/ubb/smile.gif

harsman
09-05-2002, 08:54 AM
I assumed the model you were spray painting had tex coords. Then you just do a intersection test with the cone and the geometry to get the affected trinagles, get their uv's and voila. If you don't have tex coords the problem gets more tricky. I know Jeff Lander has implemented a 3d painter, i.e something which allows you to paint on texturemaps in 3d for gamedeveloper magazine. Try looking at his site www.darwin3d.com (http://www.darwin3d.com) or at gdmag.com There should be source available.

dorbie
09-05-2002, 02:20 PM
Yep, you need to figure out where the spray gun hits the object in texture space and render to texture the paint spray color. A prerequisite is that you have an object where each area on the surface is textured with a unique part of the texture map.

cthulhu666
09-05-2002, 10:34 PM
Originally posted by harsman:
I assumed the model you were spray painting had tex coords. Then you just do a intersection test with the cone and the geometry to get the affected trinagles, get their uv's and voila. If you don't have tex coords the problem gets more tricky. I know Jeff Lander has implemented a 3d painter, i.e something which allows you to paint on texturemaps in 3d for gamedeveloper magazine. Try looking at his site www.darwin3d.com (http://www.darwin3d.com) or at gdmag.com There should be source available.
Can't the tex coords be generated, easily?

I tried looking at the site, you referred to, and I found a tech page, but there aren't really any examples or anything http://www.opengl.org/discussion_boards/ubb/frown.gif
Do the PowerPoint presentations contain anything helpfull?

Originally posted by dorbie:
Yep, you need to figure out where the spray gun hits the object in texture space and render to texture the paint spray color. A prerequisite is that you have an object where each area on the surface is textured with a unique part of the texture map.
Then I presume a have a problem... Textures have to be quadratic or...? If so, then I can't apply a texture that garanties a unique texture area for all areas on an arbitrary object (a cone for example). Or can I?

A n00b question: how do I generate texture coords (I have an array with all vertices and normals)?

harsman
09-06-2002, 02:19 AM
The source to Lander's 3d-paint app can be found here (ftp://ftp.gdmag.com/pub/src/sep00.zip) , here (ftp://ftp.gdmag.com/pub/src/nov00.zip) and here (ftp://ftp.gdmag.com/pub/src/jan01.zip) . The articles that this source code accompanies doesn't seem to be available at his site. They should've been here (http://www.darwin3d.com/gdm2000.htm) if they were. Hopefully you can get something from the source anyway.