Advertisement
Dimitri_UA

cdff01

Jun 28th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | None | 0 0
  1. int DFFImport::DoImport(const TCHAR *filename, ImpInterface *ii, Interface *gi, BOOL suppressPrompts)
  2. {
  3.     gtaRwClump clump;
  4.     gtaRwStream *stream = gtaRwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, filename);
  5.     if(!clump.StreamRead(stream))
  6.         return 0;
  7.     gtaRwStreamClose(stream);
  8.  
  9.     TriObject **objects = NULL;
  10.     INode **nodes = NULL;
  11.  
  12.     gtaMessage("Reading geometries...");
  13.     if(clump.geometryList.geometryCount > 0)
  14.     {
  15.         objects = new TriObject *[clump.geometryList.geometryCount];
  16.         for(gtaRwInt32 i = 0; i < clump.geometryList.geometryCount; i++)
  17.         {
  18.             objects[i] = (TriObject *)gi->CreateInstance(SClass_ID(GEOMOBJECT_CLASS_ID), Class_ID(EDITTRIOBJ_CLASS_ID, 0));
  19.             Mesh &mesh = objects[i]->GetMesh();
  20.             gtaRwGeometry &geom = clump.geometryList.geometries[i];
  21.             mesh.setNumVerts(geom.numVertices);
  22.             if(geom.GetTexCoordsCount())
  23.                 mesh.setNumTVerts(geom.numVertices);
  24.             mesh.setNumFaces(geom.numTriangles);
  25.             for(gtaRwInt32 j = 0; j < geom.numVertices; j++)
  26.             {
  27.                 mesh.setVert(j, ToPoint3(geom.morphTarget[0].verts[j]));
  28.                 if(geom.normals && geom.morphTarget[0].normals)
  29.                     mesh.setNormal(j, ToPoint3(geom.morphTarget[0].normals[j]));
  30.                 if(geom.GetTexCoordsCount() > 0 && geom.texCoords[0])
  31.                     mesh.setTVert(j, geom.texCoords[0][j].u, geom.texCoords[0][j].v, 1.0f);
  32.             }
  33.             for(gtaRwInt32 j = 0; j < geom.numTriangles; j++)
  34.             {
  35.                 mesh.faces[j].setVerts(geom.triangles[j].vertA, geom.triangles[j].vertB, geom.triangles[j].vertC);
  36.                 mesh.faces[j].setEdgeVisFlags(1, 1, 1);
  37.             }
  38.         }
  39.     }
  40.     gtaMessage("Reading frames...");
  41.     if(clump.frameList.frameCount > 0)
  42.     {
  43.         nodes = new INode *[clump.frameList.frameCount];
  44.         for(gtaRwInt32 i = 0; i < clump.frameList.frameCount; i++)
  45.         {
  46.             gtaRwFrame &frame = clump.frameList.frames[i];
  47.             gtaRwBool geometryAssigned = false;
  48.             for(gtaRwInt32 j = 0; j < clump.numAtomics; j++)
  49.             {
  50.                 if(clump.atomics[j].frameIndex == i)
  51.                 {
  52.                     geometryAssigned = true;
  53.                     nodes[i] = gi->CreateObjectNode(objects[clump.atomics[j].geometryIndex]);
  54.                     break;
  55.                 }
  56.             }
  57.             float tm[4][3] = {frame.right.x, frame.right.y, frame.right.z,
  58.                               frame.up.x, frame.up.y, frame.up.z,
  59.                               frame.at.x, frame.at.y, frame.at.z,
  60.                               frame.pos.x, frame.pos.y, frame.pos.z};
  61.             if(!geometryAssigned)
  62.             {
  63.                 DummyObject *dummy = (DummyObject*)gi->CreateInstance(SClass_ID(HELPER_CLASS_ID), Class_ID(DUMMY_CLASS_ID,0));
  64.                 nodes[i] = gi->CreateObjectNode(dummy);
  65.                 nodes[i]->Scale(0, tm, Point3(3.0f, 3.0f, 3.0f), 1, 0, PIV_OBJECT_ONLY, 1);
  66.             }
  67.             if(frame.Extension.nodeName.name && frame.Extension.nodeName.name[0] != '\0')
  68.                 nodes[i]->SetName(frame.Extension.nodeName.name);
  69.             else
  70.             {
  71.                 gtaRwChar temp[16];
  72.                 sprintf(temp, "frame_%d", i);
  73.                 nodes[i]->SetName(temp);
  74.             }
  75.             nodes[i]->SetNodeTM(0, Matrix3(tm));
  76.         }
  77.         for(gtaRwInt32 i = 0; i < clump.frameList.frameCount; i++)
  78.         {
  79.             if(clump.frameList.frames[i].parent != -1 && clump.frameList.frames[i].parent < clump.frameList.frameCount)
  80.                 nodes[clump.frameList.frames[i].parent]->AttachChild(nodes[i], 0);
  81.         }
  82.  
  83.     }
  84.  
  85.     delete[] objects;
  86.     delete[] nodes;
  87.  
  88.     ii->RedrawViews();
  89.     return 1;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement