Vizard 7 » Reference » Tools » Pencil
7.7

Pencil

A tool for drawing in 3D space or on object surfaces. The following command creates a Pencil object:

Command

pencil.Pencil(startColor=viz.RED)

The following methods are available on the Pencil object:

Method

Description

<Pencil>.cycleColor()

Each time this command is called the next color in the cycle list becomes the drawing color. The cycle list consists of viz.RED, viz.BLUE, viz.GREEN, viz.PURPLE, and viz.YELLOW.

<Pencil>.setColor(color)

color: A list of normalized R,G,B values (e.g. [0.1,0.2,0.3], viz.BLUE)

<Pencil>.draw()

Draws in mid air.

<Pencil>.project()

Projects the drawing onto a surface.

<Pencil>.clear()

Clears the drawing.

<Pencil>.remove()

Removes the tool.

<Pencil>.setUpdateFunction(updateFunction)

Sets the update function that gets called every frame. The update function calls methods on the tool based on the state of input devices.

Example

""" 
Left mouse button draws. 
Right mouse button clears the drawing. 
Middle mouse button changes color. 
Mouse movements control viewpoint orientation. 
Arrow Keys control viewpoint position. 
""" 

import viz
import vizshape
import vizinfo
vizinfo.InfoPanel(align=viz.ALIGN_LEFT_BOTTOM)

viz.setMultiSample(4)
viz.fov(60)
viz.go()

piazza = viz.add('piazza.osgb')
arrow = vizshape.addArrow(length=0.2, color = viz.RED)

from tools import pencil
tool = pencil.Pencil()

# update code for pencil
def update(tool):

    state = viz.mouse.getState()
    if state & viz. MOUSEBUTTON_LEFT:
        tool.draw()
    if state & viz. MOUSEBUTTON_RIGHT:
        tool.clear()
    if state & viz. MOUSEBUTTON_MIDDLE:
        tool.cycleColor()
        
tool.setUpdateFunction(update)

#Link the pencil tool to an arrow  
#Then move the arrow in the reference frame of the viewpoint
from vizconnect.util import virtual_trackers
mouseTracker = virtual_trackers.ScrollWheel(followMouse = True)
mouseTracker.distance = 1
arrowLink = viz.link(mouseTracker,arrow)
arrowLink.postMultLinkable(viz.MainView)
viz.link(arrowLink,tool)

import vizcam
vizcam.FlyNavigate()

#Hide the mouse cursor
viz.mouse.setVisible(viz.OFF)