update bullet so it actually works

Moved the addSourceDirectory for physics/Bullet into the Engine/Source/CMakeLists.txt file that way it can actually appear where we expect it to in the solution explorer.
This commit is contained in:
marauder2k7 2026-06-03 15:08:51 +01:00
parent c7be48130a
commit 13fa178cf6
5986 changed files with 1811270 additions and 453803 deletions

View file

@ -0,0 +1,3 @@
// Copyright 2012-2013, Syoyo Fujita.
//
// Licensed under 2-clause BSD liecense.

View file

@ -38,51 +38,102 @@ Licensed under 2 clause BSD.
Usage
-----
Data format
attrib_t contains single and linear array of vertex data(position, normal and texcoord).
std::string inputfile = "cornell_box.obj";
std::vector<tinyobj::shape_t> shapes;
std::string err = tinyobj::LoadObj(shapes, inputfile.c_str());
if (!err.empty()) {
std::cerr << err << std::endl;
exit(1);
}
std::cout << "# of shapes : " << shapes.size() << std::endl;
for (size_t i = 0; i < shapes.size(); i++) {
printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str());
printf("shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size());
assert((shapes[i].mesh.indices.size() % 3) == 0);
for (size_t f = 0; f < shapes[i].mesh.indices.size(); f++) {
printf(" idx[%ld] = %d\n", f, shapes[i].mesh.indices[f]);
}
printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size());
assert((shapes[i].mesh.positions.size() % 3) == 0);
for (size_t v = 0; v < shapes[i].mesh.positions.size() / 3; v++) {
printf(" v[%ld] = (%f, %f, %f)\n", v,
shapes[i].mesh.positions[3*v+0],
shapes[i].mesh.positions[3*v+1],
shapes[i].mesh.positions[3*v+2]);
}
printf("shape[%ld].material.name = %s\n", i, shapes[i].material.name.c_str());
printf(" material.Ka = (%f, %f ,%f)\n", shapes[i].material.ambient[0], shapes[i].material.ambient[1], shapes[i].material.ambient[2]);
printf(" material.Kd = (%f, %f ,%f)\n", shapes[i].material.diffuse[0], shapes[i].material.diffuse[1], shapes[i].material.diffuse[2]);
printf(" material.Ks = (%f, %f ,%f)\n", shapes[i].material.specular[0], shapes[i].material.specular[1], shapes[i].material.specular[2]);
printf(" material.Tr = (%f, %f ,%f)\n", shapes[i].material.transmittance[0], shapes[i].material.transmittance[1], shapes[i].material.transmittance[2]);
printf(" material.Ke = (%f, %f ,%f)\n", shapes[i].material.emission[0], shapes[i].material.emission[1], shapes[i].material.emission[2]);
printf(" material.Ns = %f\n", shapes[i].material.shininess);
printf(" material.map_Ka = %s\n", shapes[i].material.ambient_texname.c_str());
printf(" material.map_Kd = %s\n", shapes[i].material.diffuse_texname.c_str());
printf(" material.map_Ks = %s\n", shapes[i].material.specular_texname.c_str());
printf(" material.map_Ns = %s\n", shapes[i].material.normal_texname.c_str());
std::map<std::string, std::string>::iterator it(shapes[i].material.unknown_parameter.begin());
std::map<std::string, std::string>::iterator itEnd(shapes[i].material.unknown_parameter.end());
for (; it != itEnd; it++) {
printf(" material.%s = %s\n", it->first.c_str(), it->second.c_str());
}
printf("\n");
attrib_t::vertices => 3 floats per vertex
v[0] v[1] v[2] v[3] v[n-1]
+-----------+-----------+-----------+-----------+ +-----------+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
+-----------+-----------+-----------+-----------+ +-----------+
attrib_t::normals => 3 floats per vertex
n[0] n[1] n[2] n[3] n[n-1]
+-----------+-----------+-----------+-----------+ +-----------+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
+-----------+-----------+-----------+-----------+ +-----------+
attrib_t::texcoords => 2 floats per vertex
t[0] t[1] t[2] t[3] t[n-1]
+-----------+-----------+-----------+-----------+ +-----------+
| u | v | u | v | u | v | u | v | .... | u | v |
+-----------+-----------+-----------+-----------+ +-----------+
attrib_t::colors => 3 floats per vertex(vertex color. optional)
c[0] c[1] c[2] c[3] c[n-1]
+-----------+-----------+-----------+-----------+ +-----------+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
+-----------+-----------+-----------+-----------+ +-----------+
Each shape_t::mesh_t does not contain vertex data but contains array index to attrib_t. See loader_example.cc for more details.
mesh_t::indices => array of vertex indices.
+----+----+----+----+----+----+----+----+----+----+ +--------+
| i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | ... | i(n-1) |
+----+----+----+----+----+----+----+----+----+----+ +--------+
Each index has an array index to attrib_t::vertices, attrib_t::normals and attrib_t::texcoords.
mesh_t::num_face_vertices => array of the number of vertices per face(e.g. 3 = triangle, 4 = quad , 5 or more = N-gons).
+---+---+---+ +---+
| 3 | 4 | 3 | ...... | 3 |
+---+---+---+ +---+
| | | |
| | | +-----------------------------------------+
| | | |
| | +------------------------------+ |
| | | |
| +------------------+ | |
| | | |
|/ |/ |/ |/
mesh_t::indices
| face[0] | face[1] | face[2] | | face[n-1] |
+----+----+----+----+----+----+----+----+----+----+ +--------+--------+--------+
| i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | ... | i(n-3) | i(n-2) | i(n-1) |
+----+----+----+----+----+----+----+----+----+----+ +--------+--------+--------+
```c++
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
#include "tiny_obj_loader.h"
std::string inputfile = "cornell_box.obj";
tinyobj::attrib_t attrib;
std::vector<tinyobj::shape_t> shapes;
LoadObj(attrib, shapes, inputfile.c_str());
// Loop over shapes
for (size_t s = 0; s < shapes.size(); s++) {
// Loop over faces(polygon)
size_t index_offset = 0;
for (size_t f = 0; f < shapes[s].mesh.indices.size(); f++) {
int fv = 3;
// Loop over vertices in the face.
for (size_t v = 0; v < fv; v++) {
// access to vertex
tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v];
tinyobj::real_t vx = attrib.vertices[3*idx.vertex_index+0];
tinyobj::real_t vy = attrib.vertices[3*idx.vertex_index+1];
tinyobj::real_t vz = attrib.vertices[3*idx.vertex_index+2];
tinyobj::real_t nx = attrib.normals[3*idx.normal_index+0];
tinyobj::real_t ny = attrib.normals[3*idx.normal_index+1];
tinyobj::real_t nz = attrib.normals[3*idx.normal_index+2];
tinyobj::real_t tx = attrib.texcoords[2*idx.texcoord_index+0];
tinyobj::real_t ty = attrib.texcoords[2*idx.texcoord_index+1];
}
index_offset += fv;
}
}
```

