Loading Object Files (.obj) in Papervision3D

While working on a recent campaign we had a bit tricky production pipeline. Our 3D artist was working with modo but needed to export to Collada (which is not supported by modo and currently one of the best supported formats in Papervision3D). To be able to export his work to be used with Papervision we needed to export all the models as object files (.obj) and import them into Blender (which supports Collada export).

To overcome this two-step process (and since I knew the OBJ-format from my Computer Graphics course at college) I started to dive into writing my own an OBJ-parser for Papervision3D.

It went pretty well actually. I got some help on the Papervision mailinglist and ended up with this result (see OBJ-parser source).

It’s really simple to use actually. You can just use it as the other parsers that comes with Papervision by default. Download OBJ.as, put it together with the rest of the parsers in the GreatWhite branch. Here’s a simple example from my prototype:

var fish:OBJ = new OBJ("fish.obj", "fish.mtl");
scene.addChild(fish, "Fish");

This code loads all the geometry data from the fish.obj-file and material data from the fish.mtl-file and store it in the Papervision object model. Then the object is added to the scene so it will be visible when the scene is rendered.

The OBJ-parser currently supports:

  • Geometric vertices, Texture vertices and vertex normals
  • Seperate objects for each group
  • Parsing materials from Material Library File (.mtl)

Get the source (OBJ.as)

9 Comments

remi  on April 3rd, 2008

modo does support Collada, at least in 302 as demonstrated at GDC.
I wonder if you could give it a try ?

Thomas Viktil  on April 3rd, 2008

I use modo 301 for both PC and Mac, and the Mac version has an option of exporting to Collada. But it doesn’t work. The PC version doesn’t have the option at all.

You can find a script that does the trick (over at vertexmonkey.com I suppose), but I read somewhere that the script needs a few modifications before you can use it with PV3D. So does some of the classes in PV3D.

I haven’t yet had the chance to try your parser, Knut, but it sure seems easier to use than relying on Collada.

Hopefully Luxology have fixed the Collada exporter in 302.

wezzy  on December 29th, 2008

Hi, your parser works great! what kind of license conver your code? the same of Papervision?

thanks

Knut Urdalen  on December 30th, 2008

Ah, I didn’t put a license on the code. Feel free to use and modify it in anyway you want. I appreciate if I’ll get some kind of credit :)

juju  on January 26th, 2009

it doesn’t work with AS3?

Roberto Maiocchi  on March 29th, 2009

Hi. I am trying to utilize your .obj parser but I am having some problems and I was hoping you could help me. I am using the latest version of Papervision (Mar 08, 2009).

1. in OBJ.as, line 60
super(material, new Array(), new Array(), null, initObject); -> I get an error here: this should only have 4 parameters

2. When I declare in my main:
var fish:OBJ = new OBJ(”fish.obj”, “fish.mtl”);
addChild(fish); I get the following error message:
1067: Implicit coercion of a value of type org.papervision3d.objects.parsers:OBJ to an unrelated type flash.display:DisplayObject.

I would really like to use your .obj parser and your help would be greatly appreciated. Thank you!

Ion Drimba  on April 8th, 2009

Hi Knut,

My name is Ion Drimba and I´m a flash developer from Brazil.

I´ve downloaded your OBJ.as and I´m wondering why you pass into TriangleMesh3D constructor 5 params, it only excepts 4 params.
In the OBJ constructor it´s like this.

OBJ extends TriangleMesh3D

public function OBJ(obj:String, mtl:* = null, scale:Number = 1, initObject:Object = null) {
super(material, new Array(), new Array(), null,initObject);

};

I also downloaded all your files from the sample “Fish”…and I always get ERROR: BitmapFileMaterial: Unable to load file image/sakura_p3b-3.jpg

Have any idea?

Thanks for the class.

Sergio Urra  on July 19th, 2009

Hi Knut,

Wow! It’s a nice idea to work directly with OBJ. I didn’t test your sample yet, but I’ll do a try.

Ion, the image is here:

http://www.urdalen.com/lab/objfish/sakura_p3b-3.jpg

É só procurar no Google.
Você já resolveu o tema dos parámetros?

Cheers,

Sergio

projekt.lounge  on January 18th, 2010

Hey,

problem ist that the file “org.papervision3d.core.geom.TriangleMesh3D.as” has been changed since and accepts different parameter.

i did not test it but this might do the trick:

( in file: OBJ.as )
public function OBJ(obj:String, mtl:* = null, scale:Number = 1, nme:String = null) {
super(material, new Array(), new Array(), nme);

greetings,
m.e.

Leave a Comment