PV3D之光影篇PointLight3D
最后一篇PV3D之光影篇,现学现卖。
- package
- {
- import org.papervision3d.core.proto.MaterialObject3D;
- import org.papervision3d.lights.PointLight3D;
- import org.papervision3d.materials.shadematerials.*;
- import org.papervision3d.materials.*;
- import org.papervision3d.materials.shaders.*;
- import org.papervision3d.objects.DisplayObject3D;
- import org.papervision3d.objects.primitives.Sphere;
- public class ExampleforPointLight3D extends PaperBase
- {
- private var sphere1:Sphere;
- private var sphere2:Sphere;
- private var sphere3:Sphere;
- private var sphere4:Sphere;
- private var sphereGroup:DisplayObject3D;//用一个do3d盛放这四个Sphere
- private static const ORBITAL_RADIUS=200;
- public function ExampleforPointLight3D():void
- {
- init(600,450);
- }
- override protected function init3d():void
- {
- var light:PointLight3D=new PointLight3D(true);//括号内为true表示光源可见
- light.x=0;
- light.y=300;
- light.z=-400;//光源的3D坐标
- //下面分别用到了3种阴影材质,不同的材质表现出来的效果都不一样
- //产生光影的方法只需要将带有光源的阴影材质放入Sphere
- var gouraudMaterial:MaterialObject3D = new GouraudMaterial(light, 0x6654FF, 0x060433);
- sphere1 = new Sphere(gouraudMaterial, 50, 10, 10);
- 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;
- //如果要贴上指定位图并也要产生光影
- //我们就需要制作一个Shader 和一个BitmapMaterial 用ShadedMaterial来将他们混合到一起
- var bitmapMaterial:BitmapMaterial=new BitmapAssetMaterial("BitmapImage");
- var shader:Shader = new PhongShader(light, 0xFFFFFF, 0x333333, 50);
- var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader);
- sphere4 = new Sphere(shadedMaterial, 150, 20, 20);
- sphere4.x = -ORBITAL_RADIUS;
- sphereGroup = new DisplayObject3D();
- sphereGroup.addChild(sphere1);
- sphereGroup.addChild(sphere2);
- sphereGroup.addChild(sphere3);
- sphereGroup.addChild(sphere4);
- default_scene.addChild(sphereGroup);
- default_scene.addChild(light);
- }
- override protected function processFrame():void
- {
- sphere1.yaw(-8);
- sphere2.yaw(-8);
- sphere3.yaw(-8);
- sphere4.yaw(-8);
- sphereGroup.yaw(3);
- }
- }
- }
有关PV3D方面的学习笔记 至此就告一段落了。
更多更好的PV3D的中文学习教程请参考http://www.scile.cn/ 里面写的很好很全面。
受教了,但是打开你首页我cpu占用达到了70%+,看来pv3d还是只能做做小东西啊...
回复该留言