Created
November 24, 2008 20:53
-
-
Save johnlindquist/28609 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
import org.papervision3d.lights.PointLight3D; | |
import org.papervision3d.materials.shadematerials.CellMaterial; | |
import org.papervision3d.materials.shadematerials.FlatShadeMaterial; | |
import org.papervision3d.materials.shadematerials.GouraudMaterial; | |
import org.papervision3d.materials.shadematerials.PhongMaterial; | |
import org.papervision3d.objects.primitives.Sphere; | |
import org.papervision3d.view.BasicView; | |
[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] | |
public class PhongMaterialShineThrough extends BasicView | |
{ | |
private var sphere:Sphere; | |
private var light:PointLight3D; | |
private var phongMaterial:PhongMaterial; | |
private var gouraudMaterial:GouraudMaterial; | |
private var flatShadeMaterial:FlatShadeMaterial; | |
private var cellMaterial:CellMaterial; | |
private var materials:Array = []; | |
private var materialsNames:Array = []; | |
private var materialIndex:int = 0; | |
private var header:headerContainer = new headerContainer(); | |
public function PhongMaterialShineThrough() | |
{ | |
addChild(header); | |
light = new PointLight3D(true); | |
light.z = -1000; | |
phongMaterial = new PhongMaterial(light, 0xcc0000, 0x000000, 10); | |
gouraudMaterial = new GouraudMaterial(light, 0xcc0000); | |
flatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000); | |
cellMaterial = new CellMaterial(light, 0xcc0000, 0x000000, 10); | |
materials.push(phongMaterial, gouraudMaterial, flatShadeMaterial, cellMaterial); | |
materialsNames.push("Phong", "Gouraud", "FlatShade", "Cell"); | |
sphere = new Sphere(materials[materialIndex],300, 20, 20); | |
header.header.text = "Click to change material"; | |
scene.addChild(sphere); | |
scene.addChild(light); | |
startRendering(); | |
stage.addEventListener(MouseEvent.CLICK, mouseClickHandler); | |
} | |
private function mouseClickHandler(event:MouseEvent):void | |
{ | |
if(materialIndex < materials.length - 1) materialIndex++; | |
else materialIndex = 0; | |
sphere.material = materials[materialIndex]; | |
header.header.text = materialsNames[materialIndex]; | |
} | |
override protected function onRenderTick(event:Event=null):void | |
{ | |
light.moveForward(1000); | |
light.yaw(2); | |
light.moveBackward(1000); | |
renderer.renderScene(scene, camera, viewport); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment