Пример #1
0
  private void readMD3Data(ModelMD3 model) throws Exception {

    int i;

    // Here we allocate memory for the bone information and read the bones in.
    bones = new BoneMD3[header.numFrames];

    for (i = 0; i < header.numFrames; i++) bones[i] = new BoneMD3();

    // Free the unused bones
    bones = null;

    // Next, after the bones are read in, we need to read in the tags.
    model.setNumTags(header.numFrames * header.numTags);

    for (i = 0; i < model.getTags().length; i++) {
      TagMD3 pTags = new TagMD3();
      model.setTags(pTags, i);
    }
    // Assign the number of tags to our model
    model.setNumOfTags(header.numTags);

    // Now we want to initialize our links.
    model.setNumLinks(header.numTags);

    // Get the current offset into the file
    // loader.markPos();
    int meshOffset = loader.getFileIndex();

    // Create a local meshHeader that stores the info about the mesh
    MeshInfoMD3 meshHeader;

    // Go through all of the sub-objects in this mesh
    for (int j = 0; j < header.numMeshes; j++) {
      // Seek to the start of this mesh and read in it's header
      loader.setOffset(meshOffset);

      meshHeader = new MeshInfoMD3();

      // Here we allocate all of our memory from the header's information
      skins = new SkinMD3[meshHeader.numSkins];
      texCoords = new TexCoordMD3[meshHeader.numVertices];
      triangles = new FaceMD3[meshHeader.numTriangles];
      vertices = new TriangleMD3[meshHeader.numVertices * meshHeader.numMeshFrames];

      // Read in the skin information
      loader.setOffset(meshOffset + meshHeader.numSkins);
      for (i = 0; i < meshHeader.numSkins; i++) skins[i] = new SkinMD3();

      // Seek to the start of the triangle/face data, then read it in
      loader.setOffset(meshOffset + meshHeader.triStart);

      for (i = 0; i < meshHeader.numTriangles; i++) triangles[i] = new FaceMD3();

      // Seek to the start of the UV coordinate data, then read it in
      loader.setOffset(meshOffset + meshHeader.uvStart);

      for (i = 0; i < meshHeader.numVertices; i++) texCoords[i] = new TexCoordMD3();

      // Seek to the start of the vertex/face index information, then read it in.
      loader.setOffset(meshOffset + meshHeader.vertexStart);

      for (i = 0; i < meshHeader.numMeshFrames * meshHeader.numVertices; i++)
        vertices[i] = new TriangleMD3();

      // Now that we have the data loaded into the md3 structures, let's convert them to
      // our data types like ModelMD3 and Object3D.
      convertDataStructures(model, meshHeader);

      // Free all the memory for this mesh since we just converted it to our structures
      skins = null;
      texCoords = null;
      triangles = null;
      vertices = null;

      // Increase the offset into the file
      meshOffset += meshHeader.meshSize;
    }
  }