Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy authored Apr 30, 2021
1 parent c1980b8 commit 45f2e3f
Show file tree
Hide file tree
Showing 14 changed files with 525 additions and 199 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
sudo apt-get install xorg-dev
- name: configure
env:
CC: gcc-8
CXX: g++-8
CC: gcc-9
CXX: g++-9
run: |
mkdir build
cd build
Expand Down
76 changes: 0 additions & 76 deletions .vscode/cmake-variants.json

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools",
"cmake.buildDirectory": "${workspaceFolder}/build/vscode/${variant:buildType}",
"cmake.parallelJobs": 8,
"cmake.preferredGenerators": [ "Ninja" ],
"files.associations": {
"iosfwd": "cpp",
"__functional_03": "cpp",
Expand Down
44 changes: 44 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "release",
"description": "Release build",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"YOCTO_EMBREE": "ON",
"YOCTO_DENOISE": "ON",
"YOCTO_OPENGL": "ON"
}
},
{
"name": "debug",
"description": "Default build",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"YOCTO_EMBREE": "ON",
"YOCTO_DENOISE": "ON",
"YOCTO_OPENGL": "ON"
}
}
],
"buildPresets": [
{
"name": "release",
"configurePreset": "release"
},
{
"name": "debug",
"configurePreset": "debug"
}
]
}
28 changes: 0 additions & 28 deletions CMakeSettings.json

This file was deleted.

112 changes: 112 additions & 0 deletions apps/yshape/yshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct convert_params {
vec3f rotate = {0, 0, 0};
vec3f scale = {1, 1, 1};
float scaleu = 1;
bool toedges = false;
bool tovertices = false;
};

