Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of scene creation APIs #1076

Merged
merged 11 commits into from
Sep 9, 2020
Merged
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
235 changes: 124 additions & 111 deletions apps/ysceneitrace/ysceneitrace.cpp

Large diffs are not rendered by default.

126 changes: 68 additions & 58 deletions apps/ysceneitraces/ysceneitraces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene,
for (auto iocamera : ioscene->cameras) {
if (progress_cb)
progress_cb("converting cameras", progress.x++, progress.y);
auto camera = add_camera(scene);
set_frame(camera, iocamera->frame);
set_lens(camera, iocamera->lens, iocamera->aspect, iocamera->film,
iocamera->orthographic);
set_focus(camera, iocamera->aperture, iocamera->focus);
auto camera = add_camera(scene);
camera->frame = iocamera->frame;
camera->lens = iocamera->lens;
camera->aspect = iocamera->aspect;
camera->film = iocamera->film;
camera->orthographic = iocamera->orthographic;
camera->aperture = iocamera->aperture;
camera->focus = iocamera->focus;
camera_map[iocamera] = camera;
}

Expand All @@ -138,12 +141,9 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene,
for (auto iotexture : ioscene->textures) {
if (progress_cb)
progress_cb("converting textures", progress.x++, progress.y);
auto texture = add_texture(scene);
if (!iotexture->hdr.empty()) {
set_texture(texture, iotexture->hdr);
} else if (!iotexture->ldr.empty()) {
set_texture(texture, iotexture->ldr);
}
auto texture = add_texture(scene);
texture->hdr = iotexture->hdr;
texture->ldr = iotexture->ldr;
texture_map[iotexture] = texture;
}

Expand All @@ -152,69 +152,79 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene,
for (auto iomaterial : ioscene->materials) {
if (progress_cb)
progress_cb("converting materials", progress.x++, progress.y);
auto material = add_material(scene);
set_emission(material, iomaterial->emission,
texture_map.at(iomaterial->emission_tex));
set_color(
material, iomaterial->color, texture_map.at(iomaterial->color_tex));
set_specular(material, iomaterial->specular,
texture_map.at(iomaterial->specular_tex));
set_ior(material, iomaterial->ior);
set_metallic(material, iomaterial->metallic,
texture_map.at(iomaterial->metallic_tex));
set_transmission(material, iomaterial->transmission, iomaterial->thin,
iomaterial->trdepth, texture_map.at(iomaterial->transmission_tex));
set_translucency(material, iomaterial->translucency, iomaterial->thin,
iomaterial->trdepth, texture_map.at(iomaterial->translucency_tex));
set_roughness(material, iomaterial->roughness,
texture_map.at(iomaterial->roughness_tex));
set_opacity(
material, iomaterial->opacity, texture_map.at(iomaterial->opacity_tex));
set_thin(material, iomaterial->thin);
set_normalmap(material, texture_map.at(iomaterial->normal_tex));
set_scattering(material, iomaterial->scattering, iomaterial->scanisotropy,
texture_map.at(iomaterial->scattering_tex));
material_map[iomaterial] = material;
auto material = add_material(scene);
material->emission = iomaterial->emission;
material->color = iomaterial->color;
material->specular = iomaterial->specular;
material->roughness = iomaterial->roughness;
material->metallic = iomaterial->metallic;
material->ior = iomaterial->ior;
material->spectint = iomaterial->spectint;
material->coat = iomaterial->coat;
material->transmission = iomaterial->transmission;
material->translucency = iomaterial->translucency;
material->scattering = iomaterial->scattering;
material->scanisotropy = iomaterial->scanisotropy;
material->trdepth = iomaterial->trdepth;
material->opacity = iomaterial->opacity;
material->thin = iomaterial->thin;
material->emission_tex = texture_map.at(iomaterial->emission_tex);
material->color_tex = texture_map.at(iomaterial->color_tex);
material->specular_tex = texture_map.at(iomaterial->specular_tex);
material->metallic_tex = texture_map.at(iomaterial->metallic_tex);
material->roughness_tex = texture_map.at(iomaterial->roughness_tex);
material->transmission_tex = texture_map.at(iomaterial->transmission_tex);
material->translucency_tex = texture_map.at(iomaterial->translucency_tex);
material->spectint_tex = texture_map.at(iomaterial->spectint_tex);
material->scattering_tex = texture_map.at(iomaterial->scattering_tex);
material->coat_tex = texture_map.at(iomaterial->coat_tex);
material->opacity_tex = texture_map.at(iomaterial->opacity_tex);
material->normal_tex = texture_map.at(iomaterial->normal_tex);
material_map[iomaterial] = material;
}

