アナグリフのカラー対応をしてみた。
理屈としては単純で、red一色のディスプレイオブジェクトと、green,blue二色のディスプレイオブジェクトを用意すればいい。
こんなかんじ
1 2 3 4 5 |
//赤用のディスプレイオブジェクト redView.transform.colorTransform = new ColorTransform(1,0,0,1,0,0,0,0); //青用のディスプレイオブジェクト blueView.transform.colorTransform = new ColorTransform(0,1,1,1,0,0,0,0); blueView.blendMode = "screen"; |
▼Wonderfl
▼参考
アナグリフの問題
http://www.geocities.jp/sasagelab/stereo36.html
製作(H1) anaglyph,画像色
http://www2.aimnet.ne.jp/nakahara/3dart/3seisak12.html
▼ActionScript AS3(FP9)
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
/** * * アナグリフのカラー対応をしてみた。 * 理屈としては単純で、red一色のディスプレイオブジェクトと、 * green,blue二色のディスプレイオブジェクトを用意すればいい。 * * 赤用のディスプレイオブジェクト * redView.transform.colorTransform = new ColorTransform(1,0,0,1,0,0,0,0); * 青用のディスプレイオブジェクト * blueView.transform.colorTransform = new ColorTransform(0,1,1,1,0,0,0,0); * blueView.blendMode = "screen"; * * * * 参考 * アナグリフの問題 * http://www.geocities.jp/sasagelab/stereo36.html * * 摩訶不思議な世界・3Dアート * http://www2.aimnet.ne.jp/nakahara/3dart/3art.html * * * forked from * Papervision3Dで被写界深度 * 参照: http://clockmaker.jp/blog/2008/07/pv3d_gw_blur/ */ package { import flash.display.*; import flash.events.*; import flash.filters.*; import flash.geom.ColorTransform; import flash.display.BitmapData; [SWF(width = "465", height = "465", frameRate = "30", backgroundColor = "#000000")] public class Test2 extends Sprite { private var loadFiles_array:Array; private var MultiLoader:MultiLoaderClass = new MultiLoaderClass("http://mztm.jp/crossdomain.xml"); private var data_xml:XML; /** * Constructor */ public function Test2() { loadFiles_array = MultiLoader.setLoad(["http://mztm.jp/wonderfl/3d/arss/data.xml"], onXMLComp); } private function onXMLComp(e:*):void { var i:int; var jpg_array:Array = new Array(); data_xml = XML(loadFiles_array[0].data); var _length:int = data_xml.items.item.length(); for (i = 10; i < 30; i++) { if(data_xml.items.item[i].jpg != ""){ var _array:Array = String(data_xml.items.item[i].jpg).split('/'); var jpg_url:String = "http://mztm.jp/wonderfl/3d/arss/revolution/"+_array.pop(); jpg_url = jpg_url.replace(/%/g,''); jpg_array.push(jpg_url); } } loadFiles_array = new Array(); loadFiles_array = MultiLoader.setLoad(jpg_array, onComp); } private function onComp(e:* = null):void { var bitmap_array:Array = new Array(); for (var i:int = 0; i < 20; i++) { bitmap_array[i] = new BitmapData(150, 150,false); bitmap_array[i].draw(loadFiles_array[i]); } var redView:View = new View(true,bitmap_array); redView.transform.colorTransform = new ColorTransform(1,0,0,1,0,0,0,0); addChild(redView); var blueView:View = new View(false,bitmap_array); blueView.transform.colorTransform = new ColorTransform(0,1,1,1,0,0,0,0); blueView.blendMode = "screen"; addChild(blueView); addEventListener(Event.ENTER_FRAME, ENTER_FRAME); function ENTER_FRAME(event:Event = null):void { var mouseX:Number = Math.min(Math.max(stage.mouseX, 0), stage.stageWidth) - stage.stageWidth / 2; redView.loop(mouseX); blueView.loop(mouseX); } } } } import flash.display.*; import flash.events.*; import flash.filters.*; import org.papervision3d.view.*; import org.papervision3d.materials.*; import org.papervision3d.objects.*; import org.papervision3d.objects.primitives.* import org.papervision3d.core.effects.BitmapColorEffect; class View extends BasicView { // const vars static private const OBJ_LENGTH :int = 12; static private const CIRCLE_RANGE :int = 400; // 3d vars private var list :Array = [] private var wrap :DisplayObject3D; /** * Constructor */ public function View(isRed:Boolean,bitmap_array:Array) { //camera if(isRed){ camera.x = 30; camera.rotationY = -1; }else{ camera.x = -30; camera.rotationY = 1; } camera.y = 10; camera.z = 800; // wrap wrap = new DisplayObject3D(); wrap.localRotationX = -15; scene.addChild(wrap); for (var i:int = 0; i < OBJ_LENGTH; i++) { var rot:Number = 360 * i / OBJ_LENGTH ; var m:BitmapMaterial = new BitmapMaterial(bitmap_array[i]); m.doubleSided = true; var o:Plane = new Plane(m, 150, 150); o.x = CIRCLE_RANGE * Math.sin(rot * Math.PI / 180); o.y = 0; o.z = CIRCLE_RANGE * Math.cos(rot * Math.PI / 180); o.rotationY = rot+180; o.useOwnContainer = true; //ココ重要 var bce:BitmapColorEffect = new BitmapColorEffect(0); // 配列に追加 & wrapの子供にする list.push(wrap.addChild(o)); } startRendering(); } public function loop(num:Number):void { wrap.yaw(num/300); // 被写界深度 for (var i:int = 0; i < list.length; i++) { var o:DisplayObject3D = list[i] as DisplayObject3D; var blur:Number = Math.ceil((CIRCLE_RANGE - o.sceneZ) / 50); o.filters = [new BlurFilter(blur, blur, 2)]; } } } class MultiLoaderClass extends Sprite{ import flash.system.Security; import flash.net.URLRequest; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.events.Event; import flash.events.IOErrorEvent; import flash.display.Loader; //import flash.display.LoaderInfo; private var onComplete:Function = function(arg:Array=null):void{}; //private var onOpen:Function = function():void{}; private var loadNum:int; private var loadCompNum:int; private var error_array:Array = new Array(); private var URLs_array:Array = new Array(); public var _uniqueParam:String = ""; public function set uniqueParam(uStr:String):void { if (uStr) { if (uStr.substr(0,2) == "?=") { _uniqueParam = uStr; }else { _uniqueParam = "?=" + uStr; } }else { _uniqueParam = ""; } } public function get uniqueParam():String { return _uniqueParam; } public function MultiLoaderClass(_str:String = null,uStr:String = null){ if(_str){ Security.loadPolicyFile(_str); } uniqueParam = uStr; } public function setLoad(__item_array:Array = null, _onComp:Function = null):Array { //trace(__item_array) loadCompNum = loadNum = 0; if(_onComp != null){ onComplete = _onComp; } if (__item_array.length == 0) { loadNum ++; onComplete(); } URLs_array = __item_array.concat(); error_array = new Array(); //trace(__item_array.length) //onOpen = _onOpen; var _array:Array = new Array(); var _length:int = __item_array.length; for (var i:int = 0; i < _length; i++) { error_array[i] = false; if (__item_array[i] == null) { continue }; var _extension:String = __item_array[i].substr(-4,4).toLowerCase();//拡張子を取り出す。 if (_extension == ".xml" || _extension == "html") { //trace("**",__item_array[i]); loadNum ++; _array[i] = fnURLLoader(__item_array[i] + uniqueParam); }else if(_extension == ".jpg" || _extension == ".gif" || _extension == ".png" || _extension == ".swf"){ loadNum ++; _array[i] = img(__item_array[i] + uniqueParam); }else if(_extension == ".bin"){ loadNum ++; __item_array[i] = __item_array[i].substr(0, __item_array[i].length - 4); _array[i] = binaryFromURL(__item_array[i] + uniqueParam); }else{ //_array[i] = null; } } return _array; } private function binaryFromURL(__url:String):URLLoader{ var _loader:URLLoader = new URLLoader(); _loader.dataFormat = URLLoaderDataFormat.BINARY; _loader.addEventListener(Event.COMPLETE,completeHandler); _loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); _loader.load(new URLRequest(__url)); return _loader; } private function fnURLLoader(__url:String):URLLoader{ var _loader:URLLoader = new URLLoader(); _loader.addEventListener(Event.COMPLETE,completeHandler); _loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); //_loader.addEventListener(Event.OPEN,openHandler); _loader.load(new URLRequest(__url)); //trace(_loader.loaderInfo);//.loaderURL return _loader; } private function img(__url:String):Loader{ var _loader:Loader = new Loader(); _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); //_loader.contentLoaderInfo.addEventListener(Event.OPEN,openHandler); _loader.load(new URLRequest(__url)); //_loader.name = __url; return _loader; } private function completeHandler(event:Event = null):void { loadCompNum ++; if(loadCompNum == loadNum){ onComplete(error_array); } //var loaderInfo:LoaderInfo=event.currentTarget as LoaderInfo; //var loader:Loader=loaderInfo.loader; //addChild(loader); } private function openHandler (event:Event):void { if(Math.random()>0.95){ trace ("読み込みを開始した"); //event.currentTarget.contentLoaderInfo.close(); var str:String = event.currentTarget.toString().substr(8); if(str == "LoaderInfo]"){ //event.currentTarget.contentLoaderInfo.close(); //event.target.contentLoaderInfo.close(); //event.currentTarget.close(); //event.target.close(); }else if(str == "URLLoader]"){ event.currentTarget.close(); completeHandler(); } //completeHandler(); //onOpen(); } } private function ioErrorHandler(event:IOErrorEvent):void { //event.text = "Error #2035: URL が見つかりません。 URL: file:///~~~~~"; //event.text = "Error #2036: 読み込みが未完了です。 URL: http://~~~~~"; //から、URLのみを取り出す。 //trace(String(event.text).substr(String(event.text).indexOf(" URL: ")+6),"*****"); for (var i:int = 0; i < URLs_array.length; i++) { var _str:String = String(event.text).substr(String(event.text).indexOf(" URL: ")+6).substr(-URLs_array[i].length); if(URLs_array[i] == _str){ error_array[i] = true; //trace("これだ",i,_str) } } //URLs_array completeHandler(); } } |