tom.drastic.net

v3d exporter

  • Introduction
  • Features
  • Installation
  • File Format
  • Simple View
  • Examples
  •  

    Introduction

    v3d exporter is an 3ds max plugin to export your data to the v3d file format.
    exported v3d files are in binary format and very easy to parse.

    Features

    1. 3ds max gui
    2. exports meshes, materials, lights, cameras, splines from 3ds max
    3. exports multiple channels of texture coordinates
    4. exports sampled position/rotation/scale animations
    5. exports 3ds material settings and texture map data
    6. exports sampled mesh animations

    Installation

    blablablablablabla…….

    v3d.png

    File Format

    a v3d file consists of blocks of data called chunks. Every chunk starts the same way:

    (short / 2 byte)   - chunk_id
    (byte / 1byte)     - chunk_type
    (int / 4 byte)     - chunk_size
    (chunk size bytes) - data
    

    chunk_id describes the content of the current chunk (for example: “vertex data” or “texture coordinates” etc).
    chunk_type describes the format of the data:

    CHUNKTYPE_FLOAT   = 1  //element size is 4 bytes
    CHUNKTYPE_INT     = 2  //element size is 4 bytes
    CHUNKTYPE_STRING  = 3  //element size is 1 byte
    CHUNKTYPE_EMPTY   = 4  //has no data
    CHUNKTYPE_BYTE    = 5  //element size is 1 byte
    CHUNKTYPE_SHORT   = 6  //element size is 2 bytes
    

    chunk_size contains the length of the chunk (without header)
    if the length is 12 and the type is CHUNKTYPE_FLOAT, data contains 3 floats.
    this structure makes parsing very easy.

    parsing pseudocode:

    while(!eof)
    {
      int numElements=0;
      // read chunk header data:
      short id=readShort();
      byte type=readByte();
      int size=readInt();
    
      // calculate the number of elements in data
      switch(chunkTYPE)
      {
        case CHUNKTYPE_FLOAT:
          numElements=size/4;
        break;
        case CHUNKTYPE_INT:
          numElements=size/4;
        break;
        case CHUNKTYPE_SHORT:
          numElements=size/2;
        break;
        default:
          numElements=size;
        break;
      }
    
      // use data
      switch(id)
      {
         case "CHUNK_BACKGROUNDCOLOR":
           myscene.setBackgroundcolor(readFloatArray(numElements));
         break;
    
         //...
    
         // unknown chunk: just skip the data part...
         default:
            skipBytes(size);
         break;
      }
    }
    

    chunks
    a list of all possible chunks.

    short CHUNK_VERSION = 1;
    
    short CHUNK_BACKGROUNDCOLOR = 5;
    short CHUNK_ANIMATION_FPS = 10;
    short CHUNK_ANIMATION_SAMPLERATE = 11;
    
    short CHUNK_MOBJECT = 200;
    short CHUNK_MOBJECT_NAME = 201;
    short CHUNK_MOBJECT_POS = 202;
    short CHUNK_MOBJECT_ROT = 203;
    short CHUNK_MOBJECT_SCALE = 204;
    short CHUNK_MOBJECT_NUMVERTICES = 205;
    short CHUNK_MOBJECT_NUMFACES = 206;
    short CHUNK_MOBJECT_WIRECOLOR =215;
    short CHUNK_MOBJECT_MESH_NORMALS = 216;
    short CHUNK_MOBJECT_POS_ANIM = 217;
    short CHUNK_MOBJECT_ROT_ANIM = 218;
    short CHUNK_MOBJECT_END = 299;
    
    short CHUNK_MOBJECT_MESH_VERTICES = 301;
    short CHUNK_MOBJECT_MESH_FACES = 302;
    short CHUNK_MOBJECT_MESH_MATERIAL = 303;
    short CHUNK_MOBJECT_MESH_TEXTURE_CHANNEL = 304;
    short CHUNK_MOBJECT_MESH_TEXTURECOORDS = 305;
    short CHUNK_MOBJECT_MESH_TEXTUREFACES = 306;
    short CHUNK_MOBJECT_MESH_END = 350;
    
    short CHUNK_CAMERA	= 400;
    short CHUNK_CAMERA_POS	= 401;
    short CHUNK_CAMERA_TARGET = 402;
    short CHUNK_CAMERA_NAME = 403;
    short CHUNK_CAMERA_ROTATION = 404;
    short CHUNK_CAMERA_FOV	= 405;
    short CHUNK_CAMERA_TARGET_ANIM =407;
    short CHUNK_CAMERA_POS_ANIM =408;
    short CHUNK_CAMERA_END	= 449;
    
    short CHUNK_LIGHT = 450;
    short CHUNK_LIGHT_NAME = 451;
    short CHUNK_LIGHT_POS = 452;
    short CHUNK_LIGHT_COLOR = 453;
    short CHUNK_LIGHT_MULTIPLIER = 454;
    short CHUNK_LIGHT_END = 499;
    
    short CHUNK_MATERIAL_ID	= 600;
    short CHUNK_MATERIAL_NAME = 601;
    short CHUNK_MATERIAL_DIFFUSE = 602;
    short CHUNK_MATERIAL_AMBIENT = 603;
    short CHUNK_MATERIAL_SPECULAR = 604;
    short CHUNK_MATERIAL_OPACITY	 = 605;
    short CHUNK_MATERIAL_TWOSIDED = 606;
    short CHUNK_MATERIAL_FACETED = 607;
    short CHUNK_MATERIAL_WIRED = 608;
    short CHUNK_MATERIAL_SPECULARLEVEL = 609;
    short CHUNK_MATERIAL_GLOSSINESS = 610;
    
    short CHUNK_MATERIAL_MAP_AMBIENT = 631;
    short CHUNK_MATERIAL_MAP_DIFFUSE = 632;
    short CHUNK_MATERIAL_MAP_SPECULAR = 633;
    short CHUNK_MATERIAL_MAP_SPECULARLEVEL = 634;
    short CHUNK_MATERIAL_MAP_GLOSSINESS = 635;
    short CHUNK_MATERIAL_MAP_SELFILLUMINATION = 636;
    short CHUNK_MATERIAL_MAP_OPACITY = 637;
    short CHUNK_MATERIAL_MAP_FILTERCOLOR = 638;
    short CHUNK_MATERIAL_MAP_BUMP = 639;
    short CHUNK_MATERIAL_MAP_REFLECTION = 640;
    short CHUNK_MATERIAL_MAP_REFRACTION = 641;
    short CHUNK_MATERIAL_MAP_DISPLACEMENT = 642;
    short CHUNK_MATERIAL_MAP_FILENAME = 645;
    short CHUNK_MATERIAL_MAP_END = 660;
    
    short CHUNK_MATERIAL_END = 699;
    
    short CHUNK_EOF = 9000;
    

    Simple View

    simpleview is just a very simple tool to look into v3d files and to debug your reader.
    it just shows the file structure in a table.
    download executable nd java source here

    v3dsimpleviewer.png

    Examples