pv3d测试

来源:互联网 发布:js页面倒计时代码 编辑:程序博客网 时间:2024/05/18 01:18
来自前面介绍的日本网址: http://wonderfl.net/search?q=pv3d  
下面是其中之一:  源码:  http://wonderfl.net/code/d9bc3d0d3b237cd9feca41335fe49c4624064034/download
                         demo :  http://wonderfl.net/code/d9bc3d0d3b237cd9feca41335fe49c4624064034/fullscreen
codes :
  1. package
  2. {
  3.     import flash.display.BitmapData;
  4.     import flash.events.Event;
  5.     
  6.     import org.papervision3d.core.geom.TriangleMesh3D;
  7.     import org.papervision3d.core.math.Number3D;
  8.     import org.papervision3d.core.math.Plane3D;
  9.     import org.papervision3d.core.utils.MeshUtil;
  10.     import org.papervision3d.materials.BitmapColorMaterial;
  11.     import org.papervision3d.materials.BitmapMaterial;
  12.     import org.papervision3d.objects.primitives.Plane;
  13.     import org.papervision3d.objects.primitives.Sphere;
  14.     import org.papervision3d.view.BasicView;
  15.     public class MeshCuttingExample extends BasicView
  16.     {
  17.         protected var planeMaterial:BitmapColorMaterial;
  18.         protected var sphereMaterial:BitmapMaterial;
  19.         
  20.         protected var sourceSphere:Sphere;
  21.         protected var hemiSphereA:TriangleMesh3D;
  22.         protected var hemiSphereB:TriangleMesh3D;
  23.     
  24.         
  25.         public function MeshCuttingExample()
  26.         {
  27.             super(00truefalse);
  28.             opaqueBackground = 0;
  29.             setupScene();
  30.         }
  31.         
  32.         protected function setupScene():void
  33.         {
  34.             //Setup a bitmapdata material for the spheres to use.
  35.             var bmp:BitmapData = new BitmapData(512,255,false,0);
  36.             bmp.perlinNoise(64,64,4,123456,true,false);
  37.             
  38.             //Create a new sphere, which we will use as a source geometry, cutting it.
  39.             sphereMaterial = new BitmapMaterial(bmp);
  40.             sphereMaterial.doubleSided = true;
  41.             sourceSphere = new Sphere(sphereMaterial, 40015,15);
  42.             
  43.             //Setup a plane3d along which we will cut the sphere.
  44.             var normal:Number3D = new Number3D(.5,.5,0); //Some angle
  45.             var point:Number3D = new Number3D(0,80,0); //at position...
  46.             var cutPlane:Plane3D = Plane3D.fromNormalAndPoint(normal, point);
  47.             
  48.             //Cut the sphere along the plane3D, returns an array of maximum 2 meshes.
  49.             var meshes:Array = MeshUtil.cutTriangleMesh(sourceSphere, cutPlane);
  50.             
  51.             //Add result meshA
  52.             hemiSphereA = meshes[0];
  53.             hemiSphereA.x = 400;
  54.             scene.addChild(hemiSphereA);
  55.             
  56.             //Add result meshB
  57.             hemiSphereB = meshes[1];
  58.             hemiSphereB.x = -400;
  59.             scene.addChild(hemiSphereB);
  60.             
  61.             //Start rendering
  62.             startRendering();
  63.         }
  64.         
  65.         override protected function onRenderTick(event:Event=null):void
  66.         {
  67.             //Rotate the spheres.
  68.             hemiSphereA.yaw(1);
  69.             hemiSphereB.yaw(-1);
  70.             super.onRenderTick(event);
  71.         }
  72.         
  73.     }
  74. }
flash swf thumbnail