Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions 19 examples/cxxmodule/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 4.0.0)

project(CppmExample LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)

add_executable(main main.cc)

# The module interface file requires the tiny_obj_loader header file
target_include_directories(main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../..")

# Add the tiny_obj_loader module interface file
target_sources(main PRIVATE
FILE_SET cxx_modules
TYPE CXX_MODULES
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../.."
FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../tiny_obj_loader.cppm"
)

28 changes: 28 additions & 0 deletions 28 examples/cxxmodule/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <string>
#include <vector>
#include <iostream>

// import std;
Mysvac marked this conversation as resolved.
Show resolved Hide resolved
import tinyobj;


int main() {
// Equivalent to doing everything that #include <tiny_obj_loader.h> would do

const std::string filename = "../../models/cornell_box.obj";
tinyobj::attrib_t attrib;
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string warn, err;
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, filename.c_str())) {
throw std::runtime_error(warn + err);
}

std::cout << "shapes.size() = " << shapes.size() << std::endl;
for (const auto& shape : shapes) {
std::cout << "shape.mesh.indices.size() = " << shape.mesh.indices.size() << std::endl;
}

// ......
}

65 changes: 65 additions & 0 deletions 65 tiny_obj_loader.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module;

#define TINYOBJLOADER_IMPLEMENTATION // optional
Mysvac marked this conversation as resolved.
Show resolved Hide resolved
#include <tiny_obj_loader.h>

export module tinyobj;
Mysvac marked this conversation as resolved.
Show resolved Hide resolved


export namespace tinyobj {
using tinyobj::real_t;
using tinyobj::texture_type_t;
using tinyobj::texture_option_t;
using tinyobj::material_t;

#ifdef TINY_OBJ_LOADER_PYTHON_BINDING
using tinyobj::GetDiffuse;
using tinyobj::GetSpecular;
using tinyobj::GetTransmittance;
using tinyobj::GetEmission;
using tinyobj::GetAmbient;
using tinyobj::SetDiffuse;
using tinyobj::SetAmbient;
using tinyobj::SetSpecular;
using tinyobj::SetTransmittance;
using tinyobj::GetCustomParameter;
#endif // TINY_OBJ_LOADER_PYTHON_BINDING

using tinyobj::tag_t;
using tinyobj::joint_and_weight_t;
using tinyobj::skin_weight_t;
using tinyobj::index_t;
using tinyobj::mesh_t;
using tinyobj::lines_t;
using tinyobj::points_t;
using tinyobj::shape_t;
using tinyobj::attrib_t;
using tinyobj::callback_t;
using tinyobj::MaterialReader;
using tinyobj::MaterialFileReader;
using tinyobj::MaterialStreamReader;
using tinyobj::ObjReaderConfig;
using tinyobj::ObjReader;
using tinyobj::LoadObj;
using tinyobj::LoadObjWithCallback;
using tinyobj::LoadMtl;
using tinyobj::ParseTextureNameAndOption;


using tinyobj::vertex_index_t;
using tinyobj::face_t;
using tinyobj::__line_t;
using tinyobj::__points_t;
using tinyobj::tag_sizes;
using tinyobj::obj_shape;
using tinyobj::PrimGroup;

using tinyobj::warning_context;

using tinyobj::TinyObjPoint;
using tinyobj::cross;
using tinyobj::dot;
using tinyobj::GetLength;
using tinyobj::Normalize;
using tinyobj::WorldToLocal;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.