チェンジセット 731

差分発生行の前後
無視リスト:
コミット日時:
2008/06/29 20:15:02 (2 ヶ月前)
コミッタ:
gyuque
ログメッセージ:

texture

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Maple/swf/exl/render/collada/DAEFace.as

    r702 r731  
    11package exl.render.collada 
    22{ 
     3        import flash.display.BitmapData; 
     4 
    35        public class DAEFace 
    46        { 
     
    911                } 
    1012 
     13                public var shadingFactor:Number = 1; 
     14                public var textureIndex:int = -1; 
    1115                public var fid:uint; 
    1216                public var p:Array = [null, null, null]; 
     17                public var textureBitmap:BitmapData = null; 
    1318 
    1419                private var mHasN:uint = 0; 
  • as3/Maple/swf/exl/render/collada/DAEMaterial.as

    r702 r731  
    44        { 
    55                public var hasDiffuseColor:Boolean = false; 
    6                 public var dR:int = 255; 
    7                 public var dG:int = 255; 
    8                 public var dB:int = 255; 
     6                public var hasTexture:Boolean      = false; 
     7                public var textureIndex:int        = -1; 
     8                public var dR:int; 
     9                public var dG:int; 
     10                public var dB:int; 
    911 
    10                 public function setDiffuseRGB(r:int, g:int, b:int):void 
     12                public function setDiffuseRGB(r:int = 255, g:int = 255, b:int = 255):void 
    1113                { 
    1214                        dR = r; 
  • as3/Maple/swf/exl/render/collada/DAEModel.as

    r709 r731  
    1616 
    1717                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 
    1823                protected var mCompleteHandler:Function; 
    1924                protected var mRoot:DAESceneObject = null; 
     
    3136                        if (path) 
    3237                                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++; 
    3353                } 
    3454 
     
    177197                                                material.setDiffuseRGB(r, g, b); 
    178198                                        } 
     199                                        else if (c.type == DaeColorOrTexture.TYPE_TEXTURE) 
     200                                        { 
     201                                                material = new DAEMaterial(); 
     202                                                material.textureIndex = toTextureIndex( texture_filename(c, effect) ); 
     203                                                material.hasTexture = true; 
     204                                        } 
    179205                                } 
    180206                        } 
     
    208234                        var m:Array = geometry.materials; 
    209235                        var n:Array = geometry.normals; 
     236                        var t:Array = geometry.texcoords; 
    210237 
    211238                        var geom:DAEGeometry = new DAEGeometry(); 
     
    224251                                var tri:Array = f[i]; 
    225252                                var eff:DaeEffect; 
     253                                var texindex:int = -1; 
    226254 
    227255                                var lib_mate:DAEMaterial = mMaterialList.getMaterialByName(m[i]); 
     
    234262                                                b = lib_mate.dB; 
    235263                                        } 
     264                                        else if (lib_mate.hasTexture) 
     265                                                texindex = lib_mate.textureIndex; 
    236266                                } 
    237267                                else 
     
    250280                                                                b = Math.round(c.color[2] * 255); 
    251281                                                        } 
     282                                                        else if (c.type == DaeColorOrTexture.TYPE_TEXTURE) 
     283                                                        { 
     284                                                                texindex = toTextureIndex( texture_filename(c, eff) ); 
     285                                                        } 
    252286                                                } 
    253287                                        } 
     
    258292                                face.p[1] = new DAEVertex(geom.vertices[ tri[1] ], n[i][1], r, g, b); 
    259293                                face.p[2] = new DAEVertex(geom.vertices[ tri[2] ], n[i][2], r, g, b); 
    260  
     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                                } 
    261308                                geom.faces[i] = face; 
    262309                        } 
    263310 
    264311                        return geom; 
     312                } 
     313 
     314                private static const rxFN:RegExp = /([-a-zA-Z0-9_.]+)$/; 
     315                protected function texture_filename(ct:DaeColorOrTexture, ef:DaeEffect):String 
     316                { 
     317                        if (ct.type != DaeColorOrTexture.TYPE_TEXTURE) 
     318                                return null; 
     319 
     320                        var img:DaeImage = mDocument.images[ct.texture.texture]; 
     321                        if (!img) 
     322                        { 
     323                                img = mDocument.images[ef.texture_url]; 
     324                                if (!img) 
     325                                        return null; 
     326                        } 
     327 
     328                        var rxr:Object; 
     329                        if ( (rxr = rxFN.exec(img.init_from)) ) 
     330                                return rxr[1]; 
     331 
     332                        return img.init_from; 
    265333                } 
    266334        } 
  • as3/Maple/swf/exl/render/collada/DAEModelRenderer.as

    r709 r731  
    22{ 
    33        import flash.display.*; 
     4        import flash.geom.*; 
    45        import exl.trans3d.*; 
     6        import exl.advanced.*; 
    57 
    68        public class DAEModelRenderer 
     
    1719                private var mProjTransform:M44; 
    1820                private var mMatrixStack:Array; 
    19  
    20                 function DAEModelRenderer(scn:DAESceneObject) 
    21                 { 
     21                private var mExtentY:int = 0; 
     22 
     23                private var mTexturePool:TexturePool = null; 
     24 
     25                function DAEModelRenderer(scn:DAESceneObject, texpool:TexturePool = null) 
     26                { 
     27                        mTexturePool = texpool; 
    2228                        mSceneRoot = scn; 
    2329                        invalidateTraverse(); 
     
    9096                                        dp = N.x * vL.x + N.y * vL.y + N.z * vL.z; 
    9197                                        dp = dp*0.25 + 0.749; 
    92  
     98                                        f.shadingFactor = dp; 
    9399                                        for (i = 0;i < 3;i++) 
    94100                                        { 
     
    126132 
    127133                        finalTransform(); 
    128                         sortPrimitives(); 
    129                         drawPrimitives(g); 
     134                        if (mExtentY > 4) 
     135                                sortPrimitives(); 
     136 
     137                        if (mExtentY > 2) 
     138                                drawPrimitives(g); 
    130139                } 
    131140 
     
    156165                        var i:uint, k:uint; 
    157166                        var aout:Array = [0,0,0]; 
     167 
     168                        var screen_y_min:int = 100000; 
     169                        var screen_y_max:int = -100000; 
    158170 
    159171                        var p:TrianglePrimitive; 
     
    219231                                        tlv.pos.y = aout[1]; 
    220232                                        tlv.pos.z = aout[2]; 
    221  
     233                                        tlv.tu = f.p[k].tu; 
     234                                        tlv.tv = f.p[k].tv; 
     235 
     236                                        if (screen_y_min > tlv.pos.y) screen_y_min = tlv.pos.y; 
     237                                        if (screen_y_max < tlv.pos.y) screen_y_max = tlv.pos.y; 
    222238                                } 
    223239 
    224240                                mVisibleFacePool[mVisibleFacesCount++] = p; 
    225241                        } 
     242 
     243                        mExtentY = screen_y_max - screen_y_min; 
    226244                } 
    227245 
     
    278296                } 
    279297 
     298                protected function calcTextureTransform(vs:Array, m:Matrix, t:BitmapData):void 
     299                { 
     300                        var tw:Number = t.width; 
     301                        var th:Number = t.height; 
     302 
     303                        var M:M22 = new M22(); 
     304                        var vA_:Vec2 = new Vec2(); 
     305                        var vB_:Vec2 = new Vec2(); 
     306                        var ox:Number = vs[0].tu; 
     307                        var oy:Number = vs[0].tv; 
     308 
     309                        m.tx = vs[0].pos.x; 
     310                        m.ty = vs[0].pos.y; 
     311 
     312                        M._11 = (vs[1].tu - ox) * tw; 
     313                        M._12 = (vs[1].tv - oy) * th; 
     314                        M._21 = (vs[2].tu - ox) * tw; 
     315                        M._22 = (vs[2].tv - oy) * th; 
     316                        M = M.getInvert(); 
     317                        if (!M) return; 
     318 
     319                        vA_.x = vs[1].pos.x - m.tx; 
     320                        vA_.y = vs[1].pos.y - m.ty; 
     321                        vB_.x = vs[2].pos.x - m.tx; 
     322                        vB_.y = vs[2].pos.y - m.ty; 
     323 
     324                        m.a = vA_.x * M._11 + vB_.x * M._12; 
     325                        m.c = vA_.x * M._21 + vB_.x * M._22; 
     326 
     327                        m.b = vA_.y * M._11 + vB_.y * M._12; 
     328                        m.d = vA_.y * M._21 + vB_.y * M._22; 
     329 
     330                        ox *= tw; 
     331                        oy *= th; 
     332                        m.tx -= m.a*ox + m.c*oy; 
     333                        m.ty -= m.b*ox + m.d*oy; 
     334                } 
     335 
    280336                protected function drawPrimitives(g:Graphics):void 
    281337                { 
    282                         var i:uint
     338                        var i:uint, ti:int
    283339                        var p:TrianglePrimitive; 
     340                        var f:DAEFace; 
     341                        var t:BitmapData; 
     342 
     343                        var bM:Matrix = new Matrix(); 
    284344 
    285345                        var tlvertices:Array; 
     346                        var drawShade:Boolean = false; 
    286347                        for (i = 0;i < mVisibleFacesCount;i++) 
    287348                        { 
    288349                                p = TrianglePrimitive(mVisibleFacePool[i]); 
    289350                                tlvertices = p.tlvertices; 
     351                                f = p.f; 
     352 
     353                                ti = f.textureIndex; 
     354                                if (ti >= 0 && !f.textureBitmap && mTexturePool) 
     355                                { 
     356                                        if (( f.textureBitmap = mTexturePool.getByIndex(ti) )) 
     357                                                f.textureIndex = -1; 
     358                                } 
    290359 
    291360                                g.lineStyle(); 
    292                                 g.beginFill(p.f.p[2].computed_color, p.f.p[2].computed_color); 
     361                                if ((t = f.textureBitmap)) 
     362                                { 
     363                                        calcTextureTransform(tlvertices, bM, t); 
     364                                        g.beginBitmapFill(t, bM); 
     365                                        drawShade = f.shadingFactor < 0.99; 
     366                                } 
     367                                else 
     368                                        g.beginFill(f.p[2].computed_color, f.p[2].computed_color); 
    293369                                g.moveTo(tlvertices[0].pos.x, tlvertices[0].pos.y); 
    294370                                g.lineTo(tlvertices[1].pos.x, tlvertices[1].pos.y); 
    295371                                g.lineTo(tlvertices[2].pos.x, tlvertices[2].pos.y); 
    296372                                g.endFill(); 
     373 
     374                                if (drawShade) { 
     375                                        g.beginFill(0, 1-f.shadingFactor); 
     376                                        g.moveTo(tlvertices[0].pos.x, tlvertices[0].pos.y); 
     377                                        g.lineTo(tlvertices[1].pos.x, tlvertices[1].pos.y); 
     378                                        g.lineTo(tlvertices[2].pos.x, tlvertices[2].pos.y); 
     379                                        g.endFill(); 
     380                                } 
    297381                        } 
    298382                } 
     
    337421                protected function addFace(f:DAEFace):void 
    338422                { 
    339  
    340  
    341423                        if (!mFacePool) mFacePool = [new TrianglePrimitive()]; 
    342424                        if (mFacesCount >= mFacePool.length) 
  • as3/Maple/swf/exl/render/collada/DAEVertex.as

    r702 r731  
    2222                public var pos:Vec3; 
    2323                public var N:Vec3; 
     24 
     25                public var tu:Number = 0; 
     26                public var tv:Number = 0; 
    2427        } 
    2528}