Search Unity

Saving a mesh

Discussion in 'Scripting' started by Richard_B, Jun 17, 2006.

  1. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    If a script generates a mesh via the new Mesh class, is it possible to save the mesh to disc? I ask because a large mesh 255*255 with a mesh collider added takes quite a while for the Physics engine to process - I guess you would have to save all the pre-processing computation as well.

    thanks,
    Richard.
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    I'm not aware of any way of saving the mesh directly. However, you could use .NET functions to write an .obj file to disk and have Unity import that.

    Wavefront .obj format is pretty easy to read and write. Here's an example file of a cube. This is an terse description of the basics of the format and this is the entire specification.

    Note that you don't have to implement every feature to get a working exporter! It's quite sufficient to just write v, vt, vn and f lines (vertex, UV, normal and face respectively). You can even omit vt and vn lines if you want, although you need vts if you want to texture your object. If you omit vns, you can tell Unity to generate normals itself on import, which might be best if you're making a landscape model or something.
     
  3. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Thanks Neil I'll chase it up. I think the bottle neck is the physics engine though :( I'll probably have to write some LOD code for the terrain.

    cheers,
    Richard.