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
bac3824a
Commit
bac3824a
authored
Oct 08, 2020
by
TheNumbat
Browse files
upstream changes
parent
090fe3ef
Changes
5
Show whitespace changes
Inline
Side-by-side
src/geometry/util.cpp
View file @
bac3824a
...
...
@@ -187,7 +187,7 @@ Data cone(float bradius, float tradius, float height, int sides, bool caps) {
vertices
[
vert
]
=
Vec3
(
std
::
cos
(
rad
)
*
tradius
,
height
,
std
::
sin
(
rad
)
*
tradius
);
vert
++
;
}
in
t
v
=
0
;
size_
t
v
=
0
;
while
(
vert
<=
vertices
.
size
()
-
4
)
{
float
rad
=
(
float
)
v
/
n_sides
*
_2pi
;
vertices
[
vert
]
=
Vec3
(
std
::
cos
(
rad
)
*
tradius
,
height
,
std
::
sin
(
rad
)
*
tradius
);
...
...
src/gui/manager.cpp
View file @
bac3824a
...
...
@@ -731,6 +731,7 @@ void Manager::UInew_obj(Undo &undo) {
ImGui
::
PopID
();
}
#if 0 // These have some problems converting to halfedge
ImGui::Separator();
if (ImGui::CollapsingHeader("Cylinder")) {
...
...
@@ -748,7 +749,6 @@ void Manager::UInew_obj(Undo &undo) {
ImGui::Separator();
#if 0 // The procedural torus has some problems converting to halfedge
if(ImGui::CollapsingHeader("Torus")) {
ImGui::PushID(idx++);
static float IR = 0.8f, OR = 1.0f;
...
...
@@ -764,8 +764,24 @@ void Manager::UInew_obj(Undo &undo) {
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Cone")) {
ImGui::PushID(idx++);
static float BR = 1.0f, TR = 0.1f, H = 1.0f;
static int S = 12;
ImGui::SliderFloat("Bottom Radius", &BR, 0.01f, 10.0f, "%.2f");
ImGui::SliderFloat("Top Radius", &TR, 0.01f, 10.0f, "%.2f");
ImGui::SliderFloat("Height", &H, 0.01f, 10.0f, "%.2f");
ImGui::SliderInt("Sides", &S, 3, 100);
if (ImGui::Button("Add")) {
add_mesh("Cone", Util::cone_mesh(BR, TR, H, S));
}
ImGui::PopID();
}
#endif
ImGui
::
Separator
();
if
(
ImGui
::
CollapsingHeader
(
"Sphere"
))
{
ImGui
::
PushID
(
idx
++
);
static
float
R
=
1.0
f
;
...
...
@@ -779,22 +795,6 @@ void Manager::UInew_obj(Undo &undo) {
}
ImGui
::
PopID
();
}
ImGui
::
Separator
();
if
(
ImGui
::
CollapsingHeader
(
"Cone"
))
{
ImGui
::
PushID
(
idx
++
);
static
float
BR
=
1.0
f
,
TR
=
0.1
f
,
H
=
1.0
f
;
static
int
S
=
12
;
ImGui
::
SliderFloat
(
"Bottom Radius"
,
&
BR
,
0.01
f
,
10.0
f
,
"%.2f"
);
ImGui
::
SliderFloat
(
"Top Radius"
,
&
TR
,
0.01
f
,
10.0
f
,
"%.2f"
);
ImGui
::
SliderFloat
(
"Height"
,
&
H
,
0.01
f
,
10.0
f
,
"%.2f"
);
ImGui
::
SliderInt
(
"Sides"
,
&
S
,
3
,
100
);
if
(
ImGui
::
Button
(
"Add"
))
{
add_mesh
(
"Cone"
,
Util
::
cone_mesh
(
BR
,
TR
,
H
,
S
));
}
ImGui
::
PopID
();
}
ImGui
::
End
();
}
...
...
src/gui/model.cpp
View file @
bac3824a
...
...
@@ -217,19 +217,6 @@ std::optional<Halfedge_Mesh::ElementRef> Model::selected_element() {
void
Model
::
unset_mesh
()
{
my_mesh
=
nullptr
;
}
void
Model
::
set_mesh
(
Halfedge_Mesh
&
mesh
)
{
Halfedge_Mesh
*
old
=
my_mesh
;
my_mesh
=
&
mesh
;
if
(
old
!=
my_mesh
)
{
selected_elem_id
=
0
;
hovered_elem_id
=
0
;
rebuild
();
}
else
if
(
old
->
render_dirty_flag
)
{
rebuild
();
}
}
void
Model
::
vertex_viz
(
Halfedge_Mesh
::
VertexRef
v
,
float
&
size
,
Mat4
&
transform
)
{
// Sphere size ~ 0.05 * min incident edge length
...
...
@@ -572,23 +559,40 @@ void Model::zoom_to(Halfedge_Mesh::ElementRef ref, Camera &cam) {
cam
.
look_at
(
center
,
pos
);
}
std
::
optional
<
std
::
reference_wrapper
<
Scene_Object
>>
Model
::
i
s_my_obj
(
Scene_Maybe
obj_opt
)
{
std
::
optional
<
std
::
reference_wrapper
<
Scene_Object
>>
Model
::
s
et
_my_obj
(
Scene_Maybe
obj_opt
)
{
if
(
!
obj_opt
.
has_value
())
if
(
!
obj_opt
.
has_value
())
{
my_mesh
=
nullptr
;
return
std
::
nullopt
;
}
Scene_Item
&
item
=
obj_opt
.
value
();
if
(
!
item
.
is
<
Scene_Object
>
())
if
(
!
item
.
is
<
Scene_Object
>
())
{
my_mesh
=
nullptr
;
return
std
::
nullopt
;
}
Scene_Object
&
obj
=
item
.
get
<
Scene_Object
>
();
if
(
obj
.
opt
.
shape_type
!=
PT
::
Shape_Type
::
none
)
if
(
obj
.
opt
.
shape_type
!=
PT
::
Shape_Type
::
none
)
{
my_mesh
=
nullptr
;
return
std
::
nullopt
;
}
if
(
!
my_mesh
||
!
obj
.
is_editable
())
if
(
!
obj
.
is_editable
())
{
my_mesh
=
nullptr
;
return
std
::
nullopt
;
}
Halfedge_Mesh
*
old
=
my_mesh
;
my_mesh
=
&
obj
.
get_mesh
();
assert
(
my_mesh
==
&
obj
.
get_mesh
());
if
(
old
!=
my_mesh
)
{
selected_elem_id
=
0
;
hovered_elem_id
=
0
;
rebuild
();
}
else
if
(
old
->
render_dirty_flag
)
{
rebuild
();
}
return
obj
;
}
...
...
@@ -602,7 +606,7 @@ std::string Model::UIsidebar(Undo &undo, Widgets &widgets, Scene_Maybe obj_opt,
}
ImGui
::
Separator
();
auto
opt
=
i
s_my_obj
(
obj_opt
);
auto
opt
=
s
et
_my_obj
(
obj_opt
);
if
(
!
opt
.
has_value
())
return
{};
Scene_Object
&
obj
=
opt
.
value
();
...
...
@@ -765,7 +769,7 @@ std::string Model::UIsidebar(Undo &undo, Widgets &widgets, Scene_Maybe obj_opt,
void
Model
::
erase_selected
(
Undo
&
undo
,
Scene_Maybe
obj_opt
)
{
auto
opt
=
i
s_my_obj
(
obj_opt
);
auto
opt
=
s
et
_my_obj
(
obj_opt
);
if
(
!
opt
.
has_value
())
return
;
Scene_Object
&
obj
=
opt
.
value
();
...
...
@@ -801,21 +805,11 @@ void Model::clear_select() { selected_elem_id = 0; }
void
Model
::
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
)
{
if
(
!
obj_opt
.
has_value
())
return
;
Scene_Item
&
item
=
obj_opt
.
value
();
if
(
!
item
.
is
<
Scene_Object
>
())
return
;
Scene_Object
&
obj
=
item
.
get
<
Scene_Object
>
();
if
(
obj
.
opt
.
shape_type
!=
PT
::
Shape_Type
::
none
)
return
;
auto
obj
=
set_my_obj
(
obj_opt
);
if
(
!
obj
.
has_value
())
return
;
Mat4
view
=
cam
.
get_view
();
set_mesh
(
obj
.
get_mesh
());
Renderer
::
HalfedgeOpt
opts
(
*
this
);
opts
.
modelview
=
view
;
opts
.
v_color
=
v_col
;
...
...
src/gui/model.h
View file @
bac3824a
...
...
@@ -45,11 +45,10 @@ private:
std
::
string
update_mesh_global
(
Undo
&
undo
,
Scene_Object
&
obj
,
Halfedge_Mesh
&&
before
,
T
&&
op
);
void
zoom_to
(
Halfedge_Mesh
::
ElementRef
ref
,
Camera
&
cam
);
void
set_mesh
(
Halfedge_Mesh
&
mesh
);
void
begin_transform
();
bool
begin_bevel
(
std
::
string
&
err
);
void
set_selected
(
Halfedge_Mesh
::
ElementRef
elem
);
std
::
optional
<
std
::
reference_wrapper
<
Scene_Object
>>
i
s_my_obj
(
Scene_Maybe
obj_opt
);
std
::
optional
<
std
::
reference_wrapper
<
Scene_Object
>>
s
et
_my_obj
(
Scene_Maybe
obj_opt
);
std
::
optional
<
Halfedge_Mesh
::
ElementRef
>
selected_element
();
void
rebuild
();
...
...
src/scene/scene.cpp
View file @
bac3824a
...
...
@@ -495,11 +495,10 @@ std::string Scene::load(bool new_scene, Undo &undo, Gui::Manager &gui, std::stri
Assimp
::
Importer
importer
;
const
aiScene
*
scene
=
importer
.
ReadFile
(
file
.
c_str
(),
aiProcess_PopulateArmatureData
|
aiProcess_
FixInfacingNormal
s
|
aiProcess_ValidateDataStructure
|
aiProcess_
OptimizeMeshes
|
file
.
c_str
(),
aiProcess_PopulateArmatureData
|
aiProcess_
OptimizeMeshe
s
|
aiProcess_ValidateDataStructure
|
aiProcess_
FindInvalidData
|
aiProcess_FindInstances
|
aiProcess_FindDegenerates
|
aiProcess_DropNormals
|
aiProcess_JoinIdenticalVertices
|
aiProcess_FindInvalidData
);
aiProcess_DropNormals
|
aiProcess_JoinIdenticalVertices
);
if
(
!
scene
)
{
return
"Parsing scene "
+
file
+
": "
+
std
::
string
(
importer
.
GetErrorString
());
...
...
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