Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
/package/

# ide settings
/.idea
/.idea

#vscode config
/.vscode/
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,29 @@ objcurses [OPTIONS] <file.obj>
## Options

```
-c, --color <theme> Enable colors support, optional theme {dark|light|transparent}
-l, --light Disable light rotation
-a, --animate <deg> Start with animated object, optional speed [default: 30.0 deg/s]
-z, --zoom <x> Provide initial zoom [default: 1.0 x]
--flip Flip faces winding order
--invert-x Flip geometry along X axis
--invert-y Flip geometry along Y axis
--invert-z Flip geometry along Z axis
-h, --help Print help
-v, --version Print version
-c, --color <theme> Enable colors support, optional theme {dark|light|transparent}
-l, --light Disable light rotation
-al <deg> Start with animated altitude object, optional speed [default: 30.0 deg/s]
-az <deg> Start with animated azimuth object, optional speed [default: 30.0 deg/s]
-z, --zoom <x> Provide initial zoom [default: 1.0 x]
--azimuth <deg> Provide initial azimuth [default: 0.0 deg]
--altitude <deg> Provide initial altitude [default: 0.0 deg]
--flip Flip faces winding order
--invert-x Flip geometry along X axis
--invert-y Flip geometry along Y axis
--invert-z Flip geometry along Z axis
-h, --help Print help
-v, --version Print version

Controls:
←, h, a Rotate left
→, l, d Rotate right
↑, k, w Rotate up
↓, j, s Rotate down
+, i Zoom in
-, o Zoom out
Tab Toggle HUD
q Quit
```

