Laya 实操十五:导入模型与动画

导出模型与动画时注意:

将场景中不需要导出的物体隐藏。

将需要导出的物体设为一级节点。

导出时候节点设置勾选如下图。

带动画的物体需要加Animator控制器组件,并配置好Controller与Avatar。

Laya中创建导入的预设

export default class Test extends Laya.Script {
    constructor() { 
        super(); 
        //场景
        Laya.Scene3D.load("res/LayaScene_Scene_Test/Conventional/Scene_Test.ls",Laya.Handler.create(this,this.on_scene3d_loaded));
    }

    on_scene3d_loaded(scene3d){
        Laya.stage.addChild(scene3d);
        this.createPrefab(scene3d);
    }

    createPrefab(scene3d){
        Laya.Sprite3D.load("res/LayaScene_Scene_Person/Conventional/Golem.lh",Laya.Handler.create(this,function(prefab){
            scene3d.addChild(prefab);
            prefab.transform.position = new Laya.Vector3(0,0,5);
        }));
    }
}

 动画

export default class Test extends Laya.Script {
    constructor() { 
        super(); 
        //场景
        Laya.Scene3D.load("res/LayaScene_Scene_Test/Conventional/Scene_Test.ls",Laya.Handler.create(this,this.on_scene3d_loaded));
    }

    on_scene3d_loaded(scene3d){
        Laya.stage.addChild(scene3d);
        this.createPrefab(scene3d);
    }

    createPrefab(scene3d){
        Laya.Sprite3D.load("res/LayaScene_Scene_Person/Conventional/Golem.lh",Laya.Handler.create(this,function(prefab){
            scene3d.addChild(prefab);
            prefab.transform.position = new Laya.Vector3(0,0,5);

            var anim =  prefab.getComponent(Laya.Animator);
            Laya.AnimationClip.load("res/LayaScene_Scene_Person/Conventional/Assets/res/Fantasy Characters (Pack) Vol-Golem.lani",Laya.Handler.create(this,function(clip){
                var state = new Laya.AnimatorState();
                state.name = "aaa";
                state.clipStart = 0/197;
                state.clipEnd = 15/197;
                state.clip = clip;
                state.clip.islooping = true;
                anim.addState(state);
                anim.play("aaa");
            }));
        }));
    }
}

 


版权声明:本文为NCZ9_原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。