Ok on my previous post on getting started with FlarToolkit I had a Bunch of people asking me how do you get your own models into FlarToolkit kind of like the guys at Bofswana or the guys at North Kingdom with the GE site:
Lately I’ve been learning Blender and you know I actually kind of enjoy it once you get over the wierd kinks. Although I’d have to say I enjoy working in ALL 3d apps. I started out with some free gheto 3d app, then moved onto Swift 3d (this was before Papervision), then I did some Cinema 4d, and finally did some Maya and Zbrush stuff.
I really do like Maya but I’m anti software pirating now so I’m trying to figure out all the good free tools now. (I had a legal version of Maya and Zbrush at my old work)
So without further adieu I’d like to explain why I’ve entitled this post “You can lick my Collada”.
Click on the mouth to see my first Collada export:

For those of you who do not know what Collada is, it’s basically just the XML representation of a 3d scene. (right click and open a Collada file in a text editor and you’ll see) Papervision has some classes to parse/show these XML 3d scenes.
To export from Blender as Collada.
In Blender Click- File >> Export >> Collada 1.4(.dae)
(Note you have to have Python installed along with Blender to export Collada files)
Use the following settings for the Collada export:

Now to get your model into Papervision it’s super simple. (source download at bottom)
The following lines load in my Collada file and parse it:
mouth=new Collada("3dStuff/mouth.dae"); mouth.addEventListener(FileLoadEvent.LOAD_COMPLETE, colladaLoaded); mouth.addEventListener(FileLoadEvent.COLLADA_MATERIALS_DONE, matsLoaded);
That’s it. You actually don’t need to have the LOAD_COMPLETE event but it’s a nice to have. How Papervision loads Collada files is that it first loads and sets up the model then it goes in and loads in the Materials, hence adding the second listener for COLLADA_MATERIALS_DONE.
Within the COLLADA_MATERIALS_DONE listener I add the model to the scene and start a render loop. This is all you need to get Collada files in.
One thing to watch out for though is that the paths for your textures maybe off in your Collada file so open up your Collada file and search for your textures in my Collada file my textures are named: tongue.jpg, and mouth.jpg.
There should be no path in here it should just be the file name. Papervision will try to load the textures relative to where your Collada file is. So your textures should sit in the same folder as your Collada file. (to make things easy)
Download the source code from here. (this is a Flex Project)
The code is pretty straight forward. You may notice there is another class there called “As3ExportFromBlender.as” I’ll talk about this in my next post.
8 Comments, Comment or Ping
Nice tuto thanks
I have a question
How do you remove objet from scene when the marker are not detected ?
March 18th, 2009
Just set the visiblity of the viewport to false in the render code. Use a if, else statement to detect if the marker is detected and the in the else part, do the above.
Harry.
April 13th, 2009
Hey Mikko.
Thanks a lot for the stuff but I have a question about the dae-Files. I tried to exchange the mouth.dae with a own model I exported with Blender. When I test the project, nothing is displayed! With your dae-file it works fine.
I imported the mouth.dae in blender, change it a little bit and exported it to dae again with the settings on this post, but nothing is displayed, too.
I don’t know whats going wrong, do you have an idea??
Greetings, Chris
April 20th, 2009
Hey I have a problem, I try to switch simple AR tutorijal from goToAndLearn to display this big mouth
but all I get is realy big mouth all over camera
what should I do to make thil custom object a little smaller? This is my code
package {
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.ByteArray;
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.pv3d.FLARBaseNode;
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
[SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
public class FLARdemo extends Sprite
{
[Embed(source="pat1.pat", mimeType="application/octet-stream")]
private var pattern:Class;
[Embed(source="camera_para.dat", mimeType="application/octet-stream")]
private var params:Class;
private var fparams:FLARParam;
private var mpattern:FLARCode;
private var vid:Video;
private var cam:Camera;
private var bmd:BitmapData;
private var raster:FLARRgbRaster_BitmapData;
private var detector:FLARSingleMarkerDetector;
// pv3d
private var scene:Scene3D;
private var camera:FLARCamera3D;
private var container:FLARBaseNode;
private var vp:Viewport3D;
private var bre:BasicRenderEngine;
private var trans:FLARTransMatResult;
private var mouth:Collada;
public function FLARdemo()
{
setupFLAR();
setupCamera();
setupBitmap();
setupPV3D();
addEventListener(Event.ENTER_FRAME, loop);
}
private function setupFLAR():void
{
fparams = new FLARParam();
fparams.loadARParam(new params() as ByteArray);
mpattern = new FLARCode(16, 16);
mpattern.loadARPatt(new pattern());
}
private function setupCamera():void
{
vid = new Video(640, 480);
cam = Camera.getCamera();
cam.setMode(640, 480, 30);
//cam.z -= 300;
vid.attachCamera(cam);
addChild(vid);
}
private function setupBitmap():void
{
bmd = new BitmapData(640,480);
bmd.draw(vid);
raster = new FLARRgbRaster_BitmapData(bmd);
detector = new FLARSingleMarkerDetector(fparams, mpattern, 80);
}
private function setupPV3D():void
{
scene = new Scene3D();
camera = new FLARCamera3D(fparams);
container = new FLARBaseNode();
scene.addChild(container);
var pl:PointLight3D = new PointLight3D();
pl.x = 1000;
pl.y = 1000;
pl.z = -1000;
var ml:MaterialsList = new MaterialsList({all: new FlatShadeMaterial(pl)});
var cube1:Cube = new Cube(ml, 30, 30, 30);
var cube2:Cube = new Cube(ml, 30, 30, 30);
cube2.z = 50;
var cube3:Cube = new Cube(ml, 30, 30, 30);
cube3.z = 100;
mouth = new Collada(“3dStuff/mouth.dae”);
//mouth.scaleX = 10;
//mouth.scaleY = 10;
//mouth.y+=300;
//mouth.rotationX=-90;
container.addChild(mouth);
//container.addChild(cube1);
//container.addChild(cube2);
//container.addChild(cube3);
bre = new BasicRenderEngine();
trans = new FLARTransMatResult();
vp = new Viewport3D();
addChild(vp);
}
private function loop(evt:Event):void
{
bmd.draw(vid);
try
{
if (detector.detectMarkerLite(raster, 80) && detector.getConfidence() > 0.5)
{
detector.getTransformMatrix(trans);
container.setTransformMatrix(trans);
bre.renderScene(scene, camera, vp);
}
}
catch(e:Error)
{
// eat error
}
}
}
}
May 31st, 2009
INFO: DisplayObject3D: Tongue
WARNING: Collada material tongue_jpg not found.
INFO: DisplayObject3D: Mouth
WARNING: Collada material mouth_jpg not found.
MODEL LOADED
I get the above error i placed the mouth.jpg and tongue.jpg in the same folder as .dae file and as well as on the folder where the source files are. Iam using Flash CS4; Can you guide me to make things work?
Does I need to change anything in the .dae file?? does this has to be changed..
file://C:/Users/’/Desktop/mouthForFlarToolkitToExport.blend
October 6th, 2009
Reply to “You can lick my Collada (Getting 3d models into Papervision)”