bool Animation::Load(char* file){ Tokenizer token; if(!token.Open(file)){ return false; } while(1) { char temp[256]; token.GetToken(temp); if (strcmp(temp, "range") == 0) { time_start = token.GetFloat(); time_end = token.GetFloat(); } else if (strcmp(temp, "numchannels") == 0) { numofchannel = token.GetInt(); clist = new Channel[numofchannel]; for(int i=0; i<numofchannel; i++){ token.FindToken("channel"); token.GetToken(temp); if (strcmp(temp, "{") == 0) { // clist[i].time_start = time_start; // clist[i].time_end = time_end; clist[i].Load(&token); } } } else if(strcmp(temp, "}") == 0){ token.Close(); return true; } else token.SkipLine(); } }
bool Skeleton::Load(const char *file) { Tokenizer token; token.Open(file); token.FindToken("balljoint"); // Parse tree Root = new Joint("Root"); Root->Load(token); // Finish token.Close(); return true; }
bool Skin::morph(const char *file) { Tokenizer token; token.Open(file); int count; token.FindToken("positions"); count = token.GetInt(); token.FindToken("{"); float x; float y; float z; int vIdx; for (int i = 0; i < count; i++) { vIdx = token.GetInt(); x = token.GetFloat(); y = token.GetFloat(); z = token.GetFloat(); vertices[vIdx].setPosition(Vector3(x, y, z)); } token.FindToken("normals"); token.FindToken("{"); for (int i = 0; i < count; i++) { vIdx = token.GetInt(); x = token.GetFloat(); y = token.GetFloat(); z = token.GetFloat(); vertices[vIdx].setNormal(Vector3(x, y, z)); } // Finish token.Close(); return true; }
void Triangle::load(Tokenizer &token) { char temp[256]; nverts = token.GetInt(); vertices = new float[nverts * 3]; token.FindToken("{"); for (int i = 0; i < nverts * 3; i++) { vertices[i] = token.GetFloat(); } token.FindToken("normals"); nnorm = token.GetInt(); normals = new float[nnorm * 3]; token.FindToken("{"); for (int i = 0; i < nnorm * 3; i++) { normals[i] = token.GetFloat(); } token.FindToken("triangles"); nind = token.GetInt(); indices = new int[nind * 3]; token.FindToken("{"); for (int i = 0; i < nind * 3; i++) { indices[i] = token.GetInt(); } }
bool Skeleton::Load(const char *file){ filename = file; Tokenizer token; token.Open(file); token.FindToken("balljoint"); Root = new Joint(); Root->Load(token); Root->Initialize(); token.Close(); NumberJoints(); currentJointNum = 0; currentJoint = joints[0]; return true; }
bool Skin::Load(const char *file) { WorldMtx.Identity(); Tokenizer * token = new Tokenizer(); token->Open(file); token->FindToken("balljoint"); // Parse tree root = new Joint(); root->Load(*token); //Finish token->Close(); return true; }
bool Skin::Load(const char* file, Skeleton* skel){ filename = file; Skel = skel; Tokenizer t; t.Open(file); if(DEBUG) printf("Skeleton %s", Skel->GetFileName()); while(1){ char temp[256]; t.GetToken(temp); //------ Load Vertex Positions ------ if(strcmp(temp,"positions")==0){ numVerts = t.GetInt(); vertices = std::vector<Vertex *>(numVerts); updatedVertices = std::vector<Vertex *>(numVerts); t.FindToken("{"); int n = 0; if(DEBUG) printf("positions %d\n", numVerts); while(n < numVerts){ vertices[n] = new Vertex(); vertices[n]->SetPosition(t.GetFloat(), t.GetFloat(), t.GetFloat()); if(DEBUG){ Vector3 pos = vertices[n]->GetPosition(); printf("\t%f %f %f\n", pos.x, pos.y, pos.z); } updatedVertices[n] = new Vertex(); updatedVertices[n]->SetPosition(vertices[n]->GetPosition()); n++; } //------ Load Vertex Normals ------ } else if(strcmp(temp, "normals")==0){ t.GetInt(); t.FindToken("{"); int n = 0; if(DEBUG) printf("normals %d\n", numVerts); while(n < numVerts){ vertices[n]->SetNormal(t.GetFloat(), t.GetFloat(), t.GetFloat()); updatedVertices[n]->SetNormal(vertices[n]->GetNormal()); if(DEBUG){ Vector3 norm = vertices[n]->GetNormal(); printf("\t%f %f %f\n", norm.x, norm.y, norm.z); } n++; } //------ Load Skin Weights ------ } else if(strcmp(temp, "skinweights")==0){ t.GetInt(); t.FindToken("{"); int n = 0; if(DEBUG) printf("skinweights %d\n", numVerts); while(n < numVerts){ int numAttachments = t.GetInt(); vertices[n]->numAttachments = numAttachments; updatedVertices[n]->numAttachments = numAttachments; if(DEBUG) printf("\t%d ", numAttachments); int a = 0; while(a < numAttachments){ int jointNum = t.GetInt(); float weight = t.GetFloat(); vertices[n]->skinweights[a] = weight; vertices[n]->joints[a] = jointNum; updatedVertices[n]->skinweights[a] = weight; updatedVertices[n]->joints[a] = jointNum; a++; if(DEBUG) printf("%d %f ", jointNum, weight); } if(DEBUG) printf("\n"); n++; } //------ Load Triangles ------ } else if(strcmp(temp, "triangles")==0){ numTriangles = t.GetInt(); triangles = std::vector<Triangle *>(numTriangles); t.FindToken("{"); int n = 0; if(DEBUG) printf("triangles %d\n", numTriangles); while(n < numTriangles){ triangles[n] = new Triangle(); triangles[n]->SetVertices(t.GetInt(), t.GetInt(), t.GetInt()); if(DEBUG){ Triangle *t = triangles[n]; printf("\t%d %d %d\n", t->GetVertex1(), t->GetVertex2(), t->GetVertex3()); } n++; } //------ Load Binding Matrices ------ } else if(strcmp(temp, "bindings")==0){ numJoints = t.GetInt(); bindings = std::vector<Matrix34 *>(numJoints); int n = 0; t.FindToken("{"); if(DEBUG) printf("bindings %d\n", numJoints); while(n < numJoints){ t.FindToken("matrix {"); float ax = t.GetFloat(); float ay = t.GetFloat(); float az = t.GetFloat(); float bx = t.GetFloat(); float by = t.GetFloat(); float bz = t.GetFloat(); float cx = t.GetFloat(); float cy = t.GetFloat(); float cz = t.GetFloat(); float dx = t.GetFloat(); float dy = t.GetFloat(); float dz = t.GetFloat(); bindings[n] = new Matrix34(ax, bx, cx, dx, ay, by, cy, dy, az, bz, cz, dz); if(DEBUG){ bindings[n]->Print(); } n++; } InverseBindings(); break; } else { t.SkipLine(); } } t.Close(); }
bool Skin::Load(const char *file) { //if (tex) texture = BMPImage(); Tokenizer token; token.Open(file); int idx; token.FindToken("positions"); idx = token.GetInt(); token.FindToken("{"); float x; float y; float z; for (int i = 0; i < idx; i++) { vertices.push_back(Vertex()); draw.push_back(Vertex()); x = token.GetFloat(); y = token.GetFloat(); z = token.GetFloat(); vertices[i].setPosition(Vector3(x, y, z)); draw[i].setPosition(Vector3()); } token.FindToken("normals"); token.FindToken("{"); for (int i = 0; i < idx; i++) { x = token.GetFloat(); y = token.GetFloat(); z = token.GetFloat(); vertices[i].setNormal(Vector3(x, y, z)); draw[i].setNormal(Vector3()); } if (tex) { token.FindToken("texcoords"); token.FindToken("{"); for (int i = 0; i < idx; i++) { x = token.GetFloat(); y = token.GetFloat(); vertices[i].setTexCoord(Vector3(x, y, 0)); draw[i].setTexCoord(Vector3(x, y, 0)); } } token.FindToken("skinweights"); token.FindToken("{"); for (int i = 0; i < idx; i++) { int numJoints = token.GetInt(); vector<skinWeight> inner; for (int j = 0; j < numJoints; j++) { int joint = token.GetInt(); float w = token.GetFloat(); inner.push_back(skinWeight(joint, w)); } weights.push_back(inner); } if (tex) { token.FindToken("material"); token.FindToken("{"); token.FindToken("texture"); char temp[256]; token.GetToken(temp); texFileName = temp; //LoadGLTextures(load); } token.FindToken("triangles"); idx = token.GetInt(); token.FindToken("{"); for (int i = 0; i < idx; i++) { triangles.push_back(Triangle()); x = token.GetInt(); y = token.GetInt(); z = token.GetInt(); triangles[i].Init(&draw[x], &draw[y], &draw[z]); triangles[i].Init(x, y, z); } token.FindToken("bindings"); idx = token.GetInt(); token.FindToken("{"); for (int i = 0; i < idx; i++) { token.FindToken("{"); float ax = token.GetFloat(); float ay = token.GetFloat(); float az = token.GetFloat(); float bx = token.GetFloat(); float by = token.GetFloat(); float bz = token.GetFloat(); float cx = token.GetFloat(); float cy = token.GetFloat(); float cz = token.GetFloat(); float dx = token.GetFloat(); float dy = token.GetFloat(); float dz = token.GetFloat(); bindings.push_back(Matrix34 (ax, bx, cx, dx, ay, by, cy, dy, az, bz, cz, dz) ); bindings[i].Inverse(); } // Finish token.Close(); return true; }
bool Channel::Load(Tokenizer &token) { char temp[256]; token.FindToken("extrapolate"); for (int j = 0; j < 2; j++) { token.GetToken(temp); if (strcmp(temp, "constant") == 0) { extrap[j] = 'k'; } else if (strcmp(temp, "linear") == 0) { extrap[j] = 'l'; } else if (strcmp(temp, "cycle") == 0) { extrap[j] = 'c'; } else if (strcmp(temp, "cycle_offset") == 0) { extrap[j] = 'o'; } else if (strcmp(temp, "bounce") == 0) { extrap[j] = 'b'; } } token.FindToken("keys"); int numKeys = token.GetInt(); token.FindToken("{"); for (int i = 0; i < numKeys; i++) { Keyframe newKeyframe = Keyframe(); newKeyframe.Time = token.GetFloat(); newKeyframe.Value = token.GetFloat(); token.GetToken(temp); if (strcmp(temp, "flat") == 0) { newKeyframe.RuleIn = 'f'; newKeyframe.TangentIn = 0; } else if (strcmp(temp, "linear") == 0) { newKeyframe.RuleIn = 'l'; } else if (strcmp(temp, "smooth") == 0) { newKeyframe.RuleIn = 's'; } else { newKeyframe.RuleIn = 'f'; newKeyframe.RuleIn = atof(temp); } token.GetToken(temp); if (strcmp(temp, "flat") == 0) { newKeyframe.RuleOut = 'f'; newKeyframe.TangentOut = 0; } else if (strcmp(temp, "linear") == 0) { newKeyframe.RuleOut = 'l'; } else if (strcmp(temp, "smooth") == 0) { newKeyframe.RuleOut = 's'; } else { newKeyframe.RuleOut = 'f'; newKeyframe.TangentOut = atof(temp); } keyframes.push_back(newKeyframe); } startTime = keyframes[0].Time; endTime = keyframes[keyframes.size()-1].Time; preCompute(); return true; }