MCPcopy Create free account
hub / github.com/axmolengine/axmol / loadObj

Method loadObj

core/3d/Bundle3D.cpp:205–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205bool Bundle3D::loadObj(MeshDatas& meshdatas,
206 MaterialDatas& materialdatas,
207 NodeDatas& nodedatas,
208 std::string_view fullPath,
209 const char* mtl_basepath)
210{
211 meshdatas.resetData();
212 materialdatas.resetData();
213 nodedatas.resetData();
214
215 std::string mtlPath = "";
216 if (mtl_basepath)
217 mtlPath = mtl_basepath;
218 else
219 mtlPath = fullPath.substr(0, fullPath.find_last_of("\\/") + 1);
220
221 std::vector<tinyobj::shape_t> shapes;
222 std::vector<tinyobj::material_t> materials;
223 auto ret = tinyobj::LoadObj(shapes, materials, fullPath.data(), mtlPath.c_str());
224 if (ret.empty())
225 {
226 // fill data
227 // convert material
228 int i = 0;
229 char buf[20];
230 std::string dir;
231 auto last = fullPath.rfind('/');
232 if (last != std::string::npos)
233 dir = fullPath.substr(0, last + 1);
234 for (auto&& material : materials)
235 {
236 NMaterialData materialdata;
237
238 NTextureData tex;
239 tex.filename = material.diffuse_texname.empty() ? material.diffuse_texname : dir + material.diffuse_texname;
240 tex.type = NTextureData::Usage::Diffuse;
241 tex.wrapS = backend::SamplerAddressMode::CLAMP_TO_EDGE;
242 tex.wrapT = backend::SamplerAddressMode::CLAMP_TO_EDGE;
243
244 auto dataId = fmt::format_to_z(buf, "{}", ++i);
245 materialdata.textures.emplace_back(tex);
246 materialdata.id = dataId;
247 material.name = dataId;
248 materialdatas.materials.emplace_back(materialdata);
249 }
250
251 // convert mesh
252 i = 0;
253 for (auto&& shape : shapes)
254 {
255 auto mesh = shape.mesh;
256 MeshData* meshdata = new MeshData();
257 MeshVertexAttrib attrib;
258 attrib.type = parseGLDataType("GL_FLOAT", 3);
259
260 if (mesh.positions.size())
261 {
262 attrib.vertexAttrib = shaderinfos::VertexKey::VERTEX_ATTRIB_POSITION;

Callers

nothing calls this directly

Calls 12

LoadObjFunction · 0.85
format_to_zFunction · 0.85
getPerVertexSizeMethod · 0.80
resetDataMethod · 0.45
substrMethod · 0.45
find_last_ofMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45
emptyMethod · 0.45
rfindMethod · 0.45
emplace_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected