Babylonjs真的很酷!
初始视角问题
找了好久,不知道怎么设定初始的观测角度,感觉就是调整camera
的参数。仔细读了好几遍,原来就是通过。
https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction#arc-rotate-camera
const camera = new ArcRotateCamera(
'camera',
0,
Math.PI / 3,
20,
new Vector3(0, 0, 0)
);
//camera.setPosition(new Vector3(0, 20, 20));
alpha
设为0
,beta
设为Math.PI/3
,即180
度的1/3
,即60
度。注意!如果调用了setPosition
方法,将会覆盖原有的alpha
、beta
值。
坐标系问题
babylonjs的坐标系是左手系,即Z
轴是从屏幕外指向屏幕里。
GroundMesh
默认是XZ
平面,需要将GroundMesh
沿X
轴逆时针翻转90
度。
const ground = MeshBuilder.CreateGround('ground', {
width: 5,
height: 5,
});
ground.rotation.x = -Math.PI / 2;
光源问题
使用DirectionalLight
,光是从光源位置,即position
位置指向direction
位置。
const light = new DirectionalLight('dLight', new Vector3(0, 0, 10));
light.position = new Vector3(0, 0, -10);