From e1bf674c16e3c8472b29574159c789cd3f0c64e0 Mon Sep 17 00:00:00 2001 From: Bryan Galdrikian Date: Fri, 24 Feb 2017 09:32:20 -0800 Subject: Updating to blast_source-windows@1.0.347-21749006 and blast_tools_and_samples-windows@1.0.347-21749006 with a new directory structure. NvBlast folder is gone, files have been moved to top level directory. README is changed to reflect this. --- tools/common/ObjFileReader.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/common/ObjFileReader.cpp (limited to 'tools/common/ObjFileReader.cpp') diff --git a/tools/common/ObjFileReader.cpp b/tools/common/ObjFileReader.cpp new file mode 100644 index 0000000..30b4c5c --- /dev/null +++ b/tools/common/ObjFileReader.cpp @@ -0,0 +1,63 @@ +#include "ObjFileReader.h" + +#pragma warning(push) +#pragma warning(disable:4706) +#define TINYOBJLOADER_IMPLEMENTATION +#include "tiny_obj_loader.h" +#pragma warning(pop) + + +#include +#include "PxVec3.h" +#include "PxVec2.h" + +using physx::PxVec3; +using physx::PxVec2; +using Nv::Blast::Mesh; + + +ObjFileReader::ObjFileReader() +{ + setConvertToUE4(false); +} + +std::shared_ptr ObjFileReader::loadFromFile(std::string filename) +{ + std::vector shapes; + std::vector mats; + std::string err; + std::string mtlPath; + bool ret = tinyobj::LoadObj(shapes, mats, err, filename.c_str()); + // can't load? + if (!ret) + return nullptr; + + if (shapes.size() > 1) + { + std::cout << "Can load only one object per mesh" << std::endl; + } + + std::vector positions; + std::vector normals; + std::vector uv; + + auto& psVec = shapes[0].mesh.positions; + for (uint32_t i = 0; i < psVec.size() / 3; ++i) + { + positions.push_back(PxVec3(psVec[i * 3], psVec[i * 3 + 1], psVec[i * 3 + 2])); + } + auto& nmVec = shapes[0].mesh.normals; + for (uint32_t i = 0; i < nmVec.size() / 3; ++i) + { + normals.push_back(PxVec3(nmVec[i * 3], nmVec[i * 3 + 1], nmVec[i * 3 + 2])); + } + auto& txVec = shapes[0].mesh.texcoords; + for (uint32_t i = 0; i < txVec.size() / 2; ++i) + { + uv.push_back(PxVec2(txVec[i * 2], txVec[i * 2 + 1])); + } + PxVec3* nr = (!normals.empty()) ? normals.data() : 0; + PxVec2* uvp = (!uv.empty()) ? uv.data() : 0; + + return std::make_shared(positions.data(), nr, uvp, static_cast(positions.size()), shapes[0].mesh.indices.data(), static_cast(shapes[0].mesh.indices.size())); +} -- cgit v1.2.3