3Dモデルファイルの入出力

ポリゴンで構成された3Dモデルファイルの入出力を行うライブラリ.現在の対応は以下.

  • OBJファイルの入出力
  • DXFファイルの入出力(3DFACEエンティティのみ)
  • VRMLファイルの入力(IndexedFaceSetのみ)
  • 3DSファイルの入力(EDITチャンクのみ,KEYFRAMEチャンクには未対応)
  • STLファイルの入出力(ASCII,バイナリ両方に対応)
  • OFFファイルの入力

ダウンロード

ソースコードは以下.

使用例

  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
#include "rx_model.h"
 

void ReadOBJ(const string filename, rxPolygons &polys, Vec3 cen, Vec3 ext)
{
    if(!polys.vertices.empty()){
        polys.vertices.clear();
        polys.normals.clear();
        polys.faces.clear();
        polys.materials.clear();
        polys.open = 0;
    }
    rxOBJ obj;
    if(obj.Read(filename, polys.vertices, polys.normals, polys.faces, polys.materials, true)){
        cout << filename << " have been read." << endl;
 
        if(polys.normals.empty()){
            CalVertexNormals(polys);
        }
 
        cout << " the number of vertex   : " << polys.vertices.size() << endl;
        cout << " the number of normal   : " << polys.normals.size() << endl;
        cout << " the number of polygon  : " << polys.faces.size() << endl;
        cout << " the number of material : " << polys.materials.size() << endl;
 
        FitVertices(cen, ext, polys.vertices);
 
                if(!polys.materials.empty()){
            rxMTL::iterator iter = polys.materials.begin();
            for(; iter != polys.materials.end(); ++iter){
                if(iter->second.tex_file.empty()) continue;
 
                cout << iter->first << " : " << iter->second.tex_file;
                LoadGLTexture(iter->second.tex_file, iter->second.tex_name, true, false);
 
                cout << " : " << iter->second.tex_name << endl;
            }
        }
 
        polys.open = 1;
    }
}
 

void SaveOBJ(const string filename, rxPolygons &polys)
{
    rxOBJ obj;
    if(obj.Save(filename, polys.vertices, polys.normals, polys.faces, polys.materials)){
        cout << filename << " have been saved." << endl;
    }
}

添付ファイル: filerx_model_v0.51b.zip 1126件 [詳細] filerx_model_v0.52.zip 4031件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-11-30 (水) 13:48:05