月刊川田十夢マーカー実験
forked from FLARToolKitサンプル ロード一切なし版 (diff: 194)
AR十三兄弟オーディションにて勝手に配布された月刊川田十夢の最初のページをマーカーに出来るかなーと思って、試してみた。
ActionScript3 source code
/**
* Copyright tarotarorg ( http://wonderfl.net/user/tarotarorg )
* GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
* Downloaded from: http://wonderfl.net/c/5Uwh
*/
// forked from tarotarorg's FLARToolKitサンプル ロード一切なし版
/**
* FLARToolKit basic Sample
*
* Copyright (c) tarotarorg
*
* This work complements FLARToolkit, developed by Saqoosha as part of the Libspark project.
* http://www.libspark.org/wiki/saqoosha/FLARToolKit
* FLARToolKit is Copyright (C)2008 Saqoosha,
* and is ported from NyARToolKit, which is ported from ARToolKit.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
import flash.media.*;
import flash.net.URLRequest;
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.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.support.pv3d.*;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
public class FLARTKSample extends Sprite
{
private var _raster:FLARRgbRaster_BitmapData;
private var _detector:FLARSingleMarkerDetector;
private var _video:Video;
private var _capture:Bitmap;
private var _renderer:LazyRenderEngine;
private var _markerNode:FLARBaseNode;
private var _resultMat:FLARTransMatResult;
private const AR_SCREEN_WIDTH:int = 320;
private const AR_SCREEN_HEIGHT:int = 240;
private const SCREEN_WIDTH:int = 640;
private const SCREEN_HEIGHT:int = 480;
public function FLARTKSample()
{
var webcam:Camera = Camera.getCamera();
if (!webcam) throw new Error('No webcam!!!!');
webcam.setMode(AR_SCREEN_WIDTH, AR_SCREEN_HEIGHT, 30);
_video = new Video(AR_SCREEN_WIDTH, AR_SCREEN_HEIGHT);
_video.attachCamera(webcam);
_capture = new Bitmap(new BitmapData(AR_SCREEN_WIDTH, AR_SCREEN_HEIGHT, false, 0), PixelSnapping.AUTO, true);
_capture.width = SCREEN_WIDTH;
_capture.height = SCREEN_HEIGHT;
var code:FLARCode = new FLARCode(16, 16);
code.loadARPatt(" 20 25 121 148 57 24 23 60 67 57 28 41 35 30 44 52\r\n" +
" 21 20 45 58 85 48 42 115 27 42 45 25 69 47 23 23\r\n" +
" 37 15 29 131 119 45 104 141 60 42 23 22 49 34 21 23\r\n" +
" 26 54 66 72 72 38 36 43 40 29 18 18 21 26 20 20\r\n" +
" 17 73 60 35 39 62 19 20 20 19 19 19 19 19 19 22\r\n" +
" 34 54 60 113 106 38 18 19 19 18 19 19 19 19 19 20\r\n" +
" 95 117 56 199 179 67 20 18 18 19 19 19 19 19 19 18\r\n" +
" 97 146 83 80 205 108 20 19 18 19 19 18 18 18 17 19\r\n" +
" 65 75 43 96 206 120 20 19 19 18 17 18 18 19 20 20\r\n" +
" 79 32 27 19 204 126 19 19 18 17 19 37 22 18 17 22\r\n" +
" 190 33 27 42 210 104 20 19 19 18 19 28 22 123 124 24\r\n" +
" 51 28 39 32 122 55 19 25 22 19 19 44 22 29 25 15\r\n" +
" 19 60 35 34 33 22 21 35 26 30 19 55 23 74 22 22\r\n" +
" 18 49 66 27 128 126 81 110 35 26 19 119 36 62 38 24\r\n" +
" 77 90 70 35 122 96 66 88 39 21 39 104 104 47 58 51\r\n" +
" 36 41 40 20 116 113 14 125 97 86 62 65 63 56 20 27\r\n" +
" 27 31 112 135 51 31 32 81 96 85 46 59 82 74 127 145\r\n" +
" 28 28 46 52 87 48 55 143 56 71 61 33 108 87 32 32\r\n" +
" 68 23 34 114 107 41 128 178 100 69 29 29 65 46 30 31\r\n" +
" 74 47 73 76 72 40 44 55 49 37 26 29 31 34 28 29\r\n" +
" 32 97 90 50 57 89 27 26 27 26 27 27 26 26 27 28\r\n" +
" 47 76 90 136 119 53 26 26 27 26 26 26 26 26 26 26\r\n" +
" 104 127 63 200 186 78 28 26 26 26 26 26 26 25 25 27\r\n" +
" 98 174 162 102 215 115 27 26 26 26 26 26 26 26 26 26\r\n" +
" 90 126 104 134 221 130 27 26 26 25 25 25 25 26 27 27\r\n" +
" 114 55 59 29 220 134 27 26 26 25 26 68 44 25 24 29\r\n" +
" 200 58 63 55 223 111 28 26 26 25 27 46 32 139 212 90\r\n" +
" 50 35 70 39 128 62 27 35 29 26 27 59 28 33 53 64\r\n" +
" 26 46 54 30 48 37 28 42 37 36 26 70 31 90 29 29\r\n" +
" 26 34 60 30 154 161 150 137 51 33 26 133 38 73 48 31\r\n" +
" 71 90 95 40 140 172 213 132 58 28 46 108 93 46 59 51\r\n" +
" 47 69 69 30 144 187 42 130 103 83 56 62 58 51 27 32\r\n" +
" 34 45 182 183 97 38 40 146 191 188 91 106 162 164 195 200\r\n" +
" 35 36 79 105 132 91 71 196 163 170 181 176 163 166 179 175\r\n" +
" 78 33 64 195 169 91 151 223 188 167 179 183 134 147 185 178\r\n" +
" 80 59 93 118 117 66 52 67 68 64 74 66 60 60 80 75\r\n" +
" 48 121 128 74 83 119 35 34 35 34 34 35 34 35 35 36\r\n" +
" 67 90 118 176 160 119 37 34 34 34 34 34 34 34 35 35\r\n" +
" 131 149 73 208 211 112 35 34 34 34 34 34 34 34 35 35\r\n" +
" 114 190 173 111 220 146 35 34 33 34 34 34 34 34 34 34\r\n" +
" 115 137 124 138 224 137 35 34 34 33 33 33 33 34 35 34\r\n" +
" 154 81 107 44 221 140 33 33 33 32 33 84 54 34 34 37\r\n" +
" 202 83 129 69 224 116 35 34 34 33 35 91 53 147 223 99\r\n" +
" 58 54 113 51 131 78 34 54 44 34 33 82 42 42 58 70\r\n" +
" 34 55 56 39 83 90 36 67 67 45 33 81 42 101 38 37\r\n" +
" 34 42 76 40 180 198 169 158 67 41 33 144 55 90 67 39\r\n" +
" 81 104 114 49 171 187 218 145 74 38 57 125 158 109 75 68\r\n" +
" 57 107 90 39 184 203 58 176 152 137 109 129 128 112 37 49\r\n" +
"\r\n" +
" 52 23 23 20 22 20 18 19 20 22 24 15 22 24 51 27\r\n" +
" 44 23 21 20 19 19 19 17 20 17 124 25 22 38 58 20\r\n" +
" 30 47 34 26 19 19 19 18 19 18 123 29 74 62 47 56\r\n" +
" 35 69 49 21 19 19 19 18 18 22 22 22 23 36 104 63\r\n" +
" 41 25 22 18 19 19 19 18 18 37 28 44 55 119 104 65\r\n" +
" 28 45 23 18 19 19 19 19 17 19 19 19 19 19 39 62\r\n" +
" 57 42 42 29 19 18 19 19 18 17 18 19 30 26 21 86\r\n" +
" 67 27 60 40 20 19 18 18 19 18 19 22 26 35 39 97\r\n" +
" 60 115 141 43 20 19 18 19 19 19 19 25 35 110 88 125\r\n" +
" 23 42 104 36 19 18 20 20 20 19 20 19 21 81 66 14\r\n" +
" 24 48 45 38 62 38 67 108 120 126 104 55 22 126 96 113\r\n" +
" 57 85 119 72 39 106 179 205 206 204 210 122 33 128 122 116\r\n" +
" 148 58 131 72 35 113 199 80 96 19 42 32 34 27 35 20\r\n" +
" 121 45 29 66 60 60 56 83 43 27 27 39 35 66 70 40\r\n" +
" 25 20 15 54 73 54 117 146 75 32 33 28 60 49 90 41\r\n" +
" 20 21 37 26 17 34 95 97 65 79 190 51 19 18 77 36\r\n" +
" 145 32 31 29 28 26 27 26 27 29 90 64 29 31 51 32\r\n" +
" 127 32 30 28 27 26 25 26 27 24 212 53 29 48 59 27\r\n" +
" 74 87 46 34 26 26 25 26 26 25 139 33 90 73 46 51\r\n" +
" 82 108 65 31 26 26 26 26 25 44 32 28 31 38 93 58\r\n" +
" 59 33 29 29 27 26 26 26 25 68 46 59 70 133 108 62\r\n" +
" 46 61 29 26 27 26 26 26 25 26 27 27 26 26 46 56\r\n" +
" 85 71 69 37 26 26 26 26 25 25 25 26 36 33 28 83\r\n" +
" 96 56 100 49 27 27 26 26 26 26 26 29 37 51 58 103\r\n" +
" 81 143 178 55 26 26 26 26 26 26 26 35 42 137 132 130\r\n" +
" 32 55 128 44 27 26 28 27 27 27 28 27 28 150 213 42\r\n" +
" 31 48 41 40 89 53 78 115 130 134 111 62 37 161 172 187\r\n" +
" 51 87 107 72 57 119 186 215 221 220 223 128 48 154 140 144\r\n" +
" 135 52 114 76 50 136 200 102 134 29 55 39 30 30 40 30\r\n" +
" 112 46 34 73 90 90 63 162 104 59 63 70 54 60 95 69\r\n" +
" 31 28 23 47 97 76 127 174 126 55 58 35 46 34 90 69\r\n" +
" 27 28 68 74 32 47 104 98 90 114 200 50 26 26 71 47\r\n" +
" 200 175 178 75 36 35 35 34 34 37 99 70 37 39 68 49\r\n" +
" 195 179 185 80 35 35 35 34 35 34 223 58 38 67 75 37\r\n" +
" 164 166 147 60 35 34 34 34 34 34 147 42 101 90 109 112\r\n" +
" 162 163 134 60 34 34 34 34 33 54 53 42 42 55 158 128\r\n" +
" 106 176 183 66 35 34 34 34 33 84 91 82 81 144 125 129\r\n" +
" 91 181 179 74 34 34 34 34 33 33 35 33 33 33 57 109\r\n" +
" 188 170 167 64 34 34 34 34 33 32 33 34 45 41 38 137\r\n" +
" 191 163 188 68 35 34 34 33 34 33 34 44 67 67 74 152\r\n" +
" 146 196 223 67 34 34 34 34 34 33 34 54 67 158 145 176\r\n" +
" 40 71 151 52 35 37 35 35 35 33 35 34 36 169 218 58\r\n" +
" 38 91 91 66 119 119 112 146 137 140 116 78 90 198 187 203\r\n" +
" 97 132 169 117 83 160 211 220 224 221 224 131 83 180 171 184\r\n" +
" 183 105 195 118 74 176 208 111 138 44 69 51 39 40 49 39\r\n" +
" 182 79 64 93 128 118 73 173 124 107 129 113 56 76 114 90\r\n" +
" 45 36 33 59 121 90 149 190 137 81 83 54 55 42 104 107\r\n" +
" 34 35 78 80 48 67 131 114 115 154 202 58 34 34 81 57\r\n" +
"\r\n" +
" 27 20 56 63 65 62 86 97 125 14 113 116 20 40 41 36\r\n" +
" 51 58 47 104 104 39 21 39 88 66 96 122 35 70 90 77\r\n" +
" 24 38 62 36 119 19 26 35 110 81 126 128 27 66 49 18\r\n" +
" 22 22 74 23 55 19 30 26 35 21 22 33 34 35 60 19\r\n" +
" 15 25 29 22 44 19 19 22 25 19 55 122 32 39 28 51\r\n" +
" 24 124 123 22 28 19 18 19 19 20 104 210 42 27 33 190\r\n" +
" 22 17 18 22 37 19 17 18 19 19 126 204 19 27 32 79\r\n" +
" 20 20 19 18 18 17 18 19 19 20 120 206 96 43 75 65\r\n" +
" 19 17 18 18 18 19 19 18 19 20 108 205 80 83 146 97\r\n" +
" 18 19 19 19 19 19 19 18 18 20 67 179 199 56 117 95\r\n" +
" 20 19 19 19 19 19 18 19 19 18 38 106 113 60 54 34\r\n" +
" 22 19 19 19 19 19 19 20 20 19 62 39 35 60 73 17\r\n" +
" 20 20 26 21 18 18 29 40 43 36 38 72 72 66 54 26\r\n" +
" 23 21 34 49 22 23 42 60 141 104 45 119 131 29 15 37\r\n" +
" 23 23 47 69 25 45 42 27 115 42 48 85 58 45 20 21\r\n" +
" 52 44 30 35 41 28 57 67 60 23 24 57 148 121 25 20\r\n" +
" 32 27 51 58 62 56 83 103 130 42 187 144 30 69 69 47\r\n" +
" 51 59 46 93 108 46 28 58 132 213 172 140 40 95 90 71\r\n" +
" 31 48 73 38 133 26 33 51 137 150 161 154 30 60 34 26\r\n" +
" 29 29 90 31 70 26 36 37 42 28 37 48 30 54 46 26\r\n" +
" 64 53 33 28 59 27 26 29 35 27 62 128 39 70 35 50\r\n" +
" 90 212 139 32 46 27 25 26 26 28 111 223 55 63 58 200\r\n" +
" 29 24 25 44 68 26 25 26 26 27 134 220 29 59 55 114\r\n" +
" 27 27 26 25 25 25 25 26 26 27 130 221 134 104 126 90\r\n" +
" 26 26 26 26 26 26 26 26 26 27 115 215 102 162 174 98\r\n" +
" 27 25 25 26 26 26 26 26 26 28 78 186 200 63 127 104\r\n" +
" 26 26 26 26 26 26 26 27 26 26 53 119 136 90 76 47\r\n" +
" 28 27 26 26 27 27 26 27 26 27 89 57 50 90 97 32\r\n" +
" 29 28 34 31 29 26 37 49 55 44 40 72 76 73 47 74\r\n" +
" 31 30 46 65 29 29 69 100 178 128 41 107 114 34 23 68\r\n" +
" 32 32 87 108 33 61 71 56 143 55 48 87 52 46 28 28\r\n" +
" 145 127 74 82 59 46 85 96 81 32 31 51 135 112 31 27\r\n" +
" 49 37 112 128 129 109 137 152 176 58 203 184 39 90 107 57\r\n" +
" 68 75 109 158 125 57 38 74 145 218 187 171 49 114 104 81\r\n" +
" 39 67 90 55 144 33 41 67 158 169 198 180 40 76 42 34\r\n" +
" 37 38 101 42 81 33 45 67 67 36 90 83 39 56 55 34\r\n" +
" 70 58 42 42 82 33 34 44 54 34 78 131 51 113 54 58\r\n" +
" 99 223 147 53 91 35 33 34 34 35 116 224 69 129 83 202\r\n" +
" 37 34 34 54 84 33 32 33 33 33 140 221 44 107 81 154\r\n" +
" 34 35 34 33 33 33 33 34 34 35 137 224 138 124 137 115\r\n" +
" 34 34 34 34 34 34 34 33 34 35 146 220 111 173 190 114\r\n" +
" 35 35 34 34 34 34 34 34 34 35 112 211 208 73 149 131\r\n" +
" 35 35 34 34 34 34 34 34 34 37 119 160 176 118 90 67\r\n" +
" 36 35 35 34 35 34 34 35 34 35 119 83 74 128 121 48\r\n" +
" 75 80 60 60 66 74 64 68 67 52 66 117 118 93 59 80\r\n" +
" 178 185 147 134 183 179 167 188 223 151 91 169 195 64 33 78\r\n" +
" 175 179 166 163 176 181 170 163 196 71 91 132 105 79 36 35\r\n" +
" 200 195 164 162 106 91 188 191 146 40 38 97 183 182 45 34\r\n" +
"\r\n" +
" 36 77 18 19 51 190 79 65 97 95 34 17 26 37 21 20\r\n" +
" 41 90 49 60 28 33 32 75 146 117 54 73 54 15 20 25\r\n" +
" 40 70 66 35 39 27 27 43 83 56 60 60 66 29 45 121\r\n" +
" 20 35 27 34 32 42 19 96 80 199 113 35 72 131 58 148\r\n" +
" 116 122 128 33 122 210 204 206 205 179 106 39 72 119 85 57\r\n" +
" 113 96 126 22 55 104 126 120 108 67 38 62 38 45 48 24\r\n" +
" 14 66 81 21 19 20 19 20 20 20 18 19 36 104 42 23\r\n" +
" 125 88 110 35 25 19 19 19 19 18 19 20 43 141 115 60\r\n" +
" 97 39 35 26 22 19 18 19 18 18 19 20 40 60 27 67\r\n" +
" 86 21 26 30 19 18 17 18 19 19 18 19 29 42 42 57\r\n" +
" 62 39 19 19 19 19 19 17 19 19 19 19 18 23 45 28\r\n" +
" 65 104 119 55 44 28 37 18 18 19 19 19 18 22 25 41\r\n" +
" 63 104 36 23 22 22 22 18 18 19 19 19 21 49 69 35\r\n" +
" 56 47 62 74 29 123 18 19 18 19 19 19 26 34 47 30\r\n" +
" 20 58 38 22 25 124 17 20 17 19 19 19 20 21 23 44\r\n" +
" 27 51 24 22 15 24 22 20 19 18 20 22 20 23 23 52\r\n" +
" 47 71 26 26 50 200 114 90 98 104 47 32 74 68 28 27\r\n" +
" 69 90 34 46 35 58 55 126 174 127 76 97 47 23 28 31\r\n" +
" 69 95 60 54 70 63 59 104 162 63 90 90 73 34 46 112\r\n" +
" 30 40 30 30 39 55 29 134 102 200 136 50 76 114 52 135\r\n" +
" 144 140 154 48 128 223 220 221 215 186 119 57 72 107 87 51\r\n" +
" 187 172 161 37 62 111 134 130 115 78 53 89 40 41 48 31\r\n" +
" 42 213 150 28 27 28 27 27 27 28 26 27 44 128 55 32\r\n" +
" 130 132 137 42 35 26 26 26 26 26 26 26 55 178 143 81\r\n" +
" 103 58 51 37 29 26 26 26 26 26 27 27 49 100 56 96\r\n" +
" 83 28 33 36 26 25 25 25 26 26 26 26 37 69 71 85\r\n" +
" 56 46 26 26 27 27 26 25 26 26 26 27 26 29 61 46\r\n" +
" 62 108 133 70 59 46 68 25 26 26 26 27 29 29 33 59\r\n" +
" 58 93 38 31 28 32 44 25 26 26 26 26 31 65 108 82\r\n" +
" 51 46 73 90 33 139 25 26 26 25 26 26 34 46 87 74\r\n" +
" 27 59 48 29 53 212 24 27 26 25 26 27 28 30 32 127\r\n" +
" 32 51 31 29 64 90 29 27 26 27 26 28 29 31 32 145\r\n" +
" 57 81 34 34 58 202 154 115 114 131 67 48 80 78 35 34\r\n" +
" 107 104 42 55 54 83 81 137 190 149 90 121 59 33 36 45\r\n" +
" 90 114 76 56 113 129 107 124 173 73 118 128 93 64 79 182\r\n" +
" 39 49 40 39 51 69 44 138 111 208 176 74 118 195 105 183\r\n" +
" 184 171 180 83 131 224 221 224 220 211 160 83 117 169 132 97\r\n" +
" 203 187 198 90 78 116 140 137 146 112 119 119 66 91 91 38\r\n" +
" 58 218 169 36 34 35 33 35 35 35 37 35 52 151 71 40\r\n" +
" 176 145 158 67 54 34 33 34 34 34 34 34 67 223 196 146\r\n" +
" 152 74 67 67 44 34 33 34 33 34 34 35 68 188 163 191\r\n" +
" 137 38 41 45 34 33 32 33 34 34 34 34 64 167 170 188\r\n" +
" 109 57 33 33 33 35 33 33 34 34 34 34 74 179 181 91\r\n" +
" 129 125 144 81 82 91 84 33 34 34 34 35 66 183 176 106\r\n" +
" 128 158 55 42 42 53 54 33 34 34 34 34 60 134 163 162\r\n" +
" 112 109 90 101 42 147 34 34 34 34 34 35 60 147 166 164\r\n" +
" 37 75 67 38 58 223 34 35 34 35 35 35 80 185 179 195\r\n" +
" 49 68 39 37 70 99 37 34 34 35 35 36 75 178 175 200\r\n");
var param:FLARParam = new FLARParam();
param.changeScreenSize(AR_SCREEN_WIDTH, AR_SCREEN_HEIGHT);
_raster = new FLARRgbRaster_BitmapData(_capture.bitmapData);
_resultMat = new FLARTransMatResult();
_detector = new FLARSingleMarkerDetector(param, code, 80);
_detector.setContinueMode(true);
var base:Sprite = addChild(new Sprite()) as Sprite;
base.addChild(_capture);
var viewport:Viewport3D = base.addChild(new Viewport3D(AR_SCREEN_WIDTH, AR_SCREEN_HEIGHT)) as Viewport3D;
viewport.scaleX = SCREEN_WIDTH / AR_SCREEN_WIDTH;
viewport.scaleY = SCREEN_HEIGHT / AR_SCREEN_HEIGHT;
viewport.x = -4;
var camera3d:FLARCamera3D = new FLARCamera3D(param);
var scene:Scene3D = new Scene3D();
_markerNode = scene.addChild(new FLARBaseNode()) as FLARBaseNode;
var light:PointLight3D = new PointLight3D();
light.x = 0;
light.y = 1000;
light.z = -1000;
var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x75104e);
var cube:Cube = new Cube(new MaterialsList( { all:fmat } ), 40, 40, 40);
cube.z = 20;
_markerNode.addChild(cube);
_renderer = new LazyRenderEngine(scene, camera3d, viewport);
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
private function _onEnterFrame(e:Event = null):void {
_capture.bitmapData.draw(_video);
try {
if (_detector.detectMarkerLite(_raster, 80) && _detector.getConfidence() > 0.5) {
_detector.getTransformMatrix(_resultMat);
_markerNode.setTransformMatrix(_resultMat);
_markerNode.visible = true;
} else {
_markerNode.visible = false;
}
} catch (e:Error) {}
_renderer.render();
}
}
}
