关注Flash3D的开源项目-pv3d
2009-12-04 11:19
197 查看
Flash3d最近搞的很火,我也玩了一下,感觉悟东西还不少,我首先看了一下papervision3d引擎,试用了一个,搞了个例子,代吗如下.有兴趣的朋友可以试试:
package {
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.papervision3d.core.proto.MaterialObject3D;
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.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
public class Example004 extends BasicView {
private static const ORBITAL_RADIUS:Number = 200;
private var sphere1:Sphere;
private var sphere2:Sphere;
private var sphere3:Sphere;
private var sphere4:Sphere;
private var sphereGroup:DisplayObject3D;
public function Example004() {
super(0, 0, true, false);
// set up the stage
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
// Initialise Papervision3D
init3D();
// Create the 3D objects
createScene();
// Start rendering the scene
startRendering();
}
private function init3D():void {
// position the camera
camera.x = -200;
camera.y = 200;
camera.z = -500;
}
private function createScene():void {
// Specify a point light source and its location
var light:PointLight3D = new PointLight3D(true);
light.x = 400;
light.y = 1000;
light.z = -400;
// Create a new material (flat shaded) and apply it to a sphere
var flatShadedMaterial:MaterialObject3D = new FlatShadeMaterial(light, 0x6654FF, 0x060433);
sphere1 = new Sphere(flatShadedMaterial, 50, 10, 10);
sphere1.x = -ORBITAL_RADIUS;
// Create a new material (Gouraud shaded) and apply it to a sphere
var gouraudMaterial:MaterialObject3D = new GouraudMaterial(light, 0x6654FF, 0x060433);
sphere2 = new Sphere(gouraudMaterial, 50, 10, 10);
sphere2.x = ORBITAL_RADIUS;
// Create a new material (Phong shaded) and apply it to a sphere
var phongMaterial:MaterialObject3D = new PhongMaterial(light, 0x6654FF, 0x060433, 150);
sphere3 = new Sphere(phongMaterial, 50, 10, 10);
sphere3.z = -ORBITAL_RADIUS;
// Create a new material (cell shaded) and apply it to a sphere
var cellMaterial:MaterialObject3D = new CellMaterial(light, 0x6654FF, 0x060433, 5);
sphere4 = new Sphere(cellMaterial, 50, 10, 10);
sphere4.z = ORBITAL_RADIUS;
// Create a 3D object to group the spheres
sphereGroup = new DisplayObject3D();
sphereGroup.addChild(sphere1);
sphereGroup.addChild(sphere2);
sphereGroup.addChild(sphere3);
sphereGroup.addChild(sphere4);
// Add the light and spheres to the scene
scene.addChild(sphereGroup);
scene.addChild(light);
}
override protected function onRenderTick(event:Event=null):void {
// rotate the spheres
sphere1.yaw(-8);
sphere2.yaw(-8);
sphere3.yaw(-8);
sphere4.yaw(-8);
// rotate the group of spheres
sphereGroup.yaw(3);
// call the renderer
super.onRenderTick(event);
}
}
}
package {
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.papervision3d.core.proto.MaterialObject3D;
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.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
public class Example004 extends BasicView {
private static const ORBITAL_RADIUS:Number = 200;
private var sphere1:Sphere;
private var sphere2:Sphere;
private var sphere3:Sphere;
private var sphere4:Sphere;
private var sphereGroup:DisplayObject3D;
public function Example004() {
super(0, 0, true, false);
// set up the stage
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
// Initialise Papervision3D
init3D();
// Create the 3D objects
createScene();
// Start rendering the scene
startRendering();
}
private function init3D():void {
// position the camera
camera.x = -200;
camera.y = 200;
camera.z = -500;
}
private function createScene():void {
// Specify a point light source and its location
var light:PointLight3D = new PointLight3D(true);
light.x = 400;
light.y = 1000;
light.z = -400;
// Create a new material (flat shaded) and apply it to a sphere
var flatShadedMaterial:MaterialObject3D = new FlatShadeMaterial(light, 0x6654FF, 0x060433);
sphere1 = new Sphere(flatShadedMaterial, 50, 10, 10);
sphere1.x = -ORBITAL_RADIUS;
// Create a new material (Gouraud shaded) and apply it to a sphere
var gouraudMaterial:MaterialObject3D = new GouraudMaterial(light, 0x6654FF, 0x060433);
sphere2 = new Sphere(gouraudMaterial, 50, 10, 10);
sphere2.x = ORBITAL_RADIUS;
// Create a new material (Phong shaded) and apply it to a sphere
var phongMaterial:MaterialObject3D = new PhongMaterial(light, 0x6654FF, 0x060433, 150);
sphere3 = new Sphere(phongMaterial, 50, 10, 10);
sphere3.z = -ORBITAL_RADIUS;
// Create a new material (cell shaded) and apply it to a sphere
var cellMaterial:MaterialObject3D = new CellMaterial(light, 0x6654FF, 0x060433, 5);
sphere4 = new Sphere(cellMaterial, 50, 10, 10);
sphere4.z = ORBITAL_RADIUS;
// Create a 3D object to group the spheres
sphereGroup = new DisplayObject3D();
sphereGroup.addChild(sphere1);
sphereGroup.addChild(sphere2);
sphereGroup.addChild(sphere3);
sphereGroup.addChild(sphere4);
// Add the light and spheres to the scene
scene.addChild(sphereGroup);
scene.addChild(light);
}
override protected function onRenderTick(event:Event=null):void {
// rotate the spheres
sphere1.yaw(-8);
sphere2.yaw(-8);
sphere3.yaw(-8);
sphere4.yaw(-8);
// rotate the group of spheres
sphereGroup.yaw(3);
// call the renderer
super.onRenderTick(event);
}
}
}
相关文章推荐
- GitHub 上都有哪些值得关注学习的 iOS 开源项目?
- 2014年值得关注的9个开源项目
- 2014年值得关注的10个开源项目
- GitHub 上值得关注学习的 iOS 开源项目
- .NET开发人员值得关注的七个开源项目
- iOS:GitHub上值得关注的iOS开源项目
- Android Github上值得关注的开源项目
- 【转】最值得你所关注的10个C语言开源项目
- GitHub上值得关注的iOS开源项目
- 来自 OpenSource 2017 值得关注的十个开源项目
- 最值得你所关注的10个C语言开源项目(转自红联)
- 2014年值得关注的10个开源项目(下)
- 2014年值得关注的10个开源项目(中)
- 2014年值得关注的10个开源项目
- 2014年值得关注的10个开源项目(上)
- .NET开发人员值得关注的七个开源项目
- GitHub上值得关注的iOS开源项目
- .NET开发人员值得关注的七个开源项目
- 我关注的开源项目