0
使用Targa圖像作爲紋理加載.mtl材質的.obj模型,圖像被加載鏡像。 在以下的image中可以注意到,左邊的是.tga,右邊的是.png。TGALoader正在加載鏡像在垂直軸上的圖像
在圖像編輯器中打開兩個圖像,它們顯示的是相同的。而且,只要.png圖像正確加載,問題出在我用於.tga的加載程序中。
我正在使用TGALoader類來加載紋理。這個問題似乎是從TGALoader.js與從功能getTgaRGBA以下代碼:
TGA_ORIGIN_MASK = 0x30,
TGA_ORIGIN_SHIFT = 0x04,
TGA_ORIGIN_BL = 0x00,
TGA_ORIGIN_BR = 0x01,
TGA_ORIGIN_UL = 0x02,
TGA_ORIGIN_UR = 0x03;
function getTgaRGBA(width, height, image, palette) {
var x_start,
y_start,
x_step,
y_step,
x_end,
y_end,
data = new Uint8Array(width * height * 4);
//switch (0x02) {
switch ((header.flags & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT ) {
default:
case TGA_ORIGIN_UL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = height - 1;
y_step = - 1;
y_end = - 1;
break;
case TGA_ORIGIN_UR:
x_start = width - 1;
x_step = - 1;
x_end = - 1;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BR:
x_start = width - 1;
x_step = - 1;
x_end = - 1;
y_start = height - 1;
y_step = - 1;
y_end = - 1;
break;
}
如果從開關結果爲0×02時,圖像會被加載修正,而不被鏡像。我已經測試過不同的.tga圖像,並且它們都導致了相同的鏡像。
我不明白開關的參數意味着什麼......你們能幫我弄清楚,我怎麼能解決我的問題?
啊,但是怎麼來的巴紐版本正確加載,並且.TGA是不是?我認爲這是TGALoader中的一個問題。有沒有一種方法可以自動檢查圖像是否翻轉?爲什麼我在使用之前總是糾正它? –
由於.tga文件被視爲「THREE.DataTexture」,默認情況下不會翻轉Y.研究源代碼,或者用調試器逐步完成。 – WestLangley
在r.76dev的'TGALoader'中修正了一個bug。設置'flipY'應該不再是必要的。 – WestLangley