{"id":461,"date":"2011-10-21T19:45:50","date_gmt":"2011-10-21T18:45:50","guid":{"rendered":"http:\/\/www.aymericlamboley.fr\/blog\/?p=461"},"modified":"2011-10-21T19:56:27","modified_gmt":"2011-10-21T18:56:27","slug":"getting-started-with-away3d-for-fp11","status":"publish","type":"post","link":"http:\/\/www.aymericlamboley.fr\/blog\/getting-started-with-away3d-for-fp11\/","title":{"rendered":"Getting started with Away3D for FP11"},"content":{"rendered":"<p>It was about time to start working on 3D with flash. I was already looking at <a href=\"http:\/\/blog.papervision3d.org\/\" target=\"_blank\">Papervision3D<\/a> some years ago, but I have never worked with. Then I&#8217;ve followed differents 3D engine like <a href=\"http:\/\/www.flashsandy.org\/\" target=\"_blank\">Sandy<\/a>, <a href=\"http:\/\/five3d.mathieu-badimon.com\/\" target=\"_blank\">Five3D<\/a>, and <a href=\"http:\/\/away3d.com\" target=\"_blank\">Away3D<\/a>.<\/p>\n<p>Now that Stage3D and FP11 are out, it is time to start working with 3D in flash. However, it&#8217;s funny that my first try on a 3D Engine was made with a JS engine : <a href=\"https:\/\/github.com\/mrdoob\/three.js\/\" target=\"_blank\">Three.js<\/a><br \/>\nSo in this post I just adapt <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/quick-look-into-threejs\/\" target=\"_blank\">my previous 3D example made with Three.js and WebGL<\/a> and see how it runs with Away3D.<\/p>\n<p>Finally I have chosen Away3D instead of those 3D engine for FP11 : <a href=\"http:\/\/blog.aerys.in\/2011\/10\/07\/minko-released-as-open-source\/\" target=\"_blank\">minko<\/a>, <a href=\"http:\/\/alternativaplatform.com\" target=\"_blank\">alternativa<\/a>, <a href=\"http:\/\/www.flare3d.com\/\" target=\"_blank\">flare3D<\/a>, and <a href=\"http:\/\/labs.adobe.com\/technologies\/proscenium\/\" target=\"_blank\">adobe proscenium<\/a> because it is free and has a great community support.<\/p>\n<p><a href=\"http:\/\/www.aymericlamboley.fr\/blog\/wp-content\/uploads\/2011\/10\/Away3D\/index.html\" target=\"_blank\"><strong>The quick demo.<\/strong><\/a><\/p>\n<pre lang=\"actionscript3\" line=\"1\">package {\r\n\r\n\timport away3d.cameras.Camera3D;\r\n\timport away3d.containers.ObjectContainer3D;\r\n\timport away3d.containers.Scene3D;\r\n\timport away3d.containers.View3D;\r\n\timport away3d.debug.AwayStats;\r\n\timport away3d.lights.DirectionalLight;\r\n\timport away3d.materials.ColorMaterial;\r\n\timport away3d.materials.methods.FilteredShadowMapMethod;\r\n\timport away3d.primitives.Cube;\r\n\r\n\timport flash.display.Sprite;\r\n\timport flash.display.StageAlign;\r\n\timport flash.display.StageScaleMode;\r\n\timport flash.events.Event;\r\n\timport flash.geom.Vector3D;\r\n\r\n\t[SWF(backgroundColor=\"#FFFFFF\", frameRate=\"60\", width=\"1000\", height=\"650\")]\r\n\r\n\t\/**\r\n\t * @author Aymeric\r\n\t *\/\r\n\tpublic class Main extends Sprite {\r\n\r\n\t\tprivate const _ORIGINE:Vector3D = new Vector3D(0, 0, 0);\r\n\t\tprivate const _NBR_ELEMENTS:uint = 250;\r\n\t\t\r\n\t\tprivate var _camera:Camera3D;\r\n\t\tprivate var _scene:Scene3D;\r\n\t\tprivate var _view:View3D;\r\n\t\tprivate var _container:ObjectContainer3D;\r\n\r\n\t\tprivate var _tab:Vector.<Cube>;\r\n\r\n\t\tprivate var _formOneElement:Boolean;\r\n\r\n\t\tprivate var _diffX:int, _diffY:int, _diffZ:int;\r\n\r\n\t\tpublic function Main() {\r\n\r\n\t\t\tstage.scaleMode = StageScaleMode.NO_SCALE;\r\n\t\t\tstage.align = StageAlign.TOP_LEFT;\r\n\t\t\t\r\n\t\t\t_scene = new Scene3D();\r\n\t\t\t_camera = new Camera3D();\r\n\t\t\t_view = new View3D();\r\n\t\t\t_view.antiAlias = 2;\r\n\t\t\t_view.backgroundColor = 0xEEEEEE;\r\n\t\t\t_view.camera = _camera;\r\n\t\t\t_view.scene = _scene;\r\n\t\t\t\r\n\t\t\taddChild(_view);\r\n\t\t\taddChild(new AwayStats(_view, false));\r\n\t\t\t\r\n\t\t\t_container = new ObjectContainer3D();\r\n\t\t\t_scene.addChild(_container);\r\n\t\t\t\r\n\t\t\tvar light:DirectionalLight = new DirectionalLight(-1, -1, 1);\r\n\t\t\tlight.color = 0xFFFFFF;\r\n\t\t\tlight.castsShadows = true;\r\n\r\n\t\t\t_container.addChild(light);\r\n\t\t\tlight.x = -15000;\r\n\t\t\tlight.y = -15000;\r\n\t\t\tlight.z = -15000;\r\n\t\t\t\r\n\t\t\t_camera.lookAt(_container.position);\r\n\t\t\t\r\n\t\t\t_tab = new Vector.<Cube>();\r\n\r\n\t\t\tvar cube:Cube;\r\n\t\t\tvar colorMaterial:ColorMaterial;\r\n\t\t\tfor (var i:uint = 0; i < _NBR_ELEMENTS; ++i) {\r\n\t\t\t\t\r\n\t\t\t\tcolorMaterial = new ColorMaterial(Math.random() * 0xFFFFFF);\r\n\t\t\t\tcolorMaterial.lights = [light];\r\n\t\t\t\tcolorMaterial.shadowMethod = new FilteredShadowMapMethod(light);\r\n\t\t\t\t\r\n\t\t\t\tcube = new Cube(colorMaterial, 50, 50, 50);\r\n\t\t\t\t_container.addChild(cube);\r\n\r\n\t\t\t\tif (i == 0)\r\n\t\t\t\t\tcube.x = Math.random() * 1000;\r\n\t\t\t\telse\r\n\t\t\t\t\tcube.x = (Math.random() > 0.5) ? Math.random() * 1000 : -Math.random() * 1000;\r\n\t\t\t\tcube.y = (Math.random() > 0.5) ? Math.random() * 1000 : -Math.random() * 1000;\r\n\t\t\t\tcube.z = (Math.random() > 0.5) ? Math.random() * 1000 : -Math.random() * 1000;\r\n\r\n\t\t\t\t_tab.push(cube);\r\n\t\t\t}\r\n\r\n\t\t\t_formOneElement = false;\r\n\r\n\t\t\taddEventListener(Event.ENTER_FRAME, _ef);\r\n\t\t\tstage.addEventListener(Event.RESIZE, _resize);\r\n\t\t\t\r\n\t\t\t_resize();\r\n\t\t}\r\n\t\t\r\n\t\tprivate function _ef(evt:Event):void {\r\n\r\n\t\t\tif (!_formOneElement) {\r\n\r\n\t\t\t\tif (_tab[0].x < 1000) {\r\n\r\n\t\t\t\t\tfor each (var cube:Cube in _tab) {\r\n\r\n\t\t\t\t\t\t_diffX = 0 - cube.x;\r\n\t\t\t\t\t\t_diffY = 0 - cube.y;\r\n\t\t\t\t\t\t_diffZ = 0 - cube.z;\r\n\r\n\t\t\t\t\t\tcube.x -= _diffX * 0.05;\r\n\t\t\t\t\t\tcube.y -= _diffY * 0.05;\r\n\t\t\t\t\t\tcube.z -= _diffZ * 0.05;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t} else {\r\n\t\t\t\t\t_formOneElement = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t} else {\r\n\r\n\t\t\t\tif (_tab[0].x > 2) {\r\n\r\n\t\t\t\t\tfor each (var cubeOne:Cube in _tab) {\r\n\r\n\t\t\t\t\t\t_diffX = 0 - cubeOne.x;\r\n\t\t\t\t\t\t_diffY = 0 - cubeOne.y;\r\n\t\t\t\t\t\t_diffZ = 0 - cubeOne.z;\r\n\r\n\t\t\t\t\t\tcubeOne.x += _diffX * 0.05;\r\n\t\t\t\t\t\tcubeOne.y += _diffY * 0.05;\r\n\t\t\t\t\t\tcubeOne.z += _diffZ * 0.05;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t} else {\r\n\t\t\t\t\t_formOneElement = false;\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_view.camera.x = 3 * (stage.mouseX - stage.stageWidth * 0.5);\r\n\t\t\t_view.camera.y = 3 * (stage.mouseY - stage.stageHeight * 0.5);\r\n\t\t\t_view.camera.lookAt(_ORIGINE);\r\n\t\t\t\r\n\t\t\t_view.render();\r\n\t\t}\r\n\t\t\r\n\t\tprivate function _resize(evt:Event = null):void {\r\n\t\t\t_view.width = stage.stageWidth;\r\n\t\t\t_view.height = stage.stageHeight;\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p><a href=\"http:\/\/www.aymericlamboley.fr\/blog\/wp-content\/uploads\/2011\/10\/Away3D\/Away3D.zip\">Zip file.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It was about time to start working on 3D with flash. I was already looking at Papervision3D some years ago, but I have never worked with. Then I&#8217;ve followed differents 3D engine like Sandy, Five3D, and Away3D. Now that Stage3D and FP11 are out, it is time to start working with 3D in flash. However, &hellip; <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/getting-started-with-away3d-for-fp11\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Getting started with Away3D for FP11<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4,92,33],"tags":[15,93,34],"_links":{"self":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/461"}],"collection":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/comments?post=461"}],"version-history":[{"count":3,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":466,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/461\/revisions\/466"}],"wp:attachment":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}