Skip to content

Commit 0a3b635

Browse files
committed
Emit mesh normals only once
1 parent 3bad602 commit 0a3b635

File tree

4 files changed

+27553
-9
lines changed

4 files changed

+27553
-9
lines changed

storage.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ void regular_voxel_storage::obj_export(std::ostream& fs, bool with_components, b
7373
void regular_voxel_storage::obj_export(obj_export_helper& obj, bool with_components, bool use_value) {
7474
std::ostream& fs = *obj.stream;
7575

76-
fs << "vn 1 0 0\n";
77-
fs << "vn -1 0 0\n";
78-
fs << "vn 0 1 0\n";
79-
fs << "vn 0 -1 0\n";
80-
fs << "vn 0 0 1\n";
81-
fs << "vn 0 0 -1\n";
82-
76+
// Take care to only emit normals once, even though it does not really affect file integrity
77+
if (!obj.normals_emitted) {
78+
fs << "vn 1 0 0\n";
79+
fs << "vn -1 0 0\n";
80+
fs << "vn 0 1 0\n";
81+
fs << "vn 0 -1 0\n";
82+
fs << "vn 0 0 1\n";
83+
fs << "vn 0 0 -1\n";
84+
obj.normals_emitted = true;
85+
}
86+
87+
8388
if (with_components && !use_value) {
8489
size_t counter = 0;
8590
connected_components(this, [&obj, &fs, &counter](regular_voxel_storage* component) {

storage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ class set_voxel_iterator {
192192
struct obj_export_helper {
193193
std::ostream* stream;
194194
size_t vert_counter;
195+
bool normals_emitted = false;
196+
195197
obj_export_helper(std::ostream& fs, size_t n = 1)
196198
: stream(&fs), vert_counter(n) {}
197199
};

0 commit comments

Comments
 (0)