TGALoader 正在加载垂直轴上镜像的图像

TGALoader is loading image mirrored in vertical axis

本文关键字:镜像 图像 垂直 加载 TGALoader      更新时间:2023-09-26

使用 Targa 图像作为纹理加载带有 .mtl 材质的 .obj 模型,图像将镜像加载。在下图中可以注意到,左边是.tga的,右边是.png的。

在图像编辑器中打开两个图像,它们显示为相同。而且,只要正确加载了.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;
    } 

如果切换的结果0x02,则加载映像将进行校正,而不会进行镜像。我用不同的.tga图像进行了测试,所有这些图像都产生了相同的镜像。

我不太明白开关的参数是什么意思...你们能帮我弄清楚吗,我该如何解决我的问题?

您的纹理被翻转。使用此模式:

var loader = new THREE.TGALoader();
var texture = loader.load( 'myTexture.tga' );
texture.flipY = true;

三.js R.74