Basic Light Tutorial

To view this page ensure that Adobe Flash Player version 11.0.0 or greater is installed.

package
{
	import com.yogurt3d.Yogurt3D;
	import com.yogurt3d.core.events.Yogurt3DEvent;
	import com.yogurt3d.core.lights.Light;
	import com.yogurt3d.core.materials.MaterialDiffuseFill;
	import com.yogurt3d.core.materials.MaterialFill;
	import com.yogurt3d.core.sceneobjects.SceneObject;
	import com.yogurt3d.presets.primitives.sceneobjects.BoxSceneObject;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Vector3D;
	
	[SWF(width="400", height="300")] // initialize SWF size to be 800 by 600
	public class BasicLight extends Sprite
	{
		// We define a SceneObject varible as a member: a box of type BoxSceneObject
		public var box:BoxSceneObject;
		
		// starting point: initialize the Yogurt3D engine
		public function BasicLight()
		{
			Yogurt3D.instance.addEventListener( Yogurt3DEvent.READY, onContextReady );
			// Initilize the Yogurt3D instance
			Yogurt3D.instance.init( this.stage );
		}
		
		// Create the scene and start rendering when the Context3D is ready
		public function onContextReady( _e:Event ):void{
			// Here we initialize the scene. Nothing is drawn onto the screen yet. 
			
			// Initialize the Yogurt3D engine with the default setup (scene, camera, renderer etc.)
			Yogurt3D.instance.defaultSetup(400,300);
			// change the background color of the scene (default scene) to red (0xFF0000 in hex rgb) 
			Yogurt3D.instance.defaultScene.sceneColor = 0xEFEFEF;
			
			// create the actual box object with default parameters (at the origin)
			box = new BoxSceneObject();
			// add material to the box: Green, opaque difuse fill 
			box.material = new MaterialDiffuseFill( 0x00FF00,1 );
			
			// simply add the box to the scene. The box will apperar (be rendered) on the default scene
			Yogurt3D.instance.defaultScene.addChild( box );
			
			// Camera Setup
			// We have the default camera on the scene. Let's change its position to -20 on the z-axis
			Yogurt3D.instance.defaultCamera.transformation.position = new Vector3D( 0,10,-30 );
			// and let the camera look at to the origin (0,0,0)
			Yogurt3D.instance.defaultCamera.transformation.lookAt( new Vector3D );
			
			// Adding Lights
			// We create a new light object with default parameters. 
			// It is directional light, meaning the light rays are parallel as if they are coming from a source at the infinity.
			var light:Light = new Light( Light.DIRECTIONAL_LIGHT );
			// the set the light source position
			light.transformation.position = new Vector3D(-10,45,-10);
			// and it is directed to the scene origin
			light.transformation.lookAt( new Vector3D );
			// add the newly created light object to the scene
			Yogurt3D.instance.defaultScene.addChild( light );
			
			// Now we are ready to render the scene
			// start the rendering
			Yogurt3D.instance.startAutoUpdate();
			// register a callback function to be called before rendering each frame
			Yogurt3D.instance.enginePreUpdateCallback = onEnterFrame;
		}
		
		// this is called before rendering each frame: rotates the box around the y-axis
		public function onEnterFrame( ):void{
			box.transformation.rotationY+=1; // add a rotation of 1 degree
		}
		
	}
}

New Version with Stage3D

Yogurt3D v2.1

About Yogurt3D

Yogurt3D Game Engine is a state of the art Actionscript 3.0 library for developing 3D applications on Adobe Flash Platform. We claim it is possible to create in-browser 3D games without any plug-in installation. Its animation system, model formats, exporter plug-ins for modelling tools, scene hierarchy and scene management structure, and that it is developed with a game developer perspective, makes Yogurt3D a powerful tool for 3D game developers.

If you wish to target both casual and seasoned players with browser-based real-time 3D games on the web, Yogurt 3D Game Engine is the ultimate tool to choose.

About Yogurt Technologies

Yoğurt Technologies was founded in 1997 by a group of artists and computer engineers.

For 10 years the group worked as a new media agency producing technology for other companies.

In 2007, the decision to focus on its own products was taken as Yoğurt members foresaw that 3D would be the next big thing on the web. Thus, the company now produces 3D tools that will be available to anyone who wants to try a hand on 3D content.

Yogurt3D on Social Networks

Follow Us on Facebook, Twitter and FriendFeed.