将纹理设置为md2模型java / android

时间:2012-08-06 16:20:09

标签: java android loading textures setting

我需要帮助将纹理设置为java / android

中的.MD2模型

根据维基百科,我想出了以下内容:(MD2(file_format))

加载texCoords:

int idx = 0;
for(int i = 0; i < this.pHeader.num_st; i++) //num_st = Number of texture coordinates
{
    this.fTexCoords[i][0] =  (float)is.readShort(); //S
    this.fTexCoords[i][1] =  (float)is.readShort(); //T
}

并计算它们:

int idx2 = 0;
int idx = 0;
for(int i = 0; i < this.pHeader.num_tris; i++) //num_tris = Number of triangles
{
    this.fIndices[idx+0] = is.readUnsignedShort();
    this.fIndices[idx+1] = is.readUnsignedShort();
    this.fIndices[idx+2] = is.readUnsignedShort();

    int uvID0 = is.readUnsignedShort();
    int uvID1 = is.readUnsignedShort();
    int uvID2 = is.readUnsignedShort();

    this.fTEXTURE[idx2+0] = (float)(this.fTexCoords[uvID0][0] / (float)this.pHeader.skinwidth); //s
    this.fTEXTURE[idx2+1] = (float)(this.fTexCoords[uvID0][1] / (float)this.pHeader.skinheight); //t
    this.fTEXTURE[idx2+2] = (float)(this.fTexCoords[uvID1][0] / (float)this.pHeader.skinwidth); //s
    this.fTEXTURE[idx2+3] = (float)(this.fTexCoords[uvID1][1] / (float)this.pHeader.skinheight); //t
    this.fTEXTURE[idx2+4] = (float)(this.fTexCoords[uvID2][0] / (float)this.pHeader.skinwidth); //s
    this.fTEXTURE[idx2+5] = (float)(this.fTexCoords[uvID2][1] / (float)this.pHeader.skinheight); //t

    idx += 3;
    idx2 += 6;
}

将所有内容转换为缓冲区并绘制它:

gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, this.TextureBuffer);
gl.glNormalPointer(GL10.GL_FLOAT, 0, this.NormalBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.VertexBuffer); 

gl.glDrawElements(GL10.GL_TRIANGLES, (this.max_indices*3), GL10.GL_UNSIGNED_SHORT, this.IndexBuffer);

这是结果(模型渲染得很好,有动画等,但颜色/纹理搞砸了 - 它应该只为脚着色)

它的外观(搅拌机):http://img6.imagebanana.com/img/rh6l4awq/blender.png以及它在手机上的实际外观:http://img6.imagebanana.com/img/wud654s9/SC20120806172956.png

我将blender纹理文件保存为png(查看 - &gt;打包为PNG - &gt;另存为)

感谢您的帮助

0 个答案:

没有答案