From 7d5f7cfef570b6a784b67686fa221dc7625cab17 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 15 Nov 2020 16:55:01 +0200 Subject: [PATCH] method simplification --- tags | 8 ++--- vbModelReader.cpp | 88 ++++++++++++++++++++++------------------------- vbModelReader.h | 12 +++---- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/tags b/tags index 06912c3..51d2ade 100755 --- a/tags +++ b/tags @@ -347,6 +347,7 @@ connectNodes vbModelReader.cpp /^ void VbModelReader::connectNodes(){$/;" f clas construct mesh.cpp /^ void Mesh::construct(){$/;" f class:vb01::Mesh typeref:typename:void controller animationChannel.h /^ AnimationController *controller = nullptr;$/;" m class:vb01::AnimationChannel typeref:typename:AnimationController * controller skeleton.h /^ AnimationController *controller = nullptr;$/;" m class:vb01::Skeleton typeref:typename:AnimationController * +createBones vbModelReader.cpp /^ void VbModelReader::createBones(Skeleton *skeleton, vector &meshData){$/;" f class:vb01::VbModelReader typeref:typename:void createSkybox root.cpp /^ void Root::createSkybox(string textures[6]){$/;" f class:vb01::Root typeref:typename:void cross vector.h /^ Vector3 cross(Vector3 v){return Vector3(y * v.z - v.y * z, z * v.x - x * v.z, x * v.y - v.x * /;" f struct:vb01::Vector3 typeref:typename:Vector3 cur_x stb_image.h /^ int cur_x, cur_y;$/;" m struct:__anon84e4e8861308 typeref:typename:int @@ -753,15 +754,14 @@ ratio stb_image.h /^ int flags, bgindex, ratio, transparent, eflags;$/;" m str raw_coeff stb_image.h /^ void *raw_data, *raw_coeff;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:void ** raw_data stb_image.h /^ void *raw_data, *raw_coeff;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:void * read stb_image.h /^ int (*read) (void *user,char *data,int size); \/\/ fill 'data' with 'size' bytes. re/;" m struct:__anon84e4e8860208 typeref:typename:int (*)(void * user,char * data,int size) -readAnimations vbModelReader.cpp /^ void VbModelReader::readAnimations(Skeleton *skeleton, int animationStartLine, int endLine){$/;" f class:vb01::VbModelReader typeref:typename:void -readBones vbModelReader.cpp /^ void VbModelReader::readBones(Skeleton *skeleton, int boneStartLine, int numBones){$/;" f class:vb01::VbModelReader typeref:typename:void +readAnimations vbModelReader.cpp /^ void VbModelReader::readAnimations(Skeleton *skeleton, vector &meshData){$/;" f class:vb01::VbModelReader typeref:typename:void readFaces vbModelReader.cpp /^ void VbModelReader::readFaces($/;" f class:vb01::VbModelReader typeref:typename:void readFile util.cpp /^ void readFile(string path, vector &lines, int firstLine, int lastLine){$/;" f namespace:vb01 typeref:typename:void readLights vbModelReader.cpp /^ void VbModelReader::readLights(int startLine, int endLine){$/;" f class:vb01::VbModelReader typeref:typename:void readMeshes vbModelReader.cpp /^ void VbModelReader::readMeshes(int startLine, int endLine){$/;" f class:vb01::VbModelReader typeref:typename:void readShapeKeys vbModelReader.cpp /^ void VbModelReader::readShapeKeys(int shapeKeyStartLine, int numShapes){$/;" f class:vb01::VbModelReader typeref:typename:void -readSkeletons vbModelReader.cpp /^ void VbModelReader::readSkeletons(int startLine, int endLine){$/;" f class:vb01::VbModelReader typeref:typename:void -readVertexGroups vbModelReader.cpp /^ void VbModelReader::readVertexGroups(string *groups, int vertexGroupStartLine, int numBones){$/;" f class:vb01::VbModelReader typeref:typename:void +readSkeleton vbModelReader.cpp /^ void VbModelReader::readSkeleton(int startLine, int endLine){$/;" f class:vb01::VbModelReader typeref:typename:void +readVertexGroups vbModelReader.cpp /^ void VbModelReader::readVertexGroups(string *groups, vector &meshData, int numBones){$/;" f class:vb01::VbModelReader typeref:typename:void readVertices vbModelReader.cpp /^ void VbModelReader::readVertices($/;" f class:vb01::VbModelReader typeref:typename:void read_from_callbacks stb_image.h /^ int read_from_callbacks;$/;" m struct:__anon84e4e8860308 typeref:typename:int recip quaternion.h /^ inline Quaternion recip(){return conj()\/getLengthSq();}$/;" f class:vb01::Quaternion typeref:typename:Quaternion diff --git a/vbModelReader.cpp b/vbModelReader.cpp index 4b45ba6..7a5bc3e 100644 --- a/vbModelReader.cpp +++ b/vbModelReader.cpp @@ -22,7 +22,7 @@ namespace vb01{ getObjectBounds(meshBracketIds, skeletonBracketIds, lightBracketIds); for(int i = 0; i < skeletonBracketIds.size() / 2; i++) - readSkeletons(skeletonBracketIds[i * 2], skeletonBracketIds[i * 2 + 1]); + readSkeleton(skeletonBracketIds[i * 2], skeletonBracketIds[i * 2 + 1]); for(int i = 0; i < meshBracketIds.size() / 2; i++) readMeshes(meshBracketIds[i * 2], meshBracketIds[i * 2 + 1]); for(int i = 0; i < lightBracketIds.size() / 2; i++) @@ -89,9 +89,7 @@ namespace vb01{ model->attachChild(node); } - void VbModelReader::readBones(Skeleton *skeleton, int boneStartLine, int numBones){ - vector meshData; - readFile(path, meshData, boneStartLine, boneStartLine + numBones); + void VbModelReader::createBones(Skeleton *skeleton, vector &meshData){ vector ikRelationships; for(string line : meshData){ @@ -144,19 +142,17 @@ namespace vb01{ } } - void VbModelReader::readAnimations(Skeleton *skeleton, int animationStartLine, int endLine){ + void VbModelReader::readAnimations(Skeleton *skeleton, vector &meshData){ AnimationController *controller = skeleton->getAnimationController(); string animName = ""; Bone *animBone = nullptr; Animation::KeyframeGroup::KeyframeChannel::Type type; - vector meshData; - readFile(path, meshData, animationStartLine, endLine + 1); - for(string l : meshData){ - int colonId = getCharId(l, ':'); - string preColon = l.substr(0, colonId); + for(string line : meshData){ + int colonId = getCharId(line, ':'); + string preColon = line.substr(0, colonId); if(preColon == "animationName"){ - string postColon = l.substr(colonId + 2, string::npos); + string postColon = line.substr(colonId + 2, string::npos); animName = postColon; controller->addAnimation(new Animation(animName)); continue; @@ -178,7 +174,7 @@ namespace vb01{ KeyframeInterpolation interp; KeyframeChannel channel; - if(l == "}") + if(line == "}") break; else if(preColon == "pos_x" || preColon == "pos_y" || preColon == "pos_z" || preColon == "rot_w" || preColon == "rot_x" || preColon == "rot_y" || preColon == "rot_z"){ if(preColon == "pos_x") @@ -203,7 +199,7 @@ namespace vb01{ int numData = 3; string data[numData]; - getLineData(l, data, numData); + getLineData(line, data, numData); float value = atof(data[0].c_str()), frame = atoi(data[1].c_str()); interp = (KeyframeInterpolation)atoi(data[2].c_str()); @@ -222,7 +218,7 @@ namespace vb01{ } } - void VbModelReader::readSkeletons(int startLine, int endLine){ + void VbModelReader::readSkeleton(int startLine, int endLine){ vector meshData; readFile(path, meshData, startLine + 1, startLine + 7); string name = meshData[0].substr(getCharId(meshData[0], ':') + 2, string::npos); @@ -238,9 +234,13 @@ namespace vb01{ Skeleton *skeleton = new Skeleton(name); skeletons.push_back(skeleton); - readBones(skeleton, boneStartLine, numBones); + meshData.clear(); + readFile(path, meshData, boneStartLine, boneStartLine + numBones); + createBones(skeleton, meshData); - readAnimations(skeleton, animationStartLine, endLine); + meshData.clear(); + readFile(path, meshData, animationStartLine, endLine + 1); + readAnimations(skeleton, meshData); } @@ -248,12 +248,9 @@ namespace vb01{ vector &vertPos, vector &vertNorm, vector &vertWeights, - int vertexStartLine, - int numVertices, + vector &meshData, int numBones ){ - vector meshData; - readFile(path, meshData, vertexStartLine, vertexStartLine + numVertices); for(string line : meshData){ int numData = 6 + numBones; string data[numData]; @@ -272,20 +269,15 @@ namespace vb01{ vector &vertPos, vector &vertNorm, vector &vertWeights, - int faceStartLine, - int numFaces, - int numVertsPerFace, + vector &meshData, int numBones, Mesh::Vertex *vertices, u32 *indices ){ - int i = 0; - vector meshData; - readFile(path, meshData, faceStartLine, faceStartLine + numFaces * numVertsPerFace); - for(string line : meshData){ + for(int i = 0; i < meshData.size(); i++){ int numData = 9; string data[numData]; - getLineData(line,data,numData); + getLineData(meshData[i], data, numData); int index = atoi(data[0].c_str()); Vector2 uv = Vector2(atof(data[1].c_str()), atof(data[2].c_str())); @@ -309,14 +301,10 @@ namespace vb01{ vertices[i] = vert; indices[i] = i; - - i++; } } - void VbModelReader::readVertexGroups(string *groups, int vertexGroupStartLine, int numBones){ - vector meshData; - readFile(path, meshData, vertexGroupStartLine, vertexGroupStartLine + numBones); + void VbModelReader::readVertexGroups(string *groups, vector &meshData, int numBones){ groups = new string[numBones]; for(int i = 0; i < numBones; i++){ groups[i] = meshData[i]; @@ -324,8 +312,6 @@ namespace vb01{ } void VbModelReader::readShapeKeys(int shapeKeyStartLine, int numShapes){ - vector meshData; - readFile(path, meshData, shapeKeyStartLine, shapeKeyStartLine + numShapes); for(int i = 0; i < numShapes; i++){ } } @@ -334,18 +320,12 @@ namespace vb01{ vector meshData; readFile(path, meshData, startLine + 1, startLine + 8); - string nameLine = meshData[0], parentLine = meshData[4], skeletonLine = meshData[5], numElementsLine = meshData[6]; - - int skeletonLineColonId = getCharId(skeletonLine, ':'); - string skeletonName = skeletonLine.substr(skeletonLineColonId + 2, string::npos); - - int parentLineColonId = getCharId(parentLine, ':'); - string parent = parentLine.substr(parentLineColonId + 2, string::npos); - + string nameLine = meshData[0]; int nameLineColonId = getCharId(nameLine, ':'); string preColonNameLine = nameLine.substr(0, nameLineColonId); string postColonNameLine = nameLine.substr(nameLineColonId + 2, string::npos); + string numElementsLine = meshData[6]; int numElementsColonId = getCharId(numElementsLine, ':'); string numElementsPreColon = numElementsLine.substr(0, numElementsColonId); string numElementsPostColon = numElementsLine.substr(numElementsColonId + 2, string::npos); @@ -354,6 +334,9 @@ namespace vb01{ getLineData(numElementsPostColon, data, 4); string name = postColonNameLine; + string parentLine = meshData[4]; + int parentLineColonId = getCharId(parentLine, ':'); + string parent = parentLine.substr(parentLineColonId + 2, string::npos); relationships.push_back(postColonNameLine + " " + parent); const int numVertsPerFace = 3; @@ -372,14 +355,25 @@ namespace vb01{ u32 *indices = new u32[numFaces * numVertsPerFace]; string *groups = new string[numBones]; + meshData.clear(); + readFile(path, meshData, vertexStartLine, vertexStartLine + numVertices); + readVertices(vertPos, vertNorm, vertWeights, meshData, numBones); - readVertices(vertPos, vertNorm, vertWeights, vertexStartLine, numVertices, numBones); + meshData.clear(); + readFile(path, meshData, faceStartLine, faceStartLine + numFaces * numVertsPerFace); + readFaces(vertPos, vertNorm, vertWeights, meshData, numBones, vertices, indices); - readFaces(vertPos, vertNorm, vertWeights, faceStartLine, numFaces, numVertsPerFace, numBones, vertices, indices); + meshData.clear(); + readFile(path, meshData, vertexGroupStartLine, vertexGroupStartLine + numBones); + readVertexGroups(groups, meshData, numBones); - readVertexGroups(groups, vertexGroupStartLine, vertexGroupStartLine + numBones); + meshData.clear(); + readFile(path, meshData, shapeKeyStartLine, shapeKeyStartLine + numShapes); + readShapeKeys(shapeKeyStartLine, numShapes); - readShapeKeys(shapeKeyStartLine, shapeKeyStartLine + numShapes); + string skeletonLine = meshData[5]; + int skeletonLineColonId = getCharId(skeletonLine, ':'); + string skeletonName = skeletonLine.substr(skeletonLineColonId + 2, string::npos); Skeleton *skeleton = nullptr; for(Skeleton *sk : skeletons) diff --git a/vbModelReader.h b/vbModelReader.h index cbc9835..91622dc 100644 --- a/vbModelReader.h +++ b/vbModelReader.h @@ -22,12 +22,12 @@ namespace vb01{ void getObjectBounds(std::map&, std::map&, std::map&); void connectNodes(); - void readBones(Skeleton*, int, int); - void readAnimations(Skeleton*, int, int); - void readSkeletons(int, int); - void readVertices(std::vector&, std::vector&, std::vector&, int, int, int); - void readFaces(std::vector&, std::vector&, std::vector&, int, int, int, int, Mesh::Vertex*, u32*); - void readVertexGroups(std::string*, int, int); + void createBones(Skeleton*, std::vector&); + void readAnimations(Skeleton*, std::vector&); + void readSkeleton(int, int); + void readVertices(std::vector&, std::vector&, std::vector&, std::vector&, int); + void readFaces(std::vector&, std::vector&, std::vector&, std::vector&, int, Mesh::Vertex*, u32*); + void readVertexGroups(std::string*, std::vector&, int); void readShapeKeys(int, int); void readMeshes(int, int); void readLights(int, int);