直接上**:
using system;
using system.collections.generic;
using system.linq;
using system.text;
namespace importfbx
}
private vector3 vertices;
public vector3 vertices
}private int vertexindex;
public int vertexindex
}private vector3 normal;
public vector3 normal
}private vector2 uv;
public vector2 uv
}public void openfbxfile(string path)
, 2, stringsplitoptions.removeemptyentries);
string a = objectstr[1].split(new string , 2 ,stringsplitoptions.removeemptyentries);
unityengine.debug.log(a[1]);
string aa = a[1].split(new string , 2, stringsplitoptions.removeemptyentries);
string aaa = aa[1].split(new char ' }, 2, stringsplitoptions.removeemptyentries);
string verticesstr = aaa[0].split(new char );
unityengine.debug.log(verticesstr.length);
stringb = objectstr[1].split(new string , 2, stringsplitoptions.removeemptyentries);
stringbb = b[1].split(new string , 2, stringsplitoptions.removeemptyentries);
stringbbb = bb[1].split(new char ' }, 2, stringsplitoptions.removeemptyentries);
string vertexidstr = bbb[0].split(new char );
unityengine.debug.log(vertexidstr.length);
stringc = objectstr[1].split(new string , 2, stringsplitoptions.removeemptyentries);
stringcc = c[1].split(new string , 2, stringsplitoptions.removeemptyentries);
stringccc = cc[1].split(new char ' }, 2, stringsplitoptions.removeemptyentries);
string normalstr = ccc[0].split(new char );
unityengine.debug.log(normalstr.length);
string d = objectstr[1].split(new string , 2, stringsplitoptions.removeemptyentries);
string dd = d[1].split(new string , 2, stringsplitoptions.removeemptyentries);
string ddd = dd[1].split(new char ' }, 2, stringsplitoptions.removeemptyentries);
string uvstr = ddd[0].split(new char );
unityengine.debug.log(uvstr.length);
string e = objectstr[1].split(new string , 2, stringsplitoptions.removeemptyentries);
string ee = e[1].split(new string , 2, stringsplitoptions.removeemptyentries);
string eee = ee[1].split(new char ' }, 2, stringsplitoptions.removeemptyentries);
string uvindexstr = eee[0].split(new char );
unityengine.debug.log(uvindexstr.length);
vertices = new vector3[verticesstr.length/3];
for (int i = 0; i < verticesstr.length; i+=3)
int vertexindextemp = new int[vertexidstr.length];
int q = 0;
bool issquaremesh = false;
for (int i = 0; i < vertexidstr.length; i++)
else if (vertexindextemp[i] < 0 && q == 4)
}if (issquaremesh)
);********s.addrange(new int[3] );
}vertexindex = ********s.toarray();
}else
normal = new vector3[vertices.length];
vector3 normtemp = new vector3[normalstr.length / 3];
for (int i = 0; i < normalstr.length; i+=3)
for (int i = 0; i < vertices.length; i++)}}
uv = new vector2[vertices.length];
vector2 uvtemp = new vector2[uvstr.length / 2];//uv
vector2 uvindextemp = new vector2[uvindexstr.length];//all uv
for (int i = 0; i < uvstr.length; i += 2)
for (int i = 0; i < uvindexstr.length; i++)
for (int i = 0; i < vertices.length; i++)}}
}}
放在unity中執行:模型2是通過常規的匯入方式匯入場景中作為參考的模型。
模型1是執行時匯入的結果,也就是**執行的結果。
現在還有些問題為解決:
1.沒有獲取fbx中的transform,所以場景中的transform是錯誤的。
2.如果出現四邊面,uv的計算是錯誤的,********s的排序是錯誤的。
3.當前沒有考慮模型有子模型的情況。
使用SDK對FBX模型的載入與讀取
一.初始化fbx sdk fbxmanager pmanager null fbxscene pscene null pmanager fbxmanager create if pmanager fbxiosettings ios fbxiosettings create pmanager,iosr...
Ogre載入mesh檔案原理與路徑分析
建立模型實體 entity entobject mscenemgr createentity object ogrehead.mesh createentity 建立實體 在當前場景中建立乙個實體例項並返回它的物件指標,作為 scenemanager 類的乙個成員函式,它有兩個過載 entity o...
TLV格式解析與打包
tlv,簡單理解就是type,length,value。是一種結構化的資料。一般type為4個位元組的列舉,length為4個位元組,表示value的長度。value即為實際的值。tlv直接可以巢狀,比如大的tlv中的value又是乙個tlv。下面有個小例子幫助理解。include include ...