This Part of the Shaders Tutorial series will show you how to add Phong vshader to either a dae imported object or to a basic primitive.
If you are a novice, it is advised that you follow this tutorial from the initial section that can be found here, which explains how to set up the files and the scene. Otherwise please read on.
For those following on the shaders tutorial series, i will be calling this .as file phongMat
package phongMat { import flash.display.Sprite; import flash.events.Event; import flash.text.TextField; import flash.text.TextFormat; import org.papervision3d.cameras.CameraType; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.PhongMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.view.BasicView; import org.papervision3d.objects.parsers.DAE; import org.papervision3d.objects.DisplayObject3D; public class phongMat extends Sprite {
private var view:BasicView; private var phong:PhongMaterial; private var light:PointLight3D; private var sphere:Sphere; private var angle:Number = new Number(0); private var tf:TextField; private var format:TextFormat; private var dae:DAE; private var daeFile:String; private var daeMaterialName:String; private var statsview:StatsView; public function phongMat() { view = new BasicView(300, 300, false, false, CameraType.FREE); view.renderer = new BasicRenderEngine(); addChild(view); light = new PointLight3D(true); light.z = -800; light.y = 300; phong = new PhongMaterial(light, 0xFFFFFF, 0xEEC900, 80); daeFile = "YourDAEfileName.dae"; dae = new DAE(); dae.load(daeFile, new MaterialsList ( { all:phong} )); //dae.scale = 100; //You may need to scale and rotate your object //dae.rotationY=90; view.scene.addChild(dae); format = new TextFormat("Arial", 10, 0xFFFFFF); tf = new TextField(); tf.width = 200; tf.text = "Phong Material Shader"; tf.x = 10; tf.y = 10; tf.setTextFormat(format); addChild(tf); addEventListener(Event.ENTER_FRAME, onRenderViewport); } private function onRenderViewport(e:Event):void { //Either rotate your object, or the light source or both //dae.rotationY++; animateLight(); view.singleRender(); } private function animateLight():void { angle += 4 * (Math.PI/180); light.x = Math.cos(angle) * 800; light.z = Math.sin(angle) * 800; } } }
If you have been following this tutorial series from the beginning, you will want to add the following code to your MainShader.as file that you created, in order to run your movie.
package { import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.view.BasicView; import phongMat.phongMat; [SWF (width="800", height="600", framerate="25", backgroundColor="0x333333")]; public class MainShader extends Sprite { private var phong:phongMat; public function MainShader() { phong = new phongMat(); phong.x = 500; phong.y = 300; addChild(phong); } } }
If you like this tutorial, why not sign up to our RSS feeds and recieve the latest updates straight to your inbox/reader!
OR spread the word using the Social buttons bellow – Thanks!
Feel free to leave a comment if you require an help/suggestions, and I will get back to you ASAP.
Hi
Why when applying the shades to a Collada file, the color of the collada desapear and only keeps the shades?
Thanks
When you apply a shader, you are overwriting the original colour of the collada file
If you want to mix both materials together it is a more detailed process..