Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int DFFImport::DoImport(const TCHAR *filename, ImpInterface *ii, Interface *gi, BOOL suppressPrompts)
- {
- gtaRwClump clump;
- gtaRwStream *stream = gtaRwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, filename);
- if(!clump.StreamRead(stream))
- return 0;
- gtaRwStreamClose(stream);
- TriObject **objects = NULL;
- INode **nodes = NULL;
- gtaMessage("Reading geometries...");
- if(clump.geometryList.geometryCount > 0)
- {
- objects = new TriObject *[clump.geometryList.geometryCount];
- for(gtaRwInt32 i = 0; i < clump.geometryList.geometryCount; i++)
- {
- objects[i] = (TriObject *)gi->CreateInstance(SClass_ID(GEOMOBJECT_CLASS_ID), Class_ID(EDITTRIOBJ_CLASS_ID, 0));
- Mesh &mesh = objects[i]->GetMesh();
- gtaRwGeometry &geom = clump.geometryList.geometries[i];
- mesh.setNumVerts(geom.numVertices);
- if(geom.GetTexCoordsCount())
- mesh.setNumTVerts(geom.numVertices);
- mesh.setNumFaces(geom.numTriangles);
- for(gtaRwInt32 j = 0; j < geom.numVertices; j++)
- {
- mesh.setVert(j, ToPoint3(geom.morphTarget[0].verts[j]));
- if(geom.normals && geom.morphTarget[0].normals)
- mesh.setNormal(j, ToPoint3(geom.morphTarget[0].normals[j]));
- if(geom.GetTexCoordsCount() > 0 && geom.texCoords[0])
- mesh.setTVert(j, geom.texCoords[0][j].u, geom.texCoords[0][j].v, 1.0f);
- }
- for(gtaRwInt32 j = 0; j < geom.numTriangles; j++)
- {
- mesh.faces[j].setVerts(geom.triangles[j].vertA, geom.triangles[j].vertB, geom.triangles[j].vertC);
- mesh.faces[j].setEdgeVisFlags(1, 1, 1);
- }
- }
- }
- gtaMessage("Reading frames...");
- if(clump.frameList.frameCount > 0)
- {
- nodes = new INode *[clump.frameList.frameCount];
- for(gtaRwInt32 i = 0; i < clump.frameList.frameCount; i++)
- {
- gtaRwFrame &frame = clump.frameList.frames[i];
- gtaRwBool geometryAssigned = false;
- for(gtaRwInt32 j = 0; j < clump.numAtomics; j++)
- {
- if(clump.atomics[j].frameIndex == i)
- {
- geometryAssigned = true;
- nodes[i] = gi->CreateObjectNode(objects[clump.atomics[j].geometryIndex]);
- break;
- }
- }
- float tm[4][3] = {frame.right.x, frame.right.y, frame.right.z,
- frame.up.x, frame.up.y, frame.up.z,
- frame.at.x, frame.at.y, frame.at.z,
- frame.pos.x, frame.pos.y, frame.pos.z};
- if(!geometryAssigned)
- {
- DummyObject *dummy = (DummyObject*)gi->CreateInstance(SClass_ID(HELPER_CLASS_ID), Class_ID(DUMMY_CLASS_ID,0));
- nodes[i] = gi->CreateObjectNode(dummy);
- nodes[i]->Scale(0, tm, Point3(3.0f, 3.0f, 3.0f), 1, 0, PIV_OBJECT_ONLY, 1);
- }
- if(frame.Extension.nodeName.name && frame.Extension.nodeName.name[0] != '\0')
- nodes[i]->SetName(frame.Extension.nodeName.name);
- else
- {
- gtaRwChar temp[16];
- sprintf(temp, "frame_%d", i);
- nodes[i]->SetName(temp);
- }
- nodes[i]->SetNodeTM(0, Matrix3(tm));
- }
- for(gtaRwInt32 i = 0; i < clump.frameList.frameCount; i++)
- {
- if(clump.frameList.frames[i].parent != -1 && clump.frameList.frames[i].parent < clump.frameList.frameCount)
- nodes[clump.frameList.frames[i].parent]->AttachChild(nodes[i], 0);
- }
- }
- delete[] objects;
- delete[] nodes;
- ii->RedrawViews();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement