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
c2535f0f
Commit
c2535f0f
authored
Sep 26, 2020
by
TheNumbat
Browse files
upstream changes
parent
8b8ee1f1
Changes
93
Expand all
Show whitespace changes
Inline
Side-by-side
.clang-format
0 → 100644
View file @
c2535f0f
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
...
.gitignore
View file @
c2535f0f
...
...
@@ -19,3 +19,4 @@ settings.json
media/test.*
media/env_maps/
media/test/
debug.log
docs/building.md
View file @
c2535f0f
...
...
@@ -29,7 +29,7 @@ Finally, to build the project:
```
mkdir build
cd build
cmake ..
cmake
-DCMAKE_BUILD_TYPE=RelWithDebInfo
..
make -j4
```
...
...
@@ -73,7 +73,7 @@ To build the project:
```
mkdir build
cd build
cmake ..
cmake
-DCMAKE_BUILD_TYPE=RelWithDebInfo
..
make -j4
```
...
...
src/app.cpp
View file @
c2535f0f
...
...
@@ -4,71 +4,72 @@
#include <imgui/imgui_impl_sdl.h>
#include "app.h"
#include "scene/renderer.h"
#include "geometry/util.h"
#include "platform/platform.h"
#include "scene/renderer.h"
App
::
App
(
Settings
set
,
Platform
*
plt
)
:
window_dim
(
plt
?
plt
->
window_draw
()
:
Vec2
{
1.0
f
}),
camera
(
plt
?
plt
->
window_draw
()
:
Vec2
{
1.0
f
}),
plt
(
plt
),
scene
(
Gui
::
n_Widget_IDs
),
gui
(
scene
,
plt
?
plt
->
window_size
()
:
Vec2
{
1.0
f
}),
undo
(
scene
,
gui
)
{
App
::
App
(
Settings
set
,
Platform
*
plt
)
:
window_dim
(
plt
?
plt
->
window_draw
()
:
Vec2
{
1.0
f
}),
camera
(
plt
?
plt
->
window_draw
()
:
Vec2
{
1.0
f
}),
plt
(
plt
),
scene
(
Gui
::
n_Widget_IDs
),
gui
(
scene
,
plt
?
plt
->
window_size
()
:
Vec2
{
1.0
f
}),
undo
(
scene
,
gui
)
{
if
(
!
set
.
headless
)
assert
(
plt
);
if
(
!
set
.
headless
)
assert
(
plt
);
std
::
string
err
;
bool
loaded_scene
=
true
;
if
(
!
set
.
scene_file
.
empty
())
{
if
(
!
set
.
scene_file
.
empty
())
{
info
(
"Loading scene file..."
);
err
=
scene
.
load
(
true
,
undo
,
gui
,
set
.
scene_file
);
gui
.
set_file
(
set
.
scene_file
);
}
if
(
!
err
.
empty
())
{
if
(
!
err
.
empty
())
{
warn
(
"Error loading scene: %s"
,
err
.
c_str
());
loaded_scene
=
false
;
}
if
(
!
set
.
env_map_file
.
empty
())
{
if
(
!
set
.
env_map_file
.
empty
())
{
info
(
"Loading environment map..."
);
err
=
scene
.
set_env_map
(
set
.
env_map_file
);
if
(
!
err
.
empty
())
warn
(
"Error loading environment map: %s"
,
err
.
c_str
());
if
(
!
err
.
empty
())
warn
(
"Error loading environment map: %s"
,
err
.
c_str
());
}
if
(
!
set
.
headless
)
{
if
(
!
set
.
headless
)
{
GL
::
global_params
();
Renderer
::
setup
(
window_dim
);
apply_window_dim
(
plt
->
window_draw
());
}
else
if
(
loaded_scene
)
{
}
else
if
(
loaded_scene
)
{
info
(
"Rendering scene..."
);
err
=
gui
.
get_render
().
headless_render
(
gui
.
get_animate
(),
scene
,
set
.
output_file
,
set
.
animate
,
set
.
w
,
set
.
h
,
set
.
s
,
set
.
ls
,
set
.
d
,
set
.
exp
,
set
.
w_from_ar
);
set
.
animate
,
set
.
w
,
set
.
h
,
set
.
s
,
set
.
ls
,
set
.
d
,
set
.
exp
,
set
.
w_from_ar
);
if
(
!
err
.
empty
())
warn
(
"Error rendering scene: %s"
,
err
.
c_str
());
if
(
!
err
.
empty
())
warn
(
"Error rendering scene: %s"
,
err
.
c_str
());
else
{
auto
[
build
,
render
]
=
gui
.
get_render
().
completion_time
();
auto
[
build
,
render
]
=
gui
.
get_render
().
completion_time
();
info
(
"Built scene in %.2fs, rendered in %.2fs"
,
build
,
render
);
}
}
}
App
::~
App
()
{
Renderer
::
shutdown
();
}
App
::~
App
()
{
Renderer
::
shutdown
();
}
void
App
::
event
(
SDL_Event
e
)
{
ImGuiIO
&
IO
=
ImGui
::
GetIO
();
ImGuiIO
&
IO
=
ImGui
::
GetIO
();
IO
.
DisplayFramebufferScale
=
plt
->
scale
(
Vec2
{
1.0
f
,
1.0
f
});
switch
(
e
.
type
)
{
switch
(
e
.
type
)
{
case
SDL_KEYDOWN
:
{
if
(
IO
.
WantCaptureKeyboard
)
break
;
if
(
gui
.
keydown
(
undo
,
e
.
key
.
keysym
,
scene
,
camera
))
break
;
if
(
IO
.
WantCaptureKeyboard
)
break
;
if
(
gui
.
keydown
(
undo
,
e
.
key
.
keysym
,
scene
,
camera
))
break
;
#ifdef __APPLE__
Uint16
mod
=
KMOD_GUI
;
...
...
@@ -76,13 +77,12 @@ void App::event(SDL_Event e) {
Uint16
mod
=
KMOD_CTRL
;
#endif
if
(
e
.
key
.
keysym
.
sym
==
SDLK_z
)
{
if
(
e
.
key
.
keysym
.
mod
&
mod
)
{
if
(
e
.
key
.
keysym
.
sym
==
SDLK_z
)
{
if
(
e
.
key
.
keysym
.
mod
&
mod
)
{
undo
.
undo
();
}
}
else
if
(
e
.
key
.
keysym
.
sym
==
SDLK_y
)
{
if
(
e
.
key
.
keysym
.
mod
&
mod
)
{
}
else
if
(
e
.
key
.
keysym
.
sym
==
SDLK_y
)
{
if
(
e
.
key
.
keysym
.
mod
&
mod
)
{
undo
.
redo
();
}
}
...
...
@@ -103,11 +103,11 @@ void App::event(SDL_Event e) {
Vec2
dim
=
plt
->
window_draw
();
Vec2
n
=
Vec2
(
2.0
f
*
p
.
x
/
dim
.
x
-
1.0
f
,
2.0
f
*
p
.
y
/
dim
.
y
-
1.0
f
);
if
(
gui_capture
)
{
if
(
gui_capture
)
{
gui
.
drag_to
(
scene
,
camera
.
pos
(),
n
,
screen_to_world
(
p
));
}
else
if
(
cam_mode
==
Camera_Control
::
orbit
)
{
}
else
if
(
cam_mode
==
Camera_Control
::
orbit
)
{
camera
.
mouse_orbit
(
d
);
}
else
if
(
cam_mode
==
Camera_Control
::
move
)
{
}
else
if
(
cam_mode
==
Camera_Control
::
move
)
{
camera
.
mouse_move
(
d
);
}
else
{
gui
.
hover
(
p
,
camera
.
pos
(),
n
,
screen_to_world
(
p
));
...
...
@@ -117,35 +117,38 @@ void App::event(SDL_Event e) {
case
SDL_MOUSEBUTTONDOWN
:
{
if
(
IO
.
WantCaptureMouse
)
break
;
if
(
IO
.
WantCaptureMouse
)
break
;
Vec2
p
=
plt
->
scale
(
Vec2
{
e
.
button
.
x
,
e
.
button
.
y
});
Vec2
dim
=
plt
->
window_draw
();
Vec2
n
=
Vec2
(
2.0
f
*
p
.
x
/
dim
.
x
-
1.0
f
,
2.0
f
*
p
.
y
/
dim
.
y
-
1.0
f
);
if
(
e
.
button
.
button
==
SDL_BUTTON_LEFT
)
{
if
(
e
.
button
.
button
==
SDL_BUTTON_LEFT
)
{
Scene_ID
id
=
Renderer
::
get
().
read_id
(
p
);
if
(
cam_mode
==
Camera_Control
::
none
&&
(
plt
->
is_down
(
SDL_SCANCODE_LSHIFT
)
|
plt
->
is_down
(
SDL_SCANCODE_RSHIFT
)))
{
if
(
cam_mode
==
Camera_Control
::
none
&&
(
plt
->
is_down
(
SDL_SCANCODE_LSHIFT
)
|
plt
->
is_down
(
SDL_SCANCODE_RSHIFT
)))
{
cam_mode
=
Camera_Control
::
orbit
;
}
else
if
(
gui
.
select
(
scene
,
undo
,
id
,
camera
.
pos
(),
n
,
screen_to_world
(
p
)))
{
}
else
if
(
gui
.
select
(
scene
,
undo
,
id
,
camera
.
pos
(),
n
,
screen_to_world
(
p
)))
{
cam_mode
=
Camera_Control
::
none
;
plt
->
grab_mouse
();
gui_capture
=
true
;
}
else
if
(
id
)
{
}
else
if
(
id
)
{
selection_changed
=
true
;
}
mouse_press
=
Vec2
(
e
.
button
.
x
,
e
.
button
.
y
);
}
else
if
(
e
.
button
.
button
==
SDL_BUTTON_RIGHT
)
{
if
(
cam_mode
==
Camera_Control
::
none
)
{
}
else
if
(
e
.
button
.
button
==
SDL_BUTTON_RIGHT
)
{
if
(
cam_mode
==
Camera_Control
::
none
)
{
cam_mode
=
Camera_Control
::
move
;
}
}
else
if
(
e
.
button
.
button
==
SDL_BUTTON_MIDDLE
)
{
}
else
if
(
e
.
button
.
button
==
SDL_BUTTON_MIDDLE
)
{
cam_mode
=
Camera_Control
::
orbit
;
}
}
break
;
case
SDL_MOUSEBUTTONUP
:
{
...
...
@@ -154,8 +157,8 @@ void App::event(SDL_Event e) {
Vec2
dim
=
plt
->
window_draw
();
Vec2
n
=
Vec2
(
2.0
f
*
p
.
x
/
dim
.
x
-
1.0
f
,
2.0
f
*
p
.
y
/
dim
.
y
-
1.0
f
);
if
(
e
.
button
.
button
==
SDL_BUTTON_LEFT
)
{
if
(
!
IO
.
WantCaptureMouse
&&
gui_capture
)
{
if
(
e
.
button
.
button
==
SDL_BUTTON_LEFT
)
{
if
(
!
IO
.
WantCaptureMouse
&&
gui_capture
)
{
gui_capture
=
false
;
gui
.
drag_to
(
scene
,
camera
.
pos
(),
n
,
screen_to_world
(
p
));
gui
.
end_drag
(
undo
,
scene
);
...
...
@@ -163,14 +166,14 @@ void App::event(SDL_Event e) {
break
;
}
else
{
Vec2
diff
=
mouse_press
-
Vec2
(
e
.
button
.
x
,
e
.
button
.
y
);
if
(
!
selection_changed
&&
diff
.
norm
()
<=
3
)
{
if
(
!
selection_changed
&&
diff
.
norm
()
<=
3
)
{
gui
.
clear_select
();
}
selection_changed
=
false
;
}
}
if
((
e
.
button
.
button
==
SDL_BUTTON_LEFT
&&
cam_mode
==
Camera_Control
::
orbit
)
||
if
((
e
.
button
.
button
==
SDL_BUTTON_LEFT
&&
cam_mode
==
Camera_Control
::
orbit
)
||
(
e
.
button
.
button
==
SDL_BUTTON_MIDDLE
&&
cam_mode
==
Camera_Control
::
orbit
)
||
(
e
.
button
.
button
==
SDL_BUTTON_RIGHT
&&
cam_mode
==
Camera_Control
::
move
))
{
cam_mode
=
Camera_Control
::
none
;
...
...
@@ -179,7 +182,8 @@ void App::event(SDL_Event e) {
}
break
;
case
SDL_MOUSEWHEEL
:
{
if
(
IO
.
WantCaptureMouse
)
break
;
if
(
IO
.
WantCaptureMouse
)
break
;
camera
.
mouse_radius
((
float
)
e
.
wheel
.
y
);
}
break
;
}
...
...
@@ -191,7 +195,7 @@ void App::render() {
view
=
camera
.
get_view
();
iviewproj
=
(
proj
*
view
).
inverse
();
Renderer
&
r
=
Renderer
::
get
();
Renderer
&
r
=
Renderer
::
get
();
r
.
begin
();
r
.
proj
(
proj
);
...
...
@@ -204,8 +208,7 @@ void App::render() {
Vec3
App
::
screen_to_world
(
Vec2
mouse
)
{
Vec2
t
(
2.0
f
*
mouse
.
x
/
window_dim
.
x
-
1.0
f
,
1.0
f
-
2.0
f
*
mouse
.
y
/
window_dim
.
y
);
Vec2
t
(
2.0
f
*
mouse
.
x
/
window_dim
.
x
-
1.0
f
,
1.0
f
-
2.0
f
*
mouse
.
y
/
window_dim
.
y
);
Vec3
p
=
iviewproj
*
Vec3
(
t
.
x
,
t
.
y
,
0.1
f
);
return
(
p
-
camera
.
pos
()).
unit
();
}
...
...
@@ -216,4 +219,3 @@ void App::apply_window_dim(Vec2 new_dim) {
gui
.
update_dim
(
plt
->
window_size
());
Renderer
::
get
().
update_dim
(
window_dim
);
}
src/app.h
View file @
c2535f0f
#pragma once
#include <SDL2/SDL.h>
#include <map>
#include <string>
#include <SDL2/SDL.h>
#include "util/camera.h"
#include "lib/mathlib.h"
#include "gui/manager.h"
#include "lib/mathlib.h"
#include "util/camera.h"
#include "scene/scene.h"
#include "scene/undo.h"
...
...
@@ -17,9 +17,11 @@ class Platform;
class
App
{
public:
struct
Settings
{
std
::
string
scene_file
;
std
::
string
env_map_file
;
bool
headless
=
false
;
// If headless is true, use all of these
std
::
string
output_file
=
"out.png"
;
int
w
=
640
;
...
...
@@ -32,7 +34,7 @@ public:
bool
w_from_ar
=
false
;
};
App
(
Settings
set
,
Platform
*
plt
=
nullptr
);
App
(
Settings
set
,
Platform
*
plt
=
nullptr
);
~
App
();
void
render
();
...
...
@@ -43,11 +45,7 @@ private:
Vec3
screen_to_world
(
Vec2
mouse
);
// Camera data
enum
class
Camera_Control
{
none
,
orbit
,
move
};
enum
class
Camera_Control
{
none
,
orbit
,
move
};
Vec2
window_dim
,
mouse_press
;
bool
selection_changed
=
false
;
Camera_Control
cam_mode
=
Camera_Control
::
none
;
...
...
@@ -55,7 +53,7 @@ private:
Mat4
view
,
proj
,
iviewproj
;
// Systems
Platform
*
plt
=
nullptr
;
Platform
*
plt
=
nullptr
;
Scene
scene
;
Gui
::
Manager
gui
;
Undo
undo
;
...
...
src/geometry/halfedge.cpp
View file @
c2535f0f
This diff is collapsed.
Click to expand it.
src/geometry/halfedge.h
View file @
c2535f0f
...
...
@@ -130,19 +130,15 @@
#pragma once
#include <list>
#include <vector>
#include <variant>
#include <optional>
#include <string>
#include <variant>
#include <vector>
#include "../platform/gl.h"
// Types of sub-division
enum
class
SubD
{
linear
,
catmullclark
,
loop
};
enum
class
SubD
{
linear
,
catmullclark
,
loop
};
class
Halfedge_Mesh
{
public:
...
...
@@ -246,19 +242,22 @@ public:
Computes vertex positions for a face that was just created by beveling a vertex,
but not yet confirmed.
*/
void
bevel_vertex_positions
(
const
std
::
vector
<
Vec3
>&
start_positions
,
FaceRef
face
,
float
tangent_offset
);
void
bevel_vertex_positions
(
const
std
::
vector
<
Vec3
>
&
start_positions
,
FaceRef
face
,
float
tangent_offset
);
/*
Computes vertex positions for a face that was just created by beveling an edge,
but not yet confirmed.
*/
void
bevel_edge_positions
(
const
std
::
vector
<
Vec3
>&
start_positions
,
FaceRef
face
,
float
tangent_offset
);
void
bevel_edge_positions
(
const
std
::
vector
<
Vec3
>
&
start_positions
,
FaceRef
face
,
float
tangent_offset
);
/*
Computes vertex positions for a face that was just created by beveling a face,
but not yet confirmed.
*/
void
bevel_face_positions
(
const
std
::
vector
<
Vec3
>&
start_positions
,
FaceRef
face
,
float
tangent_offset
,
float
normal_offset
);
void
bevel_face_positions
(
const
std
::
vector
<
Vec3
>
&
start_positions
,
FaceRef
face
,
float
tangent_offset
,
float
normal_offset
);
//////////////////////////////////////////////////////////////////////////////////////////
// Student Global Operations | student/meshedit.cpp
...
...
@@ -312,8 +311,8 @@ public:
class
Vertex
{
public:
// Returns a halfedge incident from the vertex
HalfedgeRef
&
halfedge
()
{
return
_halfedge
;}
HalfedgeCRef
halfedge
()
const
{
return
_halfedge
;}
HalfedgeRef
&
halfedge
()
{
return
_halfedge
;
}
HalfedgeCRef
halfedge
()
const
{
return
_halfedge
;
}
// Returns whether the vertex is on a boundary loop
bool
on_boundary
()
const
;
...
...
@@ -326,7 +325,7 @@ public:
// Computes the centroid of the loop of the vertex
Vec3
neighborhood_center
()
const
;
// Returns an id unique to this vertex
unsigned
int
id
()
const
{
return
_id
;}
unsigned
int
id
()
const
{
return
_id
;
}
// The vertex position
Vec3
pos
;
...
...
@@ -343,8 +342,8 @@ public:
class
Edge
{
public:
// Returns one of the two halfedges associated with this edge
HalfedgeRef
&
halfedge
()
{
return
_halfedge
;}
HalfedgeCRef
halfedge
()
const
{
return
_halfedge
;}
HalfedgeRef
&
halfedge
()
{
return
_halfedge
;
}
HalfedgeCRef
halfedge
()
const
{
return
_halfedge
;
}
// Returns whether this edge is contained in a boundary loop
bool
on_boundary
()
const
;
...
...
@@ -355,7 +354,7 @@ public:
// Returns the length of the edge
float
length
()
const
;
// Returns an id unique to this edge
unsigned
int
id
()
const
{
return
_id
;}
unsigned
int
id
()
const
{
return
_id
;
}
private:
Edge
(
unsigned
int
id
)
:
_id
(
id
)
{}
...
...
@@ -369,11 +368,11 @@ public:
class
Face
{
public:
// Returns some halfedge contained within this face
HalfedgeRef
&
halfedge
()
{
return
_halfedge
;}
HalfedgeCRef
halfedge
()
const
{
return
_halfedge
;}
HalfedgeRef
&
halfedge
()
{
return
_halfedge
;
}
HalfedgeCRef
halfedge
()
const
{
return
_halfedge
;
}
// Returns whether this is a boundary face
bool
is_boundary
()
const
{
return
boundary
;}
bool
is_boundary
()
const
{
return
boundary
;
}
// Returns the centroid of this face
Vec3
center
()
const
;
// Returns an area weighted face normal
...
...
@@ -381,7 +380,7 @@ public:
// Returns the number of vertices/edges in this face
unsigned
int
degree
()
const
;
// Returns an id unique to this face
unsigned
int
id
()
const
{
return
_id
;}
unsigned
int
id
()
const
{
return
_id
;
}
private:
Face
(
unsigned
int
id
,
bool
is_boundary
=
false
)
:
_id
(
id
),
boundary
(
is_boundary
)
{}
...
...
@@ -395,34 +394,34 @@ public:
class
Halfedge
{
public:
// Retrives the twin halfedge
HalfedgeRef
&
twin
()
{
return
_twin
;}
HalfedgeCRef
twin
()
const
{
return
_twin
;}
HalfedgeRef
&
twin
()
{
return
_twin
;
}
HalfedgeCRef
twin
()
const
{
return
_twin
;
}
// Retrieves the next halfedge
HalfedgeRef
&
next
()
{
return
_next
;}
HalfedgeCRef
next
()
const
{
return
_next
;}
HalfedgeRef
&
next
()
{
return
_next
;
}
HalfedgeCRef
next
()
const
{
return
_next
;
}
// Retrieves the associated vertex
VertexRef
&
vertex
()
{
return
_vertex
;}
VertexCRef
vertex
()
const
{
return
_vertex
;}
VertexRef
&
vertex
()
{
return
_vertex
;
}
VertexCRef
vertex
()
const
{
return
_vertex
;
}
// Retrieves the associated edge
EdgeRef
&
edge
()
{
return
_edge
;}
EdgeCRef
edge
()
const
{
return
_edge
;}
EdgeRef
&
edge
()
{
return
_edge
;
}
EdgeCRef
edge
()
const
{
return
_edge
;
}
// Retrieves the associated face
FaceRef
&
face
()
{
return
_face
;}
FaceCRef
face
()
const
{
return
_face
;}
FaceRef
&
face
()
{
return
_face
;
}
FaceCRef
face
()
const
{
return
_face
;
}
// Returns an id unique to this halfedge
unsigned
int
id
()
const
{
return
_id
;}
unsigned
int
id
()
const
{
return
_id
;
}
// Returns whether this edge is inside a boundary face
bool
is_boundary
()
const
{
return
_face
->
is_boundary
();}
bool
is_boundary
()
const
{
return
_face
->
is_boundary
();
}
// Convenience function for setting all members of the halfedge
void
set_neighbors
(
HalfedgeRef
next
,
HalfedgeRef
twin
,
VertexRef
vertex
,
EdgeRef
edge
,
FaceRef
face
)
{
void
set_neighbors
(
HalfedgeRef
next
,
HalfedgeRef
twin
,
VertexRef
vertex
,
EdgeRef
edge
,
FaceRef
face
)
{
_next
=
next
;
_twin
=
twin
;
_vertex
=
vertex
;
...
...
@@ -441,13 +440,13 @@ public:
};
/*
These methods delete a specified mesh element. One should think very, very carefully
about
exactly when and how to delete mesh elements, since other elements will often still
point
to the element that is being deleted, and accessing a deleted element will cause your
program to crash (or worse!). A good exercise to think about is: suppose you're
iterating
over a linked list, and want to delete some of the elements as you go. How do you
do this
without causing any problems? For instance, if you delete the current
element, will
you be able to iterate to the next element? Etc.
These methods delete a specified mesh element. One should think very, very carefully
about
exactly when and how to delete mesh elements, since other elements will often still
point
to the element that is being deleted, and accessing a deleted element will cause your
program to crash (or worse!). A good exercise to think about is: suppose you're
iterating
over a linked list, and want to delete some of the elements as you go. How do you
do this
without causing any problems? For instance, if you delete the current
element, will
you be able to iterate to the next element? Etc.
*/
void
erase
(
HalfedgeRef
h
)
{
halfedges
.
erase
(
h
);
}
void
erase
(
VertexRef
v
)
{
vertices
.
erase
(
v
);
}
...
...
@@ -456,8 +455,8 @@ public:
void
erase_boundary
(
FaceRef
f
)
{
boundaries
.
erase
(
f
);
}
/*
These methods allocate new mesh elements, returning a pointer (i.e., iterator) to the
new element.
(These methods cannot have const versions, because they modify the mesh!)
These methods allocate new mesh elements, returning a pointer (i.e., iterator) to the
new element.
(These methods cannot have const versions, because they modify the mesh!)
*/
HalfedgeRef
new_halfedge
()
{
return
halfedges
.
insert
(
halfedges
.
end
(),
Halfedge
(
next_id
++
));
}
VertexRef
new_vertex
()
{
return
vertices
.
insert
(
vertices
.
end
(),
Vertex
(
next_id
++
));
}
...
...
@@ -506,10 +505,10 @@ public:
/*
This return simple statistics about the current mesh.
*/
Size
n_vertices
()
const
{
return
vertices
.
size
();};
Size
n_edges
()
const
{
return
edges
.
size
();};
Size
n_faces
()
const
{
return
faces
.
size
();};
Size
n_halfedges
()
const
{
return
halfedges
.
size
();};
Size
n_vertices
()
const
{
return
vertices
.
size
();
};
Size
n_edges
()
const
{
return
edges
.
size
();
};
Size
n_faces
()
const
{
return
faces
.
size
();
};
Size
n_halfedges
()
const
{
return
halfedges
.
size
();
};
/// Check if half-edge mesh is valid
std
::
string
validate
()
const
;
...
...
@@ -520,34 +519,36 @@ public:
// Various ways of constructing meshes
Halfedge_Mesh
();
Halfedge_Mesh
(
const
GL
::
Mesh
&
mesh
);
Halfedge_Mesh
(
const
std
::
vector
<
std
::
vector
<
Index
>>
&
polygons
,
const
std
::
vector
<
Vec3
>
&
verts
);
Halfedge_Mesh
(
const
Halfedge_Mesh
&
src
)
=
delete
;
Halfedge_Mesh
(
Halfedge_Mesh
&&
src
)
=
default
;
Halfedge_Mesh
(
const
GL
::
Mesh
&
mesh
);
Halfedge_Mesh
(
const
std
::
vector
<
std
::
vector
<
Index
>>
&
polygons
,
const
std
::
vector
<
Vec3
>
&
verts
);
Halfedge_Mesh
(
const
Halfedge_Mesh
&
src
)
=
delete
;
Halfedge_Mesh
(
Halfedge_Mesh
&&
src
)
=
default
;
~
Halfedge_Mesh
()
=
default
;
// Various ways of copying meshes
void
operator
=
(
const
Halfedge_Mesh
&
src
)
=
delete
;
Halfedge_Mesh
&
operator
=
(
Halfedge_Mesh
&&
src
)
=
default
;
void
copy_to
(
Halfedge_Mesh
&
mesh
);
ElementRef
copy_to
(
Halfedge_Mesh
&
mesh
,
unsigned
int
eid
);
void
operator
=
(
const
Halfedge_Mesh
&
src
)
=
delete
;
Halfedge_Mesh
&
operator
=
(
Halfedge_Mesh
&&
src
)
=
default
;
void
copy_to
(
Halfedge_Mesh
&
mesh
);
ElementRef
copy_to
(
Halfedge_Mesh
&
mesh
,
unsigned
int
eid
);
/// Clear mesh of all elements.
void
clear
();
/// Creates new sub-divided mesh with provided scheme
bool
subdivide
(
SubD
strategy
);
/// Export to renderable vertex-index mesh. Indexes the mesh.
void
to_mesh
(
GL
::
Mesh
&
mesh
,
bool
split_faces
)
const
;
void
to_mesh
(
GL
::
Mesh
&
mesh
,
bool
split_faces
)
const
;
/// Create mesh from polygon list
std
::
string
from_poly
(
const
std
::
vector
<
std
::
vector
<
Index
>>&
polygons
,
const
std
::
vector
<
Vec3
>&
verts
);
/// Create mesh from renderable triangle mesh (beware of connectivity, does not de-duplicate vertices)
std
::
string
from_mesh
(
const
GL
::
Mesh
&
mesh
);
std
::
string
from_poly
(
const
std
::
vector
<
std
::
vector
<
Index
>>
&
polygons
,
const
std
::
vector
<
Vec3
>
&
verts
);
/// Create mesh from renderable triangle mesh (beware of connectivity, does not de-duplicate
/// vertices)
std
::
string
from_mesh
(
const
GL
::
Mesh
&
mesh
);
/// For rendering
bool
render_dirty_flag
=
false
;
void
mark_dirty
();
bool
flipped
()
const
{
return
flip_orientation
;}
void
flip
()
{
flip_orientation
=
!
flip_orientation
;};
bool
flipped
()
const
{
return
flip_orientation
;
}
void
flip
()
{
flip_orientation
=
!
flip_orientation
;
};
Vec3
normal_of
(
ElementRef
elem
);
static
Vec3
center_of
(
ElementRef
elem
);
...
...
@@ -568,28 +569,28 @@ private:
Here we just say that one iterator comes before another if the address of the
object it points to is smaller. (You should not have to worry about this!)
*/
inline
bool
operator
<
(
const
Halfedge_Mesh
::
HalfedgeRef
&
i
,
const
Halfedge_Mesh
::
HalfedgeRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
HalfedgeRef
&
i
,
const
Halfedge_Mesh
::
HalfedgeRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
VertexRef
&
i
,
const
Halfedge_Mesh
::
VertexRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
VertexRef
&
i
,
const
Halfedge_Mesh
::
VertexRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
EdgeRef
&
i
,
const
Halfedge_Mesh
::
EdgeRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
EdgeRef
&
i
,
const
Halfedge_Mesh
::
EdgeRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
FaceRef
&
i
,
const
Halfedge_Mesh
::
FaceRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
FaceRef
&
i
,
const
Halfedge_Mesh
::
FaceRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
HalfedgeCRef
&
i
,
const
Halfedge_Mesh
::
HalfedgeCRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
HalfedgeCRef
&
i
,
const
Halfedge_Mesh
::
HalfedgeCRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
VertexCRef
&
i
,
const
Halfedge_Mesh
::
VertexCRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
VertexCRef
&
i
,
const
Halfedge_Mesh
::
VertexCRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
EdgeCRef
&
i
,
const
Halfedge_Mesh
::
EdgeCRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
EdgeCRef
&
i
,
const
Halfedge_Mesh
::
EdgeCRef
&
j
)
{
return
&*
i
<
&*
j
;
}
inline
bool
operator
<
(
const
Halfedge_Mesh
::
FaceCRef
&
i
,
const
Halfedge_Mesh
::
FaceCRef
&
j
)
{
inline
bool
operator
<
(
const
Halfedge_Mesh
::
FaceCRef
&
i
,
const
Halfedge_Mesh
::
FaceCRef
&
j
)
{
return
&*
i
<
&*
j
;
}
...
...
@@ -598,52 +599,52 @@ inline bool operator<(const Halfedge_Mesh::FaceCRef& i, const Halfedge_Mesh::Fac
Here we simply hash the unique ID of the element.
*/
namespace
std
{
template
<
>
struct
hash
<
Halfedge_Mesh
::
VertexRef
>
{
template
<
>
struct
hash
<
Halfedge_Mesh
::
VertexRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
VertexRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
EdgeRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
EdgeRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
EdgeRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
FaceRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
FaceRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
FaceRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
HalfedgeRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
HalfedgeRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
HalfedgeRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
VertexCRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
VertexCRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
VertexCRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
EdgeCRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
EdgeCRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
EdgeCRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
FaceCRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
FaceCRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
FaceCRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
HalfedgeCRef
>
{
};
template
<
>
struct
hash
<
Halfedge_Mesh
::
HalfedgeCRef
>
{
uint64_t
operator
()(
Halfedge_Mesh
::
HalfedgeCRef
key
)
const
{
static
const
std
::
hash
<
unsigned
int
>
h
;
return
h
(
key
->
id
());
}
};
}
};
}
// namespace std
src/geometry/spline.h
View file @
c2535f0f
#pragma once
#include "../lib/mathlib.h"
#include <map>
#include <set>
#include "../lib/mathlib.h"
template
<
typename
T
>
class
Spline
{
template
<
typename
T
>
class
Spline
{
public:
// Returns the interpolated value.
T
at
(
float
time
)
const
;
...
...
@@ -42,7 +40,8 @@ public:
// Returns set of keys
std
::
set
<
float
>
keys
()
const
{
std
::
set
<
float
>
ret
;
for
(
auto
&
e
:
control_points
)
ret
.
insert
(
e
.
first
);
for
(
auto
&
e
:
control_points
)
ret
.
insert
(
e
.
first
);
return
ret
;
}
...
...
@@ -52,18 +51,19 @@ private:
// Given a time between 0 and 1, evaluates a cubic polynomial with
// the given endpoint and tangent values at the beginning (0) and
// end (1) of the interval
static
T
cubic_unit_spline
(
float
time
,
const
T
&
position0
,
const
T
&
position1
,
const
T
&
tangent0
,
const
T
&
tangent1
);
static
T
cubic_unit_spline
(
float
time
,
const
T
&
position0
,
const
T
&
position1
,
const
T
&
tangent0
,
const
T
&
tangent1
);
};
template
<
>
class
Spline
<
Quat
>
{
template
<
>
class
Spline
<
Quat
>
{
public:
Quat
at
(
float
time
)
const
{
if
(
values
.
empty
())
return
Quat
::
euler
(
Vec3
(
0.0
f
));
if
(
values
.
size
()
==
1
)
return
values
.
begin
()
->
second
;
if
(
values
.
begin
()
->
first
>
time
)
if
(
values
.
empty
())
return
Quat
::
euler
(
Vec3
(
0.0
f
));
if
(
values
.
size
()
==
1
)
return
values
.
begin
()
->
second
;
if
(
values
.
begin
()
->
first
>
time
)
return
values
.
begin
()
->
second
;
auto
k2
=
values
.
upper_bound
(
time
);
if
(
k2
==
values
.
end
())
...
...
@@ -94,8 +94,8 @@ public:
}
float
norm_t
=
(
time
-
t1
)
/
dt
;
Quat
qa
=
tangent
(
p0
,
p1
,
p2
);
Quat
pb
=
tangent
(
p1
,
p2
,
p3
);
Quat
qa
=
tangent
(
p0
,
p1
,
p2
);
Quat
pb
=
tangent
(
p1
,
p2
,
p3
);
float
slerpT
=
2.0
f
*
norm_t
*
(
1.0
f
-
norm_t
);
Quat
slerp1
=
p1
.
slerp
(
p2
,
norm_t
);
...
...
@@ -103,18 +103,13 @@ public:
return
slerp1
.
slerp
(
slerp2
,
slerpT
);
}
Quat
operator
()(
float
time
)
const
{
return
at
(
time
);
}
void
set
(
float
time
,
Quat
value
)
{
values
[
time
]
=
value
;
}
void
erase
(
float
time
)
{
values
.
erase
(
time
);
}
Quat
operator
()(
float
time
)
const
{
return
at
(
time
);
}
void
set
(
float
time
,
Quat
value
)
{
values
[
time
]
=
value
;
}
void
erase
(
float
time
)
{
values
.
erase
(
time
);
}
std
::
set
<
float
>
keys
()
const
{
std
::
set
<
float
>
ret
;
for
(
auto
&
e
:
values
)
ret
.
insert
(
e
.
first
);
for
(
auto
&
e
:
values
)
ret
.
insert
(
e
.
first
);
return
ret
;
}
bool
has
(
float
t
)
const
{
return
values
.
count
(
t
);
}
...
...
@@ -127,7 +122,7 @@ public:
private:
std
::
map
<
float
,
Quat
>
values
;
static
Quat
tangent
(
const
Quat
&
q0
,
const
Quat
&
q1
,
const
Quat
&
q2
)
{
static
Quat
tangent
(
const
Quat
&
q0
,
const
Quat
&
q1
,
const
Quat
&
q2
)
{
Quat
q1inv
=
q1
.
inverse
();
Quat
c1
=
q1inv
*
q2
;
Quat
c2
=
q1inv
*
q0
;
...
...
@@ -141,8 +136,7 @@ private:
}
};
template
<
typename
T
,
typename
...
Ts
>
class
Splines
{
template
<
typename
T
,
typename
...
Ts
>
class
Splines
{
public:
void
set
(
float
t
,
T
arg
,
Ts
...
args
)
{
head
.
set
(
t
,
arg
);
...
...
@@ -152,12 +146,8 @@ public:
head
.
erase
(
t
);
tail
.
erase
(
t
);
}
bool
any
()
const
{
return
head
.
any
()
||
tail
.
any
();
}
bool
has
(
float
t
)
const
{
return
head
.
has
(
t
)
||
tail
.
has
(
t
);
}
bool
any
()
const
{
return
head
.
any
()
||
tail
.
any
();
}
bool
has
(
float
t
)
const
{
return
head
.
has
(
t
)
||
tail
.
has
(
t
);
}
void
clear
()
{
head
.
clear
();
tail
.
clear
();
...
...
@@ -181,33 +171,16 @@ private:
Splines
<
Ts
...
>
tail
;
};
template
<
typename
T
>
class
Splines
<
T
>
{
template
<
typename
T
>
class
Splines
<
T
>
{
public:
void
set
(
float
t
,
T
arg
)
{
head
.
set
(
t
,
arg
);
}
void
erase
(
float
t
)
{
head
.
erase
(
t
);
}
bool
any
()
const
{
return
head
.
any
();
}
bool
has
(
float
t
)
const
{
return
head
.
has
(
t
);
}
void
crop
(
float
t
)
{
head
.
crop
(
t
);
}
void
clear
()
{
head
.
clear
();
}
std
::
set
<
float
>
keys
()
const
{
return
head
.
keys
();
}
std
::
tuple
<
T
>
at
(
float
t
)
const
{
return
std
::
make_tuple
(
head
.
at
(
t
));
}
void
set
(
float
t
,
T
arg
)
{
head
.
set
(
t
,
arg
);
}
void
erase
(
float
t
)
{
head
.
erase
(
t
);
}
bool
any
()
const
{
return
head
.
any
();
}
bool
has
(
float
t
)
const
{
return
head
.
has
(
t
);
}
void
crop
(
float
t
)
{
head
.
crop
(
t
);
}
void
clear
()
{
head
.
clear
();
}
std
::
set
<
float
>
keys
()
const
{
return
head
.
keys
();
}
std
::
tuple
<
T
>
at
(
float
t
)
const
{
return
std
::
make_tuple
(
head
.
at
(
t
));
}
private:
Spline
<
T
>
head
;
...
...
src/geometry/util.cpp
View file @
c2535f0f
This diff is collapsed.
Click to expand it.
src/geometry/util.h
View file @
c2535f0f
...
...
@@ -7,42 +7,42 @@
namespace
Util
{
GL
::
Mesh
cube_mesh
(
float
radius
);
GL
::
Mesh
square_mesh
(
float
radius
);
GL
::
Mesh
quad_mesh
(
float
x
,
float
y
);
GL
::
Mesh
cyl_mesh
(
float
radius
,
float
height
,
int
sides
=
12
,
bool
cap
=
true
);
GL
::
Mesh
torus_mesh
(
float
iradius
,
float
oradius
,
int
segments
=
48
,
int
sides
=
24
);
GL
::
Mesh
sphere_mesh
(
float
r
,
int
subdivsions
);
GL
::
Mesh
hemi_mesh
(
float
r
);
GL
::
Mesh
cone_mesh
(
float
bradius
,
float
tradius
,
float
height
,
int
sides
=
12
,
bool
cap
=
true
);
GL
::
Mesh
capsule_mesh
(
float
h
,
float
r
);
GL
::
Mesh
arrow_mesh
(
float
base
,
float
tip
,
float
height
);
GL
::
Mesh
scale_mesh
();
GL
::
Lines
spotlight_mesh
(
Vec3
color
,
float
inner
,
float
outer
);
namespace
Gen
{
struct
Data
{
std
::
vector
<
GL
::
Mesh
::
Vert
>
verts
;
std
::
vector
<
GL
::
Mesh
::
Index
>
elems
;
};
struct
LData
{
std
::
vector
<
GL
::
Lines
::
Vert
>
verts
;
};
GL
::
Mesh
cube_mesh
(
float
radius
);
GL
::
Mesh
square_mesh
(
float
radius
);
GL
::
Mesh
quad_mesh
(
float
x
,
float
y
);
GL
::
Mesh
cyl_mesh
(
float
radius
,
float
height
,
int
sides
=
12
,
bool
cap
=
true
);
GL
::
Mesh
torus_mesh
(
float
iradius
,
float
oradius
,
int
segments
=
48
,
int
sides
=
24
);
GL
::
Mesh
sphere_mesh
(
float
r
,
int
subdivsions
);
GL
::
Mesh
hemi_mesh
(
float
r
);
GL
::
Mesh
cone_mesh
(
float
bradius
,
float
tradius
,
float
height
,
int
sides
=
12
,
bool
cap
=
true
);
GL
::
Mesh
capsule_mesh
(
float
h
,
float
r
);
GL
::
Mesh
merge
(
Data
&&
l
,
Data
&&
r
);
LData
merge
(
LData
&&
l
,
LData
&&
r
);
GL
::
Mesh
arrow_mesh
(
float
base
,
float
tip
,
float
height
);
GL
::
Mesh
scale_mesh
(
);
LData
circle
(
Vec3
color
,
float
r
,
int
sides
);
GL
::
Lines
spotlight_mesh
(
Vec3
color
,
float
inner
,
float
outer
);
Data
cube
(
float
r
);
Data
quad
(
float
x
,
float
y
);
namespace
Gen
{
// https://wiki.unity3d.com/index.php/ProceduralPrimitives
Data
ico_sphere
(
float
radius
,
int
level
);
Data
uv_hemisphere
(
float
radius
);
Data
cone
(
float
bradius
,
float
tradius
,
float
height
,
int
sides
,
bool
caps
);
Data
torus
(
float
iradius
,
float
oradius
,
int
segments
,
int
sides
);
}
}
struct
Data
{
std
::
vector
<
GL
::
Mesh
::
Vert
>
verts
;
std
::
vector
<
GL
::
Mesh
::
Index
>
elems
;
};
struct
LData
{
std
::
vector
<
GL
::
Lines
::
Vert
>
verts
;
};
GL
::
Mesh
merge
(
Data
&&
l
,
Data
&&
r
);
LData
merge
(
LData
&&
l
,
LData
&&
r
);
LData
circle
(
Vec3
color
,
float
r
,
int
sides
);
// https://wiki.unity3d.com/index.php/ProceduralPrimitives
Data
cube
(
float
r
);
Data
quad
(
float
x
,
float
y
);
Data
ico_sphere
(
float
radius
,
int
level
);
Data
uv_hemisphere
(
float
radius
);
Data
cone
(
float
bradius
,
float
tradius
,
float
height
,
int
sides
,
bool
caps
);
Data
torus
(
float
iradius
,
float
oradius
,
int
segments
,
int
sides
);
}
// namespace Gen
}
// namespace Util
src/gui/animate.cpp
View file @
c2535f0f
This diff is collapsed.
Click to expand it.
src/gui/animate.h
View file @
c2535f0f
#pragma once
#include <set>
#include <SDL2/SDL.h>
#include "widgets.h"
#include <SDL2/SDL.h>
#include <set>
namespace
Gui
{
...
...
@@ -15,7 +15,7 @@ public:
Anim_Camera
(
Vec2
dim
)
:
dim
(
dim
)
{}
Camera
at
(
float
t
)
const
;
void
set
(
float
t
,
const
Camera
&
cam
);
void
set
(
float
t
,
const
Camera
&
cam
);
Splines
<
Vec3
,
Quat
,
float
,
float
>
splines
;
...
...
@@ -25,31 +25,32 @@ private:
class
Animate
{
public:
Animate
(
Vec2
screen_dim
)
:
ui_camera
(
screen_dim
),
anim_camera
(
screen_dim
),
ui_render
(
screen_dim
)
{}
Animate
(
Vec2
screen_dim
)
:
ui_camera
(
screen_dim
),
anim_camera
(
screen_dim
),
ui_render
(
screen_dim
)
{}
void
update_dim
(
Vec2
dim
);
bool
keydown
(
Widgets
&
widgets
,
Undo
&
undo
,
Scene_ID
sel
,
SDL_Keysym
key
);
bool
keydown
(
Widgets
&
widgets
,
Undo
&
undo
,
Scene_ID
sel
,
SDL_Keysym
key
);
Vec3
selected_pos
(
Scene_Item
&
item
);
void
end_transform
(
Undo
&
undo
,
Scene_Item
&
obj
);
void
apply_transform
(
Widgets
&
widgets
,
Scene_Item
&
obj
);
bool
select
(
Scene
&
scene
,
Widgets
&
widgets
,
Scene_ID
selected
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
Vec3
selected_pos
(
Scene_Item
&
item
);
void
end_transform
(
Undo
&
undo
,
Scene_Item
&
obj
);
void
apply_transform
(
Widgets
&
widgets
,
Scene_Item
&
obj
);
bool
select
(
Scene
&
scene
,
Widgets
&
widgets
,
Scene_ID
selected
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
void
render
(
Scene
&
scene
,
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
);
void
timeline
(
Manager
&
manager
,
Undo
&
undo
,
Scene
&
scene
,
Scene_Maybe
obj
,
Camera
&
user_cam
);
void
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Scene_Maybe
obj_opt
,
Camera
&
user_cam
);
void
render
(
Scene
&
scene
,
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
);
void
timeline
(
Manager
&
manager
,
Undo
&
undo
,
Scene
&
scene
,
Scene_Maybe
obj
,
Camera
&
user_cam
);
void
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Scene_Maybe
obj_opt
,
Camera
&
user_cam
);
void
clear
();
void
update
(
Scene
&
scene
);
void
refresh
(
Scene
&
scene
);
void
update
(
Scene
&
scene
);
void
refresh
(
Scene
&
scene
);
std
::
string
pump_output
(
Scene
&
scene
);
Camera
set_time
(
Scene
&
scene
,
float
time
);
std
::
string
pump_output
(
Scene
&
scene
);
Camera
set_time
(
Scene
&
scene
,
float
time
);
float
fps
()
const
;
int
n_frames
()
const
;
const
Anim_Camera
&
camera
()
const
;
Anim_Camera
&
camera
();
const
Anim_Camera
&
camera
()
const
;
Anim_Camera
&
camera
();
void
set
(
int
n_frames
,
int
fps
);
private:
...
...
@@ -64,7 +65,7 @@ private:
Widget_Render
ui_render
;
Anim_Camera
anim_camera
;
Joint
*
joint_select
=
nullptr
;
Joint
*
joint_select
=
nullptr
;
unsigned
int
joint_id_offset
=
0
;
Pose
old_pose
;
...
...
@@ -75,7 +76,8 @@ private:
bool
camera_selected
=
false
;
Scene_ID
prev_selected
=
0
;
std
::
unordered_map
<
Scene_ID
,
GL
::
Lines
>
spline_cache
;
void
make_spline
(
Scene_ID
id
,
const
Anim_Pose
&
pose
);
void
make_spline
(
Scene_ID
id
,
const
Anim_Pose
&
pose
);
void
camera_spline
();
};
}
}
// namespace Gui
src/gui/layout.cpp
View file @
c2535f0f
...
...
@@ -4,26 +4,26 @@
#include "layout.h"
#include "manager.h"
#include "../scene/undo.h"
#include "../scene/renderer.h"
#include "../scene/undo.h"
namespace
Gui
{
bool
Layout
::
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
)
{
return
false
;
}
bool
Layout
::
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
)
{
return
false
;
}
void
Layout
::
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
)
{
void
Layout
::
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
)
{
if
(
!
obj_opt
.
has_value
())
return
;
Scene_Item
&
item
=
obj_opt
.
value
();
if
(
!
obj_opt
.
has_value
())
return
;
Scene_Item
&
item
=
obj_opt
.
value
();
if
(
item
.
is
<
Scene_Light
>
())
{
Scene_Light
&
light
=
item
.
get
<
Scene_Light
>
();
if
(
light
.
is_env
())
return
;
if
(
item
.
is
<
Scene_Light
>
())
{
Scene_Light
&
light
=
item
.
get
<
Scene_Light
>
();
if
(
light
.
is_env
())
return
;
}
Pose
&
pose
=
item
.
pose
();
Pose
&
pose
=
item
.
pose
();
float
scale
=
std
::
min
((
cam
.
pos
()
-
pose
.
pos
).
norm
()
/
5.5
f
,
10.0
f
);
Mat4
view
=
cam
.
get_view
();
...
...
@@ -32,32 +32,26 @@ void Layout::render(Scene_Maybe obj_opt, Widgets& widgets, Camera& cam) {
widgets
.
render
(
view
,
pose
.
pos
,
scale
);
}
Scene_ID
Layout
::
selected
()
const
{
return
selected_mesh
;
}
Scene_ID
Layout
::
selected
()
const
{
return
selected_mesh
;
}
void
Layout
::
clear_select
()
{
selected_mesh
=
0
;
void
Layout
::
clear_select
()
{
selected_mesh
=
0
;
}
}
void
Layout
::
set_selected
(
Scene_ID
id
)
{
selected_mesh
=
id
;
}
void
Layout
::
set_selected
(
Scene_ID
id
)
{
selected_mesh
=
id
;
}
Vec3
Layout
::
selected_pos
(
Scene
&
scene
)
{
Vec3
Layout
::
selected_pos
(
Scene
&
scene
)
{
auto
obj
=
scene
.
get
(
selected_mesh
);
if
(
obj
.
has_value
())
return
obj
->
get
().
pose
().
pos
;
if
(
obj
.
has_value
())
return
obj
->
get
().
pose
().
pos
;
return
{};
}
void
Layout
::
select
(
Scene
&
scene
,
Widgets
&
widgets
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
)
{
void
Layout
::
select
(
Scene
&
scene
,
Widgets
&
widgets
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
)
{
if
(
widgets
.
want_drag
())
{
Scene_Item
&
item
=
scene
.
get
(
selected_mesh
).
value
();
Pose
&
pose
=
item
.
pose
();
Scene_Item
&
item
=
scene
.
get
(
selected_mesh
).
value
();
Pose
&
pose
=
item
.
pose
();
widgets
.
start_drag
(
pose
.
pos
,
cam
,
spos
,
dir
);
old_pose
=
pose
;
...
...
@@ -66,22 +60,23 @@ void Layout::select(Scene& scene, Widgets& widgets, Scene_ID id, Vec3 cam, Vec2
}
}
void
Layout
::
end_transform
(
Undo
&
undo
,
Scene_Item
&
obj
)
{
void
Layout
::
end_transform
(
Undo
&
undo
,
Scene_Item
&
obj
)
{
undo
.
update_pose
(
obj
.
id
(),
old_pose
);
old_pose
=
{};
}
Mode
Layout
::
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Widgets
&
widgets
,
Scene_Maybe
obj_opt
)
{
Mode
Layout
::
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Widgets
&
widgets
,
Scene_Maybe
obj_opt
)
{
if
(
!
obj_opt
.
has_value
())
return
Mode
::
layout
;
if
(
!
obj_opt
.
has_value
())
return
Mode
::
layout
;
ImGui
::
Text
(
"Object Options"
);
Mode
ret
=
manager
.
item_options
(
undo
,
Mode
::
layout
,
obj_opt
.
value
(),
old_pose
);
ImGui
::
Separator
();
return
ret
;
}
void
Layout
::
apply_transform
(
Scene_Item
&
obj
,
Widgets
&
widgets
)
{
void
Layout
::
apply_transform
(
Scene_Item
&
obj
,
Widgets
&
widgets
)
{
obj
.
pose
()
=
widgets
.
apply_action
(
old_pose
);
}
}
}
// namespace Gui
src/gui/layout.h
View file @
c2535f0f
...
...
@@ -3,8 +3,8 @@
#include <SDL2/SDL.h>
#include "../util/camera.h"
#include "../scene/scene.h"
#include "../util/camera.h"
#include "widgets.h"
...
...
@@ -15,14 +15,14 @@ class Manager;
class
Layout
{
public:
bool
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
);
void
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
);
void
select
(
Scene
&
scene
,
Widgets
&
widgets
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
Vec3
selected_pos
(
Scene
&
scene
);
bool
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
);
void
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
);
void
select
(
Scene
&
scene
,
Widgets
&
widgets
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
Vec3
selected_pos
(
Scene
&
scene
);
void
apply_transform
(
Scene_Item
&
obj
,
Widgets
&
widgets
);
void
end_transform
(
Undo
&
undo
,
Scene_Item
&
obj
);
Mode
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Widgets
&
widgets
,
Scene_Maybe
obj
);
void
apply_transform
(
Scene_Item
&
obj
,
Widgets
&
widgets
);
void
end_transform
(
Undo
&
undo
,
Scene_Item
&
obj
);
Mode
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Widgets
&
widgets
,
Scene_Maybe
obj
);
Scene_ID
selected
()
const
;
void
clear_select
();
...
...
@@ -33,4 +33,4 @@ private:
Scene_ID
selected_mesh
=
(
Scene_ID
)
Widget_IDs
::
none
;
};
}
}
// namespace Gui
src/gui/manager.cpp
View file @
c2535f0f
This diff is collapsed.
Click to expand it.
src/gui/manager.h
View file @
c2535f0f
...
...
@@ -11,15 +11,15 @@
#include "../lib/mathlib.h"
#include "../util/camera.h"
#include "../scene/undo.h"
#include "../scene/scene.h"
#include "../scene/undo.h"
#include "
widgets
.h"
#include "
animate
.h"
#include "layout.h"
#include "model.h"
#include "render.h"
#include "rig.h"
#include "
animate
.h"
#include "
widgets
.h"
namespace
Gui
{
...
...
@@ -27,16 +27,9 @@ struct Settings {
int
samples
=
4
;
};
enum
class
Mode
{
layout
,
model
,
render
,
rig
,
animate
,
simulate
};
enum
class
Mode
{
layout
,
model
,
render
,
rig
,
animate
,
simulate
};
#define RGBv(n,r,g,b) static inline const Vec3 n = Vec3(r##.0f,g##.0f,b##.0f) / 255.0f;
#define RGBv(n,
r,
g,
b) static inline const Vec3 n = Vec3(r##.0f,
g##.0f,
b##.0f) / 255.0f;
struct
Color
{
RGBv
(
black
,
0
,
0
,
0
);
RGBv
(
outline
,
242
,
153
,
41
);
...
...
@@ -52,35 +45,35 @@ struct Color {
class
Manager
{
public:
Manager
(
Scene
&
scene
,
Vec2
window_dim
);
Manager
(
Scene
&
scene
,
Vec2
window_dim
);
// Input
void
update_dim
(
Vec2
dim
);
bool
keydown
(
Undo
&
undo
,
SDL_Keysym
key
,
Scene
&
scene
,
Camera
&
cam
);
bool
keydown
(
Undo
&
undo
,
SDL_Keysym
key
,
Scene
&
scene
,
Camera
&
cam
);
Rig
&
get_rig
();
Render
&
get_render
();
Animate
&
get_animate
();
const
Settings
&
get_settings
()
const
;
Rig
&
get_rig
();
Render
&
get_render
();
Animate
&
get_animate
();
const
Settings
&
get_settings
()
const
;
void
set_file
(
std
::
string
save
);
// Object interaction
bool
select
(
Scene
&
scene
,
Undo
&
undo
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
bool
select
(
Scene
&
scene
,
Undo
&
undo
,
Scene_ID
id
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
void
clear_select
();
void
set_select
(
Scene_ID
id
);
void
hover
(
Vec2
pixel
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
void
drag_to
(
Scene
&
scene
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
void
end_drag
(
Undo
&
undo
,
Scene
&
scene
);
void
drag_to
(
Scene
&
scene
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
void
end_drag
(
Undo
&
undo
,
Scene
&
scene
);
void
render_3d
(
Scene
&
scene
,
Camera
&
camera
);
void
render_ui
(
Scene
&
scene
,
Undo
&
undo
,
Camera
&
camera
);
void
render_3d
(
Scene
&
scene
,
Camera
&
camera
);
void
render_ui
(
Scene
&
scene
,
Undo
&
undo
,
Camera
&
camera
);
void
set_error
(
std
::
string
msg
);
void
invalidate_obj
(
Scene_ID
id
);
void
light_edit_gui
(
Undo
&
undo
,
Scene_Light
&
light
);
void
material_edit_gui
(
Undo
&
undo
,
Scene_ID
id
,
Material
&
material
);
Mode
item_options
(
Undo
&
undo
,
Mode
cur_mode
,
Scene_Item
&
item
,
Pose
&
old_pose
);
void
light_edit_gui
(
Undo
&
undo
,
Scene_Light
&
light
);
void
material_edit_gui
(
Undo
&
undo
,
Scene_ID
id
,
Material
&
material
);
Mode
item_options
(
Undo
&
undo
,
Mode
cur_mode
,
Scene_Item
&
item
,
Pose
&
old_pose
);
static
bool
wrap_button
(
std
::
string
label
);
...
...
@@ -88,20 +81,20 @@ private:
void
UIerror
();
void
UIstudent
();
void
UIsettings
();
void
UInew_obj
(
Undo
&
undo
);
void
UInew_light
(
Scene
&
scene
,
Undo
&
undo
);
float
UImenu
(
Scene
&
scene
,
Undo
&
undo
);
void
UIsidebar
(
Scene
&
scene
,
Undo
&
undo
,
float
menu_height
,
Camera
&
cam
);
void
load_image
(
Scene_Light
&
image
);
void
frame
(
Scene
&
scene
,
Camera
&
cam
);
void
UInew_obj
(
Undo
&
undo
);
void
UInew_light
(
Scene
&
scene
,
Undo
&
undo
);
float
UImenu
(
Scene
&
scene
,
Undo
&
undo
);
void
UIsidebar
(
Scene
&
scene
,
Undo
&
undo
,
float
menu_height
,
Camera
&
cam
);
void
load_image
(
Scene_Light
&
image
);
void
frame
(
Scene
&
scene
,
Camera
&
cam
);
static
inline
const
char
*
scene_file_types
=
"dae,obj,fbx,glb,gltf,3ds,blend,stl,ply"
;
static
inline
const
char
*
image_file_types
=
"exr,jpg,jpeg,png,tga,bmp,psd,gif"
;
static
inline
const
char
*
scene_file_types
=
"dae,obj,fbx,glb,gltf,3ds,blend,stl,ply"
;
static
inline
const
char
*
image_file_types
=
"exr,jpg,jpeg,png,tga,bmp,psd,gif"
;
void
render_selected
(
Scene_Object
&
obj
);
void
load_scene
(
Scene
&
scene
,
Undo
&
undo
,
bool
clear
);
void
write_scene
(
Scene
&
scene
);
void
save_scene
(
Scene
&
scene
);
void
render_selected
(
Scene_Object
&
obj
);
void
load_scene
(
Scene
&
scene
,
Undo
&
undo
,
bool
clear
);
void
write_scene
(
Scene
&
scene
);
void
save_scene
(
Scene
&
scene
);
Mode
mode
=
Mode
::
layout
;
Layout
layout
;
...
...
@@ -124,4 +117,4 @@ private:
Vec2
window_dim
;
};
};
};
// namespace Gui
src/gui/model.cpp
View file @
c2535f0f
This diff is collapsed.
Click to expand it.
src/gui/model.h
View file @
c2535f0f
...
...
@@ -7,10 +7,10 @@
#include <optional>
#include <unordered_map>
#include "../util/camera.h"
#include "../geometry/halfedge.h"
#include "../platform/gl.h"
#include "../scene/scene.h"
#include "../util/camera.h"
namespace
Gui
{
...
...
@@ -19,52 +19,49 @@ public:
Model
();
// Gui view API
bool
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
,
Camera
&
cam
);
bool
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
,
Camera
&
cam
);
void
unset_mesh
();
std
::
string
UIsidebar
(
Undo
&
undo
,
Widgets
&
widgets
,
Scene_Maybe
obj
,
Camera
&
cam
);
void
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
);
std
::
string
UIsidebar
(
Undo
&
undo
,
Widgets
&
widgets
,
Scene_Maybe
obj
,
Camera
&
cam
);
void
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
cam
);
Vec3
selected_pos
();
void
clear_select
();
std
::
string
end_transform
(
Widgets
&
widgets
,
Undo
&
undo
,
Scene_Object
&
obj
);
void
apply_transform
(
Widgets
&
widgets
);
std
::
string
select
(
Widgets
&
widgets
,
Scene_ID
click
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
std
::
string
end_transform
(
Widgets
&
widgets
,
Undo
&
undo
,
Scene_Object
&
obj
);
void
apply_transform
(
Widgets
&
widgets
);
std
::
string
select
(
Widgets
&
widgets
,
Scene_ID
click
,
Vec3
cam
,
Vec2
spos
,
Vec3
dir
);
std
::
tuple
<
GL
::
Mesh
&
,
GL
::
Instances
&
,
GL
::
Instances
&
,
GL
::
Instances
&>
shapes
();
std
::
tuple
<
GL
::
Mesh
&
,
GL
::
Instances
&
,
GL
::
Instances
&
,
GL
::
Instances
&>
shapes
();
unsigned
int
select_id
()
const
;
unsigned
int
hover_id
()
const
;
void
set_hover
(
unsigned
int
id
);
private:
template
<
typename
T
>
std
::
string
update_mesh
(
Undo
&
undo
,
Scene_Object
&
obj
,
Halfedge_Mesh
&&
before
,
Halfedge_Mesh
::
ElementRef
ref
,
T
&&
op
);
template
<
typename
T
>
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
);
template
<
typename
T
>
std
::
string
update_mesh
(
Undo
&
undo
,
Scene_Object
&
obj
,
Halfedge_Mesh
&&
before
,
Halfedge_Mesh
::
ElementRef
ref
,
T
&&
op
);
template
<
typename
T
>
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
);
bool
begin_bevel
(
std
::
string
&
err
);
void
set_selected
(
Halfedge_Mesh
::
ElementRef
elem
);
std
::
optional
<
Halfedge_Mesh
::
ElementRef
>
selected_element
();
void
rebuild
();
void
update_vertex
(
Halfedge_Mesh
::
VertexRef
vert
);
void
vertex_viz
(
Halfedge_Mesh
::
VertexRef
v
,
float
&
size
,
Mat4
&
transform
);
void
edge_viz
(
Halfedge_Mesh
::
EdgeRef
e
,
Mat4
&
transform
);
void
halfedge_viz
(
Halfedge_Mesh
::
HalfedgeRef
h
,
Mat4
&
transform
);
void
face_viz
(
Halfedge_Mesh
::
FaceRef
face
,
std
::
vector
<
GL
::
Mesh
::
Vert
>
&
verts
,
std
::
vector
<
GL
::
Mesh
::
Index
>
&
idxs
,
size_t
insert_at
);
void
vertex_viz
(
Halfedge_Mesh
::
VertexRef
v
,
float
&
size
,
Mat4
&
transform
);
void
edge_viz
(
Halfedge_Mesh
::
EdgeRef
e
,
Mat4
&
transform
);
void
halfedge_viz
(
Halfedge_Mesh
::
HalfedgeRef
h
,
Mat4
&
transform
);
void
face_viz
(
Halfedge_Mesh
::
FaceRef
face
,
std
::
vector
<
GL
::
Mesh
::
Vert
>
&
verts
,
std
::
vector
<
GL
::
Mesh
::
Index
>
&
idxs
,
size_t
insert_at
);
Halfedge_Mesh
*
my_mesh
=
nullptr
;
Halfedge_Mesh
*
my_mesh
=
nullptr
;
Halfedge_Mesh
old_mesh
;
enum
class
Bevel
{
face
,
edge
,
vert
};
enum
class
Bevel
{
face
,
edge
,
vert
};
Bevel
beveling
;
struct
Transform_Data
{
...
...
@@ -92,4 +89,4 @@ private:
std
::
unordered_map
<
unsigned
int
,
float
>
vert_sizes
;
};
}
}
// namespace Gui
src/gui/render.cpp
View file @
c2535f0f
#include <nfd/nfd.h>
#include <imgui/imgui.h>
#include <nfd/nfd.h>
#include <sf_libs/stb_image_write.h>
#include "../platform/platform.h"
#include "../scene/renderer.h"
#include "render.h"
#include "manager.h"
#include "render.h"
namespace
Gui
{
Render
::
Render
(
Scene
&
scene
,
Vec2
dim
)
:
ui_camera
(
dim
),
ui_render
(
dim
)
{}
Render
::
Render
(
Scene
&
scene
,
Vec2
dim
)
:
ui_camera
(
dim
),
ui_render
(
dim
)
{}
void
Render
::
update_dim
(
Vec2
dim
)
{
ui_camera
.
dim
(
dim
);
}
void
Render
::
update_dim
(
Vec2
dim
)
{
ui_camera
.
dim
(
dim
);
}
bool
Render
::
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
)
{
return
false
;
}
bool
Render
::
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
)
{
return
false
;
}
void
Render
::
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
user_cam
)
{
void
Render
::
render
(
Scene_Maybe
obj_opt
,
Widgets
&
widgets
,
Camera
&
user_cam
)
{
Mat4
view
=
user_cam
.
get_view
();
Renderer
&
renderer
=
Renderer
::
get
();
Renderer
&
renderer
=
Renderer
::
get
();
if
(
!
ui_camera
.
moving
())
{
if
(
!
ui_camera
.
moving
())
{
ui_camera
.
render
(
view
);
if
(
render_ray_log
&&
!
ui_render
.
in_progress
())
{
if
(
render_ray_log
&&
!
ui_render
.
in_progress
())
{
ui_render
.
render_log
(
view
);
}
if
(
visualize_bvh
)
{
if
(
visualize_bvh
)
{
GL
::
disable
(
GL
::
Opt
::
depth_write
);
renderer
.
lines
(
bvh_viz
,
view
);
renderer
.
lines
(
bvh_active
,
view
);
...
...
@@ -43,14 +38,15 @@ void Render::render(Scene_Maybe obj_opt, Widgets& widgets, Camera& user_cam) {
}
}
if
(
obj_opt
.
has_value
())
{
if
(
obj_opt
.
has_value
())
{
Scene_Item
&
item
=
obj_opt
.
value
();
Scene_Item
&
item
=
obj_opt
.
value
();
float
scale
=
std
::
min
((
user_cam
.
pos
()
-
item
.
pose
().
pos
).
norm
()
/
5.5
f
,
10.0
f
);
if
(
item
.
is
<
Scene_Light
>
())
{
Scene_Light
&
light
=
item
.
get
<
Scene_Light
>
();
if
(
light
.
is_env
())
return
;
if
(
item
.
is
<
Scene_Light
>
())
{
Scene_Light
&
light
=
item
.
get
<
Scene_Light
>
();
if
(
light
.
is_env
())
return
;
}
item
.
render
(
view
);
...
...
@@ -59,13 +55,12 @@ void Render::render(Scene_Maybe obj_opt, Widgets& widgets, Camera& user_cam) {
}
}
const
Camera
&
Render
::
get_cam
()
const
{
return
ui_camera
.
get
();
}
const
Camera
&
Render
::
get_cam
()
const
{
return
ui_camera
.
get
();
}
void
Render
::
load_cam
(
Vec3
pos
,
Vec3
center
,
float
ar
,
float
hfov
)
{
if
(
ar
==
0.0
f
)
ar
=
ui_render
.
wh_ar
();
if
(
ar
==
0.0
f
)
ar
=
ui_render
.
wh_ar
();
float
fov
=
2.0
f
*
std
::
atan
((
1.0
f
/
ar
)
*
std
::
tan
(
hfov
/
2.0
f
));
fov
=
Degrees
(
fov
);
...
...
@@ -73,11 +68,12 @@ void Render::load_cam(Vec3 pos, Vec3 center, float ar, float hfov) {
ui_camera
.
load
(
center
,
pos
,
ar
,
fov
);
}
Mode
Render
::
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Scene
&
scene
,
Scene_Maybe
obj_opt
,
Camera
&
user_cam
)
{
Mode
Render
::
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Scene
&
scene
,
Scene_Maybe
obj_opt
,
Camera
&
user_cam
)
{
Mode
mode
=
Mode
::
render
;
if
(
obj_opt
.
has_value
())
{
if
(
obj_opt
.
has_value
())
{
ImGui
::
Text
(
"Object Options"
);
mode
=
manager
.
item_options
(
undo
,
mode
,
obj_opt
.
value
(),
old_pose
);
ImGui
::
Separator
();
...
...
@@ -93,8 +89,8 @@ Mode Render::UIsidebar(Manager& manager, Undo& undo, Scene& scene, Scene_Maybe o
bool
update_bvh
=
false
;
if
(
visualize_bvh
)
{
if
(
ImGui
::
SliderInt
(
"Level"
,
&
bvh_level
,
0
,
(
int
)
bvh_levels
))
{
if
(
visualize_bvh
)
{
if
(
ImGui
::
SliderInt
(
"Level"
,
&
bvh_level
,
0
,
(
int
)
bvh_levels
))
{
update_bvh
=
true
;
}
}
...
...
@@ -104,29 +100,27 @@ Mode Render::UIsidebar(Manager& manager, Undo& undo, Scene& scene, Scene_Maybe o
update_bvh
=
update_bvh
||
ui_render
.
UI
(
scene
,
ui_camera
,
user_cam
,
err
);
manager
.
set_error
(
err
);
if
(
update_bvh
)
{
if
(
update_bvh
)
{
update_bvh
=
false
;
bvh_viz
.
clear
();
bvh_active
.
clear
();
bvh_levels
=
ui_render
.
tracer
().
visualize_bvh
(
bvh_viz
,
bvh_active
,
(
size_t
)
bvh_level
);
}
if
(
ImGui
::
Button
(
"Open Render Window"
))
{
if
(
ImGui
::
Button
(
"Open Render Window"
))
{
ui_render
.
open
();
}
return
mode
;
}
std
::
pair
<
float
,
float
>
Render
::
completion_time
()
const
{
return
ui_render
.
completion_time
();
}
std
::
pair
<
float
,
float
>
Render
::
completion_time
()
const
{
return
ui_render
.
completion_time
();
}
std
::
string
Render
::
headless_render
(
Animate
&
animate
,
Scene
&
scene
,
std
::
string
output
,
bool
a
,
int
w
,
int
h
,
int
s
,
int
ls
,
int
d
,
float
exp
,
bool
w_from_ar
)
{
if
(
w_from_ar
)
{
std
::
string
Render
::
headless_render
(
Animate
&
animate
,
Scene
&
scene
,
std
::
string
output
,
bool
a
,
int
w
,
int
h
,
int
s
,
int
ls
,
int
d
,
float
exp
,
bool
w_from_ar
)
{
if
(
w_from_ar
)
{
w
=
(
int
)
std
::
ceil
(
ui_camera
.
get_ar
()
*
h
);
}
return
ui_render
.
headless
(
animate
,
scene
,
ui_camera
.
get
(),
output
,
a
,
w
,
h
,
s
,
ls
,
d
,
exp
);
}
}
}
// namespace Gui
src/gui/render.h
View file @
c2535f0f
#pragma once
#include <mutex>
#include <SDL2/SDL.h>
#include <mutex>
#include "../util/camera.h"
#include "../scene/scene.h"
#include "../platform/gl.h"
#include "../rays/pathtracer.h"
#include "../scene/scene.h"
#include "../util/camera.h"
#include "widgets.h"
...
...
@@ -18,19 +18,20 @@ class Manager;
class
Render
{
public:
Render
(
Scene
&
scene
,
Vec2
dim
);
Render
(
Scene
&
scene
,
Vec2
dim
);
std
::
string
headless_render
(
Animate
&
animate
,
Scene
&
scene
,
std
::
string
output
,
bool
a
,
int
w
,
int
h
,
int
s
,
int
ls
,
int
d
,
float
exp
,
bool
w_from_ar
);
std
::
pair
<
float
,
float
>
completion_time
()
const
;
std
::
string
headless_render
(
Animate
&
animate
,
Scene
&
scene
,
std
::
string
output
,
bool
a
,
int
w
,
int
h
,
int
s
,
int
ls
,
int
d
,
float
exp
,
bool
w_from_ar
);
std
::
pair
<
float
,
float
>
completion_time
()
const
;
bool
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
);
Mode
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Scene
&
scene
,
Scene_Maybe
selected
,
Camera
&
user_cam
);
void
render
(
Scene_Maybe
obj
,
Widgets
&
widgets
,
Camera
&
user_cam
);
bool
keydown
(
Widgets
&
widgets
,
SDL_Keysym
key
);
Mode
UIsidebar
(
Manager
&
manager
,
Undo
&
undo
,
Scene
&
scene
,
Scene_Maybe
selected
,
Camera
&
user_cam
);
void
render
(
Scene_Maybe
obj
,
Widgets
&
widgets
,
Camera
&
user_cam
);
void
update_dim
(
Vec2
dim
);
void
load_cam
(
Vec3
pos
,
Vec3
front
,
float
ar
,
float
fov
);
const
Camera
&
get_cam
()
const
;
const
Camera
&
get_cam
()
const
;
private:
GL
::
Lines
bvh_viz
,
bvh_active
;
...
...
@@ -45,4 +46,4 @@ private:
size_t
bvh_levels
=
0
;
};
}
}
// namespace Gui
Prev
1
2
3
4
5
Next
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