3D Model Library
1 Introduction
This library is used to represent 3 dimensional data as vertices and polygons (or polys in short) and also auxilary data such as materials and uvmaps.
This kind of representation is used fairly common among videogames and the like. It is also used among most standard 3D model formats.
2 Getting Started
Install this library using planet or put it in racket staticlly. Then see the function new-model to start generating model data.
A model is a container of meshes. The meshes contain the actual data.
A mesh has a name aswell some amount of vertices, uv-cooridantes and polygons, also an optional origin vector to be used for movement calculations. Each mesh must have a unique name.
At this time hierachry is not supported, all meshes are linearly stored.
Vertices and uv-coordiantes are referenced by polygons. They can be refernced by multiple polygons. New ones can be inserted without having to be referenced by a polygons. However it is the programmers responsibility to ensure that polygons that have elements removed recive proper substitutes.
This library also provides some primitive geometric manipulative functions, but these are not optimized and thus unsuable for realtime or large scale data processing. OpenGL support has been dileberatly omited to keep the library simple.
3 Reference
procedure
(new-model name) → mpair?
name : (string?)
A model’s actuall data is organized into and stored inside meshes.
procedure
(add-mesh! model name [vertices uvs polys]) → mesh?
model : (mpair?) name : (string?) vertices : (list?) = '() uvs : (list?) = '() polys : (list?) = '()
A mesh is the basic data container for 3 dimensional data.
Each mesh must have a unique name.
Can optionally be initialised with data, a list of verices, a list of uvmaps and a list of polys.
Returns the new mesh.
procedure
(mesh? mesh) → boolean?
mesh : (any/c?)
procedure
(get-mesh model name) → (or/c mesh? boolean?)
model : (mpair?) name : (string?)
procedure
(get-mesh-name mesh) → string?
mesh : (mesh?)
procedure
(rename-mesh! mesh name) → void?
mesh : (mesh?) name : (string?)
procedure
(delete-mesh! model mesh) → void?
model : (mpair?) mesh : (mesh?)
procedure
(join-meshes! model mesh1 mesh2) → void?
model : (mpair?) mesh1 : (mesh?) mesh2 : (mesh?)
procedure
(get-vertices mesh) → list?
mesh : (mesh?)
procedure
(add-vertex! mesh x y z) → void?
mesh : (mesh?) x : (number?) y : (number?) z : (number?)
procedure
(delete-vertex! mesh vertex) → void?
mesh : (mesh?) vertex : (vector?)
procedure
(get-polys mesh) → list?
mesh : (mesh?)
procedure
(add-poly! mesh [vertices uvs material origin]) → void?
mesh : (mesh?) vertices : (list?) = () uvs : (list?) = () material : (string?) = "" origin : (vector?) = #(0 0 0)
procedure
(delete-poly! mesh poly) → void?
mesh : (mesh?) poly : (vector?)
This function does not remove referenced vertices or uv-coordinates.
procedure
(get-poly-vertices mesh poly) → list?
mesh : (mesh?) poly : (vector?)
procedure
(get-uvmap mesh) → list?
mesh : (mesh?)
procedure
(add-uv! mesh x y z) → void?
mesh : (mesh?) x : (number?) y : (number?) z : (number?)
procedure
(delete-uv! mesh uv) → void?
mesh : (mesh?) uv : (vector?)
procedure
(get-origin mesh) → vector?
mesh : (mesh?)
This defines the pivot point in rotations and for mirroring.
procedure
(set-origin! mesh x y z) → vector?
mesh : (mesh?) x : (number?) y : (number?) z : (number?)
procedure
(translate-vertex! vertex x-offset y-offset z-offset) → void? vertex : (vector?) x-offset : (number?) y-offset : (number?) z-offset : (number?)
procedure
(rotate-vertex! vertex xy yz zx origin) → void?
vertex : (vector?) xy : (number?) yz : (number?) zx : (number?) origin : (vector?)
Rotation for each axis is specified by a floating number between 0 and 1, where 0 is no rotation and 1 would be one whole rotation. 0.5 would be a rotation of 180 degrees. Numbers larger or equal than 1 will be wraped round.
Rotation is performed along 2 axis, you can choose any 2 axis. Subsequent roatation along an axis 2 time will be complementary.
Caution: due to impercision in the representation subsequent rotation of large object may lead to significantly deformed results.
procedure
(scale-vertex! vertex x y z) → void?
vertex : (vector?) x : (number?) y : (number?) z : (number?)
procedure
(mirror-vertex! vertex x-axis y-axis z-axis origin) → void? vertex : (vector?) x-axis : (boolean?) y-axis : (boolean?) z-axis : (boolean?) origin : (vector?)
Origin is a vector of 3 numbers, each describing the axis around which the mirroring should happen.
Set any of the cooridnate arguments to true to perform a mirroring on corresponding axis.
procedure
(translate-mesh! mesh x-offset y-offset z-offset) → void? mesh : (mesh?) x-offset : (number?) y-offset : (number?) z-offset : (number?)
Origin will be affected aswell.
procedure
(rotate-mesh! mesh xy yz zx) → void?
mesh : (mesh?) xy : (number?) yz : (number?) zx : (number?)
Rotation for each axis is specified by a floating number between 0 and 1, where 0 is no rotation and 1 would be one whole rotation. 0.5 would be a rotation of 180 degrees. Numbers larger or equal than 1 will be wraped round.
Rotation is performed along 2 axis, you can choose any 2 axis. Subsequent roatation along an axis 2 time will be complementary.
Caution: due to impercision in the representation subsequent rotation of large object may lead to significantly deformed results.
procedure
(scale-mesh! mesh x y z) → void?
mesh : (mesh?) x : (number?) y : (number?) z : (number?)
procedure
(mirror-mesh! mesh x-axis y-axis z-axis) → void?
mesh : (mesh?) x-axis : (boolean?) y-axis : (boolean?) z-axis : (boolean?)
Set any of the cooridnate arguments to true to perform a mirroring of corresponding axis.
4 Copyright and contact
Writen by "Code_Man". Send feedback to Code_Man at Cybnet.ch. See code_man.cybnet.ch for more stuff of mine.
Licenced under MIT X11.
No implied warranties or liability of any kind, use at own risk.