Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Papervision3D Essentials

You're reading from  Papervision3D Essentials

Product type Book
Published in Sep 2009
Publisher Packt
ISBN-13 9781847195722
Pages 428 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Papervision3D Essentials
Credits
About the Authors
About the Reviewers
1. Preface
1. Setting Up 2. Building Your First Application 3. Primitives 4. Materials 5. Cameras 6. Moving Things Around 7. Shading 8. External Models 9. Z-Sorting 10. Particles 11. Filters and Effects 12. 3D Vector Drawing and Text 13. Optimizing Performance

Chapter 3. Primitives

If you're familiar with 3D modeling software such as Maya, 3D Studio Max, or CINEMA 4D, you will undoubtedly know that programs like these usually have a set of built-in primitives. Primitives are basic geometric shapes such as the plane, sphere, and cube. In most 3D modeling programs you can easily add primitives to your scene by clicking and dragging, and if you like, you can modify them. In that respect primitives serve as the building blocks for advanced models. You could also create them yourself, but primitives included in 3D software programs definitely make life easier for the 3D modeler.

Papervision3D also has a set of primitive shapes. Although you cannot click and drag them to the stage, as Papervision3D is not a software program with a graphic user interface, they come in quite handy when you need basic shapes in your application.

Modifying primitives in Papervision3D is harder than in 3D modelling software, again because there is no user interface. However...

The basic elements of 3D objects


In our daily life it is not hard to imagine the third dimension, as we are part of it all the time. On a computer screen, 3D is different because a screen is 2D only. Let's get a little more familiar with the illusion of the third dimension on a two-dimensional screen.

Vertices

In 3D geometry, every object consists of a group of vertices, also known as verts (singular: vertex). A vertex is a point in 3D space. When you define the position of a sprite in Flash, you set it on two axes, the x- and y-axis. A vertex has a third coordinate, set on the z-axis. The order of the coordinates in 3D is always x, y, z.

Triangles

Vertices form triangles, also known as faces, or triangle faces, so every triangle is made of three vertices. Other 3D programs sometimes enable you to create faces that are made up of four vertices, also known as quad faces, but Papervision3D knows only triangle faces. The vertices define the shape of the triangle and because they have x, y,...

The rendering pipeline


When you publish a project, Papervision3D handles several processes, resulting in the illusion of 3D that you see on your two-dimensional screen. The sequence of processes that transform 3D information into a 2D screen is called the rendering pipeline. The Papervision3D rendering pipeline looks like this:

When you built your first application in the previous chapter, you instantiated a sphere that appeared on the screen after publishing the file. Let's run through the pipeline with the sphere example in mind.

Initialization is the part where you set up your application by creating a viewport, a scene, a camera, a renderer, and one or more 3D objects. This is something that happens only once. In the example in Chapter 2, you created a sphere with default wireframe material in the init() method, which stands for initialize.

Projection converts 3D coordinates onto a 2D screen. As said in the previous section, a 3D object is made up of vertices, which have a third...

Creating and adding primitives


Papervision3D offers a set of seven primitives:

  • Plane

  • Sphere

  • Cylinder

  • Cone

  • Cube

  • Arrow

  • PaperPlane

The arrow and the paper plane are shapes that are a little more specific than the other shapes that may have a broader use in real-world applications. The paper plane has been part of the Papervision3D library from the very start and has provided the developers with a simple object to carry out all kinds of testing. In that respect, there is an analogy between the paper plane and the famous "Utah teapot" that is included in many 3D software programs.

Note

The Utah teapot is a 3D model that was created by Martin Newell back in 1975 after his wife Sandra suggested modeling their tea service. It is known to be quite useful for testing purposes. The original teapot model can be found in the Computer History Museum in Mountain View, CA.

The primitives that come with Papervision3D are easy to instantiate. For each primitive, we will go through an example that shows...

Nesting


Nesting is the technique of adding one or multiple objects—the child or children—to a parent object. A benefit of nesting is that you can create a hierarchal structure in which children show behavior relative to their parent. For instance, you can group one set of objects by nesting them in one parent and group another set of objects by nesting them in another parent. This gives you a lot of control over both groups of objects.

In the previous examples, every time we created a primitive we added it directly to the scene using the addChild() method. But not only Scene3D has this method, so does DisplayObject3D. In the documentation we can look up the path of inheritance for both classes:

  • DisplayObject3D inherits from DisplayObjectContainer3D

  • Scene3D inherits from SceneObject3D, which inherits from DisplayObjectContainer3D

Both Scene3D and DisplayObject3D inherit the addChild() method from DisplayObjectContainer3D . This means that we can also use the addChild() method on...

Accessing vertices


Let's go back for a moment to the basic elements of a 3D object—vertices. The vertices of every do3D are stored in an array. You can access them through the geometry property.

do3D.geometry.vertices

Suppose you would like to know the x and y coordinates of all the vertices of the plane that we built in PlaneExample. Because the vertices are stored in an array, you can find out how many there are by using the length property.

var numberOfVertices = plane.geometry.vertices.length;

Then you can iterate through the array using a for loop.

for(var i:uint = 0; i < numberOfVertices; i++)
{
trace("x: " + plane.geometry.vertices[i].x,
"y: " + plane.geometry.vertices[i].y,
"z: " + plane.geometry.vertices[i].z)
}

This will output:

x: -150 y: -150 z: 0
x: -150 y: 150 z: 0
x: 150 y: -150 z: 0
x: 150 y: 150 z: 0

As you can see, only the x, y, and z positions of four points are given. Maybe you would have expected the positions of six points because every triangle has three vertices...

Summary


Primitives are basic geometric shapes such as the cone, cube, and sphere. The Papervision3D library contains a set of primitives meaning you won't have to build them yourself. For each primitive, we worked through an example that demonstrated how to instantiate it and how we can add it to our scene. We also discussed the parameters that are available such as the number of segments and the material you want to apply.

Every 3D object is made of vertices, which are coordinates in 3D space. Vertices are projected onto the 2D screen and form triangles. Every triangle is made of three vertices, and multiple triangles form a 3D object or a triangle mesh.

The sequence of processes that takes place when you publish a project is called the rendering pipeline. The Papervision3D rendering pipeline looks as follows:

  • Initialization is the part where you set up your application by creating a viewport, a scene, a camera, a renderer, and one or more 3D objects and their materials.

  • Projection converts...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Papervision3D Essentials
Published in: Sep 2009 Publisher: Packt ISBN-13: 9781847195722
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}