The Way To Great

通往伟大的路

立方体的着色,阴影效果,过度效果

阴影着色的立方体外带过渡效果【附源码】

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 (045, [0xf0f0f00xf0f0f00xf0f0f0], [00.51], [0x000x500xff], 66101"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, 0xde00000x800000);
            flatShaderMat.doubleSided 
= false;
 
            materials 
= new MaterialsList ();
            materials.addMaterial (flatShaderMat, 
"all");
 
            
// scene
            scene3d = new Scene3D();
            renderer 
= new BasicRenderEngine();
            camera 
= new FreeCamera3D(1600);
            viewport 
= new Viewport3D(effectWidth, effectHeight, falsefalsefalsefalse);
            display 
= new DisplayObject3D();
 
            
object = new Cube (materials, 300300300111);
 
            
// light
            pointLight = new PointLight3D (truefalse);  // 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 (0360);
            rotYValue 
= randomize (0360);
            rotZValue 
= randomize (0360);
 
            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 (0360);
            rotYValue 
= randomize (0360);
            rotZValue 
= randomize (0360);
 
            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);
        }

 
    }

 
}








Shaded Papervision cube with Tweener + source

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);
}
 
}
 
}
阅读更多
个人分类: RIA
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