This is a quick overview tutorial of the WireframeTetrahedron primitive in the Away3D TypeScript library.
We will be recreating the scene as seen above.
To use a WireframeTetrahedron primitive, we’ll need to:
- Declare, instantiate, and initialize a new WireframeTetrahedron object.
- Add the WireframeTetrahedron object to the scene.
Notice, we do not place the wireframe in a Mesh object. This is because a Mesh would be overkill, trying to apply materials, shaders, and what have you. So just add the wireframe object as a child of the scene itself.
This tutorial builds off of the Away3D TypeScript: Primitives – Cube. All the new or changed code will be highlighted in the full code block below.
An error has occurred. Please try again later.
Line 5 renames the class to WireframeTetrahedron.
Lines 14,15,50,56,57,58,74,75 you can comment out. We will not be using these lines from the template.
Line 17 declares a variable named _objectWireframe of type WireFrameTetrahedron().
Line 60 instantiates a new WireFrameTetrahedron object referenced by the variable _objectWireframe. It was initialized with 350, 350, 300, 0xFFFFFF, 1: which we’ll discuss more later.
Line 61 adds the WireFrameTetrahedron object to the scene.
Lines 76-77 adds a spin to our WireFrameTetrahedron object on every frame of animation.
Line 102 changes the called class name to WireframeTetrahedron.
That’s it, our object is in the scene.
However, we glazed over the initialization process, let’s take a closer look at the object’s constructor.
The constructor looks as follows:
WireframeTetrahedron(width:Number = 100, height:Number = 100, depth:Number = 100, color:uint = 0xFFFFFF, thickness:Number = 1, orientation:String = xz)
The Constructor’s Parameters:
- width:Number (default = 100) — The size of the cube along its X-axis.
- height:Number (default = 100) — The size of the cube along its Y-axis.
- depth:Number (default = 100) — The size of the cube along its Z-axis.
- color:uint (default = 0xFFFFFF) — The color of the wireframe lines
- thickness:Number (default = 1) — The thickness of the wireframe lines
- orientation:String (default = xz) — The orientation in which the tetrahedron lies.
So in our initialization we stated:
this._objectWireframe = new away.primitives.WireframeTetrahedron(350, 350, 300, 0xFFFFFF, 1);
Which created a WireframeTetrahedron:
- 350 units wide.
- 350 units high.
- 300 units deep.
- colored white (0xFFFFFF).
- With a line thickness of 1 units.
- We left the orientation at the default (XZ)
Adding a basic primitive is relatively easy. Just understanding the constructor and what the parameters are, is the hardest part. You can look at the official documentation here.