开发者

How to load textures to different faces of a cube in GLGE? (or at least WebGL)

I have 6 textures I would like to load on 6 different faces of a cube. I'm trying to make a new texture by using GLGE.TextureCube();. And then I load all six images to the faces the supposedly should be on the cube like so

    开发者_运维技巧mapTex = new GLGE.TextureCube();
    mapTex.setSrcNegX("models/map/negx.jpg"); // they are all 1024x1024
    mapTex.setSrcNegY("models/map/negy.jpg");
    mapTex.setSrcNegZ("models/map/negz.jpg");
    mapTex.setSrcPosX("models/map/posx.jpg");
    mapTex.setSrcPosY("models/map/posy.jpg");
    mapTex.setSrcPosZ("models/map/posz.jpg");

And then I add the texture to the Wavefront object. However, it seems only one of the 6 texture images is getting mapped and its mapped incorrectly.

My guess is that when it creates the new texture map out of the other 6, it tiles them beside each other so the new texture map's co-ordinates no longer correspond to that my obj file.

How can I properly combine 6 textures to one map to be used with GLGE? Or is there a way to manually load a texture on a face of a Mesh?


Cube maps are somewhat special, as the usual UV (ST) texture coordinates don't work for them. A cube map, the name suggests it, consists of 6 quadratic textures, arranged as the faces of a cube. The texture coordinates are not absolute positions on the cube's faces, but directions from the center of the cube away, and the position where a ray from the center in the given direction hits the cube, is the position of the texture on that particular face.

If you apply texture coordinates with the third coordinate being zero, like those in Wavefront, you will address only a slice of the cube's face, namely the part that intersects with the XY plane. If you want to see a working cubemap in action, use the object's smooth normals as texture coordinates.


You'll need to use a different texture coordinate, eg: materialLayer.setMapinput(GLGE.MAP_OBJ) depending on what you want try GLGE.MAP_OBJ,GLGE.MAP_NORM or GLGE.MAP_ENV

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