FLARToolKit demo Rasengan from NARUTO

Source of main class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.tarotaro.flash.ar 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.GlowFilter;
	import flash.media.Camera;
	import flash.media.Video;
	import flash.utils.ByteArray;
	import org.libspark.flartoolkit.core.FLARCode;
	import org.libspark.flartoolkit.core.param.FLARParam;
	import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
	import org.libspark.flartoolkit.core.raster.rgb.IFLARRgbRaster;
	import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
	import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
	import org.libspark.flartoolkit.pv3d.FLARBaseNode;
	import org.libspark.flartoolkit.pv3d.FLARCamera3D;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.render.LazyRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	import org.tarotaro.flash.pv3d.Rasengan;
 
	/**
	 * FLARToolKit demo
	 * @author tarotarorg
	 */
	[SWF(width="640", height="480", backgroundColor="0xFFFFFF", frameRate="30")]
	public class FLARasengan extends Sprite
	{
		[Embed(source = "assets/camera_para.dat", mimeType = "application/octet-stream")]
		private var CParam:Class;
		[Embed(source = "assets/naruto16.pat", mimeType = "application/octet-stream")]
		private var CodeData:Class;
 
		private var _capture:Bitmap;
		private var _video:Video;
 
		protected var _detector:FLARSingleMarkerDetector;
		protected var _resultMat:FLARTransMatResult;
		protected var _confidence:Number;
		protected var _source:IFLARRgbRaster;
		protected var _thresh:int;
 
		private var _rasen:Rasengan;
		protected var _viewport:Viewport3D;
		protected var _camera3d:FLARCamera3D;
		protected var _scene:Scene3D;
		protected var _renderer:LazyRenderEngine;
		protected var _baseNode:FLARBaseNode;
 
		public function FLARasengan() 
		{
			var param:FLARParam = new FLARParam();
			param.loadARParam(new CParam() as ByteArray);
			param.changeScreenSize(320, 240);
			var code:FLARCode = new FLARCode(16, 16, 90, 90);
			var codeFile:ByteArray = new CodeData() as ByteArray;
			code.loadARPatt(codeFile.readMultiByte(codeFile.length, "shift-jis"));
 
 
			this._detector = new FLARSingleMarkerDetector(param, code, 80);
			this._resultMat = new FLARTransMatResult();
			this._confidence = 0.3;
			this._thresh = 75;
 
			this._capture = new Bitmap(new BitmapData(320, 240, false, 0), PixelSnapping.AUTO, true);
			this._capture.scaleX = this._capture.scaleY = 2;
			this._source = new FLARRgbRaster_BitmapData(this._capture.bitmapData);
 
			var webcam:Camera = Camera.getCamera();
			if (!webcam) {
				return;
			}
			webcam.setMode(320, 240, 30);
			this._video = new Video();
			this._video.attachCamera(webcam);
 
			this.addChild(this._capture);
 
			this._viewport = new Viewport3D(320, 240);
			this._viewport.scaleX = 2;
			this._viewport.scaleY = 2;
			this._viewport.x = -4; // 4pix ???
			this._viewport.filters = [new GlowFilter(0x000000, 1, 4, 4, 10)];
			this._camera3d = new FLARCamera3D(param);
			this._scene = new Scene3D();
			this._baseNode = this._scene.addChild(new FLARBaseNode()) as FLARBaseNode;
			this._renderer = new LazyRenderEngine(this._scene, this._camera3d, this._viewport);
 
			this.addChild(this._viewport);
 
			this._rasen = new Rasengan(5, 2, 5, 25, 3, 1, new PointLight3D(),
									   0xCCCCFF, 0xCCCCFF, 0xFFFFCC, 0xFFFFFF);
			this._baseNode.addChild(_rasen);
 
			this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
 
		private function onEnterFrame(e:Event):void 
		{
			this._capture.bitmapData.draw(this._video);
			if (this._detector.detectMarkerLite(this._source, 80)) {
				var conf:Number = this._detector.getConfidence();
				if (conf > 0.3) {
					this._detector.getTransformMatrix(this._resultMat);
					this._baseNode.setTransformMatrix(this._resultMat);
					this._baseNode.visible = true;
 
					this._rasen.sizeMin = 25 * conf;
					this._rasen.z = 25 * conf + 20;
					this._rasen.draw();
				} else {
					this._baseNode.visible = false;
				}
			} else {
				this._baseNode.visible = false;
			}
			this._renderer.render();
		}
 
	}
 
}
Ads

Ad

Ad

Share

  • Add this article to hatena bookmark
  • 0

Follow

Ads

Ad

Comments

  1. i watch Naruto series after going to school. i love the action and powers of naruto.”;`

Leave a Comment

Your email address will not be published. Required fields are marked *