void add_command(cli_command& cli, const string& name, convert_params& params,
Expand All @@ -73,6 +75,9 @@ void add_command(cli_command& cli, const string& name, convert_params& params,
add_option(cmd, "rotatex", params.rotate.x, "Rotate shape.");
add_option(cmd, "rotatey", params.rotate.y, "Rotate shape.");
add_option(cmd, "rotatez", params.rotate.z, "Rotate shape.");
add_option(cmd, "toedges", params.toedges, "Convert shape to edges.");
add_option(
cmd, "tovertices", params.tovertices, "Convert shape to vertices.");
}

// convert images
Expand Down Expand Up @@ -122,6 +127,24 @@ int run_convert(const convert_params& params) {
n = transform_normal(xform, n, nonuniform_scaling);
}

// convert to edges
if (params.toedges) {
// check faces
if (shape.triangles.empty() && shape.quads.empty())
print_fatal("empty faces");

// convert to edges
auto edges = !shape.triangles.empty() ? get_edges(shape.triangles)
: get_edges(shape.quads);
shape = lines_to_cylinders(edges, shape.positions, 4, 0.001f);
}

// convert to vertices
if (params.tovertices) {
// convert to spheres
shape = points_to_spheres(shape.positions);
}

// compute normals
if (params.smooth) {
if (!shape.points.empty()) {
Expand Down Expand Up @@ -375,13 +398,94 @@ int run_heightfield(const heightfield_params& params) {
for (auto& n : shape.normals)
n = transform_normal(xform, n, nonuniform_scaling);
}

// save mesh
if (!save_shape(params.output, shape, ioerror, true)) print_fatal(ioerror);

// done
return 0;
}

struct hair_params {
string shape = "shape.ply"s;
string output = "out.ply"s;
int hairs = 65536;
int steps = 8;
float length = 0.02f;
float noise = 0.001f;
float gravity = 0.0005f;
float radius = 0.0001f;
};

void add_command(cli_command& cli, const string& name, hair_params& params,
const string& usage) {
auto& cmd = add_command(cli, name, usage);
add_argument(cmd, "shape", params.shape, "Input shape.");
add_option(cmd, "output", params.output, "Output shape.");
add_option(cmd, "hairs", params.hairs, "Number of hairs.");
add_option(cmd, "steps", params.steps, "Hair steps.");
add_option(cmd, "length", params.length, "Hair length.");
add_option(cmd, "noise", params.noise, "Noise weight.");
add_option(cmd, "gravity", params.gravity, "Gravity scale.");
add_option(cmd, "radius", params.radius, "Hair radius.");
}

int run_hair(const hair_params& params) {
// load mesh
auto shape = scene_shape{};
auto ioerror = ""s;
if (!load_shape(params.shape, shape, ioerror)) print_fatal(ioerror);

// generate hair
auto hair = make_hair2(shape, {params.steps, params.hairs},
{params.length, params.length}, {params.radius, params.radius},
params.noise, params.gravity);

// save mesh
if (!save_shape(params.output, hair, ioerror, true)) print_fatal(ioerror);

// done
return 0;
}

struct sample_params {
string shape = "shape.ply"s;
string output = "out.ply"s;
int samples = 4096;
};

void add_command(cli_command& cli, const string& name, sample_params& params,
const string& usage) {
auto& cmd = add_command(cli, name, usage);
add_argument(cmd, "shape", params.shape, "Input shape.");
add_option(cmd, "output", params.output, "Output shape.");
add_option(cmd, "samples", params.samples, "Number of samples.");
}

int run_sample(const sample_params& params) {
// load mesh
auto shape = scene_shape{};
auto ioerror = ""s;
if (!load_shape(params.shape, shape, ioerror)) print_fatal(ioerror);

// generate samples
auto samples = sample_shape(shape, params.samples);

// sample shape
auto sshape = scene_shape{};
for (auto& sample : samples) {
sshape.points.push_back((int)sshape.points.size());
sshape.positions.push_back(eval_position(shape, sample.element, sample.uv));
sshape.radius.push_back(0.001f);
}

// save mesh
if (!save_shape(params.output, sshape, ioerror, true)) print_fatal(ioerror);

// done
return 0;
}

struct glview_params {
string shape = "shape.ply";
bool addsky = false;
Expand Down Expand Up @@ -428,6 +532,8 @@ struct app_params {
fvconvert_params fvconvert = {};
view_params view = {};
heightfield_params heightfield = {};
hair_params hair = {};
sample_params sample = {};
glview_params glview = {};
};

Expand All @@ -441,6 +547,8 @@ void add_commands(cli_command& cli, const string& name, app_params& params,
cli, "fvconvert", params.fvconvert, "Convert face-varying shapes.");
add_command(cli, "view", params.view, "View shapes.");
add_command(cli, "heightfield", params.heightfield, "Create an heightfield.");
add_command(cli, "hair", params.hair, "Grow hairs on a shape.");
add_command(cli, "sample", params.sample, "Sample shapepoints on a shape.");
add_command(cli, "glview", params.glview, "View shapes with OpenGL.");
}

Expand All @@ -465,6 +573,10 @@ int main(int argc, const char* argv[]) {
return run_view(params.view);
} else if (params.command == "heightfield") {
return run_heightfield(params.heightfield);
} else if (params.command == "hair") {
return run_hair(params.hair);
} else if (params.command == "sample") {
return run_sample(params.sample);
} else if (params.command == "glview") {
return run_glview(params.glview);
} else {
Expand Down
8 changes: 8 additions & 0 deletions libs/yocto/yocto_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ void make_ridgemap(vector<vec4f>& pixels, int width, int height,
float scale = 1, const vec4f& noise = {2, 0.5, 8, 1},
const vec4f& color0 = {0, 0, 0, 1}, const vec4f& color1 = {1, 1, 1, 1});

// Make a random image.
void make_randpoints(vector<vec4f>& pixels, int width, int height,
float scale = 1, const vec4f& color0 = vec4f{0.2f, 0.2f, 0.2f, 1.0f},
const vec4f& color1 = vec4f{0.5f, 0.5f, 0.5f, 1.0f});
void make_randlines(vector<vec4f>& pixels, int width, int height,
float scale = 1, const vec4f& color0 = vec4f{0.2f, 0.2f, 0.2f, 1.0f},
const vec4f& color1 = vec4f{0.5f, 0.5f, 0.5f, 1.0f});

// Make a sunsky HDR model with sun at sun_angle elevation in [0,pif/2],
// turbidity in [1.7,10] with or without sun. The sun can be enabled or
// disabled with has_sun. The sun parameters can be slightly modified by
Expand Down
Loading

0 comments on commit 45f2e3f

Please sign in to comment.