Cool AS3 Source

http://wonderfl.kayac.com/

Man, this guy so kicks arse in Flash 3D

http://3dflashlo.wordpress.com/

Wooden box code

Files here.

package {
	import flash.display.*;
	import flash.events.*;
	//
	import caurina.transitions.Tweener;
	//
	import org.papervision3d.view.BasicView;
	import org.papervision3d.objects.primitives.*;
	//import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.*;
	import org.papervision3d.materials.utils.*;
	//import org.papervision3d.materials.MovieAssetMaterial;
	import org.papervision3d.materials.shaders.*;
	import org.papervision3d.materials.shadematerials.*;

	public class KeyFlip extends MovieClip {
		private var spinning:Boolean;
		private var cube:Cube;
		private var floorPlane:Plane;
		private var boxMat1:MovieAssetMaterial;
		private var boxMat2:MovieAssetMaterial;
		private var boxMat3:MovieAssetMaterial;
		private var boxMat4:MovieAssetMaterial;
		private var boxMat5:MovieAssetMaterial;
		private var boxMat6:MovieAssetMaterial;
		private var flooorMat:MovieAssetMaterial;
		private var materialsList:MaterialsList;
		private var papervision:BasicView;
		private var light:PointLight3D;
		private var flatShader:FlatShader;
		private var shadedMaterial1:ShadedMaterial;
		private var shadedMaterial2:ShadedMaterial;
		private var shadedMaterial3:ShadedMaterial;
		private var shadedMaterial4:ShadedMaterial;
		private var shadedMaterial5:ShadedMaterial;
		private var shadedMaterial6:ShadedMaterial;

		public function KeyFlip():void {
			//Listeners:
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false,0,true);
			addEventListener(Event.ENTER_FRAME,render);

			//Init Papervision:
			initPapervision();
		}

		private function initPapervision():void {
			//BasicView:
			papervision=new BasicView(1,1,true,true);
			addChild(papervision);

			//Light:
			light= new PointLight3D(true);
			light.x=-454
			light.y=454

			//Materials:
			//Needs major work to still be able to get to and change the frame of each material
			boxMat1=new MovieAssetMaterial("WoodTexture",false,true,true);
			MovieClip(boxMat1.movie).gotoAndStop(1);
			flatShader = new FlatShader(light, 0xFFFFFF, 0x000000);
        	shadedMaterial1 = new ShadedMaterial(boxMat1, flatShader);

			boxMat2=new MovieAssetMaterial("WoodTexture",false,true,true);
			MovieClip(boxMat2.movie).gotoAndStop(2);
			flatShader = new FlatShader(light, 0xFFFFFF, 0x000000);
        	shadedMaterial2 = new ShadedMaterial(boxMat2, flatShader);

			boxMat3=new MovieAssetMaterial("WoodTexture",false,true,true);
			MovieClip(boxMat3.movie).gotoAndStop(3);
			flatShader = new FlatShader(light, 0xFFFFFF, 0x000000);
        	shadedMaterial3 = new ShadedMaterial(boxMat3, flatShader);

			boxMat4=new MovieAssetMaterial("WoodTexture",false,true,true);
			MovieClip(boxMat4.movie).gotoAndStop(4);
			flatShader = new FlatShader(light, 0xFFFFFF, 0x000000);
        	shadedMaterial4 = new ShadedMaterial(boxMat4, flatShader);

			boxMat5=new MovieAssetMaterial("WoodTexture",false,true,true);
			MovieClip(boxMat5.movie).gotoAndStop(5);
			flatShader = new FlatShader(light, 0xFFFFFF, 0x000000);
        	shadedMaterial5 = new ShadedMaterial(boxMat5, flatShader);

			boxMat6=new MovieAssetMaterial("WoodTexture",false,true,true);
			MovieClip(boxMat6.movie).gotoAndStop(6);
			flatShader = new FlatShader(light, 0xFFFFFF, 0x000000);
        	shadedMaterial6 = new ShadedMaterial(boxMat6, flatShader);

			flooorMat=new MovieAssetMaterial("ShadowPlane");

			//MaterialList:
			materialsList = new MaterialsList();
			materialsList.addMaterial(shadedMaterial1, "front" );
			materialsList.addMaterial(shadedMaterial2, "back" );
			materialsList.addMaterial(shadedMaterial3, "left" );
			materialsList.addMaterial(shadedMaterial4, "right" );
			materialsList.addMaterial(shadedMaterial5, "top" );
			materialsList.addMaterial(shadedMaterial6, "bottom" );

			//Primitives:
			cube=new Cube(materialsList,200,200,200,4,4,4);
			papervision.scene.addChild(cube);

			floorPlane=new Plane(flooorMat,286,286,4,4);
			floorPlane.rotationX=90;
			floorPlane.y=-140;
			papervision.scene.addChild(floorPlane);

			//Camera:
			papervision.camera.focus=100;
			papervision.camera.zoom=10;
			papervision.camera.y=376;
			papervision.camera.x=-450;
			papervision.camera.lookAt(cube);
		}

		private function keyDownHandler(e:KeyboardEvent):void {
			if (! spinning) {
				//Left
				if (e.keyCode==37) {
					spinning=true;
					Tweener.addTween(cube,{rotationY:cube.rotationY+90,time:.5,transition:"easeInOutExpo",onComplete:resetSpinning});
					Tweener.addTween(floorPlane,{rotationY:floorPlane.rotationY+90,time:.5,transition:"easeInOutExpo"});
				}
				//Up
				if (e.keyCode==38) {
					spinning=true;
					Tweener.addTween(cube,{rotationX:cube.rotationX+90,time:.5,transition:"easeInOutExpo",onComplete:resetSpinning});
					Tweener.addTween(floorPlane,{scaleY:.5,time:.25,transition:"easeInExpo"});
					Tweener.addTween(floorPlane,{scaleY:1,time:.25,transition:"easeOutExpo",delay:.25});
				}
				//Right
				if (e.keyCode==39) {
					spinning=true;
					Tweener.addTween(cube,{rotationY:cube.rotationY-90,time:.5,transition:"easeInOutExpo",onComplete:resetSpinning});
					Tweener.addTween(floorPlane,{rotationY:floorPlane.rotationY-90,time:.5,transition:"easeInOutExpo"});
				}
				//Down
				if (e.keyCode==40) {
					spinning=true;
					Tweener.addTween(cube,{rotationX:cube.rotationX-90,time:.5,transition:"easeInOutExpo",onComplete:resetSpinning});
					Tweener.addTween(floorPlane,{scaleY:.5,time:.25,transition:"easeInExpo"});
					Tweener.addTween(floorPlane,{scaleY:1,time:.25,transition:"easeOutExpo",delay:.25});
				}
			}
		}

		private function resetSpinning():void {
			spinning=false;
		}

		private function render(e:Event):void {
			xRotation.text="Rotation X: "+cube.rotationX + " : " + cube.rotationX%360;
			yRotation.text="Rotation Y: "+cube.rotationY + " : " + cube.rotationY%360;
			papervision.singleRender();
		}
	}
}

