Alternativa 7.7 조명/파서 연습

[이 글은 이전에 쓰던 블로그에서 작성된 이후 새 블로그로 이전된 글입니다.]

방향키 + 드래그

코드
package  {
    import flash.display.MovieClip;
    import flash.events.Event;

    import alternativa.engine3d.containers.ConflictContainer;
    import alternativa.engine3d.core.Camera3D;
    import alternativa.engine3d.core.View;
    import alternativa.engine3d.loaders.ParserCollada;
    import alternativa.engine3d.objects.Mesh;
    import alternativa.engine3d.lights.DirectionalLight;
    import alternativa.engine3d.controllers.SimpleObjectController;
    import alternativa.engine3d.materials.FlatShadingMaterial;

    public class ParserPractice extends MovieClip {

        [Embed("something.dae", mimeType="application/octet-stream")] static private const SomethingModel:Class;

        private var world:ConflictContainer;
        private var camera:Camera3D;
        private var something:Mesh;
        private var light:DirectionalLight;
        private var soc:SimpleObjectController;

        public function ParserPractice() {
            world = new ConflictContainer();

            camera = world.addChild(new Camera3D()) as Camera3D;
            camera.view = addChild(new View(stage.stageWidth, stage.stageHeight)) as View;

            camera.z = -10;

            var somethingParser:ParserCollada = new ParserCollada();
            somethingParser.parse(XML(new SomethingModel()));

            something = world.addChild(somethingParser.objects[0]) as Mesh;

            var somethingMaterial:FlatShadingMaterial = new FlatShadingMaterial();
            something.setMaterialToAllFaces(somethingMaterial);

            light = world.addChild(new DirectionalLight(0xFFFF00)) as DirectionalLight;

            soc = new SimpleObjectController(stage, camera, 10);
            camera.lookAt(something.x, something.y, something.z);

            this.addEventListener(Event.ENTER_FRAME, update);
        }

        private function update(e:Event):void{
            something.rotationY += 0.03;
            something.rotationZ += 0.03;
            soc.update();
            light.x = camera.x;
            light.y = camera.y;
            light.z = camera.z;
            light.lookAt(something.x, something.y, something.z);
            camera.render();
        }
    }
}

댓글 남기기