PV3D之光影篇PointLight3D

最后一篇PV3D之光影篇,现学现卖。

 

 

  1. package
  2. {
  3.     import org.papervision3d.core.proto.MaterialObject3D;
  4.     import org.papervision3d.lights.PointLight3D;
  5.     import org.papervision3d.materials.shadematerials.*;
  6.     import org.papervision3d.materials.*;
  7.     import org.papervision3d.materials.shaders.*;
  8.     import org.papervision3d.objects.DisplayObject3D;
  9.     import org.papervision3d.objects.primitives.Sphere;
  10.     public class ExampleforPointLight3D extends PaperBase
  11.     {
  12.         private var sphere1:Sphere;
  13.         private var sphere2:Sphere;
  14.         private var sphere3:Sphere;
  15.         private var sphere4:Sphere;
  16.         private var sphereGroup:DisplayObject3D;//用一个do3d盛放这四个Sphere
  17.         private static const ORBITAL_RADIUS=200;
  18.         public function ExampleforPointLight3D():void
  19.         {
  20.             init(600,450);
  21.         }
  22.         override protected function init3d():void
  23.         {
  24.             var light:PointLight3D=new PointLight3D(true);//括号内为true表示光源可见
  25.             light.x=0;
  26.             light.y=300;
  27.             light.z=-400;//光源的3D坐标
  28.             //下面分别用到了3种阴影材质,不同的材质表现出来的效果都不一样
  29.             //产生光影的方法只需要将带有光源的阴影材质放入Sphere
  30.             var gouraudMaterial:MaterialObject3D = new GouraudMaterial(light, 0x6654FF, 0x060433);
  31.             sphere1 = new Sphere(gouraudMaterial, 50, 10, 10);
  32.             sphere1.x = ORBITAL_RADIUS;
    •             var phongMaterial:MaterialObject3D = new PhongMaterial(light, 0x6654FF, 0x060433, 150);
    •             sphere2 = new Sphere(phongMaterial, 50, 10, 10);
    •             sphere2.z = -ORBITAL_RADIUS;
    •             var cellMaterial:MaterialObject3D = new CellMaterial(light, 0x6654FF, 0x060433, 5);
    •             sphere3 = new Sphere(cellMaterial, 50, 10, 10);
    •             sphere3.z = ORBITAL_RADIUS;
  33.             //如果要贴上指定位图并也要产生光影
  34.             //我们就需要制作一个Shader 和一个BitmapMaterial 用ShadedMaterial来将他们混合到一起
  35.             var bitmapMaterial:BitmapMaterial=new BitmapAssetMaterial("BitmapImage");
  36.             var shader:Shader = new PhongShader(light, 0xFFFFFF, 0x333333, 50);
  37.             var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader);
  38.             sphere4 = new Sphere(shadedMaterial, 150, 20, 20);
  39.             sphere4.x = -ORBITAL_RADIUS;
  40.             
  41.             sphereGroup = new DisplayObject3D();
  42.             sphereGroup.addChild(sphere1);
  43.             sphereGroup.addChild(sphere2);
  44.             sphereGroup.addChild(sphere3);
  45.             sphereGroup.addChild(sphere4);
  46.  
  47.             default_scene.addChild(sphereGroup);
  48.             default_scene.addChild(light);
  49.  
  50.         }
  51.         override protected function processFrame():void
  52.         {
  53.             sphere1.yaw(-8);
  54.             sphere2.yaw(-8);
  55.             sphere3.yaw(-8);
  56.             sphere4.yaw(-8);
  57.             sphereGroup.yaw(3);
  58.         }
  59.     }
  60. }

有关PV3D方面的学习笔记 至此就告一段落了。
更多更好的PV3D的中文学习教程请参考http://www.scile.cn/  里面写的很好很全面。

Tags:PV3D  Papervision3D  PointLight3D  

2 Comment so far

  1. xyz on 2009-2-26 14:58:44

    受教了,但是打开你首页我cpu占用达到了70%+,看来pv3d还是只能做做小东西啊...


    回复该留言
  1. 翼灵 on 2009-2-26 16:41:34

    你错了,我这个是面切的太多导致的。PV3D大的应用已经很多了。
    不过谢谢提醒,我换个CPU消耗少一点的上来


    回复该留言


Leave a reply