mesh
capov
capov(cap:poslist) returns the outermost vertices of a cap (a fan of pos'es)
cone
cone(outer_radius,inner_radius,resolution) makes a cone mesh
cube
cylinder
cylinder(res) makes a cylinder mesh
dodecahedron
dodecahedron() makes a dodecahedron mesh
extrude
extrude(m:mesh,v:vertex,[dir:vec3],magnitude)
Extrudes all neighbouring faces in the direction given (or the normal if dir is omitted), and re-orients the
faces to align perpendicularly along the extrusion axis
Note: Assumes direction is normalised.
Returns the pos loop at the end of the extrusion
extrude_and_scale
extrude_and_scale(m:mesh,v:vertex,dir:vec3,magnitude,scale) extrudes and scales the faces adjacent to v
face
a face is a triangle within a mesh.
Attributes:
n -- normal
valid -- true if the face is still part of a mesh
Member functions:
calculate_normal -- recalculate the normal
v(i) -- return the i'th vertex of this face (i = 0 to 2)
facelist
facelist(m:mesh) returns a list of all faces in the mesh m
flattenvl
flattenvl(m:mesh,vl:list,p:vec3,n:vec3) flattens a list of vertices, vl, so they align on the plane specified by p and n
foreachv
foreachv(m:mesh,f:function) applies f to each vertex in m
icosahedron
icosahedron() makes an icosahedron mesh
ifaces
ifaces(faces:poslist) returns an iterator over the faces in this poslist
inset
inset(m:mesh,v:vertex,s:number) insets all the faces surrounding vertex v and scales them by s
iso
iso(res,f) creates an isosurface from function f(x,y,z) within a 2x2x2 space of resolution res
load_mesh
load_mesh(file) loads a mesh from a file. supported formats: obj
loopp
loopp(v:vertex) returns the loop of pos'es surrounding v
loopv
loopv(v:vertex) returns the loop of vertices surrounding v
mesh
mesh is a triangular mesh. You construct a mesh as a primitive (cube,icosahedron,etc.) or with load_mesh().
Member functions:
subdivide(n) -- subdivide the mesh n times
smooth_subdivide(n) -- smooth subdivide the mesh n times (Loop Subdivision)
sync() -- recalculate all the vertex and face normals
apply_transform(mtx) -- apply the transform matrix to the mesh vertices
clone():mesh -- copy the mesh
nearbyv
nearbyv(m:mesh,v:vertex,n:integer) returns a list of vertices with edge distance n of v
octahedron
octahedron() makes an octahedron mesh
pos
a pos is a (vertex,edge,face) triple that uniquely identifies a position on a mesh.
Constructors:
pos(f,e,v) -- construct from a face, edge(int) and vertex
pos(f,v) -- construct from a face and vertex
Attributes:
v -- the vertex
e -- the edge (an integer from 0 to 2)
f -- the face
Properties:
flip_v, flip_e, flip_f -- navigate the mesh
A pos can walk around a mesh by calling flip_v, flip_e or flip_f.
flip_v, for instance, changes the pos by selecting the pos that has the same e and f, but differs in v.
sphere
sphere() makes a spherical mesh
split_edge
split_edge(mesh,pos) splits the edge in pos into two and retriangulates the adjacent faces
tetrahedron
tetrahedron() makes a tetrahedron mesh
tofaces
tofaces(vl:list) returns a list of those faces adjacent to the vertices in vl
turtle
turtle() creates a turtle.
A turtle can be used either:
- as a navigation tool
- or to create generalised cylinders
Check the examples for more info.
Member functions:
move(dist)
yaw(angle)
roll(angle)
pitch(angle)
set_frame(pos,heading,up) -- sets the turtles position heading and orientation
set_stiffness(s1,s2) -- controls the shape of the generalised cylinder
set_scale(scale) -- controls the shape of the generalised cylinder
set_cross_section(index) -- controls the shape of the generalised cylinder
push -- record current state/position
pop -- restore to old state/position
set_carrier_mode(cm) -- cm=0 use linear interpolation, cm=1 use bezier interpolation
begin_cross_section
end_cross_section
begin_cylinder
end_cylinder
add_point(n)
get_position
get_heading
get_up
get_frame
mesh():mesh -- generate and return the generalised cylinder
vertex
a vertex is a part of a mesh.
Attributes:
p -- position
n -- normal (read-only)
c -- colour
valid -- true if the vertex is still part of a mesh
Member functions:
calculate_normal -- recalculate the normal based on the adjacent faces
set_uv(u,v) -- set the uv coordinates
get_adjacent_face -- returns an adjacent face
vertexlist
vertexlist(m:mesh) returns a list of all vertices in the mesh m
util
sort(table [,comp])
sorts table elements in a given order, in-place, from table[1] to table[n]
comp is an optional comparison function s.t., comp(a,b) = true if a<b.
all
all(iter, [func]) Returns true if func(item) returns true for all item in items. (see http://mirven.github.com/underscore.lua/ for more info.)
any
any(iter, [func]) Returns true if func(item) returns true for any item in items. (see http://mirven.github.com/underscore.lua/ for more info.)
choose
choose(list) returns a random element from list
collect
collect is documented externally at http://mirven.github.com/underscore.lua/
compose
compose(func1, func2, [...]) Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())). (see http://mirven.github.com/underscore.lua/ for more info.)
concat
concat(table [,sep [,i [,j]]]) returns table[i]..sep..table[i+1].. ..sep..table[j]
copy
copy(table) returns a (deep) copy of a table
curry
curry(func, arg) Creates a wrapper function substituing the supplied arg for the first argument in original function. (see http://mirven.github.com/underscore.lua/ for more info.)
detect
detect(iter, func) Looks through a list returning the first element that matches a truth function. The function returns as soon as it finds an acceptable element. (see http://mirven.github.com/underscore.lua/ for more info.)
each
each(iter, func) Passes each value to function(i) and returns the input. (see http://mirven.github.com/underscore.lua/ for more info.)
every
every is documented externally at http://mirven.github.com/underscore.lua/
extend
extend(destination, source) Copy all of the properties in the source object over to the destination object. (see http://mirven.github.com/underscore.lua/ for more info.)
filter
filter is documented externally at http://mirven.github.com/underscore.lua/
find
find(l,f) finds element v of l satisfying f(v)
first
first(array, [length]) Returns the first element of an array. Optionally it will return an array of the first n items. (see http://mirven.github.com/underscore.lua/ for more info.)
flatten
flatten(array) Flattens a nested array (the nesting can be to any depth). (see http://mirven.github.com/underscore.lua/ for more info.)
foldl
foldl is documented externally at http://mirven.github.com/underscore.lua/
for_each
for_each is documented externally at http://mirven.github.com/underscore.lua/
foreach
foreach(table, f) executes f on each element of table
head
head is documented externally at http://mirven.github.com/underscore.lua/
include
include is documented externally at http://mirven.github.com/underscore.lua/
inject
inject is documented externally at http://mirven.github.com/underscore.lua/
insert
insert(table, [pos,] value) inserts value at position pos in table
invoke
invoke(list_of_items, function_name) Calls a function with specified name on each item using the colon operator. (see http://mirven.github.com/underscore.lua/ for more info.)
is_empty
is_empty(object) Returns true if object contains no values. (see http://mirven.github.com/underscore.lua/ for more info.)
is_equal
is_equal is documented externally at http://mirven.github.com/underscore.lua/
join
join(array) Returns a string with all items in the array concatenated together with an optional separator. (see http://mirven.github.com/underscore.lua/ for more info.)
keys
keys(object) Returns an array of all the property names in a table. (Note: order is not defined) (see http://mirven.github.com/underscore.lua/ for more info.)
map
map(iter, func) Produces a new array by mapping each value in iter through a transformation function. (see http://mirven.github.com/underscore.lua/ for more info.)
maxn
maxn(table) returns the largest positive numerical index of table
pluck
pluck(iter, property_name) An convenient version of the common use-case of mapextracting a list of properties. (see http://mirven.github.com/underscore.lua/ for more info.)
pop
pop(array) Removes and returns the last item in an array (see http://mirven.github.com/underscore.lua/ for more info.)
push
push(array, item) Inserts item at the end of an array (see http://mirven.github.com/underscore.lua/ for more info.)
reduce
reduce(iter, memo, func) Boils down a list of values into a single value. Memo is the initial state of the reduction, and each successive step of it should be returned by func. (see http://mirven.github.com/underscore.lua/ for more info.)
reject
reject(iter, func) Removes items that match the provided criteria. (see http://mirven.github.com/underscore.lua/ for more info.)
remove
remove(table [,pos])
removes the element at position pos from table, shifting down other elements to
close the space. returns the removed element. pos defaults to #table.
rest
rest(array, [start_index]) Returns an array of all items except the first. Optionally it will start at start_index. (see http://mirven.github.com/underscore.lua/ for more info.)
reverse
reverse(iter, [comparison_func]) Iterates over all the items and returns a new array with the items in reverse order. (see http://mirven.github.com/underscore.lua/ for more info.)
select
select(iter, func) Removes items that do not match the provided criteria. (see http://mirven.github.com/underscore.lua/ for more info.)
set
set(l) converts list l to a set
shift
shift(array) Removes and returns the first item in an array (see http://mirven.github.com/underscore.lua/ for more info.)
slice
slice(array, start_index, length) Returns a section of an array starting with start_index of length items length. (see http://mirven.github.com/underscore.lua/ for more info.)
some
some is documented externally at http://mirven.github.com/underscore.lua/
sort
sort(iter, [comparison_func]), Returns an array with all elements sorted by the comparison function, by default it uses the < operator. If an array is passed in it will sort the elements in place and not create a new array. (see http://mirven.github.com/underscore.lua/ for more info.)
tail
tail is documented externally at http://mirven.github.com/underscore.lua/
to_array
to_array(iter) Collects all values into a new array. (see http://mirven.github.com/underscore.lua/ for more info.)
to_string
to_string(tbl) converts tbl to a human-readable string
unshift
unshift(array, item) Inserts item at the beginning of an array (see http://mirven.github.com/underscore.lua/ for more info.)
values
values(object) Returns an array of all the property values in a table. (Note: order is not defined) (see http://mirven.github.com/underscore.lua/ for more info.)
wrap
wrap(func, wrapper) Wraps the first function inside of the wrapper function, passing it as the first argument. This allows the wrapper to execute code before and after the function runs, adjust the arguments, and execute it conditionally. (see http://mirven.github.com/underscore.lua/ for more info.)