auto shape_map = unordered_map<sceneio_shape*, trace_shape*>{};
shape_map[nullptr] = nullptr;
for (auto ioshape : ioscene->shapes) {
if (progress_cb) progress_cb("converting shapes", progress.x++, progress.y);
auto shape = add_shape(scene);
set_points(shape, ioshape->points);
set_lines(shape, ioshape->lines);
set_triangles(shape, ioshape->triangles);
set_quads(shape, ioshape->quads);
set_fvquads(
shape, ioshape->quadspos, ioshape->quadsnorm, ioshape->quadstexcoord);
set_positions(shape, ioshape->positions);
set_normals(shape, ioshape->normals);
set_texcoords(shape, ioshape->texcoords);
set_colors(shape, ioshape->colors);
set_radius(shape, ioshape->radius);
set_tangents(shape, ioshape->tangents);
set_subdivision(
shape, ioshape->subdivisions, ioshape->catmullclark, ioshape->smooth);
shape_map[ioshape] = shape;
auto shape = add_shape(scene);
shape->points = ioshape->points;
shape->lines = ioshape->lines;
shape->triangles = ioshape->triangles;
shape->quads = ioshape->quads;
shape->quadspos = ioshape->quadspos;
shape->quadsnorm = ioshape->quadsnorm;
shape->quadstexcoord = ioshape->quadstexcoord;
shape->positions = ioshape->positions;
shape->normals = ioshape->normals;
shape->texcoords = ioshape->texcoords;
shape->colors = ioshape->colors;
shape->radius = ioshape->radius;
shape->tangents = ioshape->tangents;
shape->subdivisions = ioshape->subdivisions;
shape->catmullclark = ioshape->catmullclark;
shape->smooth = ioshape->smooth;
shape->displacement = ioshape->displacement;
shape->displacement_tex = texture_map.at(ioshape->displacement_tex);
shape_map[ioshape] = shape;
}

for (auto ioinstance : ioscene->instances) {
if (progress_cb)
progress_cb("converting instances", progress.x++, progress.y);
auto instance = add_instance(scene);
set_frame(instance, ioinstance->frame);
set_shape(instance, shape_map.at(ioinstance->shape));
set_material(instance, material_map.at(ioinstance->material));
auto instance = add_instance(scene);
instance->frame = ioinstance->frame;
instance->shape = shape_map.at(ioinstance->shape);
instance->material = material_map.at(ioinstance->material);
}

for (auto ioenvironment : ioscene->environments) {
if (progress_cb)
progress_cb("converting environments", progress.x++, progress.y);
auto environment = add_environment(scene);
set_frame(environment, ioenvironment->frame);
set_emission(environment, ioenvironment->emission,
texture_map.at(ioenvironment->emission_tex));
auto environment = add_environment(scene);
environment->frame = ioenvironment->frame;
environment->emission = ioenvironment->emission;
environment->emission_tex = texture_map.at(ioenvironment->emission_tex);
}

// done
Expand Down
48 changes: 29 additions & 19 deletions apps/ysceneproc/ysceneproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,46 +62,56 @@ triangles_shape make_bunny(float scale = 1, bool align_middle = true) {

sceneio_camera* add_camera(sceneio_scene* scene, const string& name,
const vec3f& from, const vec3f& to, const vec3f& up, float lens,
float aspect, float aperture = 0, bool ortho = false, float film = 0.036) {
auto camera = add_camera(scene, name);
set_frame(camera, lookat_frame(from, to, up));
set_lens(camera, lens, aspect, film, ortho);
set_focus(camera, aperture, length(from - to));
float aspect, float aperture = 0, bool orthographic = false,
float film = 0.036) {
auto camera = add_camera(scene, name);
camera->frame = lookat_frame(from, to, up);
camera->lens = lens;
camera->aspect = aspect;
camera->film = film;
camera->orthographic = orthographic;
camera->aperture = aperture;
camera->focus = length(from - to);
return camera;
}
sceneio_camera* add_camera(sceneio_scene* scene, const string& name,
const frame3f& frame, float lens, float aspect, float aperture = 0,
float focus = 10, bool ortho = false, float film = 0.036) {
auto camera = add_camera(scene, name);
set_frame(camera, frame);
set_lens(camera, lens, aspect, film, ortho);
set_focus(camera, aperture, focus);
float focus = 10, bool orthographic = false, float film = 0.036) {
auto camera = add_camera(scene, name);
camera->frame = frame;
camera->lens = lens;
camera->aspect = aspect;
camera->film = film;
camera->orthographic = orthographic;
camera->aperture = aperture;
camera->focus = focus;
return camera;
}
sceneio_instance* add_instance(sceneio_scene* scene, const string& name,
const frame3f& frame, sceneio_shape* shape, sceneio_material* material) {
auto instance = add_instance(scene, name);
set_frame(instance, frame);
set_shape(instance, shape);
set_material(instance, material);
auto instance = add_instance(scene, name);
instance->frame = frame;
instance->shape = shape;
instance->material = material;
return instance;
}
sceneio_environment* add_environment(sceneio_scene* scene, const string& name,
const frame3f& frame, const vec3f& emission,
sceneio_texture* emission_tex = nullptr) {
auto environment = add_environment(scene, name);
set_frame(environment, frame);
set_emission(environment, emission, emission_tex);
auto environment = add_environment(scene, name);
environment->frame = frame;
environment->emission = emission;
environment->emission_tex = emission_tex;
return environment;
}
sceneio_texture* add_texture(sceneio_scene* scene, const string& name,
const image<vec4f>& img, bool hdr = false, bool ldr_linear = false,
bool single_channel = false) {
auto texture = add_texture(scene, name);
if (hdr) {
set_texture(texture, img);
texture->hdr = img;
} else {
set_texture(texture, ldr_linear ? float_to_byte(img) : rgb_to_srgbb(img));
texture->ldr = ldr_linear ? float_to_byte(img) : rgb_to_srgbb(img);
}
return texture;
}
Expand Down
Loading