new obj parser
This commit is contained in:
parent
c266a18d59
commit
4c25bd6784
|
|
@ -1,11 +1,11 @@
|
||||||
#include "FileMeshData.h"
|
#include "FileMeshData.h"
|
||||||
#include "tiny_obj_loader.h"
|
#include "OBJ_Loader.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace RBX;
|
using namespace RBX;
|
||||||
using namespace tinyobj;
|
using namespace objl;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -16,12 +16,12 @@ int main(int argc, char* argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_t attrib;
|
std::string filename = argv[1];
|
||||||
std::vector<shape_t> shapes;
|
|
||||||
|
|
||||||
if (!LoadObj(&attrib, &shapes, nullptr, nullptr, nullptr, argv[1]))
|
Loader objLoader;
|
||||||
|
if (!objLoader.LoadFile(filename))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to parse obj!" << std::endl;
|
std::cout << "Failed to open obj!" << std::endl;
|
||||||
std::cin.get();
|
std::cin.get();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -30,51 +30,46 @@ int main(int argc, char* argv[])
|
||||||
std::vector<FileMeshVertexNormalTexture3d> vnts;
|
std::vector<FileMeshVertexNormalTexture3d> vnts;
|
||||||
std::vector<FileMeshFace> faces;
|
std::vector<FileMeshFace> faces;
|
||||||
|
|
||||||
for (size_t i = 0; i < shapes.size(); ++i)
|
for (size_t i = 0; i < objLoader.LoadedMeshes.size(); ++i)
|
||||||
{
|
{
|
||||||
size_t offset = 0;
|
Mesh currentMesh = objLoader.LoadedMeshes[i];
|
||||||
|
|
||||||
for (size_t j = 0; j < shapes[i].mesh.num_face_vertices.size(); ++j)
|
for (size_t j = 0; j < currentMesh.Vertices.size(); ++j)
|
||||||
{
|
{
|
||||||
uint8_t faceVertices = shapes[i].mesh.num_face_vertices[j];
|
Vertex vertex = currentMesh.Vertices[j];
|
||||||
|
|
||||||
for (size_t k = 0; k < faceVertices; ++k)
|
FileMeshVertexNormalTexture3d vnt;
|
||||||
{
|
|
||||||
index_t indices = shapes[i].mesh.indices[offset + k];
|
|
||||||
|
|
||||||
FileMeshVertexNormalTexture3d vnt;
|
vnt.vx = vertex.Position.X;
|
||||||
vnt.vx = attrib.vertices[3 * indices.vertex_index + 0];
|
vnt.vy = vertex.Position.Y;
|
||||||
vnt.vy = attrib.vertices[3 * indices.vertex_index + 1];
|
vnt.vz = vertex.Position.Z;
|
||||||
vnt.vz = attrib.vertices[3 * indices.vertex_index + 2];
|
|
||||||
vnt.nx = attrib.normals[3 * indices.normal_index + 0];
|
|
||||||
vnt.ny = attrib.normals[3 * indices.normal_index + 1];
|
|
||||||
vnt.nz = attrib.normals[3 * indices.normal_index + 2];
|
|
||||||
vnt.tu = 0;
|
|
||||||
vnt.tv = 0;
|
|
||||||
vnt.tw = 0;
|
|
||||||
|
|
||||||
if (attrib.texcoords.size() != 0)
|
vnt.nx = vertex.Normal.X;
|
||||||
{
|
vnt.ny = vertex.Normal.Y;
|
||||||
vnt.tu = attrib.texcoords[2 * indices.texcoord_index + 0];
|
vnt.nz = vertex.Normal.Z;
|
||||||
vnt.tv = 1 - attrib.texcoords[2 * indices.texcoord_index + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
vnts.push_back(vnt);
|
vnt.tu = vertex.TextureCoordinate.X;
|
||||||
}
|
vnt.tv = 1 - vertex.TextureCoordinate.Y;
|
||||||
|
|
||||||
|
vnts.push_back(vnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t k = 0; k < currentMesh.Indices.size(); k += 3)
|
||||||
|
{
|
||||||
FileMeshFace face;
|
FileMeshFace face;
|
||||||
face.a = 3 * j + 0;
|
|
||||||
face.b = 3 * j + 1;
|
|
||||||
face.c = 3 * j + 2;
|
|
||||||
faces.push_back(face);
|
|
||||||
|
|
||||||
offset += faceVertices;
|
face.a = currentMesh.Indices[k];
|
||||||
|
face.b = currentMesh.Indices[k + 1];
|
||||||
|
face.c = currentMesh.Indices[k + 2];
|
||||||
|
|
||||||
|
faces.push_back(face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
meshData.vnts = vnts;
|
meshData.vnts = vnts;
|
||||||
meshData.faces = faces;
|
meshData.faces = faces;
|
||||||
|
|
||||||
std::ofstream result(std::string(argv[1]) + ".mesh", std::ios::binary);
|
std::ofstream result(filename + ".mesh", std::ios::binary);
|
||||||
writeFileMesh(result, meshData);
|
writeFileMesh(result, meshData);
|
||||||
result.close();
|
result.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
|
@ -169,8 +169,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="FileMeshData.h" />
|
<ClInclude Include="FileMeshData.h" />
|
||||||
<ClInclude Include="MeshFileStructs.h" />
|
<ClInclude Include="MeshFileStructs.h" />
|
||||||
|
<ClInclude Include="OBJ_Loader.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
<ClInclude Include="tiny_obj_loader.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="RBXMeshConverter.rc" />
|
<ResourceCompile Include="RBXMeshConverter.rc" />
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@
|
||||||
<ClInclude Include="FileMeshData.h">
|
<ClInclude Include="FileMeshData.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="tiny_obj_loader.h">
|
<ClInclude Include="resource.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="resource.h">
|
<ClInclude Include="OBJ_Loader.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -2,6 +2,6 @@
|
||||||
Convert a wavefront OBJ to RBX mesh V2
|
Convert a wavefront OBJ to RBX mesh V2
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
[tinyobjloader](https://github.com/tinyobjloader/tinyobjloader)
|
[OBJ-Loader](https://github.com/Bly7/OBJ-Loader)
|
||||||
|
|
||||||
[Roblox Mesh Format](https://devforum.roblox.com/t/roblox-mesh-format/326114)
|
[Roblox Mesh Format](https://devforum.roblox.com/t/roblox-mesh-format/326114)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue