看了warning的代码,是平行光那里的, 但是看API 没有transform 的属性,代码如下:
function LayaAir3D() {
//初始化微信小游戏
Laya.MiniAdpter.init();
//初始化引擎
Laya3D.init(0, 0, true);
//适配模式
Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;
//开启统计信息
Laya.Stat.show();
var scene = Laya.stage.addChild(new Laya.Scene());
var camera = scene.addChild(new Laya.Camera(0, 0.1, 1000));
camera.transform.translate(new Laya.Vector3(0, 1.5, 4));
camera.transform.rotate(new Laya.Vector3(-15, 0, 0), true, false);
camera.addComponent(CameraMoveScript);
//方向光
var directionLight = scene.addChild(new Laya.DirectionLight());
directionLight.color = new Laya.Vector3(0.7, 0.6, 0.6);
directionLight.direction = new Laya.Vector3(0, -1.0, -1.0);
//灯光开启阴影
directionLight.shadow = true;
//可见阴影距离
directionLight.shadowDistance = 3;
//生成阴影贴图尺寸
directionLight.shadowResolution = 2048;
//生成阴影贴图数量
directionLight.shadowPSSMCount = 1;
//模糊等级,越大越高,更耗性能
directionLight.shadowPCFType = 3;
Laya.loader.create([
"res/plane.lh",
"res/LayaMonkey.lh"
], Laya.Handler.create(this, onComplete));
var _quaternion = new Laya.Quaternion();
Laya.timer.frameLoop(1, null, function () {
Laya.Quaternion.createFromYawPitchRoll(0.025, 0, 0, _quaternion);
var _direction = directionLight.direction;
Laya.Vector3.transformQuat(_direction, _quaternion, _direction);
directionLight.direction = _direction;
});
function onComplete() {
var grid = scene.addChild(Laya.Sprite3D.load("res/plane.lh"));
//地面接收阴影
grid.getChildAt(0).meshRender.receiveShadow = true;
var layaMonkey = scene.addChild(Laya.Sprite3D.load("res/LayaMonkey.lh"));
//产生阴影
layaMonkey.getChildAt(0).getChildAt(0).skinnedMeshRender.castShadow = true;
layaMonkey.once(Laya.Event.HIERARCHY_LOADED, this, function () {
var aniSprite3d = layaMonkey.getChildAt(0);
var animator = aniSprite3d.getComponentByType(Laya.Animator);
animator.play(null, 1.0, 40, 70);
});
var monkeys = {};
var vx = -1.65;
var vz = -1.65;
for (var y = 0; y < 10; y++) {
for (var x = 0; x < 10; x++) {
monkeys['monkey_' + x] = Laya.Sprite3D.instantiate(layaMonkey, scene, false, new Laya.Vector3(vx, 0, vz));
vx += 0.3;
};
vz += 0.4;
vx = -1.65;
}
};
}