Notes on <Papervision 3D Essentials> - 01

Ok, it is a path which I have to go through.


cover


Chapter 2: Building your First Application


concepts-in-pv3d


This diagram illustrates the main concepts in Papervision3d, and their relationships. And the most basic PV3D program's skeleton would be:

package {
	import flash.display.Sprite;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	public class FirstApplication extends Sprite
	{
		private var scene:Scene3D;
		private var viewport:Viewport3D;
		private var camera:Camera3D;
		private var renderEngine:BasicRenderEngine;
		private var sphere:Sphere;
		public function FirstApplication()
		{
			scene = new Scene3D();
			camera = new Camera3D();
			sphere = new Sphere();
			scene.addChild(sphere);
			viewport = new Viewport3D();
			addChild(viewport);
			renderEngine = new BasicRenderEngine();
			renderEngine.renderScene(scene,camera,viewport);
		}
	}
}


And, here only one point to emphasis is that the direction of Y axis in PV3D is different from that in Actionscript.

coordination-in-pv3d



Chapter 3: Primitives

 

Most of the information is essential to Computer Graphic: triangles are basic building brick for each 3D object, and each triangle is constructed by vertices.


Each DisplayObject3D object can play a role as containers. I found that in the sample, the author use localRotationY instead of rotationY, and for the current PV3D version, that won't work,rotationY works fine, it seems that localRotationY is obsolete.


If you follow the sample at the end of this chapter, you will get a program like:

sphere-of-sphere


Chapter 4: Materials


The usage of WireframeMaterial:

package {
	import flash.display.Shape;
	import flash.display.BitmapData;
	import flash.events.Event;
	
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.objects.primitives.Cone;
	
	public class main extends BasicView
	{
		public function main()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			
			var $mat:WireframeMaterial = new WireframeMaterial(0x31D6AD, 0.5, 4);
			var cone:Cone = new Cone($mat, 800, 600);
			scene.addChild(cone);
			
		}	
		
	}
}


wireframematerial


The usage of ColorMaterial:

package {
	import flash.display.Shape;
	import flash.display.BitmapData;
	import flash.events.Event;
	
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Cone;
	
	public class main extends BasicView
	{
		public function main()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			
			var $colMat:ColorMaterial = new ColorMaterial(0x9B1FA6, 0.5);
			var cone:Cone = new Cone($colMat, 800, 600);
			scene.addChild(cone);
			
		}	
		
	}
}


colormaterial


The usage of BitmapMaterial:

package {
	import flash.display.Shape;
	import flash.display.BitmapData;
	import flash.events.Event;
	
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.primitives.Plane;
	
	public class main extends BasicView
	{
		public function main()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			var circle:Shape = new Shape();
			circle.graphics.beginFill(0xFF0000);
			circle.graphics.drawCircle(100, 100, 300);
			var bmp:BitmapData = new BitmapData(600, 600, true, 0x0);
			bmp.draw(circle);
			var material:BitmapMaterial = new BitmapMaterial(bmp);
			material.smooth = true;
			var plane:Plane = new Plane(material);
			scene.addChild(plane);
		}
			
		
	}
}


The usage of BitmapFileMaterial:

package {
	import flash.display.Shape;
	import flash.display.BitmapData;
	import flash.events.Event;
	
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.objects.primitives.Plane;
	
	public class main extends BasicView
	{
		public function main()
		{
			stage.frameRate = 40;
			init();
		}
		
		
		private function init():void
		{
			var material:BitmapFileMaterial = new BitmapFileMaterial("olegoprisco12.jpg");
			material.addEventListener(FileLoadEvent.LOAD_COMPLETE,loadComplete);
			var plane:Plane = new Plane(material,700,700,2,2);
			plane.rotationY -=20;
			scene.addChild(plane);
		}
		
		
		override protected function onRenderTick(e:Event=null):void
		{
			super.onRenderTick();
		}
		
		
		private function loadComplete(e:FileLoadEvent):void
		{
			trace("Completed loading file: " + e.file);
			startRendering();
		}
		
		
	}
}


bitmapfilematerial


The usage of MovieMaterial:

