**Update
This tutorial has been updated:
![]()
Hi, Today we're going to modify the "Creating Objects" project again, this time to load a Collada Model file.
Loading Collada files is the fastest and easiest way in Papervision 3d to get a complex model into your scene. By changing a few lines in your code, we can quickly load a model of a cow and make it spin! The result will be this:
All that, in just a few lines of code!
Let's show you how to spin cows..
We'll need to use the org.papervision3d.objects.DisplayObject3D package to store our model in. This will store the geometry, materials and everything like the position and rotation. We'll also need the Collada file parser.. Change your import lines so they look like this:
import PaperBase; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.parsers.Collada;
They're the only three imports needed!
Now, instead of making a cone, this time we're making a cow, so we change the "public var cone" line to this:
public var cow:DisplayObject3D;
So, that line tells our program that we want to store a DisplayObject3D in a variable called cow.
Now, in the init3d() function code we'll load the Collada file. I have the file stored on my server. You can download it if you want but this example will refer to the model on my server so it will work wherever. Change all of the code in "init3d" to this:
cow = new Collada("http://papervision2.com/wp-content/downloads/dae/cow.dae");
cow.moveDown(100);
cow.scale = 3;
cow.pitch(-30);
default_scene.addChild(cow);
Most of that code is just positioning the cow in the scene!
The first line of that code makes the cow variable load the Collada model file from my server. All of the parsing, getting the material and everything like that is done by the Collada package which is pretty neat!
We then move the cow down a bit, tilt her towards the camera, and add her to the scene.
All that's needed now is to rotate the cow each time the frame is processed. Simple! Change the code under "processFrame" so that it reads:
cow.yaw(5);
and you're all done!
My final code is here:
-
package {
-
-
import PaperBase;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.objects.parsers.Collada;
-
-
public class Main extends PaperBase {
-
-
public var cow:DisplayObject3D;
-
-
public function Main() {
-
init();
-
}
-
-
override protected function init3d():void {
-
cow = new Collada("http://papervision2.com/wp-content/downloads/dae/cow.dae");
-
cow.moveDown(100);
-
cow.scale = 3;
-
cow.pitch( -30);
-
default_scene.addChild(cow);
-
}
-
-
override protected function processFrame():void {
-
cow.yaw(5);
-
}
-
-
}
-
-
}

