summaryrefslogtreecommitdiff
path: root/graphics/asymptote/prc/PRCTools/iPRCFile.h
blob: 2622cb966d1efd0c5f8df33294c21719068a2d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/************
*
*   This file is part of a tool for reading 3D content in the PRC format.
*   Copyright (C) 2008 Orest Shardt <shardtor (at) gmail dot com>
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU Lesser General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU Lesser General Public License for more details.
*
*   You should have received a copy of the GNU Lesser General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*************/

#ifndef __READPRC_H
#define __READPRC_H

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
#include "../PRC.h"
#include "inflation.h"

struct FileStructureInformation
{
  unsigned int UUID[4];
  unsigned int reserved;
  std::vector<unsigned int> offsets;
};


const int GLOBALS_SECTION = 0;
const int TREE_SECTION = 1;
const int TESSELLATION_SECTION = 2;
const int GEOMETRY_SECTION = 3;
const int EXTRA_GEOMETRY_SECTION = 4;

struct FileStructure
{
  unsigned int readVersion;
  unsigned int authoringVersion;
  unsigned int fileUUID[4];
  unsigned int appUUID[4];
  char* sections[5];
  unsigned int sectionLengths[5];
};

class iPRCFile
{
  public:
    iPRCFile(std::istream&);

    ~iPRCFile()
    {
      for(unsigned int i = 0; i < fileStructures.size(); ++i)
        for(unsigned int j = 0; j < 5; ++j)
          if(fileStructures[i].sections[j] != NULL)
            free(fileStructures[i].sections[j]);
      if(modelFileData!=NULL)
        free(modelFileData);
      if(buffer != 0)
        delete[] buffer;
    }

    void describe();
    void dumpSections(std::string);

  private:
    // header data
    std::vector<FileStructureInformation> fileStructureInfos;
    std::vector<FileStructure> fileStructures;
    unsigned int modelFileOffset;
    char* modelFileData;
    unsigned int modelFileLength;
    char *buffer;
    unsigned int fileSize;
    unsigned int numberOfUncompressedFiles;
};
#endif // __READPRC_H