的法線我試圖根據this documentation實現.3DS進口商和我走近階段,當我需要計算頂點的法線,因爲.3DS文件不提供這些服務。這裏是Java代碼:計算.3DS模型
/* Sctructure of vertex array is {x0, y0, z0, x1, y1, z1...}
*
* Basically, MathUtils.generateNormal_f(x0,y0,z0, x1,y1,z1, x2,y2,z2) is cross
* product between (x1-x0, y1-y0, z1-z0) and (x2-x0, y2-y0, z2-z0) */
normals = new float[this.vertex.length]; //every vertex has it's own normal
int n = 0;
for (int i=0; i<this.index.length; i++){
float[] Normal = MathUtils.generateNormal_f(//getting xyz coords of 1 normal
vertex[index[i]*3], vertex[index[i]*3+1], vertex[index[i]*3+2],
vertex[index[++i]*3], vertex[index[i]*3+1], vertex[index[i]*3+2],
vertex[index[++i]*3], vertex[index[i]*3+1], vertex[index[i]*3+2]);
normals[n++] = Normal[0];
normals[n++] = Normal[1];
normals[n++] = Normal[2];
}
方法MathUtils.generateNormal_f(...)
測試和工作正常。此代碼的結果可以在下面看到(第一張圖片)。舉例來說,在第二張圖片中,模型的每個法線都是相同的,並指向光源。
的問題是:如何正確計算法線?
3ds確實沒有法線,整個應用程序是圍繞平滑組計算法線的想法而構建的。其中工作正常,你點給用戶任何其他選項。 – joojaa
1.否,法線不倒置。他們隨便指點。 2. 3ds格式根本不支持法線。 3.不明白你在說什麼巫師和法師:) – TomatoMato