| mesh |
Simulation will be more interesting when more complex objects can be used.
ThreeDimSim supports the simulation of meshes that are imported from dxf, 3ds
and stl files. The idea is that you define meshes in a dedicated CAD program and
import these into the simulator. Example:
// assign a default material
factory.material = Material(1e-6, 1, .5, .4);
// load the meshfile
var m = Mesh("mesh_file_name.3ds");
When this line is executed, the program
will load the file "mesh_file_name.3ds" and checks if it meets the criteria for
simulating the object. If this is the case, mechanical properties of the mesh
(volume, mass, center of mass, inertia tensor) are calculated. The most
important restriction is that the mesh is a closed polyhedral. In other words,
it should have a well defined (finite) volume. If the program detects edges
connected to one face only, it will conclude the mesh is not closed, and will
warn you that the mechanical properties may be inaccurate. Another
restriction is that the faces of the mesh should be consistently directed. When
this is not the case, the mechanical properties, collision detection and shadow
rendering may be inaccurate. |
| hierarchical import |
A mesh file may contain more than one objects. A 3ds file may define a
hierarchical arranged set of objects. The mesh construction in the previous
example loads all objects defined in the file, and will construct a hierarchical
object, just like the class keyword. Each object is accessible by its object
name, given in the file. Suppose the mesh_file_name.3ds contains 3 objects A, B
and C, then these objects can be referenced as m.A, m.B and m.C . When an
objectname is equal to a reserved word then the member should be quoted,
otherwise a syntax error will occur:
// reference to the "var" member.
// The name "var" was defined in the mesh-file
m."var"
So we could set the color of an individual member like:m.A.color = m.B.color;
When the imported hierarchy is more complex, this is reflected in the imported
structure. Suppose member C is a a child of member B, then C would be referenced
like m.B.C. You can browse the contents of a mesh file by choosing menu
View->Mesh File Info. When you select a file, then this command will show the
hierarchy of objects present in the build tab. |