View file

@ -6,37 +6,31 @@
#include <iostream>
static bool
TestLoadObj(
TestLoadObj(
const char* fileName,
bool verbose
)
bool verbose)
{
const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"};
const char* prefix[] = {"./data/", "../data/", "../../data/", "../../../data/", "../../../../data/"};
char fullPath[1024];
int index=-1;
int index = -1;
{
int numPrefixes = sizeof(prefix)/sizeof(char*);
int numPrefixes = sizeof(prefix) / sizeof(char*);
for (int i=0;i<numPrefixes;i++)
for (int i = 0; i < numPrefixes; i++)
{
sprintf(fullPath,"%s%s",prefix[i],fileName);
sprintf(fullPath, "%s%s", prefix[i], fileName);
FILE* f;
f = fopen(fullPath,"r");
f = fopen(fullPath, "r");
if (f)
{
index=i;
index = i;
fclose(f);
break;
}
}
}
if (index<0)
if (index < 0)
{
printf("file not found %s\n", fileName);
return false;
@ -44,10 +38,11 @@ static bool
std::cout << "Loading " << fullPath << std::endl;
std::vector<tinyobj::shape_t> shapes;
std::string err = tinyobj::LoadObj(shapes, fullPath, prefix[index]);
std::vector<bt_tinyobj::shape_t> shapes;
std::string err = bt_tinyobj::LoadObj(shapes, fullPath, prefix[index]);
if (!err.empty()) {
if (!err.empty())
{
std::cerr << err << std::endl;
return false;
}
@ -56,21 +51,24 @@ static bool
if (verbose)
{
for (size_t i = 0; i < shapes.size(); i++) {
for (size_t i = 0; i < shapes.size(); i++)
{
printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str());
printf("shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size());
assert((shapes[i].mesh.indices.size() % 3) == 0);
for (size_t f = 0; f < shapes[i].mesh.indices.size(); f++) {
for (size_t f = 0; f < shapes[i].mesh.indices.size(); f++)
{
printf(" idx[%ld] = %d\n", f, shapes[i].mesh.indices[f]);
}
printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size());
assert((shapes[i].mesh.positions.size() % 3) == 0);
for (size_t v = 0; v < shapes[i].mesh.positions.size() / 3; v++) {
for (size_t v = 0; v < shapes[i].mesh.positions.size() / 3; v++)
{
printf(" v[%ld] = (%f, %f, %f)\n", v,
shapes[i].mesh.positions[3*v+0],
shapes[i].mesh.positions[3*v+1],
shapes[i].mesh.positions[3*v+2]);
shapes[i].mesh.positions[3 * v + 0],
shapes[i].mesh.positions[3 * v + 1],
shapes[i].mesh.positions[3 * v + 2]);
}
printf("shape[%ld].material.name = %s\n", i, shapes[i].material.name.c_str());
@ -86,7 +84,8 @@ static bool
printf(" material.map_Ns = %s\n", shapes[i].material.normal_texname.c_str());
std::map<std::string, std::string>::iterator it(shapes[i].material.unknown_parameter.begin());
std::map<std::string, std::string>::iterator itEnd(shapes[i].material.unknown_parameter.end());
for (; it != itEnd; it++) {
for (; it != itEnd; it++)
{
printf(" material.%s = %s\n", it->first.c_str(), it->second.c_str());
}
printf("\n");
@ -96,12 +95,11 @@ static bool
return true;
}
int main( int argc, char **argv)
int main(int argc, char** argv)
{
// assert(true == TestLoadObj("cornell_box.obj",true));
// assert(true == TestLoadObj("cube.obj",true));
assert(true==TestLoadObj("samurai_monastry.obj",false));
assert(true==TestLoadObj("teddy2_VHACD_CHs.obj",true));
// assert(true == TestLoadObj("cornell_box.obj",true));
// assert(true == TestLoadObj("cube.obj",true));
assert(true == TestLoadObj("samurai_monastry.obj", false));
assert(true == TestLoadObj("teddy2_VHACD_CHs.obj", true));
return 0;
}

View file

@ -3,58 +3,97 @@
//
// Licensed under 2-clause BSD liecense.
//
#ifndef _TINY_OBJ_LOADER_H
#define _TINY_OBJ_LOADER_H
#ifndef _BT_TINY_OBJ_LOADER_H
#define _BT_TINY_OBJ_LOADER_H
#include <string>
#include <vector>
#include <map>
namespace tinyobj {
struct CommonFileIOInterface;
namespace bt_tinyobj
{
struct vertex_index_t
{
int v_idx, vt_idx, vn_idx;
vertex_index_t() : v_idx(-1), vt_idx(-1), vn_idx(-1) {}
explicit vertex_index_t(int idx) : v_idx(idx), vt_idx(idx), vn_idx(idx) {}
vertex_index_t(int vidx, int vtidx, int vnidx)
: v_idx(vidx), vt_idx(vtidx), vn_idx(vnidx) {}
};
typedef std::vector<vertex_index_t> face_t;
typedef struct
{
std::string name;
std::string name;
float ambient[3];
float diffuse[3];
float specular[3];
float transmittance[3];
float emission[3];
float shininess;
float ambient[3];
float diffuse[3];
float specular[3];
float transmittance[3];
float emission[3];
float shininess;
float transparency; // 1 == opaque; 0 == fully transparent
std::string ambient_texname;
std::string diffuse_texname;
std::string specular_texname;
std::string normal_texname;
std::map<std::string, std::string> unknown_parameter;
std::string ambient_texname; // map_Ka
std::string diffuse_texname; // map_Kd
std::string specular_texname; // map_Ks
std::string normal_texname;
std::map<std::string, std::string> unknown_parameter;
} material_t;
// Index struct to support different indices for vtx/normal/texcoord.
// -1 means not used.
typedef struct
{
std::vector<float> positions;
std::vector<float> normals;
std::vector<float> texcoords;
std::vector<unsigned int> indices;
int vertex_index;
int normal_index;
int texcoord_index;
} index_t;
typedef struct
{
std::vector<index_t> indices;
} mesh_t;
typedef struct
{
std::string name;
material_t material;
mesh_t mesh;
std::string name;
material_t material;
mesh_t mesh;
} shape_t;
// Vertex attributes
struct attrib_t
{
std::vector<float> vertices; // 'v'(xyz)
std::vector<float> normals; // 'vn'
std::vector<float> texcoords; // 'vt'(uv)
attrib_t() {}
};
/// Loads .obj from a file.
/// 'shapes' will be filled with parsed shape data
/// The function returns error string.
/// Returns empty string when loading .obj success.
/// 'mtl_basepath' is optional, and used for base path for .mtl file.
#ifdef USE_STREAM
std::string LoadObj(
std::vector<shape_t>& shapes, // [output]
const char* filename,
const char* mtl_basepath = NULL);
attrib_t& attrib,
std::vector<shape_t>& shapes, // [output]
const char* filename,
const char* mtl_basepath = NULL);
#else
std::string
LoadObj(
attrib_t& attrib,
std::vector<shape_t>& shapes,
const char* filename,
const char* mtl_basepath,
CommonFileIOInterface* fileIO);
#endif
};
}; // namespace bt_tinyobj
#endif // _TINY_OBJ_LOADER_H
#endif // _BT_TINY_OBJ_LOADER_H