blob: 8dd60d1710097ca552a74c896ab2deb80d1ffb83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup obj
*/
#pragma once
#include "BLI_fileops.hh"
#include "IO_wavefront_obj.h"
#include "obj_import_mtl.hh"
#include "obj_import_objects.hh"
namespace blender::io::obj {
/* Note: the OBJ parser implementation is planned to get fairly large changes "soon",
* so don't read too much into current implementation... */
class OBJParser {
private:
const OBJImportParams &import_params_;
FILE *obj_file_;
Vector<std::string> mtl_libraries_;
size_t read_buffer_size_;
public:
/**
* Open OBJ file at the path given in import parameters.
*/
OBJParser(const OBJImportParams &import_params, size_t read_buffer_size);
~OBJParser();
/**
* Read the OBJ file line by line and create OBJ Geometry instances. Also store all the vertex
* and UV vertex coordinates in a struct accessible by all objects.
*/
void parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
GlobalVertices &r_global_vertices);
/**
* Return a list of all material library filepaths referenced by the OBJ file.
*/
Span<std::string> mtl_libraries() const;
private:
void add_mtl_library(const std::string &path);
void add_default_mtl_library();
};
class MTLParser {
private:
char mtl_file_path_[FILE_MAX];
/**
* Directory in which the MTL file is found.
*/
char mtl_dir_path_[FILE_MAX];
public:
/**
* Open material library file.
*/
MTLParser(StringRef mtl_library_, StringRefNull obj_filepath);
/**
* Read MTL file(s) and add MTLMaterial instances to the given Map reference.
*/
void parse_and_store(Map<std::string, std::unique_ptr<MTLMaterial>> &r_materials);
};
} // namespace blender::io::obj
|