Mesh::Mesh(string filepath) : File(filepath) { MeshLoader mesh_loader = MeshLoader(filepath); std::vector<GLfloat> vertices = mesh_loader.getVertexArray(); std::vector<GLuint> elements = mesh_loader.getFaceArray(); loadMeshData(vertices, elements); }
bool Sprite3D::loadFromC3x(const std::string& path) { std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path); //find from the cache std::string key = fullPath + "#"; auto mesh = MeshCache::getInstance()->getMesh(key); if (mesh) { _mesh = mesh; _mesh->retain(); auto tex = Sprite3DMaterialCache::getInstance()->getSprite3DMaterial(key); setTexture(tex); _skin = MeshSkin::create(fullPath, ""); CC_SAFE_RETAIN(_skin); genGLProgramState(); return true; } //load from .c3b or .c3t auto bundle = Bundle3D::getInstance(); if (!bundle->load(fullPath)) return false; MeshData meshdata; bool ret = bundle->loadMeshData("", &meshdata); if (!ret) { return false; } _mesh = Mesh::create(meshdata.vertex, meshdata.vertexSizeInFloat, meshdata.indices, meshdata.attribs); CC_SAFE_RETAIN(_mesh); _skin = MeshSkin::create(fullPath, ""); CC_SAFE_RETAIN(_skin); MaterialData materialdata; ret = bundle->loadMaterialData("", &materialdata); if (ret) { setTexture(materialdata.texturePath); } genGLProgramState(); //add to cache auto cache = Director::getInstance()->getTextureCache(); auto tex = cache->addImage(materialdata.texturePath); if (tex) Sprite3DMaterialCache::getInstance()->addSprite3DMaterial(key, tex); MeshCache::getInstance()->addMesh(key, _mesh); return true; }
Mesh::Mesh(string directory, string filename) : File(directory, filename) { #warning make sure all meshes have filenames even if they are not loaded from a file // This constructor loads geometry data (vertices and faces) from a .obj file. MeshLoader mesh_loader = MeshLoader(getFilepath()); std::vector<GLfloat> vertices = mesh_loader.getVertexArray(); std::vector<GLuint> elements = mesh_loader.getFaceArray(); loadMeshData(vertices, elements); }
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<GLuint> elements){ // This constructor loads geometry data (vertices and faces) from std::vectors. std::vector<GLfloat> out_vertices; for (int i = 0; i < vertices.size(); ++i){ Vertex vertex = vertices[i]; out_vertices.push_back(vertex.position.x); out_vertices.push_back(vertex.position.y); out_vertices.push_back(vertex.position.z); out_vertices.push_back(vertex.normal.x); out_vertices.push_back(vertex.normal.y); out_vertices.push_back(vertex.normal.z); out_vertices.push_back(vertex.tangent.x); out_vertices.push_back(vertex.tangent.y); out_vertices.push_back(vertex.tangent.z); out_vertices.push_back(vertex.binormal.x); out_vertices.push_back(vertex.binormal.y); out_vertices.push_back(vertex.binormal.z); out_vertices.push_back(vertex.texcoord.x); out_vertices.push_back(vertex.texcoord.y); } loadMeshData(out_vertices, elements); }
Mesh::Mesh(std::vector<GLfloat> vertices, std::vector<GLuint> elements){ // This constructor loads geometry data (vertices and faces) from std::vectors. loadMeshData(vertices, elements); }
Mesh::Mesh(std::string&& filename) { loadMeshData(filename); processMeshData(); freeMeshData(); }