April 28th, 2008 | Flash Fun
If you have been visiting this current incarnation of this site since opening day, you may remember that this little Flash-thing used to be part of the original version of the header.
It gave me numerous headaches primarily due to this problem, so I decided to remove it and publish the source instead.
It's really pretty basic - a cube primitive, a FlatShadeMaterial, a GradientGlowFilter, with some random elastic rotation done with Tweener - but I suspect that it could come very handy especially for those who are just starting with Papervision3D. Have fun with it.
Here's the source (of course you will need the Papervision3D Great White branch and Tweener to run it):
//
ShadedPapervisionCubewithTweener(C)edvardtoth.com

package
...
{
importflash.display.*;
importflash.events.*;
importflash.filters.GradientGlowFilter;
importorg.papervision3d.scenes.*;
importorg.papervision3d.cameras.*;
importorg.papervision3d.view.Viewport3D;
importorg.papervision3d.events.*;
importorg.papervision3d.render.BasicRenderEngine;
importorg.papervision3d.lights.PointLight3D;
importorg.papervision3d.objects.*;
importorg.papervision3d.objects.primitives.Cube;
importorg.papervision3d.materials.*;
importorg.papervision3d.materials.utils.MaterialsList;
importorg.papervision3d.materials.shadematerials.FlatShadeMaterial;
importcaurina.transitions.Tweener;
publicclassThreeDeeextendsMovieClip
...{
privatevareffectWidth:Number=300;//becauseviewporthasclippingturnedoff
privatevareffectHeight:Number=300;
privatevarglowFilter:GradientGlowFilter=newGradientGlowFilter(0,45,[0xf0f0f0,0xf0f0f0,0xf0f0f0],[0,0.5,1],[0x00,0x50,0xff],6,6,10,1,"outer",false);
privatevarviewport:Viewport3D;
privatevarscene3d:Scene3D;
privatevarrenderer:BasicRenderEngine;
privatevardisplay:DisplayObject3D;
privatevarobject:Cube;
privatevarcamera:FreeCamera3D;
privatevarpointLight:PointLight3D;
privatevarmaterials:MaterialsList;
privatevarflatShaderMat:FlatShadeMaterial;
privatevarrotXValue:Number;
privatevarrotZValue:Number;
privatevarrotYValue:Number;
privatevarlimit:Number=1.5;
publicfunctionThreeDee()
...{
stage.showDefaultContextMenu=false;
stage.quality=StageQuality.MEDIUM;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
this.filters=[glowFilter];
//material
flatShaderMat=newFlatShadeMaterial(pointLight,0xde0000,0x800000);
flatShaderMat.doubleSided=false;
materials=newMaterialsList();
materials.addMaterial(flatShaderMat,"all");
//scene
scene3d=newScene3D();
renderer=newBasicRenderEngine();
camera=newFreeCamera3D(1,600);
viewport=newViewport3D(effectWidth,effectHeight,false,false,false,false);
display=newDisplayObject3D();
object=newCube(materials,300,300,300,1,1,1);
//light
pointLight=newPointLight3D(true,false);//2ndwouldbetrueforcollada
pointLight.x=200;
pointLight.y=0;
pointLight.z=500;
display.addChild(object);
scene3d.addChild(display,"Display");
scene3d.addChild(pointLight);
addChild(viewport);
rotXValue=randomize(0,360);
rotYValue=randomize(0,360);
rotZValue=randomize(0,360);
camera.rotationX=rotXValue;
camera.rotationY=rotYValue;
camera.rotationZ=rotZValue;
updateFrame();
recalcValues();
}
privatefunctionupdateFrame():void
...{
camera.x=camera.y=camera.z=0;
camera.moveBackward(500);
pointLight.copyPosition(camera);
renderer.renderScene(scene3d,camera,viewport);
}
privatefunctionrecalcValues():void
...{
rotXValue=randomize(0,360);
rotYValue=randomize(0,360);
rotZValue=randomize(0,360);

Tweener.addTween(camera,...{rotationX:rotXValue,rotationY:rotYValue,rotationZ:rotZValue,onUpdate:updateFrame,onComplete:recalcValues,transition:"easeInOutElastic",time:3});
}
privatefunctionrandomize(min:Number,max:Number):Number
...{
return(Math.random()*(max-min)+min);
}
}
}


