Write a 3D paint tool

From JReality Wiki
Jump to: navigation, search

Source file: Paint3DToolExample

JavaDoc: Texture2D


Run as Java webstart


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.
  • 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 underlying BufferedImage 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 of BufferedImage 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.


PaintToolExample-01.png


Previous: Write a texture dragging tool Developer Tutorial: Contents Next: Use the mouse-over input slot