Page 1 of 1

PLY loader

Posted: Fri Sep 01, 2006 9:17 pm
by agrif
So... I made a .ply loader. See a little more about it, and some sample files, here [graphics.stanford.edu] and here [local.wasp.uwa.edu.au].

Basically, it's a simple, usually text-based mesh format that's really extendable. The Stanford Bunny [en.wikipedia.org] originally came in this format.

I wanted a loader for this format because I wanted a simple format to write a loader for in order to learn how 3d models work. I was also tired of model formats also trying to cover materials and textures. To me, a model file should have all a model needs, but nothing more :roll: . The .ply format can be used for materials etc., but usually isn't. I also needed a file format exportable from blender that preserved smooth normals.

Right now, there are a few problems:
  • Does not handle faces with more than 4 verts
  • Blender-exported meshes do not have the right axes
  • Does not handle binary .ply formats
  • Will not handle corrupted data sections correctly (SEGFAULT :x )
but, it works for what I want it for, and I thought maybe someone would find it useful.

Download Zip [projectfaint.hopto.org]

(Sorry for the slow server)

Here's the Stanford Bunny, 16000 polygon version, with some very bad UV coords.
Image

Things in the zip:
  • bunnyuv.ply, bunny.ply, cube.ply, monkey.ply - Some simple .ply files
  • PLYloader.exe - windows binary demo. Usage: PLYloader [ply file]
  • testAll.bat - runs PLYloader.exe on all of the .ply files.
  • src/main.cpp - demo program source
  • src/CPLYMeshFileLoader.cpp, .h - Source of the loader
WARNING:I have a bad habit of not commenting. Sorry... :oops:

So yeah, if anyone uses this it'd be cool to know. Under the same license as Irrlicht. Also, if anyone finds a binary-format .ply file, or a file that does not work with this loader, I'll see what I can do. Just send it to me :)

agrif

Posted: Fri Sep 01, 2006 11:39 pm
by hybrid
Nice, although the models are really huge. I'll put it onto my patch page where also other additional file formats live :)

Posted: Sat Sep 02, 2006 8:16 am
by vermeer
cool.

I used to use a free ply model viewer and converter, but is nice to see such a project in irrlicht.
I dont remember it supporting uv textures...


Hybrid, the ply format is the most used for 3d scans, together with -dont ask me why- dxf. Are a lot in university papers, projects, thesis, scanned samples at those centers, or simply samples for 3d scanners for pre purchases tests and stuff.

Scans are often millions of polies.

A note here...When I used to do this, the ply I could converte them to OBJs or the like...metasequoia was the only tool to handle well those huge meshes.

That rabbit is quite known in hi res meshes samples ;)

Cool thing.

Posted: Sat Sep 02, 2006 8:22 am
by vermeer
oh, ur adding uv and materials support...great..I never saw a ply with textures...

maybe it had it, just nobody cared on doing an UV map for any....

and indeed you...made a plugin also for Blender? maybe I understood wrong...

You made plugin for export smooth normals + uv textures out from belnder, in the ply format? great then. I guess would be then a nice format for terrains, indeed...

cool...

Oh, and your problems, arent real problems :


# Does not handle faces with more than 4 verts

3d cards support triangles only, as far as I know. Few softwares support more than 4 verts, WIngs is one, but for game engines, I allways need to traingulate, anyway.


# Blender-exported meshes do not have the right axes

They never have with most formats. Go ask whoever decided Z had to be so intead of Y axe...;) Is a Blender..."feature" ;)


# Does not handle binary .ply formats

well, maybe then will be of slower loading ingame, but it depends, maybe not.

# Will not handle corrupted data sections correctly (SEGFAULT Mad )

Corrupted? for scanning fails? Well...If you modeled the mesh in Blender, or fixed an imported 3d scan, no issue...

Posted: Sat Sep 02, 2006 10:48 am
by hybrid
Triangulation is also done in other mesh loaders. Just check the sources, I should have documented the parts in my loaders.
And corrupted data is likely to crash a loader. You can try to avoid buffer overruns (end of file overruns) by checking the file position and size constantly, which should help in most cases. And of course check all return values of memory allocations.

Grampus

Posted: Sat Sep 02, 2006 3:43 pm
by agrif
hybrid: I'll have to look at that triangulation code. Glad you commented your code, unlike me.

vermeer:

I don't know whether UV coords are an official part of the format, but the general consesnus on the web is they are added by the s and t properties of the vertex. As for the blender plugin, at least Blender 2.42 (maybe earlier) comes with a .ply import/export plugin. Also, it would be good for terrain... for one, it's easy as anything to edit.

Along with UVs, I also load vertex colors. No other Blender-exportable format I know of can export vertex colors, and these can really come in handy sometimes. Although, they aren't loaded right yet... I'm either doing something wrong, or Irrlicht is insisting only to use the luminosity of the colors.

As for polygons, the .ply format supports faces with as many verts as you want, although they are usually triangles. I just need to figure out how to triangulate them into a format that Irrlicht can draw.

I was looking in to changing the loader so that if it sees the "Created in Blender" comment, it would switch around the axes. Always been a little pet peeve of mine, having to rotate models around just so they come out right.

The text-file loader shouldn't be much slower than the binary, when it's done. It's just a problem of file sizes. Text .plys can be huge, but binary ones are reasonable.

A currupted data section crash only happens if an entry with a list-type property specifies the wrong number of entries. I don't know how to check this. All the other crashes, though, are handled well.

I wish I had a sanner to use this, but alas, they aren't exactly in the price range of a high school student :( . I'm only using these with meshes from Blender.

thanks,
agrif