FLines in 3d &mdash

Field contains quite a bit of support for procedural 2d drawing. This page assumes that you are familiar with this "FLine" drawing system. If not, see BasicDrawing, and the series of pages around DrawingFLines first. This "FLine" drawing system can present a 2d face to you, but it's secretly a full 3d geometry container.

Here's where we're aiming for right now:

This picture tells pretty much the complete story as of writing. Things to note:

  • FLine attributes work just the way that they normally do — see DrawingFLinesProperties. So you fill, color and so on in just the normal way.
  • Those dots you see are in fact the standard FLine editing tools (see BasicDrawing and LineBasedInteraction). You can drag nodes, split them, smooth them and so on just like you can in 2d. Mouse movement moves nodes at the "depth" that they are at, parallel to the viewing plane.
  • Fills work, but only when you fill planar things. Filling non-planar things gives you results that appear to be missing triangles. This is intentional. If you want to make complex, non flat surfaces, you need to use NURBS, see below.
  • Unlike the normal spline drawing helper, the contents of a 3d spline drawer is clipped to its frame. This means that you have one window per 3d spline drawer. Obviously you can have as many windows as you like. You can drag them around.
  • Associated with a 3d spline drawer is a camera. You can change the camera programmatically, or by using the mouse.

FLine3 basics

The example code largely speaks for itself:

_self.lines.clear()

p1 = FLine3()

p1.moveTo(0,0,0)
p1.lineTo(1,0,4)
p1.lineTo(1,1,4)
p1.lineTo(0,1,0)
p1.lineTo(0,0,0)

p1.filled=1

p1.color=Vector4(0,0,0,0.5)

p1 *= Vector3(10,10,10)

_self.lines.add(p1)

_self.camera.position[:]=(0,0,50)
_self.camera.target[:]=(0,0,0)
_self.camera.up[:]=(0,1,0)

Yields:

![](images/threed1.png]

Things to note:

  • '''moveTo''' and friends can take 3 parameters rather than 2. cubicTo can take 9 rather than 6.
  • ''' *=''' (rescale / rotate) and friends can now take Vector3 rather than just Vector2 and they rescale and rotate around the 3d center of the Line by default
  • '''Pay close attention to where you put the camera'''. There's nothing worse than being lost in 3d. See [BaseGraphicsSystem] for more information about 3d cameras.

Camera control

Two things might help in placing the camera. Firstly, the three-camera defaults to a position where drawing 2d things (at z=0) appears roughly where they would appear if you were drawing them into a "normal" spline drawer. That is with the origin in the top left in coordinates that are pixels. This is correct until you move the actual three-d spline drawer — then the camera comes along with the spline drawer.

Secondly there's a mouse operated camera, very much like Maya. With the three-d spline viewer selected tap 'space'. Now (until you press space again), hold option. '''Left mouse rotates, middle mouse translates and right mouse pans.'''

The above image shows two drawers (that happen to overlap) in camera navigation mode (with space pressed).

Mouse Editing works (and that's harder than you think)

The summary is that self.tweaks() does exactly what you'd expect — see BasicDrawing. Mouse editing on 3d objects gets replayed precisely — nodes that are manipulated get projected onto the 2d 'screen', manipulated, and then put back again to the same depth. This is basically what you'd expect for the simplest thing. Clearly it would be nice to have a greater range of tools, including some that are much more 3d aware, and, since Field's mouse-tool system is already very extensible, this will be pretty straightforward

Getting this to work was a little lest straightforward than you might think, because the simplest case of a mouse edit that we've just described is ''view dependent'' — you get a different edit from the same mouse drag if the camera is in a different spot. So, the camera position where edits take place is recorded as well.

In any case, now that this machinery is in place we can grow some interesting and code-based 3d mouse editing tools pretty rapidly.