三个js定义几何轴 [英] Three js define axis of the geomatry

查看:30
本文介绍了三个js定义几何轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个盒子几何体,

我想定义几何体的前面在哪里,设置一个框:

I want to define where is the front of my geometry, setting a box:

var materialArray = [];
    materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'test/Three.js/images/xpos.png' ) }));
    materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'test/Three.js/images/xneg.png' ) }));
    materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'test/Three.js/images/ypos.png' ) }));
    materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'test/Three.js/images/yneg.png' ) }));
    materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'test/Three.js/images/zpos.png' ) }));
    materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'test/Three.js/images/zneg.png' ) }));
    var MovingCubeMat = new THREE.MeshFaceMaterial(materialArray);
    var MovingCubeGeom = new THREE.BoxGeometry( 100*meter, 50*meter, 300*meter, 1, 1, 1, materialArray );
    myMesh = new THREE.Mesh( MovingCubeGeom, MovingCubeMat );       
    scene.add( myMesh );    

当我使用 myMesh.lookAt(myTarget) 瞄准目标时,带有纹理zneg.png"(应该是物体的正面)的一侧在背面,物体是定向的通过zpos.png"面向目标的一面.

When i use myMesh.lookAt(myTarget) for aiming a target, side with texture "zneg.png" (which should be a front of object) is on the back side, object is oriented by "zpos.png" side facing to the target.

如何定义对象的正面和底部,或顶部和背面,以便简单地使用旋转?

How can i define front and bottom, or top and back side of my object, for simple using rotations?

谢谢.

推荐答案

当一个对象处于其默认方向时,它被认为是在看其内部的正 z 轴的方向.(相机是个例外,它正朝着其内部负 z 轴的方向看.)

When an object is in its default orientation, it is considered to be looking in the direction of its internal, positive z-axis. (The exception is the camera, which is looking in the direction of its internal negative z-axis.)

当你调用 object.lookAt( target ) 时,对象被旋转,所以它的内部 z 轴指向目标的方向.

When you call object.lookAt( target ), the the object is rotated so its internal z-axis points in the direction of the target.

如果您希望几何体的另一侧面向内部正 z 轴,请在创建几何体后立即对其应用变换.

If you want a different side of your geometry to face the internal positive z-axis, apply a transform to your geometry right after you create it.

geometry.applyMatrix( new THREE.Matrix4().makeRotation( 0, Math.PI, 0 ) );

您还可以使用其中一种内置方法.例如,

You can also use one of the built-in methods. For example,

geometry.rotateY( Math.PI );

three.js r.100

three.js r.100

这篇关于三个js定义几何轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