main.cpp
#include <vector> #include <stdio.h> #include <cstring> #include <string.h> #include <iostream> using namespace std; typedef struct VertexStruct//頂点データ 構造体 { float x,y,z,w; }TVertex; typedef struct PlateStruct//面データ 構造体 { int size; int ix1,ix2,ix3,ix4; }TPlate; //配列vector vector<TVertex> v1;//頂点データ格納配列 vector<int> ix1;//インデックスデータ格納配列 //個数データ int vertexNum = 0;//頂点の総数 int indexNum = 0;//インデックスの総数 //フラグ変数 bool meshFlag = false; bool vertexNumFlag = false; bool vertexDataFlag = false; bool indexNumFlag = false; bool indexDataFlag = false; int main() { //変数 FILE *fp; //tmp用 char buf1[256]; float x,y,z,w;//頂点用tmp char str1[256]; char str2[256]; int plateSize,ixp1,ixp2,ixp3,ixp4; int plateOneWithVertexNum = 0;//1つの面の頂点数 //ファイル 読み込み fp = fopen("aa1.x", "r"); if (fp == NULL) {printf("can't open the file");}; int tmp_eof = 0; //mesh の場所まで移動 while(feof(fp) != true) { memset(buf1, 0, sizeof(buf1)); fgets(buf1, 256, fp);//一行進める tmp_eof = fscanf(fp, "%s %s", &str1, &str2); if (strcmp(str1, "Mesh") == 0) { printf("mesh OK\n"); meshFlag = true; break; }; if (tmp_eof == EOF) break; if (feof(fp)) break; }; //vertex 頂点の総数 読み込み if (meshFlag) { fgets(buf1, 256, fp);//一行進める tmp_eof = fscanf(fp, "%d;", &vertexNum); printf("vertexNum is %d \n", vertexNum); if (vertexNum > 0) vertexNumFlag = true; }; TVertex tmpV1; //vertex 頂点 配列 読み込み if (vertexNumFlag) { for (int i=0; i < vertexNum; i++) { fgets(buf1, 256, fp); tmp_eof = fscanf(fp, "%f,%f,%f;", &tmpV1.x,&tmpV1.y,&tmpV1.z); v1.push_back(tmpV1); if (tmp_eof == EOF) break; if (feof(fp)) break; } if (v1.size() > 0) {vertexDataFlag = true;printf("vertex data readed\n");}; } //頂点データ 表示 if (vertexDataFlag) { for(auto itr = v1.begin(); itr != v1.end(); ++itr) { cout << itr->x << "," << itr->y << "," << itr->z << "\n"; } } //インデックスの総数を得る if (vertexDataFlag) { //2行進める fgets(buf1, 256, fp); fgets(buf1, 256, fp); //インデックスの総数 読み込み tmp_eof = fscanf(fp, "%d;", &indexNum); if (tmp_eof == EOF) printf("eof indexNum"); printf("indexNum is %d \n", indexNum); if (indexNum > 0) indexNumFlag = true; } //fgets(buf1, 256, fp);//1行進める //インデックス配列データを得る if (indexNumFlag) { for (int i=0; i < indexNum; i++) { fgets(buf1, 256, fp);//1行進める tmp_eof = fscanf(fp, "%d;%d,%d,%d,%d;", &plateSize,&ixp1,&ixp2,&ixp3,&ixp4); printf("plate size is %d\n", plateSize); tmp_eof = fscanf(fp, "%d;%d,%d,%d,%d;", &plateSize,&ixp1,&ixp2,&ixp3,&ixp4); if (plateSize == 4) { printf("ixp1 is %d\n", ixp1); ix1.push_back(ixp1); printf("ixp2 is %d\n", ixp2); ix1.push_back(ixp2); printf("ixp3 is %d\n", ixp3); ix1.push_back(ixp3); printf("ixp4 is %d\n", ixp4); ix1.push_back(ixp4); } if (plateSize == 3) { ix1.push_back(ixp1); ix1.push_back(ixp2); ix1.push_back(ixp3); } if (tmp_eof == EOF) break; if (feof(fp)) break; } if (ix1.size() > 0) {indexDataFlag = true; printf("index data readed\n");}; } //インデックスデータ 表示 if (indexDataFlag) { for(auto itr = ix1.begin(); itr != ix1.end(); ++itr) { cout << *itr << "\n"; } } fclose(fp); };
aa1.x
blenderで作成
xof 0302txt 0032 # Created by DodgeeSoftware's DirectX Model Exporter # Website: www.dodgeesoftware.com # Email: dodgeesoftware@gmail.com template Header { <3D82AB43-62DA-11cf-AB39-0020AF71E433> WORD major; WORD minor; DWORD flags; } template Vector { <3D82AB5E-62DA-11cf-AB39-0020AF71E433> FLOAT x; FLOAT y; FLOAT z; } template Coords2d { <F6F23F44-7686-11cf-8F52-0040333594A3> FLOAT u; FLOAT v; } template Matrix4x4 { <F6F23F45-7686-11cf-8F52-0040333594A3> array FLOAT matrix[16]; } template ColorRGBA { <35FF44E0-6C7C-11cf-8F52-0040333594A3> FLOAT red; FLOAT green; FLOAT blue; FLOAT alpha; } template ColorRGB { <D3E16E81-7835-11cf-8F52-0040333594A3> FLOAT red; FLOAT green; FLOAT blue; } template TextureFilename { <A42790E1-7810-11cf-8F52-0040333594A3> STRING filename; } template Material { <3D82AB4D-62DA-11cf-AB39-0020AF71E433> ColorRGBA faceColor; FLOAT power; ColorRGB specularColor; ColorRGB emissiveColor; [...] } template MeshFace { <3D82AB5F-62DA-11cf-AB39-0020AF71E433> DWORD nFaceVertexIndices; array DWORD faceVertexIndices[nFaceVertexIndices]; } template MeshTextureCoords { <F6F23F40-7686-11cf-8F52-0040333594A3> DWORD nTextureCoords; array Coords2d textureCoords[nTextureCoords]; } template MeshMaterialList { <F6F23F42-7686-11cf-8F52-0040333594A3> DWORD nMaterials; DWORD nFaceIndexes; array DWORD faceIndexes[nFaceIndexes]; [Material] } template MeshNormals { <F6F23F43-7686-11cf-8F52-0040333594A3> DWORD nNormals; array Vector normals[nNormals]; DWORD nFaceNormals; array MeshFace faceNormals[nFaceNormals]; } template Mesh { <3D82AB44-62DA-11cf-AB39-0020AF71E433> DWORD nVertices; array Vector vertices[nVertices]; DWORD nFaces; array MeshFace faces[nFaces]; [...] } template FrameTransformMatrix { <F6F23F41-7686-11cf-8F52-0040333594A3> Matrix4x4 frameMatrix; } template Frame { <3D82AB46-62DA-11cf-AB39-0020AF71E433> [...] } template FloatKeys { <10DD46A9-775B-11cf-8F52-0040333594A3> DWORD nValues; array FLOAT values[nValues]; } template TimedFloatKeys { <F406B180-7B3B-11cf-8F52-0040333594A3> DWORD time; FloatKeys tfkeys; } template AnimationKey { <10DD46A8-775B-11cf-8F52-0040333594A3> DWORD keyType; DWORD nKeys; array TimedFloatKeys keys[nKeys]; } template AnimationOptions { <E2BF56C0-840F-11cf-8F52-0040333594A3> DWORD openclosed; DWORD positionquality; } template Animation { <3D82AB4F-62DA-11cf-AB39-0020AF71E433> [...] } template AnimationSet { <3D82AB50-62DA-11cf-AB39-0020AF71E433> [Animation] } template XSkinMeshHeader { <3cf169ce-ff7c-44ab-93c0-f78f62d172e2> WORD nMaxSkinWeightsPerVertex; WORD nMaxSkinWeightsPerFace; WORD nBones; } template VertexDuplicationIndices { <b8d65549-d7c9-4995-89cf-53a9a8b031e3> DWORD nIndices; DWORD nOriginalVertices; array DWORD indices[nIndices]; } template SkinWeights { <6f0d123b-bad2-4167-a0d0-80224f25fabb> STRING transformNodeName; DWORD nWeights; array DWORD vertexIndices[nWeights]; array FLOAT weights[nWeights]; Matrix4x4 matrixOffset; } # Cube Frame { FrameTransformMatrix { 1.000000,0.000000,0.000000,0.000000, 0.000000,1.000000,0.000000,0.000000, 0.000000,0.000000,1.000000,0.000000, 0.000000,0.000000,0.000000,1.000000;; } Mesh Cube { 24; 1.000000;1.000000;1.0000008;, -1.000000;1.000000;1.0000008;, -1.000000;1.000000;-1.0000008;, 1.000000;1.000000;-1.0000008;, 1.000000;-1.000000;-1.0000008;, 1.000000;1.000000;-1.0000008;, -1.000000;1.000000;-1.0000008;, -1.000000;-1.000000;-1.0000008;, -1.000000;-1.000000;-1.0000008;, -1.000000;1.000000;-1.0000008;, -1.000000;1.000000;1.0000008;, -1.000000;-1.000000;1.0000008;, -1.000000;-1.000000;1.0000008;, 1.000000;-1.000000;1.0000008;, 1.000000;-1.000000;-1.0000008;, -1.000000;-1.000000;-1.0000008;, 1.000000;-1.000000;1.0000008;, 1.000000;1.000000;1.0000008;, 1.000000;1.000000;-1.0000008;, 1.000000;-1.000000;-1.0000008;, -1.000000;-1.000000;1.0000008;, -1.000000;1.000000;1.0000008;, 1.000000;1.000000;1.0000008;, 1.000000;-1.000000;1.0000008;; 6; 4;3,2,1,0;, 4;7,6,5,4;, 4;11,10,9,8;, 4;15,14,13,12;, 4;19,18,17,16;, 4;23,22,21,20;; MeshNormals { 24; 0.000000;1.000000;-0.000000;, 0.000000;1.000000;-0.000000;, 0.000000;1.000000;-0.000000;, 0.000000;1.000000;-0.000000;, 0.000000;0.000000;-1.000000;, 0.000000;0.000000;-1.000000;, 0.000000;0.000000;-1.000000;, 0.000000;0.000000;-1.000000;, -1.000000;0.000000;-0.000000;, -1.000000;0.000000;-0.000000;, -1.000000;0.000000;-0.000000;, -1.000000;0.000000;-0.000000;, 0.000000;-1.000000;0.000000;, 0.000000;-1.000000;0.000000;, 0.000000;-1.000000;0.000000;, 0.000000;-1.000000;0.000000;, 1.000000;0.000000;-0.000000;, 1.000000;0.000000;-0.000000;, 1.000000;0.000000;-0.000000;, 1.000000;0.000000;-0.000000;, 0.000000;0.000000;1.000000;, 0.000000;0.000000;1.000000;, 0.000000;0.000000;1.000000;, 0.000000;0.000000;1.000000;; 6; 4;3,2,1,0;, 4;7,6,5,4;, 4;11,10,9,8;, 4;15,14,13,12;, 4;19,18,17,16;, 4;23,22,21,20;; } # UVMap MeshTextureCoords { 24; 0.625000;0.500000;, 0.875000;0.500000;, 0.875000;0.250000;, 0.625000;0.250000;, 0.375000;0.250000;, 0.625000;0.250000;, 0.625000;0.000000;, 0.375000;0.000000;, 0.375000;1.000000;, 0.625000;1.000000;, 0.625000;0.750000;, 0.375000;0.750000;, 0.125000;0.500000;, 0.375000;0.500000;, 0.375000;0.250000;, 0.125000;0.250000;, 0.375000;0.500000;, 0.625000;0.500000;, 0.625000;0.250000;, 0.375000;0.250000;, 0.375000;0.750000;, 0.625000;0.750000;, 0.625000;0.500000;, 0.375000;0.500000;; } MeshMaterialList { 1; 6; 0, 0, 0, 0, 0, 0; Material Material { # Exporter deliberately and only supports the Specular Material Node in the Shader Graph 1.000000;1.000000;1.000000;1.000000;; 200.000000; 1.000000;1.000000;1.000000;; 0.000000;0.000000;0.000000;; } } } }
コメントをかく