Examples:
Expand All @@ -62,8 +75,8 @@ Examples:
objcurses file.obj # basic
objcurses -c file.obj # enable colors
objcurses -c transparent file.obj # set transparent color theme
objcurses -c -a -z 1.5 file.obj # start animation with zoom 1.5 x
objcurses -c -a 10 file.obj # start animation with speed 10.0 deg/s
objcurses -c -al -z 1.5 file.obj # start animation altitude with zoom 1.5 x
objcurses -c -az 10 file.obj # start animation azimuth with speed 10.0 deg/s
objcurses -c --invert-z file.obj # flip z axis if blender model
```

Expand Down
5 changes: 4 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ inline constexpr float ZOOM_START = 1.0f;
inline constexpr float ZOOM_STEP = 0.1f;
inline constexpr float ZOOM_MIN = 0.10f;
inline constexpr float ZOOM_MAX = 5.00f;
inline constexpr float ALTITUDE_START = 0.00f;
inline constexpr float AZIMUTH_START = 0.00f;

// animation
inline constexpr float FRAME_DURATION = 1.0f / 60.0f; // 60 fps
inline constexpr float ANIMATION_STEP = 30.0f;
inline constexpr float ANIMATION_STEP_ALTITUDE = 30.0f;
inline constexpr float ANIMATION_STEP_AZIMUTH = 30.0f;
4 changes: 2 additions & 2 deletions entities/view/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class Camera {
}
void rotate_up(float degree = ANGLE_STEP)
{
altitude = std::min(altitude + deg2rad(degree), PI / 2);
altitude = rad_norm(altitude - deg2rad(degree));
}
void rotate_down(float degree = ANGLE_STEP)
{
altitude = std::max(altitude - deg2rad(degree), -PI / 2);
altitude = rad_norm(altitude - deg2rad(degree));
}

void zoom_in(float step = ZOOM_STEP)
Expand Down
101 changes: 84 additions & 17 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ static void print_help()
"Options:\n"
" -c, --color <theme> Enable colors support, optional theme {dark|light|transparent}\n"
" -l, --light Disable light rotation\n"
" -a, --animate <deg> Start with animated object, optional speed [default: " << std::fixed << std::setprecision(1) << ANIMATION_STEP << std::defaultfloat << " deg/s]\n"
" -z, --zoom <x> Provide initial zoom [default: " << std::fixed << std::setprecision(1) << ZOOM_START << std::defaultfloat << " x]\n"
" -al <deg> Start with animated altitude object, optional speed [default: "<< std::fixed << std::setprecision(1) << ANIMATION_STEP_ALTITUDE << std::defaultfloat << " deg/s]\n"
" -az <deg> Start with animated azimuth object, optional speed [default: "<< std::fixed << std::setprecision(1) << ANIMATION_STEP_AZIMUTH << std::defaultfloat << " deg/s]\n"
" -z, --zoom <x> Provide initial zoom [default: "<< std::fixed << std::setprecision(1) << ZOOM_START << std::defaultfloat << " x]\n"
" --azimuth <deg> Provide initial azimuth [default: "<< std::fixed << std::setprecision(1) << AZIMUTH_START << std::defaultfloat << " deg]\n"
" --altitude <deg> Provide initial altitude [default: "<< std::fixed << std::setprecision(1) << ALTITUDE_START << std::defaultfloat << " deg]\n"
" --flip Flip faces winding order\n"
" --invert-x Flip geometry along X axis\n"
" --invert-y Flip geometry along Y axis\n"
Expand All @@ -142,19 +145,24 @@ static void print_version()
struct Args {
std::filesystem::path input_file;

bool color_support = false; // -c / --color
bool color_support = false; // -c / --color
Theme theme = Theme::Dark;

bool static_light = false; // -l / --light
bool flip_faces = false; // -f / --flip
bool invert_x = false; // -x / --invert-x
bool invert_y = false; // -y / --invert-y
bool invert_z = false; // -z / --invert-z
bool static_light = false; // -l / --light
bool flip_faces = false; // -f / --flip
bool invert_x = false; // -x / --invert-x
bool invert_y = false; // -y / --invert-y
bool invert_z = false; // -z / --invert-z

bool animate = false; // -a / --animate
float speed = ANIMATION_STEP; // deg/s
bool animate_altitude = false; // -al
bool animate_azimuth = false; // -az
float speed_altitude = ANIMATION_STEP_ALTITUDE; // deg/s
float speed_azimuth = ANIMATION_STEP_AZIMUTH; // deg/s

float zoom = ZOOM_START; // -z / --zoom
float zoom = ZOOM_START; // -z / --zoom

float altitude = ALTITUDE_START; // --altitude
float azimuth = AZIMUTH_START; // --azimuth
};

static Args parse_args(int argc, char **argv)
Expand Down Expand Up @@ -208,18 +216,30 @@ static Args parse_args(int argc, char **argv)
{
a.static_light = true;
}
else if (arg == "-a" || arg == "--animate")
else if (arg == "-az")
{
a.animate_azimuth = true;

if (i + 1 < argc && argv[i + 1][0] != '-')
{
if (auto val = safe_stof(argv[i + 1]); val)
{
a.speed_azimuth = val.value();
++i;
}
}
}
else if (arg == "-al")
{
a.animate = true;
a.animate_altitude = true;

if (i + 1 < argc && argv[i + 1][0] != '-')
{
if (auto val = safe_stof(argv[i + 1]); val)
{
a.speed = val.value();
a.speed_altitude = val.value();
++i;
}
// else - file name
}
}
else if (arg == "-z" || arg == "--zoom")
Expand All @@ -240,6 +260,42 @@ static Args parse_args(int argc, char **argv)

a.zoom = val.value();
}
else if (arg == "--altitude")
{
if (++i == argc)
{
std::cerr << "error: altitude needs value\n";
std::exit(1);
}

auto val = safe_stof(argv[i]);

if (!val)
{
std::cerr << "error: invalid altitude value\n";
std::exit(1);
}

a.altitude = val.value();
}
else if (arg == "--azimuth")
{
if (++i == argc)
{
std::cerr << "error: azimuth needs value\n";
std::exit(1);
}

auto val = safe_stof(argv[i]);

if (!val)
{
std::cerr << "error: invalid azimuth value\n";
std::exit(1);
}

a.azimuth = val.value();
}
else if (arg == "--flip")
{
a.flip_faces = true;
Expand Down Expand Up @@ -386,8 +442,12 @@ int main(int argc, char **argv)
Light light; // default
bool hud = false;

// change initial view
cam.altitude = deg2rad(args.altitude);
cam.azimuth = deg2rad(args.azimuth);

// animation
bool rotate = args.animate;
bool rotate = args.animate_altitude || args.animate_azimuth;
auto last = SteadyClock::now();

// optimizing drawing
Expand All @@ -402,7 +462,14 @@ int main(int argc, char **argv)
float fps = dt > 0.f ? 1.f / dt : 0.f;

if (rotate) {
cam.rotate_left(args.speed * dt);
if (args.animate_altitude)
{
cam.rotate_down(args.speed_altitude * dt);
}
if (args.animate_azimuth)
{
cam.rotate_left(args.speed_azimuth * dt);
}
needs_redraw = true;
}

Expand Down
26 changes: 26 additions & 0 deletions resources/objects/katana.mlt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# File generated by ImageToStl.com - Free Image and 3D model conversion tools

newmtl mat0
Ns 641.90367
Ka 1.0 1.0 1.0
Kd 1 1 1
Ks 0.5 0.5 0.5
Ke 0.0 0.0 0.0
Ni 1.0
d 1
illum 2
map_Kd DefaultMaterial_baseColor.jpg
map_Ns DefaultMaterial_metallicRoughness.png
refl DefaultMaterial_metallicRoughness.png
bump DefaultMaterial_normal.png

newmtl mat1
Ns 250
Ka 1.0 1.0 1.0
Kd 0.85 0.85 0.85
Ks 0 0 0
Ke 0.0 0.0 0.0
Ni 1.0
d 1
illum 1

Loading