Write a 3D paint tool
From JReality Wiki
Source file: Paint3DToolExample
JavaDoc: Texture2D
The following example is built on the previous one, which drags a 2d texture around on its surface. Instead however of using a static texture and moving it, the tool featured in this example creates the texture image by painting into the BufferedImage
object associated to the texture.
To operate the example:
- Drag while holding the left mouse button down with the cursor is over the geometry.
- Each new position of the mouse composites a transparent image of a shaded blue sphere into the texture image.
- The image of the sphere is provided by the utility method
ShadedSphereImage.shadedSphereImage(...)
which is the same method which produces the texture for the JOGL backend to render points as sprites. - The image is centered at the texture coordinates corresponding to surface point under the cursor position.
- The image of the sphere is provided by the utility method
- As before, to rotate the object, move the cursor away from the geometry (over the background) before dragging.
New things to notice:
- We use an animated
Texture2D
which means that changes made to the underlyingBufferedImage
will be updated correctly.- See Use an animated 2d texture for introduction to animated textures.
- Here we don't need to provide a
Runnable
since the paint process occurs asyncronously to the render process
- The tool uses the
drawImage()
method ofBufferedImage
to composite the image of the sphere over the existing image.
Obviously, there are lots of features which could be easily added to this paint tool: color chooser, size and transparency control for the brush. Additionally, one could use geometric information from the surface to modulate the painting style.
|