"Triangles"
David Sharp mailto:dsharp@interport.net
Here is a link to the web version of this page:www.oocities.org/Athens/Academy/8764/triangles.htm
Download (latest version: March 23,
2000)
Source code to Triangles
Source code posted here will usually be about two updates behind, until
the development gets more stable.
To compile (without modification of the code) you need to have installed
DJGPP and the Allegro
game library.
Table of Contents
Triangles is a free DOS program, distributed without warranties or
guarantees. It is a "manual tri-mesh contruction
utility" for making a mesh (mess?) of virtual triangles
mainly using the mouse, and saving the result in a small choice
of different formats (RAW , POV , PCM1, and Triangles's own TRI
format).
Triangles is meant for modeling objects, not for producing images. It intended use is
for making objects to be rendered using POV-Ray
ray-tracing program.
There is an upper bound on the number of triangles
allowed (currently 50,000), so its main value is for modeling 'objects' rather than
entire scenes. Even given the
narrow niche Triangles is meant to fill, it is still missing
many valuable features and I can't say that development will
continue beyond what I personally need.
Setting up
Create a directory for Triangles. Unzip the downloaded zip file
into this directory. To use under Windows, double click on the
Triang.exe icon in Windows Explorer (or File Manager, or
whatever), or get a DOS prompt and run Triang.exe. To use under
plain DOS (not shelled to DOS from Windows), it is necessary to
have the file CWSDPMI.EXE in your 'PATH', or in the directory you
are running Triangles from. You will need to have video
supporting 'at least' 640x480 pixels and 256 colors. You can
set the video resolution to a few different settings using the
Options Menu after Triangles starts. To have Triangles start up
in a particular resolution (640x480, 800x600, 1024x768, 1200x1024, or
1600x1200), modify the file 'triangles.ini'. It must have one of the
above copied literally into the first line of the file.
To have Triangles always start in 1024x768, for example, modify (or create) the ASCII text file
named 'triangles.ini' so that the first line is
1024x768
and make sure
that your 'triangles.ini' is in Triangles's working directory.
Using Triangles
There are four view windows to see what you are doing. Three
wire-frame views, and one '3-d' view. The wire-frame views are not
adjustable (zooming or panning), but you can easily scale, rotate, or move your mesh
around to get an appropriate view. The 3-d view presently uses
the simplest "painter's algorithm" for rendering, and
it can sometimes create false impressions, like triangles which
seem to disappear when rotating, especially when the edge angles
are large. Once the mesh has been smoothed some,
the weirdness usually goes away. I may eventually add z-buffering
to eliminate the problem, but maybe not.
Command Line
The Triangles command line can take the name of a TRI or RAW file to start up with.
(This allows you to 'drag and drop' a file onto a Triangles icon).
e.g.:
C:\Triangles>Triang.exe myfile.tri
would start Triangles with the file 'myfile.tri'.
Another command line option is how much memory to allocate for meshes.
'-mN', where N is an integer, will make room for Nx1000 vertices, Nx1000 triangles,
and 2N*1000 edges.
e.g.:
C:\Triangles>Triang.exe -m100
would start Triangles with room for 100,000 vertices, 100,000 triangles,
and 200,000 edges. The default (without using the command line option) is 50,000 vertices.
Mouse
The right mouse button in any of the three wire-frame view
windows brings up a menu of "mouse choices". This is a
list of things you can have the mouse do in the wire-frame views:
-
After choosing "Create vertex ('c')",
clicking in one of the wire-frame views will create a new
vertex under the mouse's position. The created vertex is
"selected" (and shown green). A
"plain" left click (no CTRL key held) will
unselect everything but the new vertex (so that all the
green highlighting gets transferred to the new vertex).
To have a new vertex added to whatever is already
selected instead, use CTRL-left-click (hold down the
Control key while clicking the left mouse button) in
creating the vertex.
- "Select vertex ('s')" will cause the
vertex (or vertices) directly under the mouse cursor to
be selected when the mouse is left-clicked. A plain left
click unselects everthing else. A CTRL-left-click will
add the vertex (or vertices) under the mouse to the ranks
of the "selected vertices", if that vertex is
not already selected, or unselect it if it is already
among the selected.
- "Unselect vertex ('u')", naturally,
causes vertices left-clicked on to be removed from the
selected vertices.
- "select in rectanGle ('g')" is for
'drag-drawing' a rectangle in a wire-frame view. Any
vertices inside the drawn rectangle when the left button
is released become selected. If the CTRL key is held down
during this rectangle drawing, the vertices inside the
rectangle are added to those already selected, otherwise
everything outside the rectangle becomes unselected.
- "unselect in rectanGle ('Alt-g')"
unselects any vertices inside a drawn rectangle.
- "selecT connecTed componenT ('t')"
selects all vertices connected by triangle edges to the clicked-on vertex.
Holding down the <Ctrl> key while clicking on a vertex will add
those connected vertices to whatever is already selected.
- "unselecT connecTed componenT ('alt-t')"
unselects all vertices connected by triangle edges to the clicked-on vertex.
- Dragging the mouse in a wire-frame view while "Move
selected ('m')" ("Move
all ('Alt-m')") is in effect moves the selected (all)
vertices with the mouse. (Restrict
the movement to either horizontal or vertical directions by
holding down a Shift key while moving the mouse).
- "mouse moVe ('v')" is for clicking on a
single vertex and dragging it with the mouse. (Restrict
the movement to either horizontal or vertical directions by
holding down a Shift key while moving the mouse).
While mouse moVe
is in effect, if you move a vertex 'on top' of another
(one on top of other in the current wire-frame view), and
right-mouse-click while the left-button is still held
down, the two vertices will meld into one
and can be used as a 'manual' mesh size reducer
- "Pull selected ('p')" and "Pull all ('Alt-p')"
are similar to mouse moVe, but drag the selected (or all) vertices along.
The further away from the dragged vertex any particular vertex is, the
less strongly it is pulled. Under the Options Menu, Pull can be adjusted.
Higher values reduce the effect on distant vertices, and lower values (closer to zero)
increase the dragging effect on distant vertices. (Distance is through
'space', not through edges. A vertex sitting near the pulled vertex
will be pulled strongly, whether or not the two are connected)
- "Pull edges ('p')" is like 'Pull all', but the distance
of vertices from the 'pulled' vertex is calculated by following the edges connecting
the vertices. Vertices which are not connected to the pulled vertex through any
sequence of edges are not pulled at all. With meshes larger than even 100 vertices, the time needed for the calculation
of distances is a real hindrance, so you can set (under the Options Menu) the maximum number
of edges through which the pull effect will travel. Setting 'Max Edges' to a larger value
means vertices farther away will be pulled, but the required calculation times go up quickly!
- "repulsive mouse ('h')" pushes vertices away from (or towards) the mouse position,
Xnew=X + c * (X-M)*e-a*(||X-M||^b)
where X is a vertex position, and M is the mouse's position.
Pushes points of the mesh
away from (c>0) or towards (c<0) the mouse. Mesh vertices
closer to the mouse are pushed/pulled more.
Set the parameters a,
b, and c in the box that pops up on selecting
'repulsive mouse'. Note that these parameters are the same
ones used for 'Repulsive point' (Edit->Deform->Repulsive point),
and the settings for a,
b, and c persist into Repulsive point.
- Dragging the mouse in a wire-frame view while "Rotate
selected ('r')" (Rotate
all ('Alt-r')") is in effect rotates the
selected (all) vertices in the viewing plane of the view where
you start the mouse dragging. The amount and direction of the rotation
are determined by the arc the mouse makes about the center of the view
window, (so dragging the mouse through an arc further from the center of the
view window gives more control)
- "scaLe selected ('L')" ("scaLe all ('Alt-L')") lets you change
the size of the triangle mesh by dragging the mouse. If
the "scale uniformly" box is checked in the Options Menu, then all
dimensions of the mesh will be scaled at the same rate.
If scale uniformly is not checked, the scaling is only in
the directions of the axes corresponding to up/down or
left/right in that particular wire-frame view.
- "Insert vertex ('Alt-I')" finds the
edge nearest where the mouse is clicked, and inserts
a new vertex connecting the endpoints of that edge, making new triangles as
necessary.
- The "Delete vertex ('d')" menu item
enables clicking on a single vertex to delete it.
Deleting vertex also removes from the mesh any triangles
the vertex is a corner of.
The right mouse button in the "3-d" view window
brings up a menu of 3-d view "mouse functions".
Note that rotations, translations, and scalings in the 3-d
view have no effect on the actual mesh. That is, they should be
considered as changing your viewpoint, not moving or rotating the
mesh.
- Picking Rotate (1) or Rotate (2) cause dragging the mouse in the 3-d view to
rotate your view around the mesh.
- Picking a Pan causes dragging the mouse in the
3-d view to move your viewpoint left, right, up, down,
in, or out.
- Scale makes the mesh appear larger or smaller.
File menu
To use files/objects other than RAW or TRI files, you will first need to convert
them to RAW triangles files (other than Triangles itself, no conversion programs exist to convert
from TRI to other formats, unless you count Triangles itself).
A couple of valuable 3D format conversion tools are
Thomas Baier's 3DWin and
Keith Rule's Crossroads.
Here is a link to some other conversion utilities
Edit menu
To perform one of the 'edit' operations without opening the menu,
hold down the control key (Ctrl) and hit the function's keyboard letter
For example,
Ctrl-'t' (hit 't' while Control key is pressed) will make a
triangle from three selected vertices.
-
make Triangle (Ctrl-'t')
When exactly three vertices are highlighted (selected and
green), make Triangle becomes enabled. Hitting make
Triangle creates a triangle from the three vertices (that
is, if they are not already the corners of a mesh
triangle). The triangle icon on the main screen shows
an "incomplete" triangle when exactly three vertices are
selected and they do not already make a triangle
- delete trianGle (Ctrl-'g')
When exactly three vertices are highlighted which do make
up a triangle, delete trianGle is enabled. delete trianGle
only removes a triangle, not the vertices at the
triangle's corners. The triangle icon shows a "shaded" triangle
when Triangles thinks the three vertices actually do make a triangle
- copy selected (Ctrl-'c') copies selection to a 'clipboard', ready to
be pasted.
- paste copy (Ctrl-'v') puts a copied selection (copy selected)
into the mesh. The wire-frame mouse mode automatically becomes "move selected".
- duP selected (Ctrl-'p') creates an
exact duplicate of the selected vertices, with whatever
triangles are completely defined by the selected
vertices (equivalent to 'copy' followed by 'paste'). Since the duplicate is exact, it appears
'invisible' since it is in the same place as original.
However, the 'selection' is shifted to
the duplicates. Use 'move selected' or 'rotate selected'
under the mouse menus to move the duplicate into a
visible location. (The duplicate is not connected to the
original.)
- detach selected (Ctrl-'b')
'Detaches' the selection from the rest of the mesh. If the selection
is connected (or consists of connected parts), this will create
new connected components. For example, if a mesh has
a leg connected through edges to the rest of the mesh and the leg is then 'detached', the leg will not be connected
to the rest of the mesh anymore.
The wire-frame mouse mode automatically becomes "move selected".
- Reflect selected (Ctrl-'r') reflects
the selected vertices through the plane normal to the
coordinate you choose from the popup menu. That is,
Reflect X multiplies each selected vertex's x coordinate
by -1.
- Delete selected (Ctrl-'d' or Del)
deletes the selected vertices, and any triangles
containing any of those vertices. The mouse mode
automatically changes to "move selected"
- Meld vertices (Ctrl-'r') will
"meld" all selected vertices into one. That
vertex will be located at the 'center of gravity' of
the original selection. This is a way to reduce the size of your
mesh 'manually'.
- eXtrude selection (Ctrl-'x') makes a copy
of the selection, and tries to connect it up to the original
selection along whatever part of the mesh's boundary which is
in the selection. If the selection doesn't actually contain any
of the mesh's boundary, the 'extrusion' is aborted. Otherwise,
the mouse mode automatically changes to "move selected"
- mArk selected (Ctrl-'a') (unmarK
selected (Ctrl-'k')) "marks"
("unmarks") the currently selected vertices.
What "marking" means is not stable at this
point. Currently, it holds the marked vertices in place
during smootH subdivision, but the way this is
accomplished in the program is not quite adequate.
- Select all (Ctrl-'s') (Unselect
all (Ctrl-'u')) causes all vertices in the mesh to
become selected (unselected).
- snap (Ctrl-'y')
'Snap to grid'. Pushes each vertex (or each selected vertex) onto the
nearest "grid" intersection. A box appears where you choose the
grid resolution, and which coordinates (x, and/or y, and/or z)
to force onto the grid.
- Invert selection (Ctrl-'i') causes
all unselected vertices to become selected and removes
all selected vertices from the selection.
- remove 'loose' vertices
Some operations (delete
trianGle, remove selected triangles, etc) may leave unconnected
vertices laying about. If you don't want them, use remove 'loose' vertices to find and
delete them.
- meld coincident vertices (Ctrl-'w')
looks for pairs of vertices within
'epsilon' distance (which you can set when invoking the 'meld coincident vertices'
command) of each other and melds them into one, if they are not both vertices of
the same triangle. If 'selected' is checked, looks for and melds vertices within 'epsilon' distance
of the selected vertices.
- try Orient (Ctrl-'o') tries
to make the mesh consistently oriented, meaning it tries
to orient all normals to point "out" of the
mesh, or all point "in", but this is not always
possible.
- Evert selection (Ctrl-'e') reverses
the "normal orientation" of triangles contained
in the selection. Note that the results of this operation
are usually lost during "try Orient",
"smootH subdivision", and other operations
which apply 'try Orient'. The orientation of triangles is
not normally visible in Triangles but hitting the 'f' key
will show "inward" pointing triangles as darker
than "outward" oriented neighbors.
- Smooth/Divide/Reduce/Deform (Ctrl-'d')
Divide, smooth, and reduce can each be applied either to
the entire mesh, or to an (entire) connected component of the mesh.
(A 'connected component' is a set of vertices all connected one to another by some sequence
of triangle edges).
To apply to a connected component, select that component ('t' followed
by clicking on one its vertices), then use 'divide selection', 'smooth subdivide selection', or 'reduce selection'.
If, instead of selecting a whole component first, less than an entire connected component is selected, these functions go ahead and
'do' the whole component, but if the selected vertices happen to belong to more than
one component, they will pick just one of the components.
- divide (Ctrl-'f') turns each
edge of the mesh (or connected component) into two edges, connecting the vertices
so that each triangle is split into 4. Note that
Triangles has a limit on the number of triangles,
vertices, and edges that are allowed. (currently there is
a 50000 vertex, 50000 triangle, 100000 edge limit.)
- smootH subdivision (Ctrl-'h')
is basically an adaptation of John VanSickle's POV
macro. It divides each triangle into 4 and tries to make
the resulting mesh smooth using an algorithm invented by
Charles Loop. The best results are with closed surfaces (no boundary).
Outer boundaries actually sometimes become more jagged. A work around for the
bad behavior of this algorithm on boundaries is: 1) before smoothing, select the mesh (or just
the boundary of concern) and 'extrude'
it (hit Ctrl-'x'), but don't actually move the 'extrusion'. 2) Next, remove
all the new ('extruded') triangles by hitting Ctrl-'j'. 3) Remove vertices
left over by the last step with 'remove loose vertices' (hit Ctrl-'l'), 4) Then go ahead
and smooth (Ctrl-'h'). Finally, you can delete the 'extrusion' (hit Del). Eventually I may
fix this (or at least automate this sequence of operations) but for now
this seems to work pretty well.
Set the smoothing scale under the 'Options' menu.
Also under Smooth Subdivision options is the cryptic
'Average between marked'. Marked vertices do not move
during the subdivisions. Choose 'Average between marked'
(checked) to have the newly inserted edges go straight
between the marked vertices. Note that the new vertices
in between marked vertices are not automatically marked,
and will have to be marked 'manually' between subdivision
iterations in order for 'Average between marked' to work
the way it sounds.
- mesh ReductioN (Ctrl-'n')
Tries to reduce the number of vertices (and hence number of triangles)
by collapsing the 'least important' edges. Works best with closed (no boundary) meshes. The 'Fraction' is the
fraction of the original number of mesh vertices that will be removed; e.g. a fraction of
.1 will remove 10% of the vertices, leaving 90%. For each vertex to be
removed, the entire calculation of 'least important edge' is done/redone,
so, on larger meshes, this can take an extremely long time. Hit <ESC> key once
to abort.
- deformations
Various ways to deform a mesh. Can be applied to either the entire
mesh or a selection.
- repulsive point
Xnew=X + c * (X-P)*e-a*(||X-P||^b)
where P is the 'repulsive point'.
Pushes points of the mesh
away from (c>0) or towards (c<0) the 'repulsive point'. Mesh vertices
closer to the repulse point are pushed/pulled harder
.
- Roughen (Adapted from John Van Sickle's
POV macro) displaces vertices a random amount
normal to the mesh surface, making surfaces
rougher. Experiment with the sequence 'diVide',
'roughen', 'diVide', 'roughen' on a mesh.
These four are adaptations of Chris Colefax POV-Ray
macros:
- Wave
Moves vertices as a 'wave' symmetric about the y-axis.
- Ripple
- Twist
Twist the mesh about the specified twist center. Vertices further from the twist center are rotated more. The specified 'angle' is the rate at which the amount of rotation increases as
distance of a vertex from the 'twist center' increases. With
'about Axis' checked, the twist is about the specified axis vector based at the twist center, helix-like.
- Bend
- delete all
Deletes all. Start anew.
Options menu
- scale Uniformly. Checked, wire-frame view mouse
scaling operations scale equally in the x, y, and z
directions. Unchecked, the mouse scales only in the two
view directions of the wire-frame view plane where you
start dragging the mouse.
- rotate about view center. When this is checked,
the 'Rotate selected' mouse mode rotates the selected vertices
about (0,0,0). Unchecked, the
selection is rotated about the 'center of gravity' of the
selection.
- Pull fall-off rate adjusts how strongly pulling vertices with the
mouse affects vertices distant from the dragged vertex. (Higher values here
decrease the effect). Max Edges is a distance (in edges) separating
the pulled vertex from distant vertices. When 'pulling' with Pull Edges, vertices further than Max Edges from
the vertex you are pulling will not move.
- Show 3d Axes toggles drawing the axes in the
3d view.
- Display Resolution is for changing video resolution.
Your system may not support all offered resolutions. Mine doesn't,
and the 1200x1024 and 1600x1200 are untested.
Please send me a note (dsharp@interport.net) to tell me your results if your
system supports them to let me know how well they work.
- Shading Palette presents a menu of base colors for the '3-d' view shading. The default grey palette is larger (more shades) than green or red.
Polygon button:
Opens a drawing area for drawing a polygon
to be triangulated or lathed. Left-clicking the mouse creates a new polygon
vertex, connected to the last-created vertex. Holding down a shift key while left-clicking
forces the new vertex to be aligned horizontally or vertically with the last created vertex
(whether it is aligned horizontally or vertically depends on which difference is less). A right-mouse click closes/finishes the polygon (if it has at least three vertices).
Make holes in the polygon by drawing more polygons inside
the first. The first shape you draw must be the 'outer' polygon
and all subsequent shapes (holes) must be inside the outer shape, and no
line segments are allowed to cross. Also, each polygon must be completed (closed with a right-mouse click) before
the next shape is started, and a polygon will not close if the closing edge
would cross any other segment. These conditions are enforced by
Triangles, so if you find that the program will not place a new vertex, check
for violations of these conditions. It is currently possible to draw a new 'inner' polygon
around an already drawn inner polygon, but the triangulation results are unpredictable and
for all I know may even cause a crash.
- Triangulate triangulates the polygon and adds the polygon
to your mesh. (The outer polygon and holes must be closed).
- Lathe creates a "surface of rotation" by rotating the polygon about the y-axis.
(The polygon need not be closed. But realize that you can't draw inner polygons unless the outer one is closed).
- Pipe extrudes the polygon without filling it in (the 'pipe' is open-ended). It doesn't actually move the extruding
end, so that the polygon appears to be a flat polygon, but dragging the
mouse in a flat-wire-frame view will make the extrusion appear.
The polygon drawing area may be larger than the wire-frame view areas, and
larger polygons may not completely fit in the wire-frame windows when done.
If the 'reScale output' check-box is checked, the polygon or lathe will be
rescaled so that the edges of the polygon drawing area coincide with the
edges of the XY plane wire-frame view (that is, what you draw in the polygon
drawing area will fit in the wire-frame view).