----------------------------------------------------------------------------- create array of tangent vectors -----------------------------------------------------------------------------
| 3016 | // create array of tangent vectors |
| 3017 | //----------------------------------------------------------------------------- |
| 3018 | void TSMesh::createTangents(const Vector<Point3F> &_verts, const Vector<Point3F> &_norms) |
| 3019 | { |
| 3020 | if (_verts.size() == 0) // can only be done in editable mode |
| 3021 | return; |
| 3022 | |
| 3023 | U32 numVerts = _verts.size(); |
| 3024 | U32 numNorms = _norms.size(); |
| 3025 | if ( numVerts <= 0 || numNorms <= 0 ) |
| 3026 | return; |
| 3027 | |
| 3028 | if( numVerts != numNorms) |
| 3029 | return; |
| 3030 | |
| 3031 | Vector<Point3F> tan0; |
| 3032 | tan0.setSize( numVerts * 2 ); |
| 3033 | |
| 3034 | Point3F *tan1 = tan0.address() + numVerts; |
| 3035 | dMemset( tan0.address(), 0, sizeof(Point3F) * 2 * numVerts ); |
| 3036 | |
| 3037 | U32 numPrimatives = mPrimitives.size(); |
| 3038 | |
| 3039 | for (S32 i = 0; i < numPrimatives; i++ ) |
| 3040 | { |
| 3041 | const TSDrawPrimitive & draw = mPrimitives[i]; |
| 3042 | GFXPrimitiveType drawType = getDrawType( draw.matIndex >> 30 ); |
| 3043 | |
| 3044 | U32 p1Index = 0; |
| 3045 | U32 p2Index = 0; |
| 3046 | |
| 3047 | U32 *baseIdx = &mIndices[draw.start]; |
| 3048 | |
| 3049 | const U32 numElements = (U32)draw.numElements; |
| 3050 | |
| 3051 | switch( drawType ) |
| 3052 | { |
| 3053 | case GFXTriangleList: |
| 3054 | { |
| 3055 | for( U32 j = 0; j < numElements; j += 3 ) |
| 3056 | findTangent( baseIdx[j], baseIdx[j + 1], baseIdx[j + 2], tan0.address(), tan1, _verts ); |
| 3057 | break; |
| 3058 | } |
| 3059 | |
| 3060 | case GFXTriangleStrip: |
| 3061 | { |
| 3062 | p1Index = baseIdx[0]; |
| 3063 | p2Index = baseIdx[1]; |
| 3064 | for( U32 j = 2; j < numElements; j++ ) |
| 3065 | { |
| 3066 | findTangent( p1Index, p2Index, baseIdx[j], tan0.address(), tan1, _verts ); |
| 3067 | p1Index = p2Index; |
| 3068 | p2Index = baseIdx[j]; |
| 3069 | } |
| 3070 | break; |
| 3071 | } |
| 3072 | |
| 3073 | default: |
| 3074 | AssertFatal( false, "TSMesh::createTangents: unknown primitive type!" ); |
| 3075 | } |