赞
踩
创建3D场景
- export default class Test extends Laya.Script {
- constructor() {
- super();
-
- //搭建场景
- var scene3d = new Laya.Scene3D();
- Laya.stage.addChild(scene3d);
- //创建相机
- var camera = new Laya.Camera(0,0.3,100);
- camera.fieldOfView = 60;
- camera.clearColor = new Laya.Vector4(0,0,0,1);
- scene3d.addChild(camera);
- camera.transform.translate(new Laya.Vector3(0,1,0));
- camera.cullingMask = 1<<2;//层级
- //camera.removeAllLayers();
- //camera.addLayer(1);
- //camera.cullingMask = (1<<1)|(1<<2);
- //物体
- //几何网格/网格图元
- var cube = new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1,1,1));
- scene3d.addChild(cube);
- //位置
- cube.transform.translate(new Laya.Vector3(0,0,-10));
- //层级
- cube.layer = 2;
- //材质
- var m = new Laya.UnlitMaterial();
- //贴图
- Laya.Texture2D.load("res/background.png",Laya.Handler.create(this,function(tex){
- m.albedoTexture = tex;
- }));
- //绘制
- cube.meshRenderer.material = m;
- }
- }
transform
- export default class Test extends Laya.Script {
- constructor() {
- super();
-
- //搭建场景
- var scene3d = new Laya.Scene3D();
- Laya.stage.addChild(scene3d);
- //创建相机
- var camera = new Laya.Camera(0,0.3,100);
- camera.fieldOfView = 60;
- camera.clearColor = new Laya.Vector4(0,0,0,1);
- scene3d.addChild(camera);
- camera.transform.translate(new Laya.Vector3(0,1,0));
- camera.cullingMask = 1<<2;//层级
- //camera.removeAllLayers();
- //camera.addLayer(1);
- //camera.cullingMask = (1<<1)|(1<<2);
- //物体
- //几何网格/网格图元
- var cube = new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1,1,1));
- scene3d.addChild(cube);
- //位置
- cube.transform.translate(new Laya.Vector3(0,0,-10));
- //层级
- cube.layer = 2;
- //材质
- var m = new Laya.UnlitMaterial();
- //贴图
- Laya.Texture2D.load("res/background.png",Laya.Handler.create(this,function(tex){
- m.albedoTexture = tex;
- }));
- //绘制
- cube.meshRenderer.material = m;
-
-
- console.log(cube.transform.localPosition);
- console.log(cube.transform.position);
-
- this.cube = cube;
- }
- cube = null;
-
- onUpdate(){
- //平移
- /*
- var pos = this.cube.transform.position;
- pos.z -= 5 * Laya.timer.delta/1000;
- this.cube.transform.position = pos;
- */
- /*
- var offset = new Laya.Vector3(0,0,-5 * Laya.timer.delta/1000);
- this.cube.transform.translate(offset,false);
- */
-
- //缩放
- /*
- var s = new Laya.Vector3(5,2,1);
- this.cube.transform.scale = s;
- */
-
- //旋转
- //欧拉
- //yaw-y,pitch-x,roll-z
- //this.cube.transform.rotationEuler = new Laya.Vector3(15,0,0);
- //四元数
- /*
- var rot = new Laya.Quaternion();
- Laya.Quaternion.createFromYawPitchRoll(0,15,0,rot);
- this.cube.transform.rotation = rot;
- */
- //持续
- //this.cube.transform.rotate(new Laya.Vector3(0,30 * Laya.timer.delta/1000,0),false,false);
-
- //转动后移动
- /*
- this.cube.transform.rotationEuler = new Laya.Vector3(15,0,0);
- var forward = new Laya.Vector3(0,0,0);
- this.cube.transform.getForward(forward);
- var s = 5 * Laya.timer.delta/1000;
- var offset = new Laya.Vector3(s*forward.x,s*forward.y,s*forward.z);
- this.cube.transform.translate(offset,true);
- */
-
- //朝向
- //this.cube.transform.lookAt(new Laya.Vector3(0,-10,-20),new Laya.Vector3(0,1,0));
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。