Shaded Papervision cube with Tweener + source
April 28th, 2008 | Flash Fun
If you have been visiting this current incarnation of this site since opening day, you may remember that this little Flash-thing used to be part of the original version of the header.
It gave me numerous headaches primarily due to this problem, so I decided to remove it and publish the source instead.
It's really pretty basic - a cube primitive, a FlatShadeMaterial, a GradientGlowFilter, with some random elastic rotation done with Tweener - but I suspect that it could come very handy especially for those who are just starting with Papervision3D. Have fun with it.
Here's the source (of course you will need the Papervision3D Great White branch and Tweener to run it):
// Shaded Papervision Cube with Tweener (C) edvardtoth.com
package {
import flash.display.*;
import flash.events.*;
import flash.filters.GradientGlowFilter;
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.events.*;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import caurina.transitions.Tweener;
public class ThreeDee extends MovieClip
{
private var effectWidth:Number = 300; // because viewport has clipping turned off
private var effectHeight:Number = 300;
private var glowFilter:GradientGlowFilter = new GradientGlowFilter (0, 45, [0xf0f0f0, 0xf0f0f0, 0xf0f0f0], [0, 0.5, 1], [0x00, 0x50, 0xff], 6, 6, 10, 1, "outer", false);
private var viewport:Viewport3D;
private var scene3d:Scene3D;
private var renderer:BasicRenderEngine;
private var display:DisplayObject3D;
private var object:Cube;
private var camera:FreeCamera3D;
private var pointLight:PointLight3D;
private var materials:MaterialsList;
private var flatShaderMat:FlatShadeMaterial;
private var rotXValue:Number;
private var rotZValue:Number;
private var rotYValue:Number;
private var limit:Number = 1.5;
public function ThreeDee ()
{
stage.showDefaultContextMenu = false;
stage.quality = StageQuality.MEDIUM;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
this.filters = [glowFilter];
// material
flatShaderMat = new FlatShadeMaterial (pointLight, 0xde0000, 0x800000);
flatShaderMat.doubleSided = false;
materials = new MaterialsList ();
materials.addMaterial (flatShaderMat, "all");
// scene
scene3d = new Scene3D();
renderer = new BasicRenderEngine();
camera = new FreeCamera3D(1, 600);
viewport = new Viewport3D(effectWidth, effectHeight, false, false, false, false);
display = new DisplayObject3D();
object = new Cube (materials, 300, 300, 300, 1, 1, 1);
// light
pointLight = new PointLight3D (true, false); // 2nd would be true for collada
pointLight.x = 200;
pointLight.y = 0;
pointLight.z = 500;
display.addChild (object);
scene3d.addChild (display, "Display");
scene3d.addChild (pointLight);
addChild (viewport);
rotXValue = randomize (0, 360);
rotYValue = randomize (0, 360);
rotZValue = randomize (0, 360);
camera.rotationX = rotXValue;
camera.rotationY = rotYValue;
camera.rotationZ = rotZValue;
updateFrame();
recalcValues();
}
private function updateFrame():void
{
camera.x=camera.y=camera.z=0;
camera.moveBackward(500);
pointLight.copyPosition (camera);
renderer.renderScene (scene3d, camera, viewport);
}
private function recalcValues ():void
{
rotXValue = randomize (0, 360);
rotYValue = randomize (0, 360);
rotZValue = randomize (0, 360);
Tweener.addTween (camera, {rotationX:rotXValue, rotationY:rotYValue, rotationZ: rotZValue, onUpdate:updateFrame, onComplete:recalcValues, transition:"easeInOutElastic", time:3});
}
private function randomize(min:Number, max:Number):Number
{
return (Math.random()*(max - min) + min);
}
}
}
本文介绍了一个使用Papervision3D实现的带有过渡效果的阴影立方体示例。该示例利用了FlatShadeMaterial材质和GradientGlowFilter滤镜,并通过Tweener实现了弹性旋转效果。
1079

被折叠的 条评论
为什么被折叠?



