Blender
V5.0
source
blender
io
stl
importer
stl_import_binary_reader.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#include <cstdint>
10
#include <cstdio>
11
12
#include "
BKE_mesh.hh
"
13
14
#include "
BLI_array.hh
"
15
16
#include "
DNA_mesh_types.h
"
17
18
#include "
stl_data.hh
"
19
#include "
stl_import.hh
"
20
#include "
stl_import_binary_reader.hh
"
21
#include "
stl_import_mesh.hh
"
22
23
namespace
blender::io::stl
{
24
25
Mesh
*
read_stl_binary
(FILE *file,
const
bool
use_custom_normals)
26
{
27
const
int
chunk_size = 1024;
28
uint32_t num_tris = 0;
29
fseek(file,
BINARY_HEADER_SIZE
, SEEK_SET);
30
if
(fread(&num_tris,
sizeof
(uint32_t), 1, file) != 1) {
31
stl_import_report_error
(file);
32
return
nullptr
;
33
}
34
35
if
(num_tris == 0) {
36
return
BKE_mesh_new_nomain
(0, 0, 0, 0);
37
}
38
39
Array<PackedTriangle>
tris_buf(chunk_size);
40
STLMeshHelper
stl_mesh(num_tris, use_custom_normals);
41
size_t
num_read_tris;
42
while
((num_read_tris = fread(tris_buf.
data
(),
sizeof
(
PackedTriangle
), chunk_size, file))) {
43
for
(
size_t
i
= 0;
i
< num_read_tris;
i
++) {
44
stl_mesh.
add_triangle
(tris_buf[
i
]);
45
}
46
}
47
48
return
stl_mesh.
to_mesh
();
49
}
50
51
}
// namespace blender::io::stl
BKE_mesh_new_nomain
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
Definition
blenkernel/intern/mesh.cc:1218
BKE_mesh.hh
BLI_array.hh
DNA_mesh_types.h
blender::Array
Definition
BLI_array.hh:50
blender::Array::data
const T * data() const
Definition
BLI_array.hh:312
blender::io::stl::STLMeshHelper
Definition
stl_import_mesh.hh:50
blender::io::stl::STLMeshHelper::add_triangle
bool add_triangle(const PackedTriangle &data)
Definition
stl_import_mesh.cc:37
blender::io::stl::STLMeshHelper::to_mesh
Mesh * to_mesh()
Definition
stl_import_mesh.cc:57
blender::io::stl
Definition
stl_export.cc:40
blender::io::stl::read_stl_binary
Mesh * read_stl_binary(FILE *file, const bool use_custom_normals)
Definition
stl_import_binary_reader.cc:25
blender::io::stl::BINARY_HEADER_SIZE
constexpr size_t BINARY_HEADER_SIZE
Definition
stl_data.hh:21
blender::io::stl::stl_import_report_error
void stl_import_report_error(FILE *file)
Definition
stl_import.cc:42
stl_data.hh
stl_import.hh
stl_import_binary_reader.hh
stl_import_mesh.hh
Mesh
Definition
DNA_mesh_types.h:58
blender::io::stl::PackedTriangle
Definition
stl_data.hh:14
i
i
Definition
text_draw.cc:230
Generated on
for Blender by
doxygen
1.16.1