VizualPV3D - Papervision made visual

http://www.juxtinteractive.com/work/vizualpv3d/

Three things to remember…

For adding to iPhone speed:

1. #pragma strict

2. Script Call Optimization

A good development practice on the iPhone is to never rely on exception handling (either internally or through the use of try/catch blocks). When using the default Slow and Safe option, any exceptions that occur on the device will be caught and a stack trace will be provided. When using the Fast but no Exceptions option, any exceptions that occur will crash the game, and no stack trace will be provided. However, the game will run faster since the processor is not diverting power to handle exceptions. When releasing your game to the world, it’s best to publish with the Fast but no Exceptions option.

3. Stripping Level

Most games don’t use all necessary dlls. With this option, you can strip out unused parts to reduce the size of the built player on the iPhone. If your game is using classes that would normally be stripped out by the option you currently have selected, you’ll be presented with a Debug message when you make a build.

Keeping those Draw Calls down…

Diffuse shader that doesn’t need a light:

Shader "Texture Simple" {
   Properties {
      _MainTex ("Base (RGB)", 2D) = "white"
   }
   SubShader {
      Pass {
         SetTexture [_MainTex]
      }
   }
}

Transparent Diffuse shader that doesn’t need a light:

Shader "Texture Simple Transparent" {
   Properties {
      _Color ("Main Color", Color) = (1,1,1,1)
      _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
   }
   Category {
      //ZWrite Off
      Alphatest Greater 0
      Tags {Queue=Transparent}
      Blend SrcAlpha OneMinusSrcAlpha

      SubShader {
         Pass {
            Lighting Off
            SetTexture [_MainTex]
            {
               constantColor [_Color]
               Combine texture * constant, texture * constant
            }
         }
      }
   }
}

Some inspiration

http://www.thebestdesigns.com/
http://creativejuice.wordpress.com/
http://www.frederiksamuel.com/blog/
http://www.websitedesignawards.com/
http://www.newwebpick.com/
http://www.xhilarate.com/
http://www.webcreme.com/
http://thefwa.com/
http://www.fwatheater.com/
http://www.mows.sk/awards/index.php
http://www.designineurope.eu/
http://creattica.com/
http://www.designsnack.com/
http://www.webdesignermag.co.uk/

UV Animations in Unity iPhone

var tileSize : Vector2;
var columns : float = 6;
var rows : float = 7;
var startPosition : Vector2;
var framesPerSecond : float = 41;

function Start (){
	tileSize=Vector2(1/columns,1/rows);
	startPosition=Vector2(0,tileSize.y*(rows-1));
	renderer.material.mainTextureOffset = startPosition;
	renderer.material.mainTextureScale=Vector2(1/columns,1/rows);
}

function Update(){
	var index : int = Time.time * framesPerSecond;
	var offset : Vector2 = Vector2(tileSize.x*(index%columns),startPosition.y-(Mathf.Floor((index/columns)%rows)*tileSize.y));
	renderer.material.mainTextureOffset = offset;
}

Grid positioning based on an increasing index.

var col=5;
var row=4;
var index=0;

addEventListener(Event.ENTER_FRAME,loop);

function loop(e:Event):void {
	var xpos=index%col;
	var ypos=Math.floor((index/col)%row);
	index+=1;
	box.x=xpos*box.width;
	box.y=ypos*box.height;
}

Smoothing out iPhone’s accelerometers

Short. Simple. Works.

var steering:float;

function Update () {
	steering = Mathf.Round(Mathf.Lerp(steering, iPhoneInput.acceleration.y*10, Time.time));
}

Next Page »