Changeset 14858
- Timestamp:
- 06/29/08 22:09:50 (5 years ago)
- Location:
- lang/actionscript/gmapkmz/exl/render/collada
- Files:
-
- 5 modified
-
DAEFace.as (modified) (2 diffs)
-
DAEMaterial.as (modified) (1 diff)
-
DAEModel.as (modified) (9 diffs)
-
DAEModelRenderer.as (modified) (7 diffs)
-
DAEVertex.as (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/gmapkmz/exl/render/collada/DAEFace.as
r14593 r14858 1 1 package exl.render.collada 2 2 { 3 import flash.display.BitmapData; 4 3 5 public class DAEFace 4 6 { … … 9 11 } 10 12 13 public var shadingFactor:Number = 1; 14 public var textureIndex:int = -1; 11 15 public var fid:uint; 12 16 public var p:Array = [null, null, null]; 17 public var textureBitmap:BitmapData = null; 13 18 14 19 private var mHasN:uint = 0; -
lang/actionscript/gmapkmz/exl/render/collada/DAEMaterial.as
r14723 r14858 5 5 public var hasDiffuseColor:Boolean = false; 6 6 public var hasTexture:Boolean = false; 7 public var dR:int = 255; 8 public var dG:int = 255; 9 public var dB:int = 255; 7 public var textureIndex:int = -1; 8 public var dR:int; 9 public var dG:int; 10 public var dB:int; 10 11 11 public function setDiffuseRGB(r:int , g:int, b:int):void12 public function setDiffuseRGB(r:int = 255, g:int = 255, b:int = 255):void 12 13 { 13 14 dR = r; -
lang/actionscript/gmapkmz/exl/render/collada/DAEModel.as
r14723 r14858 16 16 17 17 protected var mNameMap:Dictionary = new Dictionary(true); 18 19 protected var mTextureNameMap:Dictionary = new Dictionary(); 20 protected var mTextureIndexMap:Dictionary = new Dictionary(); 21 protected var mNextTexIndex:int = 1; 22 18 23 protected var mCompleteHandler:Function; 19 24 protected var mRoot:DAESceneObject = null; … … 31 36 if (path) 32 37 mReader.read(path); 38 } 39 40 public function get textureIndexMap():Dictionary 41 { 42 return mTextureIndexMap; 43 } 44 45 private function toTextureIndex(name:String):uint 46 { 47 if (mTextureNameMap[name]) 48 return mTextureNameMap[name]; 49 50 mTextureNameMap[name] = mNextTexIndex; 51 mTextureIndexMap[mNextTexIndex] = name; 52 return mNextTexIndex++; 33 53 } 34 54 … … 179 199 else if (c.type == DaeColorOrTexture.TYPE_TEXTURE) 180 200 { 181 // STDOUT.puts( texture_filename(c, effect) ); 201 material = new DAEMaterial(); 202 material.textureIndex = toTextureIndex( texture_filename(c, effect) ); 203 material.hasTexture = true; 182 204 } 183 205 } … … 212 234 var m:Array = geometry.materials; 213 235 var n:Array = geometry.normals; 236 var t:Array = geometry.texcoords; 214 237 215 238 var geom:DAEGeometry = new DAEGeometry(); … … 228 251 var tri:Array = f[i]; 229 252 var eff:DaeEffect; 253 var texindex:int = -1; 230 254 231 255 var lib_mate:DAEMaterial = mMaterialList.getMaterialByName(m[i]); … … 238 262 b = lib_mate.dB; 239 263 } 264 else if (lib_mate.hasTexture) 265 texindex = lib_mate.textureIndex; 240 266 } 241 267 else … … 256 282 else if (c.type == DaeColorOrTexture.TYPE_TEXTURE) 257 283 { 258 // STDOUT.puts( texture_filename(c) );284 texindex = toTextureIndex( texture_filename(c, eff) ); 259 285 } 260 286 } … … 266 292 face.p[1] = new DAEVertex(geom.vertices[ tri[1] ], n[i][1], r, g, b); 267 293 face.p[2] = new DAEVertex(geom.vertices[ tri[2] ], n[i][2], r, g, b); 268 294 face.textureIndex = texindex; 295 296 if (t[i] && t[i].length > 2) 297 { 298 var ti:Array = t[i]; 299 face.p[0].tu = ti[0][0]; 300 face.p[0].tv = 1-ti[0][1]; 301 302 face.p[1].tu = ti[1][0]; 303 face.p[1].tv = 1-ti[1][1]; 304 305 face.p[2].tu = ti[2][0]; 306 face.p[2].tv = 1-ti[2][1]; 307 } 269 308 geom.faces[i] = face; 270 309 } … … 273 312 } 274 313 275 private static const rxFN:RegExp = / \/([-a-zA-Z0-9_.]+)$/;314 private static const rxFN:RegExp = /([-a-zA-Z0-9_.]+)$/; 276 315 protected function texture_filename(ct:DaeColorOrTexture, ef:DaeEffect):String 277 316 { -
lang/actionscript/gmapkmz/exl/render/collada/DAEModelRenderer.as
r14723 r14858 2 2 { 3 3 import flash.display.*; 4 import flash.geom.*; 4 5 import exl.trans3d.*; 6 import exl.advanced.*; 5 7 6 8 public class DAEModelRenderer … … 19 21 private var mExtentY:int = 0; 20 22 21 function DAEModelRenderer(scn:DAESceneObject) 22 { 23 private var mTexturePool:TexturePool = null; 24 25 function DAEModelRenderer(scn:DAESceneObject, texpool:TexturePool = null) 26 { 27 mTexturePool = texpool; 23 28 mSceneRoot = scn; 24 29 invalidateTraverse(); … … 91 96 dp = N.x * vL.x + N.y * vL.y + N.z * vL.z; 92 97 dp = dp*0.25 + 0.749; 93 98 f.shadingFactor = dp; 94 99 for (i = 0;i < 3;i++) 95 100 { … … 111 116 } 112 117 113 public function render(g:Graphics):void 114 { 115 if (mTraverseDirty) 116 { 117 mMatrixStack = []; 118 if (mTopTransform) 119 mMatrixStack.push(mTopTransform); 120 121 mFacesCount = 0; 122 traverse(mSceneRoot, g); 123 mTraverseDirty = false; 124 } 125 else 126 invalidateAll(); 127 128 finalTransform(); 129 if (mExtentY > 4) 130 sortPrimitives(); 118 public function render(g:Graphics, redrawOnly:Boolean = false):void 119 { 120 if (mTraverseDirty || !redrawOnly) 121 { 122 if (mTraverseDirty) 123 { 124 mMatrixStack = []; 125 if (mTopTransform) 126 mMatrixStack.push(mTopTransform); 127 128 mFacesCount = 0; 129 traverse(mSceneRoot, g); 130 mTraverseDirty = false; 131 } 132 else 133 invalidateAll(); 134 135 finalTransform(); 136 if (mExtentY > 4) 137 sortPrimitives(); 138 } 131 139 132 140 if (mExtentY > 2) … … 226 234 tlv.pos.y = aout[1]; 227 235 tlv.pos.z = aout[2]; 236 tlv.tu = f.p[k].tu; 237 tlv.tv = f.p[k].tv; 228 238 229 239 if (screen_y_min > tlv.pos.y) screen_y_min = tlv.pos.y; … … 289 299 } 290 300 301 protected function calcTextureTransform(vs:Array, m:Matrix, t:BitmapData):void 302 { 303 var tw:Number = t.width; 304 var th:Number = t.height; 305 306 var M:M22 = new M22(); 307 var vA_:Vec2 = new Vec2(); 308 var vB_:Vec2 = new Vec2(); 309 var ox:Number = vs[0].tu; 310 var oy:Number = vs[0].tv; 311 312 m.tx = vs[0].pos.x; 313 m.ty = vs[0].pos.y; 314 315 M._11 = (vs[1].tu - ox) * tw; 316 M._12 = (vs[1].tv - oy) * th; 317 M._21 = (vs[2].tu - ox) * tw; 318 M._22 = (vs[2].tv - oy) * th; 319 M = M.getInvert(); 320 if (!M) return; 321 322 vA_.x = vs[1].pos.x - m.tx; 323 vA_.y = vs[1].pos.y - m.ty; 324 vB_.x = vs[2].pos.x - m.tx; 325 vB_.y = vs[2].pos.y - m.ty; 326 327 m.a = vA_.x * M._11 + vB_.x * M._12; 328 m.c = vA_.x * M._21 + vB_.x * M._22; 329 330 m.b = vA_.y * M._11 + vB_.y * M._12; 331 m.d = vA_.y * M._21 + vB_.y * M._22; 332 333 ox *= tw; 334 oy *= th; 335 m.tx -= m.a*ox + m.c*oy; 336 m.ty -= m.b*ox + m.d*oy; 337 } 338 291 339 protected function drawPrimitives(g:Graphics):void 292 340 { 293 var i:uint ;341 var i:uint, ti:int; 294 342 var p:TrianglePrimitive; 343 var f:DAEFace; 344 var t:BitmapData; 345 346 var bM:Matrix = new Matrix(); 295 347 296 348 var tlvertices:Array; 349 var drawShade:Boolean = false; 297 350 for (i = 0;i < mVisibleFacesCount;i++) 298 351 { 299 352 p = TrianglePrimitive(mVisibleFacePool[i]); 300 353 tlvertices = p.tlvertices; 354 f = p.f; 355 356 ti = f.textureIndex; 357 if (ti >= 0 && !f.textureBitmap && mTexturePool) 358 { 359 if (( f.textureBitmap = mTexturePool.getByIndex(ti) )) 360 f.textureIndex = -1; 361 } 301 362 302 363 g.lineStyle(); 303 g.beginFill(p.f.p[2].computed_color, p.f.p[2].computed_color); 364 if ((t = f.textureBitmap)) 365 { 366 calcTextureTransform(tlvertices, bM, t); 367 g.beginBitmapFill(t, bM); 368 drawShade = f.shadingFactor < 0.99; 369 } 370 else 371 g.beginFill(f.p[2].computed_color, f.p[2].computed_color); 304 372 g.moveTo(tlvertices[0].pos.x, tlvertices[0].pos.y); 305 373 g.lineTo(tlvertices[1].pos.x, tlvertices[1].pos.y); 306 374 g.lineTo(tlvertices[2].pos.x, tlvertices[2].pos.y); 307 375 g.endFill(); 376 377 if (drawShade) { 378 g.beginFill(0, 1-f.shadingFactor); 379 g.moveTo(tlvertices[0].pos.x, tlvertices[0].pos.y); 380 g.lineTo(tlvertices[1].pos.x, tlvertices[1].pos.y); 381 g.lineTo(tlvertices[2].pos.x, tlvertices[2].pos.y); 382 g.endFill(); 383 } 308 384 } 309 385 } … … 348 424 protected function addFace(f:DAEFace):void 349 425 { 350 351 352 426 if (!mFacePool) mFacePool = [new TrianglePrimitive()]; 353 427 if (mFacesCount >= mFacePool.length) -
lang/actionscript/gmapkmz/exl/render/collada/DAEVertex.as
r14593 r14858 22 22 public var pos:Vec3; 23 23 public var N:Vec3; 24 25 public var tu:Number = 0; 26 public var tv:Number = 0; 24 27 } 25 28 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)