okay why not asking further questions:
how can i move the camera using basicview on every frame.
I have this function:
override protected function onRenderTick(event:Event = null):void
{
model.yaw(2);
super.onRenderTick(event);
}
So I want the camera to target the model and than rotate the camera around the model and not like here, rotating the model itself.
i have to search for solutions by mayself, I’m only spamming.
So i’ve got this code and it works.thanks.
/**
* @author Karol
* @version 0.7
*/
package
{
import flash.events.*;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.Viewport3D;
public class Main extends BasicView
{
protected var model:DAE;
public function Main()
{
super(640, 320, true, true, “Camera3D”);
// Initialise Papervision3D
init3D();
// Create the 3D objects
createScene();
// Start rendering the scene
startRendering();
}
private function init3D():void
{
camera.x = 100;
camera.y = 20;
camera.z = 100;
camera.zoom = 5;
}
private function createScene():void
{
model = new DAE(true, “house”, false);
model.load(“http://karol.bplaced.net/media/bla.dae”);
model.scale = 0.5;
model.moveDown(50);
//model.moveBackward(50);
model.pitch( -10);
scene.addChild(model);
camera.target = model;
}
override protected function onRenderTick(event:Event = null):void
{
model.yaw(2);
super.onRenderTick(event);
}
}
}
hello
i have some questeion to my source code above.
if you compile it, it will work.
But now i havetextures on my 3D model made in lightwave and exportet to DAE.
How will I get them in the flash file?
Do I have to do somthing with matarial
lists or something like that?
Another problem I have is that the camera has to move around the object, but it looks very unnormal, e.g. the corners seem to come nearer to the camera and so on
can anybody help me plaese?
Karol
At first
You must open your Texture .tga file with PhotoShop and “Save As” PNG/JPG/GIF
I’m using Blender on mesh I had putted Texture UV/Image Editor
And on Mesh in “EDIT MODE” I open my .png Texture
Put back “Object Mode” and export as .dae
Now you must to open your .dae file with “notepad” or I using “Notepad Plus”
And find
C:\YuorTexture.png
Chandge to
YourTexture.png
Now your Mesh.dae and texture must to be in same folder
Sorry for my English
Example there http://www.risdesigns.eu/Paper/Orc/
OPEN Orc.swf
Exporting u must to use Collada 1.4.0 and Select “Use UV Image Mats”
Does anyone know the number of tris in this model???
RipX
Does somebody knows how can I replace the ENTER_FRAME event with a TIMER_EVENT so the model can spin slower or faster?
I’m getting this error when I try this:
“1180: Call to a possibly undefined method addFrameScript.”
Any idea what I’m doing wrong?
Dimitree: the benefit of the enter_frame event is that it keeps the animation in sync with the flash player redraw (which varies inr realtime playback afaik). you could tweak the onrender function to skip ahead/behind or adjust the amount of animation (yaw, etc) to slow or speed up the spinning. That said, there is the Timer and TimerEvent that can also force a redraw (with event.updateAfterEvent()), more info on these timers here:
http://livedocs.adobe.com/flex/3/langref/flash/utils/Timer.html
http://livedocs.adobe.com/flex/3/langref/flash/events/TimerEvent.html
Does have some way to export a animated DAE that work on papervision? I´m trying with max 2009 and several kins of Collada files e plugins… and nothing… Does anybody knows about it?
i’m using flex builder 3 as compiler and it works. But, I’v got a problem with my own 3D object, i’ve made using Sketchup 7. There was a wire shows around the object and also the material didn’t works properly, it looks mess. Can u help me please?
Wondering why current_scene.removeChild(cow) does not remove the model from the scene when using PaperBase class. I need to browse many models by loading/unloading them.
Wow! Thanks SO much for this tutorial – I found it after some random googling and it really cleared up a lot of the collada integration for me. Absolutely stellar work, and I’m looking forward to checking out the rest of your work.
I’m using this script and I don´t changed anything. When my SWF is running and I show the symbol in the camera JUST appear a model in wireframe… I changed the DAE and nothing !! Please what I can do to fix this ?
Hi, I have a little question if someone could help me…
How can I load my model so it looks good, without “cutting” some faces?
here is my model:
http://www.zix.com.mx/Auto_Lv.swf
Note how windows and door, dont load ok.
thanks
Hi there,
I am having a problem in running the above code.Actually i am getting as the final output only the wire frame of the cow’s model.I wonder how can i apply the texture so that it looks a bit nice.Thanks alot for you Tutorial.
Hi there!
Nice tutorial!
Today it is my first day using papervision and I’m really enjoying!
But now I’m stucked when importing a .DAE. If I use this code, it works ok for me. But my problem is when I want to load a model from my local. I have dae and jpg files in the root of the project and I cannot see anything…
I thought it might be my model, but I downloaded cow.dae and cow.png and I cannot see it either… Does anyone know what I’m doing wrong??
Thanks a lot.
For those of you who need the texture file, it’s at:
http://papervision2.com/wp-content/downloads/dae/Cow.png
In order to render the skin.
Hi i have downloaded the dae file and the png file both are in the same folder along with the source files but i can only see a wireframe of cow not the cow skin. I face the same problem with few more examples.
Thanks
Hari
hi am using following code to load Max3Ds file but it does not load 3D file….kindly help me …
package {
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Max3DS;
import org.papervision3d.view.BasicView;
public class pv3d extends BasicView
{
private var model:DisplayObject3D;
public function pv3d()
{
stage.frameRate=40;
init();
}
private function init():void
{
model = new Max3DS();
model.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
Max3DS(model).load(“assets/teapot.3ds”, null, “./assets/”);
}
private function modelLoaded(e:FileLoadEvent):void
{
scene.addChild(model);
}
}
}
Thanks for this very usefull Tutorials and sources
##################################################
@mac, try this:
package
{
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.parsers.Max3DS;
import org.papervision3d.lights.PointLight3D;
[SWF(width="800", height="600", frameRate="30", backgroundColor="0x000000")]
public class cow3d extends BasicView
{
protected var light:PointLight3D;
protected var my3ds:Max3DS;
public function cow3d()
{
super();
createChildren();
startRendering();
}
public function createChildren():void
{
// where to find textures
var textureDir:String = “./assets/”; // use a trailing slash!
// optional materialsList
var materials:MaterialsList = new MaterialsList();
// the 3DS file
var fileName:String = “./assets/YOURFILE.3ds”;
// load it!
var my3ds:Max3DS = new Max3DS();
my3ds.load(fileName, materials);
my3ds.yaw(200);
// add to scene
scene.addChild(my3ds);
var light:PointLight3D = new PointLight3D(true);
light.x = 400;
light.y = 1000;
light.z = -400;
}
}
}
I copied and pasted everything in this tutorial letter for letter to test out and got this:
WARNING: Collada material mat0 not found.
Any ideas? Digging into the Collada file, I see that it’s looking for Cow.png and I see it’s located on the server in the same folder as cow.dae? Confused.
@RiS:
Actually, shouldn’t the texture target reference be:
“./yourTexture.png”
Instead of what you said: “yourTexture.png” ??
@BonesMcChan
I have an updated version of this tutorial with full source @
http://papervision2.com/loading-complex-models-v2/
Hope this helps solve some of your issues.
Charlie
hello.
I have a problem with texture mapping, models of imported and 3ds MAX.
I can not understand how to impose a complex texture with UV.
Maybe someone has already faced a similar problem, help please how to translate the correct texture mapping from 3ds MAX into flash, or what may be a mistake. Sorry for my English, thanks in advance.