Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Courses
Scotty3D
Commits
57f98ce1
Commit
57f98ce1
authored
Sep 30, 2020
by
TheNumbat
Browse files
fix multi-boundary mesh loading
parent
768c19db
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/geometry/halfedge.cpp
View file @
57f98ce1
...
...
@@ -28,6 +28,7 @@ void Halfedge_Mesh::clear() {
faces
.
clear
();
boundaries
.
clear
();
render_dirty_flag
=
true
;
next_id
=
Gui
::
n_Widget_IDs
;
}
void
Halfedge_Mesh
::
copy_to
(
Halfedge_Mesh
&
mesh
)
{
copy_to
(
mesh
,
0
);
}
...
...
@@ -42,10 +43,10 @@ Halfedge_Mesh::ElementRef Halfedge_Mesh::copy_to(Halfedge_Mesh &mesh, unsigned i
// with elements of the new mesh. (Note that we can use a single
// map for both interior and boundary faces, because the map
// doesn't care which list of faces these iterators come from.)
std
::
unordered_map
<
HalfedgeCRef
,
HalfedgeRef
>
halfedgeOldToNew
(
n_halfedges
());
std
::
unordered_map
<
VertexCRef
,
VertexRef
>
vertexOldToNew
(
n_vertices
());
std
::
unordered_map
<
EdgeCRef
,
EdgeRef
>
edgeOldToNew
(
n_edges
());
std
::
unordered_map
<
FaceCRef
,
FaceRef
>
faceOldToNew
(
n_faces
());
std
::
unordered_map
<
unsigned
int
,
HalfedgeRef
>
halfedgeOldToNew
(
n_halfedges
());
std
::
unordered_map
<
unsigned
int
,
VertexRef
>
vertexOldToNew
(
n_vertices
());
std
::
unordered_map
<
unsigned
int
,
EdgeRef
>
edgeOldToNew
(
n_edges
());
std
::
unordered_map
<
unsigned
int
,
FaceRef
>
faceOldToNew
(
n_faces
());
// Copy geometry from the original mesh and create a map from
// pointers in the original mesh to those in the new mesh.
...
...
@@ -53,49 +54,49 @@ Halfedge_Mesh::ElementRef Halfedge_Mesh::copy_to(Halfedge_Mesh &mesh, unsigned i
auto
hn
=
mesh
.
halfedges
.
insert
(
mesh
.
halfedges
.
end
(),
*
h
);
if
(
h
->
id
()
==
eid
)
ret
=
hn
;
halfedgeOldToNew
[
h
]
=
hn
;
halfedgeOldToNew
[
h
->
id
()
]
=
hn
;
}
for
(
VertexCRef
v
=
vertices_begin
();
v
!=
vertices_end
();
v
++
)
{
auto
vn
=
mesh
.
vertices
.
insert
(
mesh
.
vertices
.
end
(),
*
v
);
if
(
v
->
id
()
==
eid
)
ret
=
vn
;
vertexOldToNew
[
v
]
=
vn
;
vertexOldToNew
[
v
->
id
()
]
=
vn
;
}
for
(
EdgeCRef
e
=
edges_begin
();
e
!=
edges_end
();
e
++
)
{
auto
en
=
mesh
.
edges
.
insert
(
mesh
.
edges
.
end
(),
*
e
);
if
(
e
->
id
()
==
eid
)
ret
=
en
;
edgeOldToNew
[
e
]
=
en
;
edgeOldToNew
[
e
->
id
()
]
=
en
;
}
for
(
FaceCRef
f
=
faces_begin
();
f
!=
faces_end
();
f
++
)
{
auto
fn
=
mesh
.
faces
.
insert
(
mesh
.
faces
.
end
(),
*
f
);
if
(
f
->
id
()
==
eid
)
ret
=
fn
;
faceOldToNew
[
f
]
=
fn
;
faceOldToNew
[
f
->
id
()
]
=
fn
;
}
for
(
FaceCRef
b
=
boundaries_begin
();
b
!=
boundaries_end
();
b
++
)
{
auto
bn
=
mesh
.
boundaries
.
insert
(
mesh
.
boundaries
.
end
(),
*
b
);
if
(
b
->
id
()
==
eid
)
ret
=
bn
;
faceOldToNew
[
b
]
=
bn
;
faceOldToNew
[
b
->
id
()
]
=
bn
;
}
// "Search and replace" old pointers with new ones.
for
(
HalfedgeRef
he
=
mesh
.
halfedges_begin
();
he
!=
mesh
.
halfedges_end
();
he
++
)
{
he
->
next
()
=
halfedgeOldToNew
[
he
->
next
()];
he
->
twin
()
=
halfedgeOldToNew
[
he
->
twin
()];
he
->
vertex
()
=
vertexOldToNew
[
he
->
vertex
()];
he
->
edge
()
=
edgeOldToNew
[
he
->
edge
()];
he
->
face
()
=
faceOldToNew
[
he
->
face
()];
he
->
next
()
=
halfedgeOldToNew
[
he
->
next
()
->
id
()
];
he
->
twin
()
=
halfedgeOldToNew
[
he
->
twin
()
->
id
()
];
he
->
vertex
()
=
vertexOldToNew
[
he
->
vertex
()
->
id
()
];
he
->
edge
()
=
edgeOldToNew
[
he
->
edge
()
->
id
()
];
he
->
face
()
=
faceOldToNew
[
he
->
face
()
->
id
()
];
}
for
(
VertexRef
v
=
mesh
.
vertices_begin
();
v
!=
mesh
.
vertices_end
();
v
++
)
v
->
halfedge
()
=
halfedgeOldToNew
[
v
->
halfedge
()];
v
->
halfedge
()
=
halfedgeOldToNew
[
v
->
halfedge
()
->
id
()
];
for
(
EdgeRef
e
=
mesh
.
edges_begin
();
e
!=
mesh
.
edges_end
();
e
++
)
e
->
halfedge
()
=
halfedgeOldToNew
[
e
->
halfedge
()];
e
->
halfedge
()
=
halfedgeOldToNew
[
e
->
halfedge
()
->
id
()
];
for
(
FaceRef
f
=
mesh
.
faces_begin
();
f
!=
mesh
.
faces_end
();
f
++
)
f
->
halfedge
()
=
halfedgeOldToNew
[
f
->
halfedge
()];
f
->
halfedge
()
=
halfedgeOldToNew
[
f
->
halfedge
()
->
id
()
];
for
(
FaceRef
b
=
mesh
.
boundaries_begin
();
b
!=
mesh
.
boundaries_end
();
b
++
)
b
->
halfedge
()
=
halfedgeOldToNew
[
b
->
halfedge
()];
b
->
halfedge
()
=
halfedgeOldToNew
[
b
->
halfedge
()
->
id
()
];
mesh
.
render_dirty_flag
=
true
;
mesh
.
next_id
=
next_id
;
...
...
@@ -467,6 +468,8 @@ bool Halfedge_Mesh::subdivide(SubD strategy) {
}
break
;
case
SubD
::
loop
:
{
if
(
boundaries
.
size
())
return
false
;
for
(
FaceRef
f
=
faces_begin
();
f
!=
faces_end
();
f
++
)
{
if
(
f
->
degree
()
!=
3
)
return
false
;
...
...
src/geometry/halfedge.h
View file @
57f98ce1
...
...
@@ -508,6 +508,7 @@ public:
Size
n_vertices
()
const
{
return
vertices
.
size
();
};
Size
n_edges
()
const
{
return
edges
.
size
();
};
Size
n_faces
()
const
{
return
faces
.
size
();
};
Size
n_boundaries
()
const
{
return
boundaries
.
size
();
};
Size
n_halfedges
()
const
{
return
halfedges
.
size
();
};
/// Check if half-edge mesh is valid
...
...
src/gui/model.cpp
View file @
57f98ce1
...
...
@@ -62,24 +62,30 @@ void Model::update_vertex(Halfedge_Mesh::VertexRef vert) {
vertex_viz
(
v
,
d
,
vi
.
transform
);
vert_sizes
[
v
->
id
()]
=
d
;
size_t
idx
=
id_to_info
[
h
->
face
()
->
id
()].
instance
;
face_viz
(
h
->
face
(),
face_mesh
.
edit_verts
(),
face_mesh
.
edit_indices
(),
idx
);
Halfedge_Mesh
::
HalfedgeRef
fh
=
h
->
face
()
->
halfedge
();
do
{
halfedge_viz
(
fh
,
arrows
.
get
(
id_to_info
[
fh
->
id
()].
instance
).
transform
);
fh
=
fh
->
next
();
}
while
(
fh
!=
h
->
face
()
->
halfedge
());
if
(
!
h
->
face
()
->
is_boundary
())
{
size_t
idx
=
id_to_info
[
h
->
face
()
->
id
()].
instance
;
face_viz
(
h
->
face
(),
face_mesh
.
edit_verts
(),
face_mesh
.
edit_indices
(),
idx
);
Halfedge_Mesh
::
HalfedgeRef
fh
=
h
->
face
()
->
halfedge
();
do
{
halfedge_viz
(
fh
,
arrows
.
get
(
id_to_info
[
fh
->
id
()].
instance
).
transform
);
fh
=
fh
->
next
();
}
while
(
fh
!=
h
->
face
()
->
halfedge
());
}
h
=
h
->
twin
()
->
next
();
}
while
(
h
!=
vert
->
halfedge
());
// Update surrounding halfedges & edges
do
{
GL
::
Instances
::
Info
&
hi
=
arrows
.
get
(
id_to_info
[
h
->
id
()].
instance
);
halfedge_viz
(
h
,
hi
.
transform
);
GL
::
Instances
::
Info
&
thi
=
arrows
.
get
(
id_to_info
[
h
->
twin
()
->
id
()].
instance
);
halfedge_viz
(
h
->
twin
(),
thi
.
transform
);
if
(
!
h
->
is_boundary
())
{
GL
::
Instances
::
Info
&
hi
=
arrows
.
get
(
id_to_info
[
h
->
id
()].
instance
);
halfedge_viz
(
h
,
hi
.
transform
);
}
if
(
!
h
->
twin
()
->
is_boundary
())
{
GL
::
Instances
::
Info
&
thi
=
arrows
.
get
(
id_to_info
[
h
->
twin
()
->
id
()].
instance
);
halfedge_viz
(
h
->
twin
(),
thi
.
transform
);
}
GL
::
Instances
::
Info
&
e
=
cylinders
.
get
(
id_to_info
[
h
->
edge
()
->
id
()].
instance
);
edge_viz
(
h
->
edge
(),
e
.
transform
);
...
...
@@ -375,8 +381,6 @@ void Model::rebuild() {
std
::
vector
<
GL
::
Mesh
::
Index
>
idxs
;
for
(
auto
f
=
mesh
.
faces_begin
();
f
!=
mesh
.
faces_end
();
f
++
)
{
if
(
f
->
is_boundary
())
continue
;
face_viz
(
f
,
verts
,
idxs
,
verts
.
size
());
}
face_mesh
.
recreate
(
std
::
move
(
verts
),
std
::
move
(
idxs
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment