This is a quick overview tutorial of the WireframeSphere primitive in the Away3D TypeScript library.
We will be recreating the scene as seen above.
To use a WireframeSphere primitive, we’ll need to:
- Declare, instantiate, and initialize a new WireframeSphere object.
- Add the WireframeSphere 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 – Sphere. 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 WireframeSphere.
Line 17 declares a variable named _objectWireframe of type WireframeSphere().
Line 60 instantiates a new WireframeSphere() object referenced by the variable _objectWireframe. It was initialized with 300, 16, 16, 0xFFFFFF, 1: which we’ll discuss more later.
Line 61 adds the WireframeSphere object to the scene.
Lines 76-77 adds a spin to our WireframeSphere object on every frame of animation.
Line 102 changes the called class name to WireframeSphere.
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:
WireframeSphere(radius:Number = 50, segmentsW:uint = 16, segmentsH:uint = 12, color:uint = 0xFFFFFF, thickness:Number = 1)
The Constructor’s Parameters:
- radius:Number (default = 50) — The radius of the sphere.
- segmentsW:uint (default = 16) — Defines the number of horizontal segments that make up the sphere.
- segmentsH:uint (default = 12) — Defines the number of vertical segments that make up the sphere.
- color:uint (default = 0xFFFFFF) — The color of the wireframe lines
- thickness:Number (default = 1) — The thickness of the wireframe lines
So in our initialization we stated:
this._objectWireframe = new away.primitives.WireframeSphere(300, 16, 16, 0xFFFFFF, 1);
Which created a WireframeSphere:
- With a radius of 300 units. (Half of the circular width).
- 16 segments in the circular width.
- 16 segments along the height.
- colored white (0xFFFFFF).
- With a line thickness of 1 units.
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.