package {
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.events.Event;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.objects.primitives.Plane;
	
	public class main extends BasicView
	{
		private var plane:Plane;
		
		public function main()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			var materialSprite:Sprite = new Sprite();
			materialSprite.graphics.beginFill(0x777777);
			materialSprite.graphics.drawRect(0,0,400,400);
			
			var textfield:TextField = new TextField();
			textfield.text = "Hello 3D world!";
			textfield.autoSize = TextFieldAutoSize.LEFT;
			textfield.setTextFormat(new TextFormat("Arial",25));
			
			textfield.x = (materialSprite.width - textfield.width) / 2;
			textfield.y = (materialSprite.height - textfield.height) / 2;
			
			materialSprite.addChild(textfield);
			
			var material:MovieMaterial = new MovieMaterial(materialSprite);
			material.smooth = true;
			material.doubleSided = true;
			plane = new Plane(material);
			scene.addChild(plane);
			
			camera.zoom = 10;
			
			//trace(camera.zoom);	// 2
		}
		
		
		override protected function onRenderTick(e:Event=null):void
		{
			super.onRenderTick();
			plane.rotationY++;
		}
		
	}
}


movieMaterial-front


movieMaterial-back


The usage of MovieAssetMaterial:

The basic code skeleton is as:

package {
	
	import flash.events.Event;
	
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.MovieAssetMaterial;
	import org.papervision3d.objects.primitives.Plane;
	
	public class movieAssMatMain extends BasicView
	{
		private var plane:Plane;
		
		public function movieAssMatMain()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			var material:MovieAssetMaterial = new MovieAssetMaterial("material", false, true);
			material.doubleSided = true;
			plane = new Plane(material,500,500);
			scene.addChild(plane);
		}
		
		
		override protected function onRenderTick(e:Event=null):void
		{
			super.onRenderTick();
			plane.rotationY++;
		}
		
	}
}


movieassetmaterial


The author listed three problems with this program, as:

ProblemCause
Floating textureCaused by the movie that changes size during animation
Flickering and pixelated textCaused by skewed bitmaps
Texture distortionCaused by using a low number of segments

And then the author gave the solutions for them, but the way how it gets working has been changed due to the version advance. Let's take a close look.


I seems that the version I was using is too old: Public Alpha 2.0 - Great White, the book's examples were built with Papervision3D_2.1.920.zip, which is the second latest version I can find from official site.  With the old version, there couldn't find rect and presiceMode properties on MovieAssetMaterialclass.


This version is called: INFO: Papervision3D 2.1 rev920 (August 11th, 2009).


The lines for fixing the first 2 problems are:

material.rect = new Rectangle(0, 0, 200, 200);
material.smooth = true;


On the last problem, we can add more segment to the plane, and set its precision mode to stable:

package {
	
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.MovieAssetMaterial;
	import org.papervision3d.materials.utils.PrecisionMode;
	import org.papervision3d.objects.primitives.Plane;
	
	public class movieAssMatMain extends BasicView
	{
		private var plane:Plane;
		
		public function movieAssMatMain()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			var material:MovieAssetMaterial = new MovieAssetMaterial("material", false, true, false, true);
			material.doubleSided = true;
			material.rect = new Rectangle(0, 0, 200, 200);
			material.smooth = true;
			material.precisionMode = PrecisionMode.STABLE;
			
			plane = new Plane(material, 500, 500);
			scene.addChild(plane);
		}
		
		
		override protected function onRenderTick(e:Event=null):void
		{
			super.onRenderTick();
			plane.rotationY++;
		}
		
	}
}


The usage of VideoStreamMaterial:(skipped since I have no camera)


Combining different materials:

package {
	
	import flash.events.Event;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.special.CompositeMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	
	public class compositMain extends BasicView
	{
		private var plane:Plane;
		
		public function compositMain()
		{
			stage.frameRate = 40;
			init();
			startRendering();
		}
		
		
		private function init():void
		{
			var bmpMaterial:BitmapFileMaterial = new BitmapFileMaterial("olegoprisco12.jpg");
			var wireMaterial:WireframeMaterial = new WireframeMaterial();
			var material:CompositeMaterial = new CompositeMaterial();
			material.addMaterial(bmpMaterial);
			material.addMaterial(wireMaterial);
			plane = new Plane(material,700,700,3,3);
			scene.addChild(plane);
		}
		
		
		override protected function onRenderTick(e:Event=null):void
		{
			super.onRenderTick();
			plane.rotationY++;
		}
		
	}
}


composite-material


There is one point to notice is, the relationship between the mutual property of the composite material and each material's own setting.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值