Sample of Text3D
...
@author ...
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import org.papervision3d.core.view.IView;
import org.libspark.thread.Thread;
import org.libspark.thread.EnterFrameThreadExecutor;
/**
* ...
* @author ...
*/
public class Pv3d013 extends Sprite
{
public function Pv3d013()
{
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
}
private function addedToStageHandler(e:Event):void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//stage.frameRate = 24;
if (!Thread.isReady) {
Thread.initialize(new EnterFrameThreadExecutor());
}
var t:Thread = new MainThread(this);
t.start();
}
}
}
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import org.papervision3d.materials.special.Letter3DMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.typography.Font3D;
import org.papervision3d.typography.fonts.HelveticaLight;
import org.papervision3d.typography.Text3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.special.ParticleField;
import org.papervision3d.materials.special.BitmapParticleMaterial;
import org.papervision3d.materials.special.ParticleMaterial;
import org.libspark.thread.Thread;
import org.libspark.thread.threads.display.LoaderThread;
import caurina.transitions.Tweener;
internal class MainThread extends Thread {
private var _view:BasicView;
private var container:Sprite;
public function MainThread(container:Sprite) {
super();
this.container = container;
}
override protected function run():void
{
_view = new CustomView();
container.addChild(_view);
}
}
internal class CustomView extends BasicView {
private var msg:String = "I thought what I'd do was I'd pretend I was one of those trolls Or should I?";
private var textContainer:DisplayObject3D;
private var isInALine:Boolean = false;
private var aryText3D:Array;
public function CustomView() {
super(0, 0, true, true);
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void
{
buildScene();
startRendering();
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
}
private function mouseWheelHandler(e:MouseEvent):void
{
if (e.delta > 0) {
Tweener.addTween(camera, { zoom:camera.zoom + 1 , time:1});
} else {
Tweener.addTween(camera, { zoom:camera.zoom - 1 , time:1});
}
}
private function mouseDownHandler(e:MouseEvent):void
{
var i:int = 0;
var text:Text3D;
var posX:Number = -600;
var posY:Number = 600;
var delay:Number = 0;
if (isInALine) {
Tweener.removeAllTweens();
for each( text in aryText3D) {
randomize(text);
}
isInALine = !isInALine;
}else {
Tweener.removeAllTweens();
i = 0;
for each( text in aryText3D) {
Tweener.addTween(text,
{
x:posX,
y:posY,
z:0,
rotationX:0,
rotationY:0,
rotationZ:0,
time:1.5,
delay:delay
} );
i++;
if (i % 10 == 0) {
posY -= 80;
posX = -600;
}
posX += text.font.widths[text.text] + 10;
delay += 0.1;
}
isInALine = !isInALine;
}
}
private function enterFrameHandler(e:Event):void
{
super.onRenderTick(e);
if (isInALine) {
Tweener.addTween(textContainer, {
rotationX:0,
rotationY:0,
rotationZ:0,
time:3
} );
}else {
textContainer.rotationY += 2;
textContainer.rotationX += 2;
}
}
protected function buildScene():void {
textContainer = new DisplayObject3D();
scene.addChild(textContainer);
aryText3D = [];
var i:int;
var color:uint;
var lmat:Letter3DMaterial;
var text3d:Text3D;
var font:Font3D = new HelveticaLight();
for (i = 0; i < msg.length; i++) {
//color = Math.random() * 0xffffff;
color = 0x00ff00;
lmat = new Letter3DMaterial(color, 1);
text3d = new Text3D(msg.charAt(i), font, lmat, "text"+i);
text3d.useOwnContainer = true;
text3d.alpha = 0;
textContainer.addChild(text3d);
aryText3D.push(text3d);
randomize(text3d);
}
camera.x = 0;
camera.y = 0;
camera.z = -1000;
}
private function randomize(text3d:Text3D):void {
Tweener.addTween(text3d,
{
alpha:1,
x:getRandomNumber(-500, 500),
y:getRandomNumber(-500, 500),
z:getRandomNumber( -500, 500),
rotationX:getRandomNumber( -360, 360),
rotationY:getRandomNumber( -360, 360),
rotationZ:getRandomNumber( -360, 360),
time:3
});
}
private function getRandomNumber(min:Number, max:Number):Number {
return Math.random() * (max - min) + min;
}
}