**UPDATE**
This tutorial has been updated:
![]()
Before starting this tutorial, please note that it follows on from Tutorial 4 - Basic Template Usage. If you haven't followed that tutorial, I suggest that you do so.
Be modifying a few lines, we're going to give our spinning cone a texture. The result will be something like this:
Firstly, open up the project that you made in tutorial 4. I'm going to show you how to use the BitmapFileMaterial, so before we start, you need to import org.papervision3d.materials.BitmapFileMaterial. To do this, find where you have two lines starting with import and just below them, add the line:
import org.papervision3d.materials.BitmapFileMaterial;
That line will import the BitmapFileMaterial package into your project, so that you can use it.
Now, we need to add a BitmapFileMaterial to our cone. We can do this when we create it, but first I'll explain BitmapFileMaterial.
BitmapFileMaterial is a papervision 3d material which takes a url of an image file, and creates a texture from it. This is very useful when loading collada models, and it opens possibilities of having things like user-uploaded textures.
When you create a new BitmapFileMaterial object, you pass it a URL from which the texture will be fetched.
To add the material to our cone, we're going to pass a BitmapFileMaterial object to the cone when we create it. This is really simple to do, simply change the line:
public var cone:Cone = new Cone();
to:
public var cone:Cone = new Cone(
new BitmapFileMaterial(
"http://papervision2.com/wp-content/downloads/ourtex.jpg"
)
);
This will now get the file from my server and use it as the texture on your cone.
Now, when you run your code you'll see the red and white texture on your cone. Simple!
My final code looks like this:
-
package {
-
-
import PaperBase;
-
import org.papervision3d.objects.primitives.Cone;
-
import org.papervision3d.materials.BitmapFileMaterial;
-
-
public class Main extends PaperBase {
-
-
public var cone:Cone = new Cone(new BitmapFileMaterial("http://papervision2.com/wp-content/downloads/ourtex.jpg"), 20, 200);
-
// I've added a width and height to change the shape of my cone.
-
-
public function Main() {
-
init();
-
}
-
-
override protected function init3d():void {
-
cone.scale = 3;
-
cone.pitch( -30);
-
default_scene.addChild(cone);
-
}
-
-
override protected function processFrame():void {
-
cone.yaw(20);
-
// Here, I've made my cone spin faster by increasing the amount sent to yaw();
-
}
-
-
}
-
-
}








