| 30 | //------------------------------------------------- |
| 31 | |
| 32 | void TSShape::fixupOldSkins(S32 numMeshes, S32 numSkins, S32 numDetails, S32 * detFirstSkin, S32 * detailNumSkins) |
| 33 | { |
| 34 | #if !defined(TORQUE_MAX_LIB) |
| 35 | // this method not necessary in exporter, and a couple lines won't compile for exporter |
| 36 | if (!objects.address() || !meshes.address() || !numSkins) |
| 37 | // not ready for this yet, will catch it on the next pass |
| 38 | return; |
| 39 | S32 numObjects = objects.size(); |
| 40 | TSObject * newObjects = objects.address() + objects.size(); |
| 41 | TSSkinMesh ** skins = (TSSkinMesh**)&meshes[numMeshes]; |
| 42 | Vector<TSSkinMesh*> skinsCopy; |
| 43 | // Note: newObjects has as much free space as we need, so we just need to keep track of the |
| 44 | // number of objects we use and then update objects.size |
| 45 | S32 numSkinObjects = 0; |
| 46 | S32 skinsUsed = 0; |
| 47 | S32 emptySkins = 0; |
| 48 | S32 i; |
| 49 | for (i=0; i<numSkins; i++) |
| 50 | if (skins[i]==NULL) |
| 51 | emptySkins++; // probably never, but just in case |
| 52 | while (skinsUsed<numSkins-emptySkins) |
| 53 | { |
| 54 | TSObject & object = newObjects[numSkinObjects++]; |
| 55 | objects.increment(); |
| 56 | object.nameIndex = 0; // no name |
| 57 | object.numMeshes = 0; |
| 58 | object.startMeshIndex = numMeshes + skinsCopy.size(); |
| 59 | object.nodeIndex = -1; |
| 60 | object.nextSibling = -1; |
| 61 | for (S32 dl=0; dl<numDetails; dl++) |
| 62 | { |
| 63 | // find one mesh per detail to add to this object |
| 64 | // don't really need to be versions of the same object |
| 65 | i = 0; |
| 66 | while (i<detFirstSkin[dl] || detFirstSkin[dl]<0) |
| 67 | i++; |
| 68 | for (; i<numSkins && i<detFirstSkin[dl]+detailNumSkins[dl]; i++) |
| 69 | { |
| 70 | if (skins[i]) |
| 71 | { |
| 72 | // found an unused skin... copy it to skinsCopy and set to NULL |
| 73 | skinsCopy.push_back(skins[i]); |
| 74 | skins[i]=NULL; |
| 75 | object.numMeshes++; |
| 76 | skinsUsed++; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | if (i==numSkins || i==detFirstSkin[dl]+detailNumSkins[dl]) |
| 81 | { |
| 82 | skinsCopy.push_back(NULL); |
| 83 | object.numMeshes++; |
| 84 | } |
| 85 | } |
| 86 | // exit above loop with one skin per detail...despose of trailing null meshes |
| 87 | while (!skinsCopy.empty() && skinsCopy.last()==NULL) |
| 88 | { |
| 89 | skinsCopy.decrement(); |