[LayaNative 2.0]修改position与修改localPosition结果不一致(同处于3d场景下的两个节点)
//添加自定义模型
var box: Laya.MeshSprite3D = scene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1, 1, 1))) as Laya.MeshSprite3D;
box.transform.rotate(new Laya.Vector3(0, 45, 0), false, false);
var material: Laya.BlinnPhongMaterial = new Laya.BlinnPhongMaterial();
Laya.Texture2D.load("res/layabox.png", Laya.Handler.create(null, function (tex: Laya.Texture2D) {
material.albedoTexture = tex;
}));
//测试遮挡剔除
material.cull = 0
box.meshRenderer.material = material;
let res1 = Laya.Sprite3D.instantiate(box);
let res2 = Laya.Sprite3D.instantiate(box);
scene.addChild(res1);
scene.addChild(res2);
Laya.timer.frameLoop(1, this, () => {
res1.transform.localPositionX += 0.016;
res2.transform.position.x += 0.016;
console.log("本地坐标1:", res1.transform.localPosition);
console.log("世界坐标1:", res1.transform.position);
console.log("本地坐标2:", res2.transform.localPosition);
console.log("世界坐标2:", res2.transform.position);
// camera.transform.position = new Laya.Vector3(res.transform.position.x, res.transform.position.y+10, res.transform.position.z);
camera.transform.lookAt(res1.transform.position, new Laya.Vector3(0, 1, 0));
})
本地坐标1: Vector3 {x: 8.752000000000006, y: 0, z: 0}
世界坐标1: Vector3 {x: 8.752000000000006, y: 0, z: 0}
本地坐标2: Vector3 {x: 0, y: 0, z: 0}
世界坐标2: Vector3 {x: 8.752000000000006, y: 0, z: 0}
var box: Laya.MeshSprite3D = scene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1, 1, 1))) as Laya.MeshSprite3D;
box.transform.rotate(new Laya.Vector3(0, 45, 0), false, false);
var material: Laya.BlinnPhongMaterial = new Laya.BlinnPhongMaterial();
Laya.Texture2D.load("res/layabox.png", Laya.Handler.create(null, function (tex: Laya.Texture2D) {
material.albedoTexture = tex;
}));
//测试遮挡剔除
material.cull = 0
box.meshRenderer.material = material;
let res1 = Laya.Sprite3D.instantiate(box);
let res2 = Laya.Sprite3D.instantiate(box);
scene.addChild(res1);
scene.addChild(res2);
Laya.timer.frameLoop(1, this, () => {
res1.transform.localPositionX += 0.016;
res2.transform.position.x += 0.016;
console.log("本地坐标1:", res1.transform.localPosition);
console.log("世界坐标1:", res1.transform.position);
console.log("本地坐标2:", res2.transform.localPosition);
console.log("世界坐标2:", res2.transform.position);
// camera.transform.position = new Laya.Vector3(res.transform.position.x, res.transform.position.y+10, res.transform.position.z);
camera.transform.lookAt(res1.transform.position, new Laya.Vector3(0, 1, 0));
})
本地坐标1: Vector3 {x: 8.752000000000006, y: 0, z: 0}
世界坐标1: Vector3 {x: 8.752000000000006, y: 0, z: 0}
本地坐标2: Vector3 {x: 0, y: 0, z: 0}
世界坐标2: Vector3 {x: 8.752000000000006, y: 0, z: 0}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Aar0n
赞同来自: