Lagrange
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
load_obj.h
1/*
2 * Copyright 2023 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/SurfaceMesh.h>
15#include <lagrange/fs/filesystem.h>
16#include <lagrange/io/types.h>
17
18#include <tiny_obj_loader.h>
19
20#include <iosfwd>
21
22namespace lagrange::io::internal {
23
27tinyobj::ObjReader load_obj(const fs::path& filename, const LoadOptions& options = {});
28
32tinyobj::ObjReader load_obj(
33 std::istream& input_stream_obj,
34 std::istream& input_stream_mtl,
35 const LoadOptions& options = {});
36
40template <typename MeshType>
41MeshType load_mesh_obj(const tinyobj::ObjReader& reader, const LoadOptions& options = {});
42
46template <typename SceneType>
47SceneType load_simple_scene_obj(const tinyobj::ObjReader& reader, const LoadOptions& options = {});
48
52template <typename SceneType>
53SceneType load_scene_obj(const tinyobj::ObjReader& reader, const LoadOptions& options = {});
54
55
56// ==== Old API below ====
57
64template <typename Scalar, typename Index>
66{
68 bool success = true;
69
73
75 std::vector<tinyobj::material_t> materials;
76
78 std::vector<std::string> names;
79};
80
81template <typename MeshType>
83 const tinyobj::ObjReader& reader,
84 const LoadOptions& options = {});
85
96template <typename MeshType>
97auto load_mesh_obj(const fs::path& filename, const LoadOptions& options = {})
98 -> ObjReaderResult<typename MeshType::Scalar, typename MeshType::Index>;
99
110template <typename MeshType>
111auto load_mesh_obj(
112 std::istream& input_stream_obj,
113 std::istream& input_stream_mtl,
114 const LoadOptions& options = {})
115 -> ObjReaderResult<typename MeshType::Scalar, typename MeshType::Index>;
116
117} // namespace lagrange::io::internal
Definition: Mesh.h:48
MeshType load_mesh_obj(std::istream &input_stream_obj, const LoadOptions &options={})
Loads a mesh from a file in MSH format.
Definition: load_obj.cpp:488
SceneType load_scene_obj(const fs::path &filename, const LoadOptions &options={})
Load an obj into a scene.
Definition: load_obj.cpp:511
Options used when loading a mesh or a scene.
Definition: types.h:77
Output of the obj mesh loader.
Definition: load_obj.h:66
SurfaceMesh< Scalar, Index > mesh
Aggregated mesh containing all elements in the .obj file.
Definition: load_obj.h:72
bool success
Whether the load operation was successful.
Definition: load_obj.h:68
std::vector< tinyobj::material_t > materials
Materials associated with the mesh.
Definition: load_obj.h:75
std::vector< std::string > names
Names of each object in the aggregate mesh.
Definition: load_obj.h:78