首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反转ThreeJS纹理

反转ThreeJS纹理
EN

Stack Overflow用户
提问于 2014-09-18 17:34:46
回答 3查看 1.8K关注 0票数 2

我对threejs是个新手,只是做了一个基本的立方体,背面有一个纹理。我在纹理的颜色方面有文字。然而,这些话出来的时候就像是镜子一样。我怎样才能让它们正确地出来。

EN

回答 3

Stack Overflow用户

发布于 2015-10-08 00:17:44

可以负向缩放立方体以撤消镜像效果,如下所示:

代码语言:javascript
复制
cube.scale.x = -1;
票数 2
EN

Stack Overflow用户

发布于 2014-09-18 20:54:50

您可以做两件事:

  1. 在立方体的每个面上反转或旋转UV坐标,直到获得所需的结果。这很容易,因为立方体的UV坐标通常是0.0和1.0。
  2. 使用图像包来旋转纹理。
票数 0
EN

Stack Overflow用户

发布于 2015-10-25 02:15:51

我想我有和你一样的问题,关于纹理一个立方体。

据我所知,除了背面之外,所有的表面都是正确的方向。我解决这个问题的方法是将纹理放置在每个面的立方体上,然后更改背面的UV贴图。

这解决了背面方向不正确的问题,并且由于UV映射的结果,我现在可以将纹理放置在不规则的面上,如金字塔等。

这是通过更改背面的UV来解决问题的方法。只需替换加载的纹理与本地纹理剪切和粘贴到记事本,并保存为html文件和您的good to go。

代码语言:javascript
复制
 <html> 
 <head>

</head> <body> <script src="js/three.min.js"></script> <script> var
scene, camera, renderer; var geometry, material; var modarray=[];
var material=[]; var rotation=0; init(); animate(); function init() 
{


    renderer = new THREE.WebGLRenderer();
    //renderer.setPixelRatio(window.devicePixelRatio);
        renderer.setSize( window.innerWidth, 100 );
        document.body.appendChild( renderer.domElement );

    ///////////     // Camera//     ///////////
        camera = new THREE.OrthographicCamera( window.innerWidth / - 2, 

window.innerWidth / 2, 100 / 2, 100 / - 2, - 500, 1000 );
        camera.position.z = 2000;   camera.position.y = 0;  camera.position.x = 0;  scene= new THREE.Scene();
        geometry = new THREE.BoxGeometry( 50, 50, 50 );     geometry2 = new THREE.BoxGeometry( 50, 50, 50 );

    ///////////////////////////////     // Store Materials for blocks//
    /////////////////////////////// var bricks;         material[0] = new
THREE.MeshPhongMaterial( { map: 

THREE.ImageUtils.loadTexture('10.png') } );

var basex=-455; //////////////////////////////////////////////////
// Vector array to hold where UV will be placed //
////////////////////////////////////////////////// bricks = [new
THREE.Vector2(1, 0), new THREE.Vector2(1, 1), new 

THREE.Vector2(0, 1), new THREE.Vector3(0, 0)];

///////////////////////////////////////////////////// // choose what
face this eccects from vertex array //  // in this case backside    
// // choose the orientation of the triangles         //
/////////////////////////////////////////////////////
geometry.faceVertexUvs[0][10] = [ bricks[0], bricks[1], bricks[3]];
geometry.faceVertexUvs[0][11] = [ bricks[1], bricks[2], bricks[3]];


        modarray[0] = new THREE.Mesh( geometry, material[0]);   modarray[1] = new THREE.Mesh( geometry2, material[0]);

    modarray[0].position.x=basex;   modarray[0].position.z=1000;
    modarray[0].position.y=0;
        scene.add(modarray[0]);

    modarray[1].position.x=basex+65;    modarray[1].position.z=1000;
    modarray[1].position.y=0;
        scene.add(modarray[0]);     scene.add(modarray[1]);

    //////////  // LIGHT//  //////////  var light2 = new
THREE.AmbientLight(0xffffff);   light2.position.set(0,100,2000);
    scene.add(light2);


}


//////////////////// // Animation Loop // ///////////////////
function animate()  {

        requestAnimationFrame( animate ); var flag=0;

    for(n=0; n<2; n++)  {

            modarray[n].rotation.x=rotation;

    }       rotation+=0.03;

    renderer.render( scene, camera );


}

</script> <p>The cube on the left is with UV mapping to correct the
back surface.

The cube on the right is without the UV mapping.</p> </body>

</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25909107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档