### Install RapidObj System-Wide Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Install the RapidObj package to system directories after configuration. This typically requires administrative privileges. ```bash cd build sudo make install ``` -------------------------------- ### Configure RapidObj with Custom Install Directories Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Configure RapidObj to install into custom directories using CMake cache variables. This avoids the need for sudo during installation. ```bash cmake -B build -DRAPIDOBJ_INCLUDE_DIR=${HOME}/local/include -DRAPIDOBJ_CMAKE_DIR=${HOME}/local/cmake . ``` -------------------------------- ### Install RapidObj to Custom Location Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Install RapidObj to the custom directories specified during configuration. Administrative access is not required for user-defined locations. ```bash cd build make install ``` -------------------------------- ### Configure RapidObj Build Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Configure the build for RapidObj using CMake. This is the first step for external installation. ```bash cmake -B build . ``` -------------------------------- ### Find RapidObj with Custom Install Hints Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Find the RapidObj package in your CMakeLists.txt when installed to a custom location. Provide hints to the find_package command. ```cmake add_executable(my_app my_src.cpp) find_package(RapidObj REQUIRED HINTS $ENV{HOME}/local/cmake) target_link_libraries(my_app PRIVATE rapidobj::rapidobj) ``` -------------------------------- ### CMakeLists.txt for readobj Example Source: https://github.com/guybrush77/rapidobj/blob/master/example/readobj/CMakeLists.txt Configures the build for the readobj executable. It specifies the minimum CMake version, executable name, source files, C++ standard, and links against the rapidobj library. ```cmake cmake_minimum_required(VERSION 3.20) add_executable(readobj) target_sources(readobj PRIVATE "src/readobj.cpp") target_compile_features(readobj PRIVATE cxx_std_17) target_link_libraries(readobj PRIVATE rapidobj) ``` -------------------------------- ### Link RapidObj in CMakeLists.txt Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Link the installed RapidObj library to your executable in your project's CMakeLists.txt file. Ensure RapidObj is found using find_package. ```cmake add_executable(my_app my_src.cpp) find_package(RapidObj REQUIRED) target_link_libraries(my_app PRIVATE rapidobj::rapidobj) ``` -------------------------------- ### Embed RapidObj using add_subdirectory Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Embed RapidObj directly into your project by adding its directory. This method does not require a separate installation step. ```cmake add_executable(my_app my_src.cpp) add_subdirectory(thirdparty/rapidobj) target_link_libraries(my_app PRIVATE rapidobj::rapidobj) ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/guybrush77/rapidobj/blob/master/tests/CMakeLists.txt Specifies the minimum required version of CMake for this project. Ensure your CMake installation meets this requirement. ```cmake cmake_minimum_required(VERSION 3.20) ``` -------------------------------- ### Fetch RapidObj using FetchContent Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use CMake's FetchContent module to automatically download and integrate RapidObj from its Git repository. This simplifies dependency management. ```cmake add_executable(my_app my_src.cpp) include(FetchContent) FetchContent_Declare(rapidobj GIT_REPOSITORY https://github.com/guybrush77/rapidobj.git GIT_TAG origin/master) FetchContent_MakeAvailable(rapidobj) target_link_libraries(my_app PRIVATE rapidobj::rapidobj) ``` -------------------------------- ### Load Material Library (Default, Optional) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Uses the default location to look for the .mtl file and continues parsing if it's not found. The Materials array will be empty. ```c++ // Look for .mtl file in default location. // If the file cannot be found, ParseFile function will continue .obj loading and parsing. // MaterialLibrary mtllib = MaterialLibrary::Default(Load::Optional); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` -------------------------------- ### MaterialLibrary::SearchPaths(std::vector paths, Load policy) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Constructs a MaterialLibrary specifying multiple search paths for .mtl files and a loading policy. ```APIDOC ## MaterialLibrary::SearchPaths(std::vector paths, Load policy) ### Description Constructor used to specify multiple .mtl file's relative or absolute search paths and [loading policy](#load-policy). The paths are examined in order; the first .mtl file found will be loaded and parsed. A relative search path's current directory is .obj file's parent folder. A relative search path only applies to the [`ParseFile`](#parsefile) function; specifying a relative search path for the [`ParseStream`](#parsestream) function will generate an error. ### Method static MaterialLibrary SearchPaths(std::vector paths, Load policy = Load::Mandatory) ### Parameters #### Path Parameters - **paths** (std::vector) - A vector of relative or absolute paths to search for .mtl files. - **policy** (Load) - Optional. The loading policy (defaults to Load::Mandatory). ### Request Example ```cpp // Look for .mtl file in folder /home/user/teapot/materials, then /home/user/materials, then /home/user/teapot. MaterialLibrary mtllib = MaterialLibrary::SearchPaths({ "materials", "../materials", "." }); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` ### Response (No specific response details provided for this constructor) ``` -------------------------------- ### Link Libraries Source: https://github.com/guybrush77/rapidobj/blob/master/tests/unit-tests/CMakeLists.txt Links the necessary libraries, doctest and rapidobj, for the unit tests. ```cmake target_link_libraries(unit-tests PRIVATE doctest rapidobj) ``` -------------------------------- ### Add Executable and Sources Source: https://github.com/guybrush77/rapidobj/blob/master/tests/unit-tests/CMakeLists.txt Defines the executable name and lists the source files for the unit tests. ```cmake add_executable(unit-tests) target_sources(unit-tests PRIVATE "src/test_main.cpp" "src/test_material_parsing.cpp" "src/test_mtllib.cpp" "src/test_parsing.cpp" ) ``` -------------------------------- ### MaterialLibrary::String(std::string_view text) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Constructs a MaterialLibrary from a string containing material definitions. ```APIDOC ## MaterialLibrary::String(std::string_view text) ### Description Constructor used to provide .mtl material description as a string. ### Method static MaterialLibrary String(std::string_view text) ### Parameters #### Path Parameters - **text** (std::string_view) - A string view containing the .mtl material definitions. ### Request Example ```cpp // Define a material library as a string, then pass it to ParseFile function. static constexpr auto materials = R"( newmtl red Kd 1 0 0 )"; Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::String(materials)); ``` ### Response (No specific response details provided for this constructor) ``` -------------------------------- ### MaterialLibrary::SearchPath(std::filesystem::path path, Load policy) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Constructs a MaterialLibrary specifying a search path for .mtl files and a loading policy. ```APIDOC ## MaterialLibrary::SearchPath(std::filesystem::path path, Load policy) ### Description Constructor used to specify .mtl file's relative or absolute search path and [loading policy](#load-policy). A relative search path's current directory is .obj file's parent folder. A relative search path only applies to the [`ParseFile`](#parsefile) function; specifying a relative search path for the [`ParseStream`](#parsestream) function will generate an error. ### Method static MaterialLibrary SearchPath(std::filesystem::path path, Load policy = Load::Mandatory) ### Parameters #### Path Parameters - **path** (std::filesystem::path) - The relative or absolute path to search for .mtl files. - **policy** (Load) - Optional. The loading policy (defaults to Load::Mandatory). ### Request Example ```cpp // Look for .mtl file in subfolder 'materials' using a relative search path. Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::SearchPath("materials")); // Look for .mtl file in an arbitrary file folder using an absolute search path. Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::SearchPath("/home/user/materials")); ``` ### Response (No specific response details provided for this constructor) ``` -------------------------------- ### Compile with C++17 Standard Source: https://github.com/guybrush77/rapidobj/blob/master/README.md When compiling your project, ensure you use the C++17 standard flag. This is required for rapidobj. ```bash g++ -std=c++17 my_src.cpp -pthread -o my_app ``` -------------------------------- ### MaterialLibrary::Default(Load policy) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Creates a default MaterialLibrary with a specified loading policy, primarily for ParseFile. ```APIDOC ## MaterialLibrary::Default(Load policy) ### Description A convenience constructor for [`ParseFile`](#parsefile) only. Identical to `MaterialLibrary::SearchPath(".", policy)`. ### Method static MaterialLibrary Default(Load policy) ### Parameters #### Path Parameters - **policy** (Load) - Description of the loading policy (e.g., Mandatory, Optional). ### Request Example ```cpp // Look for the teapot.mtl file in the teapot folder. // This call will not generate an error if teapot.mtl cannot be found. Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::Default(Load::Optional)); ``` ### Response (No specific response details provided for this constructor) ``` -------------------------------- ### Load Material Library (Optional) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Allows ParseFile to continue .obj loading even if the .mtl file is not found. The Materials array will be empty in this case. ```c++ // Look for .mtl file in subfolder 'materials'. // If the file cannot be found, ParseFile function will continue .obj loading and parsing. // MaterialLibrary mtllib = MaterialLibrary::SearchPath("materials", Load::Optional); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` -------------------------------- ### Parse OBJ File Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Load and parse a Wavefront .obj file from a given file path. Uses default material library loading policy. ```cpp rapidobj::Result result = rapidobj::ParseFile("/home/user/teapot/teapot.obj"); ``` -------------------------------- ### Load Material Library (Mandatory) Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Instructs ParseFile to stop execution if the .mtl file cannot be opened. Ensure the .mtl file exists in the specified path. ```c++ // Look for .mtl file in subfolder 'materials'. // If the file cannot be found, ParseFile function will fail with an error. // MaterialLibrary mtllib = MaterialLibrary::SearchPath("materials", Load::Mandatory); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` -------------------------------- ### Configure Executable and Sources Source: https://github.com/guybrush77/rapidobj/blob/master/tests/func-tests/CMakeLists.txt Defines the executable name for the functional tests and lists the source files to be compiled. ```cmake cmake_minimum_required(VERSION 3.20) add_executable(func-tests) target_sources(func-tests PRIVATE "src/test_main.cpp" "src/test_rapidobj.cpp" ) ``` -------------------------------- ### MaterialLibrary::Default() Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Creates a default MaterialLibrary. For ParseFile, it searches the current directory. For ParseStream, it ignores materials but populates material IDs. ```APIDOC ## MaterialLibrary::Default() ### Description A convenience constructor. For [`ParseFile`](#parsefile), this constructor is identical to `MaterialLibrary::SearchPath(".", Load::Mandatory)`. For [`ParseStream`](#parsestream), this constructor is identical to `MaterialLibrary::Ignore()`, except that [`Mesh::material_ids`](#meshmaterial_ids) will be populated. ### Method static MaterialLibrary Default() ### Request Example ```cpp // Default search assumes .obj and .mtl file are in the same folder. Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::Default()); ``` ### Response (No specific response details provided for this constructor) ``` -------------------------------- ### Parse OBJ with Material Library Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use this to parse an OBJ file and load its associated material library. The 'materials' string will be populated with the library's content. ```c++ Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::String(materials)); ``` -------------------------------- ### Parse with Material Library from String Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use MaterialLibrary::String to provide material definitions directly as a string when parsing. ```c++ // Define a material library as a string, then pass it to ParseFile function. // // home // └── user // └── teapot // └── teapot.obj static constexpr auto materials = R"( newmtl red Kd 1 0 0 )"; ``` -------------------------------- ### ParseFile Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Loads and parses a Wavefront .obj file from a given file path. It returns a binary Result object containing the parsed data. An optional MaterialLibrary can be provided to specify .mtl file search paths and loading policies. ```APIDOC ## ParseFile ### Description Loads a Wavefront .obj data from a file, parses it and returns a binary [`Result`](#result) object. ### Signature ```c++ Result ParseFile( const std::filesystem::path& obj_filepath, const MaterialLibrary& mtl_library = MaterialLibrary::Default()); ``` ### Parameters - `obj_filepath` - Path to .obj file to be parsed. - `mtl_library` - [`MaterialLibrary`](#materiallibrary) object specifies .mtl file search path(s) and loading policy. ### Result - [`Result`](#result) - The .obj file data in a binary format. ### Request Example ```c++ rapidobj::Result result = rapidobj::ParseFile("/home/user/teapot/teapot.obj"); ``` ``` -------------------------------- ### Include Rapidobj Header Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Include the rapidobj header file to use the library in your C++ project. Ensure your compiler supports C++17. ```cpp #include "rapidobj.hpp" ``` -------------------------------- ### Configure make-test Executable Source: https://github.com/guybrush77/rapidobj/blob/master/tools/make-test/CMakeLists.txt Defines the make-test executable, specifies its source files, C++ standard, and linked libraries. ```cmake cmake_minimum_required(VERSION 3.20) add_executable(make-test) target_sources(make-test PRIVATE "src/make-test.cpp") target_compile_features(make-test PRIVATE cxx_std_17) target_link_libraries(make-test PRIVATE cxxopts serializer tinyobjloader) ``` -------------------------------- ### Parse OBJ Stream Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Load and parse a Wavefront .obj file from a standard input stream. This method is generally less performant than ParseFile due to stream sequential access. ```cpp std::ifstream stream("/home/user/teapot/teapot.obj"); rapidobj::Result result = rapidobj::ParseStream(stream); ``` -------------------------------- ### Parse OBJ with Multiple Search Paths Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use MaterialLibrary::SearchPaths to specify multiple search paths for .mtl files. Paths are checked in order. Relative paths are relative to the .obj file's parent directory and only apply to ParseFile. ```c++ // Look for .mtl file in folder /home/user/teapot/materials, // then /home/user/materials, then /home/user/teapot. // // home // └── user // ├── materials // │   └── teapot.mtl // └── teapot // ├── materials // │   └── teapot.mtl // ├── teapot.mtl // └── teapot.obj MaterialLibrary mtllib = MaterialLibrary::SearchPaths({ "materials", "../materials", "." }); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` -------------------------------- ### Count Triangles in OBJ File Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Parses an OBJ file, triangulates its geometry, and counts the total number of triangles. Includes error handling for parsing and triangulation steps. Requires the rapidobj library and iostream. ```cpp #include "rapidobj/rapidobj.hpp" #include int main() { rapidobj::Result result = rapidobj::ParseFile("/path/to/my.obj"); if (result.error) { std::cout << result.error.code.message() << '\n'; return EXIT_FAILURE; } bool success = rapidobj::Triangulate(result); if (!success) { std::cout << result.error.code.message() << '\n'; return EXIT_FAILURE; } size_t num_triangles{}; for (const auto& shape : result.shapes) { num_triangles += shape.mesh.num_face_vertices.size(); } std::cout << "Shapes: " << result.shapes.size() << '\n'; std::cout << "Materials: " << result.materials.size() << '\n'; std::cout << "Triangles: " << num_triangles << '\n'; return EXIT_SUCCESS; } ``` -------------------------------- ### Include RapidObj Header Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Include the main RapidObj header file in your C++ source code. The header is located in a 'rapidobj' subfolder. ```cpp #include "rapidobj/rapidobj.hpp" ``` -------------------------------- ### Parse OBJ with Default Material Library and Optional Loading Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use MaterialLibrary::Default(Load::Optional) for ParseFile to specify optional loading of the .mtl file in the current directory. ```c++ // Look for the teapot.mtl file in the teapot folder. // This call will not generate an error if teapot.mtl cannot be found. // // home // └── user // └── teapot // └── teapot.obj Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::Default(Load::Optional)); ``` -------------------------------- ### Set C++ Standard Source: https://github.com/guybrush77/rapidobj/blob/master/tests/unit-tests/CMakeLists.txt Specifies that the C++17 standard should be used for compiling the unit tests. ```cmake target_compile_features(unit-tests PRIVATE cxx_std_17) ``` -------------------------------- ### Set Compile Definitions Source: https://github.com/guybrush77/rapidobj/blob/master/tests/unit-tests/CMakeLists.txt Defines TEST_DATA_DIR for the unit tests, allowing it to be set externally. ```cmake target_compile_definitions(unit-tests PUBLIC TEST_DATA_DIR=${TEST_DATA_DIR}) ``` -------------------------------- ### Link Libraries for Tests Source: https://github.com/guybrush77/rapidobj/blob/master/tests/func-tests/CMakeLists.txt Links the necessary libraries for the functional tests to use. ```cmake target_link_libraries(func-tests PRIVATE doctest compare-test) ``` -------------------------------- ### Add Test Subdirectories Source: https://github.com/guybrush77/rapidobj/blob/master/tests/CMakeLists.txt Includes subdirectories for functional and unit tests. These subdirectories should contain their own CMakeLists.txt files. ```cmake add_subdirectory(func-tests) ``` ```cmake add_subdirectory(unit-tests) ``` -------------------------------- ### Load Policy Configuration Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Defines how the library handles missing material (.mtl) files during parsing. Users can choose between mandatory loading (which fails on missing files) or optional loading (which continues without error). ```APIDOC ## Load Policy Load is passed as an argument to [`MaterialLibrary`](#materiallibrary) `SearchPath(s)` constructors to specify which actions to take if the material library file cannot be opened. Mandatory loading instructs the [`ParseFile`](#parsefile) and [`ParseStream`](#parsestream) functions to immediately stop further execution and produce an error if the .mtl file cannot be opened. Optional loading instructs the Parse functions to continue .obj loading and parsing, even if the .mtl file cannot be opened. No error will be generated. However, in this case, the [`Materials`](#materials) array will be empty. [`Mesh::material_ids`](#meshmaterial_ids) will contain ids assigned in order of appearance in the .obj file (0, 1, 2 etc.). **Signature:** ```cpp enum class Load { Mandatory, Optional }; ``` ### Examples ```cpp // Look for .mtl file in subfolder 'materials'. // If the file cannot be found, ParseFile function will fail with an error. // MaterialLibrary mtllib = MaterialLibrary::SearchPath("materials", Load::Mandatory); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` ```cpp // Look for .mtl file in subfolder 'materials'. // If the file cannot be found, ParseFile function will continue .obj loading and parsing. // MaterialLibrary mtllib = MaterialLibrary::SearchPath("materials", Load::Optional); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` ```cpp // Look for .mtl file in default location. // If the file cannot be found, ParseFile function will continue .obj loading and parsing. // MaterialLibrary mtllib = MaterialLibrary::Default(Load::Optional); Result result = ParseFile("/home/user/teapot/teapot.obj", mtllib); ``` ``` -------------------------------- ### Parse OBJ with Default Material Library Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use MaterialLibrary::Default() when the .mtl file is in the same directory as the .obj file. This can be omitted as it's the default argument for ParseFile. ```c++ // Default search assumes .obj and .mtl file are in the same folder. // // home // └── user // └── teapot // ├── teapot.mtl // └── teapot.obj Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::Default()); ``` ```c++ // MaterialLibrary::Default can be omitted since it is the default argument of ParseFile. // // home // └── user // └── teapot // ├── teapot.mtl // └── teapot.obj Result result = ParseFile("/home/user/teapot/teapot.obj"); ``` -------------------------------- ### MaterialLibrary::Ignore() Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Creates a MaterialLibrary that ignores all material definitions. ```APIDOC ## MaterialLibrary::Ignore() ### Description Creates a MaterialLibrary that ignores all material definitions. ### Method static MaterialLibrary Ignore() ### Response (No specific response details provided for this constructor) ``` -------------------------------- ### Define Test Data Directory Source: https://github.com/guybrush77/rapidobj/blob/master/tests/CMakeLists.txt Sets a variable for the directory containing test data. This path is relative to the current source directory. ```cmake set(TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data) ``` -------------------------------- ### Set C++ Standard and Definitions Source: https://github.com/guybrush77/rapidobj/blob/master/tests/func-tests/CMakeLists.txt Specifies the C++ standard required for compilation and defines preprocessor macros. ```cmake target_compile_features(func-tests PRIVATE cxx_std_17) target_compile_definitions(func-tests PUBLIC TEST_DATA_DIR=${TEST_DATA_DIR}) ``` -------------------------------- ### Parse OBJ with Specific Search Path Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use MaterialLibrary::SearchPath to specify a relative or absolute path for .mtl files when parsing with ParseFile. Relative paths are relative to the .obj file's parent directory. ```c++ // Look for .mtl file in subfolder 'materials' using a relative search path. // // home // └── user // └── teapot // ├── materials // │   └── teapot.mtl // └── teapot.obj Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::SearchPath("materials")); ``` ```c++ // Look for .mtl file in an arbitrary file folder using an absolute search path. // // home // └── user // ├── materials // │   └── teapot.mtl // └── teapot // └── teapot.obj Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::SearchPath("/home/user/materials")); ``` -------------------------------- ### Define Test Targets Source: https://github.com/guybrush77/rapidobj/blob/master/tests/CMakeLists.txt Creates test targets for the unit and functional tests. These can be run using the 'ctest' command. ```cmake add_test(NAME unit-tests COMMAND $) ``` ```cmake add_test(NAME func-tests COMMAND $) ``` -------------------------------- ### ParseStream Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Loads and parses Wavefront .obj data from a standard library input stream. This function returns a binary Result object. Due to the sequential nature of streams, this method is typically less performant than ParseFile. An optional MaterialLibrary can be provided. ```APIDOC ## ParseStream ### Description Loads a Wavefront .obj data from a standard library input stream, parses it and returns a binary [`Result`](#result) object. Because input streams are sequential, this function is usually less performant than the similar [`ParseFile`](#parsefile) function. ### Signature ```c++ Result ParseStream( std::istream& obj_stream, const MaterialLibrary& mtl_library = MaterialLibrary::Default()); ``` ### Parameters - `obj_filepath` - Input stream to parse. - `mtl_library` - [`MaterialLibrary`](#materiallibrary) object specifies .mtl file search path(s) and loading policy. ### Result - [`Result`](#result) - The .obj file data in a binary format. ### Request Example ```c++ std::ifstream stream("/home/user/teapot/teapot.obj"); rapidobj::Result result = rapidobj::ParseStream(stream); ``` ``` -------------------------------- ### Ignore Material Library in OBJ Parsing Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Instructs ParseFile to completely ignore any material libraries, ensuring the 'Materials' array and 'material_ids' are empty. Useful when material data is not needed or might cause issues. ```c++ // Instruct ParseFile to ignore teapot.mtl file. // // home // └── user // └── teapot // ├── teapot.mtl // └── teapot.obj Result result = ParseFile("/home/user/teapot/teapot.obj", MaterialLibrary::Ignore()); ``` -------------------------------- ### Parse Stream with Default Material Library Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Use MaterialLibrary::Default() with ParseStream. The material library won't be parsed, but Mesh::material_ids will be populated. This can be omitted as it's the default argument. ```c++ // MaterialLibrary::Default can be omitted since it is the default argument of ParseStream. // Material library will not be parsed, but Mesh::material_ids will be populated. // Result result = ParseStream(input_stream); ``` -------------------------------- ### Triangulate Mesh Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Converts all triangular faces in the provided Result object into triangles. This is useful for rendering or further processing that requires a triangular mesh. ```APIDOC ## Triangulate Triangulate all meshes in the [`Result`](#result) object. **Signature:** ```cpp bool Triangulate(Result& result) ``` **Parameters:** - `result` - [`Result`](#result) object returned from the [`ParseFile`](#parsefile) or [`ParseStream`](#parsestream) functions. **Result:** - `bool` - True if triangulation was successful; false otherwise. ### Examples ```cpp Result result = ParseFile("/home/user/teapot/teapot.obj"); bool success = Triangulate(result); ``` ``` -------------------------------- ### Triangulate Mesh Data Source: https://github.com/guybrush77/rapidobj/blob/master/README.md Converts all meshes within the Result object into triangles. This function modifies the Result object in place. ```c++ Result result = ParseFile("/home/user/teapot/teapot.obj"); bool success = Triangulate(result); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.