From 39d30a7ccbe5e1275de873e3168116843f7174c2 Mon Sep 17 00:00:00 2001 From: volivarez60 <57726285+volivarez60@users.noreply.github.com> Date: Mon, 18 Oct 2021 20:41:30 -0500 Subject: [PATCH 01/14] Create gltf_read.cpp --- src/libgcv/plugins/gltf/gltf_read.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/libgcv/plugins/gltf/gltf_read.cpp diff --git a/src/libgcv/plugins/gltf/gltf_read.cpp b/src/libgcv/plugins/gltf/gltf_read.cpp new file mode 100644 index 00000000000..cbeb52dc3b5 --- /dev/null +++ b/src/libgcv/plugins/gltf/gltf_read.cpp @@ -0,0 +1 @@ +// insert code here From 9e6fb7a99c7e14b11914ce54318610ea3e07c2f9 Mon Sep 17 00:00:00 2001 From: f4alt Date: Wed, 20 Oct 2021 14:30:42 -0500 Subject: [PATCH 02/14] updated appleseed cmake so that it points to correct files when setting paths --- misc/CMake/FindAppleseed.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/misc/CMake/FindAppleseed.cmake b/misc/CMake/FindAppleseed.cmake index 94a4421652c..ebe8f319f8f 100644 --- a/misc/CMake/FindAppleseed.cmake +++ b/misc/CMake/FindAppleseed.cmake @@ -49,16 +49,15 @@ find_path (Appleseed_INCLUDE_DIR renderer/api/project.h ${Appleseed_ROOT} PATH_SUFFIXES include - appleseed/include ) find_library (Appleseed_LIBRARY - NAMES appleseed + NAMES Appleseed HINTS ${Appleseed_ROOT} PATH_SUFFIXES - lib64 lib + lib64 ) # Handle the QUIETLY and REQUIRED arguments and set Appleseed_FOUND. From 46859022172d5314c6961efe0c977ee1c8e46cb4 Mon Sep 17 00:00:00 2001 From: f4alt Date: Tue, 2 Nov 2021 13:54:15 -0500 Subject: [PATCH 03/14] art update and testing dump - I should've been incrementally pushing changes --- src/art/art.cpp | 140 +++++-- src/art/art.cpp.old | 633 ++++++++++++++++++++++++++++++ src/art/art_test_static_model.cpp | 469 ++++++++++++++++++++++ 3 files changed, 1213 insertions(+), 29 deletions(-) create mode 100644 src/art/art.cpp.old create mode 100644 src/art/art_test_static_model.cpp diff --git a/src/art/art.cpp b/src/art/art.cpp index 301edef8377..cc8f34b4d80 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -115,6 +115,7 @@ #include "renderer/api/scene.h" #include "renderer/api/surfaceshader.h" #include "renderer/api/utility.h" +#include "renderer/api/shadergroup.h" // appleseed.foundation headers. #include "foundation/core/appleseed.h" @@ -271,6 +272,10 @@ asf::auto_release_ptr build_project(const char* file, const char* // Create an empty project. asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); project->search_paths().push_back_explicit_path("build/Debug"); + // ***** add path for shaders + // todo: make this dynamic to the project + project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/appleseed"); + project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/max"); // Add default configurations to the project. project->add_default_configurations(); @@ -300,34 +305,102 @@ asf::auto_release_ptr build_project(const char* file, const char* //------------------------------------------------------------------------ // Create a color called "gray" and insert it into the assembly. - static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; - assembly->colors().insert( - asr::ColorEntityFactory::create( - "gray", - asr::ParamArray() - .insert("color_space", "srgb"), - asr::ColorValueArray(3, GrayReflectance))); + // static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; + // assembly->colors().insert( + // asr::ColorEntityFactory::create( + // "gray", + // asr::ParamArray() + // .insert("color_space", "srgb"), + // asr::ColorValueArray(3, GrayReflectance))); // Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. - assembly->bsdfs().insert( - asr::LambertianBRDFFactory().create( - "diffuse_gray_brdf", - asr::ParamArray() - .insert("reflectance", "gray"))); + // assembly->bsdfs().insert( + // asr::LambertianBRDFFactory().create( + // "diffuse_gray_brdf", + // asr::ParamArray() + // .insert("reflectance", "gray"))); + + // create a shader group called "Material_tree" + asf::auto_release_ptr shader_grp( + asr::ShaderGroupFactory().create( + "Material_tree", + asr::ParamArray())); + + // THIS IS OUR INPUT SHADER - add to shader group + /* This uses an already created appleseed .oso shader + in the form of + type + shader name + layer + paramArray + */ + shader_grp->add_shader( + "shader", + "as_metal", + "shader_in", + asr::ParamArray() + ); + + /* import generic .osl shader + in the form of + type + name + layer + source + paramArray + */ + // shader_grp->add_source_shader( + // "shader", + // "toon", + // "shader_in", + // "as_toon", + // asr::ParamArray() + // ); + + // add material2surface so we can see the shader in action + shader_grp->add_shader( + "surface", + "as_closure2surface", + "close", + asr::ParamArray() + ); + + // connect the two shader nodes + shader_grp->add_connection( + "shader_in", + "out_outColor", + "close", + "in_input" + ); + + // add the shader group to the assembly + assembly->shader_groups().insert( + shader_grp + ); // Create a physical surface shader and insert it into the assembly. assembly->surface_shaders().insert( asr::PhysicalSurfaceShaderFactory().create( - "physical_surface_shader", - asr::ParamArray())); + "Material_mat_surface_shader", + asr::ParamArray() + .insert("lighting_samples", "1"))); // Create a material called "gray_material" and insert it into the assembly. + // assembly->materials().insert( + // asr::GenericMaterialFactory().create( + // "gray_material", + // asr::ParamArray() + // .insert("surface_shader", "physical_surface_shader") + // .insert("bsdf", "diffuse_gray_brdf"))); + + // create a material called "Material_mat" with our shader_group assembly->materials().insert( - asr::GenericMaterialFactory().create( - "gray_material", - asr::ParamArray() - .insert("surface_shader", "physical_surface_shader") - .insert("bsdf", "diffuse_gray_brdf"))); + asr::OSLMaterialFactory().create( + "Material_mat", + asr::ParamArray() + .insert("osl_surface", "Material_tree") + .insert("surface_shader", "Material_mat_surface_shader") + )); //------------------------------------------------------------------------ // Geometry @@ -342,24 +415,27 @@ asf::auto_release_ptr build_project(const char* file, const char* std::string obj_num = std::string("object.") + std::to_string(i + 1); std::string obj_name = std::string(objv[i]); geometry_parameters.insert_path(obj_num, obj_name); - } - +} asf::auto_release_ptr brlcad_object( - new BrlcadObject{"brlcad geometry", + // new BrlcadObject{obj_name.c_str(), + new BrlcadObject{"brlcad_object", geometry_parameters, &APP, resources}); assembly->objects().insert(brlcad_object); - const std::string instance_name = "brlcad_inst"; + + // const std::string instance_name = obj_name + "_brlcad_inst"; + const std::string instance_name = "_brlcad_inst"; assembly->object_instances().insert( asr::ObjectInstanceFactory::create( instance_name.c_str(), asr::ParamArray(), - "brlcad geometry", + // obj_name.c_str(), + "brlcad_object", asf::Transformd::identity(), asf::StringDictionary() - .insert("default", "gray_material") - .insert("default2", "gray_material"))); + .insert("default", "Material_mat") + .insert("default2", "Material_mat"))); //------------------------------------------------------------------------ @@ -411,8 +487,11 @@ asf::auto_release_ptr build_project(const char* file, const char* // Environment //------------------------------------------------------------------------ + // OPTIONAL: this creates a blue background color // Create a color called "sky_radiance" and insert it into the scene. - static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; + // static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; + // statically making this 'white' for now so we don't blue wash the image + static const float SkyRadiance[] = { 1.0f, 1.0f, 1.0f }; scene->colors().insert( asr::ColorEntityFactory::create( "sky_radiance", @@ -537,6 +616,9 @@ main(int argc, char **argv) * command processing. Initialize the table. */ BU_GET(cmd_objs, struct bu_ptbl); bu_ptbl_init(cmd_objs, 8, "initialize cmdobjs table"); + + // log and gracefully exit for now + bu_exit(EXIT_FAILURE, "No Region specified\n"); } } else { //objs_free_argv = 1; @@ -605,13 +687,13 @@ main(int argc, char **argv) renderer->render(renderer_controller); // Save the frame to disk. - char *default_out = bu_strdup("art.png"); + char *default_out = bu_strdup("output/art.png"); outputfile = default_out; project->get_frame()->write_main_image(outputfile); bu_free(default_out, "default name"); // Save the project to disk. - //asr::ProjectFileWriter::write(project.ref(), "output/objects.appleseed"); + asr::ProjectFileWriter::write(project.ref(), "output/objects.appleseed"); // Make sure to delete the master renderer before the project and the logger / log target. renderer.reset(); diff --git a/src/art/art.cpp.old b/src/art/art.cpp.old new file mode 100644 index 00000000000..8cc86a34d1a --- /dev/null +++ b/src/art/art.cpp.old @@ -0,0 +1,633 @@ +/* A R T . C P P + * BRL-CAD + * + * Copyright (c) 2004-2021 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file art/art.cpp + * + * Once you have appleseed installed, run BRL-CAD's CMake with APPLESEED_ROOT + * set to enable this program: + * + * cmake .. -DAPPLESEED_ROOT=/path/to/appleseed -DBRLCAD_PNG=SYSTEM -DBRLCAD_ZLIB=SYSTEM + * + * (the appleseed root path should contain bin, lib and include directories) + * + * On Linux, if using the prebuilt binary you'll need to set LD_LIBRARY_PATH: + * export LD_LIBRARY_PATH=/path/to/appleseed/lib + * + * + * The example scene object used by helloworld is found at: + * https://raw.githubusercontent.com/appleseedhq/appleseed/master/sandbox/examples/cpp/helloworld/data/scene.obj + * + * basic example helloworld code from + * https://github.com/appleseedhq/appleseed/blob/master/sandbox/examples/cpp/helloworld/helloworld.cpp + * has the following license: + * + * This software is released under the MIT license. + * + * Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited + * Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include "common.h" +/* avoid redefining the appleseed sleep function */ +#undef sleep + +#include +#include +#include +#include + +#include +#include +#include + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +#endif +#if defined(__clang__) +# pragma clang diagnostic push +#endif +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic ignored "-Wfloat-equal" +# pragma GCC diagnostic ignored "-Wunused-parameter" +# pragma GCC diagnostic ignored "-Wpedantic" +# pragma GCC diagnostic ignored "-Wignored-qualifiers" +# if (__GNUC__ >= 8) +# pragma GCC diagnostic ignored "-Wclass-memaccess" +# endif +#endif +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wfloat-equal" +# pragma clang diagnostic ignored "-Wunused-parameter" +# pragma clang diagnostic ignored "-Wpedantic" +# pragma clang diagnostic ignored "-Wignored-qualifiers" +#endif + + +// appleseed.renderer headers. Only include header files from renderer/api/. +#include "renderer/api/bsdf.h" +#include "renderer/api/camera.h" +#include "renderer/api/color.h" +#include "renderer/api/environment.h" +#include "renderer/api/environmentedf.h" +#include "renderer/api/environmentshader.h" +#include "renderer/api/frame.h" +#include "renderer/api/light.h" +#include "renderer/api/log.h" +#include "renderer/api/material.h" +#include "renderer/api/object.h" +#include "renderer/api/project.h" +#include "renderer/api/rendering.h" +#include "renderer/api/scene.h" +#include "renderer/api/surfaceshader.h" +#include "renderer/api/utility.h" + +// appleseed.foundation headers. +#include "foundation/core/appleseed.h" +#include "foundation/math/matrix.h" +#include "foundation/math/scalar.h" +#include "foundation/math/transform.h" +#include "foundation/math/vector.h" +#include "foundation/utility/containers/dictionary.h" +#include "foundation/utility/log/consolelogtarget.h" +#include "foundation/utility/autoreleaseptr.h" +#include "foundation/utility/searchpaths.h" + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + +#include "vmath.h" /* vector math macros */ +#include "raytrace.h" /* librt interface definitions */ +#include "bu/app.h" +#include "bu/getopt.h" +#include "bu/vls.h" +#include "art.h" + +struct application APP; +struct resource* resources; +extern "C" { + FILE* outfp = NULL; + int save_overlaps = 1; + size_t n_malloc; /* Totals at last check */ + size_t n_free; + size_t n_realloc; + mat_t view2model; + mat_t model2view; + struct icv_image* bif = NULL; +} + +/* NOTE: stub in empty rt_do_tab to satisfy ../rt/opt.c - this means + * we can't run the commands, but they are tied deeply into the various + * src/rt files and a significant refactor is in order to properly + * extract that functionality into a library... */ + +extern "C" { + struct command_tab rt_do_tab[] = { {NULL, NULL, NULL, 0, 0, 0} }; + void usage(const char* argv0, int verbose); + int get_args(int argc, const char* argv[]); + + extern char* outputfile; + extern int objc; + extern char** objv; + extern size_t npsw; + extern struct bu_ptbl* cmd_objs; + extern size_t width, height; + extern fastf_t azimuth, elevation; + extern point_t eye_model; /* model-space location of eye */ + extern fastf_t eye_backoff; /* dist from eye to center */ + extern mat_t Viewrotscale; + extern fastf_t viewsize; + extern fastf_t aspect; + + void grid_setup(); +} + +void +do_ae(double azim, double elev) +{ + vect_t temp; + vect_t diag; + mat_t toEye; + struct rt_i* rtip = APP.a_rt_i; + + if (rtip == NULL) + return; + + if (rtip->nsolids <= 0) + bu_exit(EXIT_FAILURE, "ERROR: no primitives active\n"); + + if (rtip->nregions <= 0) + bu_exit(EXIT_FAILURE, "ERROR: no regions active\n"); + + if (rtip->mdl_max[X] >= INFINITY) { + bu_log("do_ae: infinite model bounds? setting a unit minimum\n"); + VSETALL(rtip->mdl_min, -1); + } + if (rtip->mdl_max[X] <= -INFINITY) { + bu_log("do_ae: infinite model bounds? setting a unit maximum\n"); + VSETALL(rtip->mdl_max, 1); + } + + /* + * Enlarge the model RPP just slightly, to avoid nasty effects + * with a solid's face being exactly on the edge NOTE: This code + * is duplicated out of librt/tree.c/rt_prep(), and has to appear + * here to enable the viewsize calculation to match the final RPP. + */ + rtip->mdl_min[X] = floor(rtip->mdl_min[X]); + rtip->mdl_min[Y] = floor(rtip->mdl_min[Y]); + rtip->mdl_min[Z] = floor(rtip->mdl_min[Z]); + rtip->mdl_max[X] = ceil(rtip->mdl_max[X]); + rtip->mdl_max[Y] = ceil(rtip->mdl_max[Y]); + rtip->mdl_max[Z] = ceil(rtip->mdl_max[Z]); + + MAT_IDN(Viewrotscale); + bn_mat_angles(Viewrotscale, 270.0 + elev, 0.0, 270.0 - azim); + + /* Look at the center of the model */ + MAT_IDN(toEye); + toEye[MDX] = -((rtip->mdl_max[X] + rtip->mdl_min[X]) / 2.0); + toEye[MDY] = -((rtip->mdl_max[Y] + rtip->mdl_min[Y]) / 2.0); + toEye[MDZ] = -((rtip->mdl_max[Z] + rtip->mdl_min[Z]) / 2.0); + + /* Fit a sphere to the model RPP, diameter is viewsize, unless + * viewsize command used to override. + */ + if (viewsize <= 0) { + VSUB2(diag, rtip->mdl_max, rtip->mdl_min); + viewsize = MAGNITUDE(diag); + if (aspect > 1) { + /* don't clip any of the image when autoscaling */ + viewsize *= aspect; + } + } + + /* sanity check: make sure viewsize still isn't zero in case + * bounding box is empty, otherwise bn_mat_int() will bomb. + */ + if (viewsize < 0 || ZERO(viewsize)) { + viewsize = 2.0; /* arbitrary so Viewrotscale is normal */ + } + + Viewrotscale[15] = 0.5 * viewsize; /* Viewscale */ + bn_mat_mul(model2view, Viewrotscale, toEye); + bn_mat_inv(view2model, model2view); + VSET(temp, 0, 0, eye_backoff); + MAT4X3PNT(eye_model, view2model, temp); +} + +// Define shorter namespaces for convenience. +namespace asf = foundation; +namespace asr = renderer; + +asf::auto_release_ptr build_project(const char* file, const char* UNUSED(objects)) +{ + /* If user gave no sizing info at all, use 512 as default */ + struct bu_vls dimensions = BU_VLS_INIT_ZERO; + if (width <= 0) + width = 512; + if (height <= 0) + height = 512; + + // Create an empty project. + asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); + project->search_paths().push_back_explicit_path("build/Debug"); + + // Add default configurations to the project. + project->add_default_configurations(); + + // Set the number of samples. This is the main quality parameter: the higher the + // number of samples, the smoother the image but the longer the rendering time. + project->configurations() + .get_by_name("final")->get_parameters() + .insert_path("uniform_pixel_renderer.samples", "25") + .insert_path("rendering_threads", "1"); /* multithreading not supported yet */ + + project->configurations() + .get_by_name("interactive")->get_parameters() + .insert_path("rendering_threads", "1"); /* no multithreading - for debug rendering on appleseed */ + + // Create a scene. + asf::auto_release_ptr scene(asr::SceneFactory::create()); + + // Create an assembly. + asf::auto_release_ptr assembly( + asr::AssemblyFactory().create( + "assembly", + asr::ParamArray())); + + //------------------------------------------------------------------------ + // Materials + //------------------------------------------------------------------------ + + // Create a color called "gray" and insert it into the assembly. + static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; + assembly->colors().insert( + asr::ColorEntityFactory::create( + "gray", + asr::ParamArray() + .insert("color_space", "srgb"), + asr::ColorValueArray(3, GrayReflectance))); + + // Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. + assembly->bsdfs().insert( + asr::LambertianBRDFFactory().create( + "diffuse_gray_brdf", + asr::ParamArray() + .insert("reflectance", "gray"))); + + // Create a physical surface shader and insert it into the assembly. + assembly->surface_shaders().insert( + asr::PhysicalSurfaceShaderFactory().create( + "physical_surface_shader", + asr::ParamArray())); + + // Create a material called "gray_material" and insert it into the assembly. + assembly->materials().insert( + asr::GenericMaterialFactory().create( + "gray_material", + asr::ParamArray() + .insert("surface_shader", "physical_surface_shader") + .insert("bsdf", "diffuse_gray_brdf"))); + + //------------------------------------------------------------------------ + // Geometry + //------------------------------------------------------------------------ + + // Load the brlcad geometry + renderer::ParamArray geometry_parameters = asr::ParamArray() + .insert("database_path", file) + .insert("object_count", objc); + for (int i = 0; i < objc; i++) + { + std::string obj_num = std::string("object.") + std::to_string(i + 1); + std::string obj_name = std::string(objv[i]); + geometry_parameters.insert_path(obj_num, obj_name); + } + + asf::auto_release_ptr brlcad_object( + new BrlcadObject{"brlcad geometry", + geometry_parameters, + &APP, resources}); + assembly->objects().insert(brlcad_object); + + const std::string instance_name = "brlcad_inst"; + assembly->object_instances().insert( + asr::ObjectInstanceFactory::create( + instance_name.c_str(), + asr::ParamArray(), + "brlcad geometry", + asf::Transformd::identity(), + asf::StringDictionary() + .insert("default", "gray_material") + .insert("default2", "gray_material"))); + + + //------------------------------------------------------------------------ + // Light + //------------------------------------------------------------------------ + + // Create a color called "light_intensity" and insert it into the assembly. + static const float LightRadiance[] = { 1.0f, 1.0f, 1.0f }; + assembly->colors().insert( + asr::ColorEntityFactory::create( + "light_intensity", + asr::ParamArray() + .insert("color_space", "srgb") + .insert("multiplier", "30.0"), + asr::ColorValueArray(3, LightRadiance))); + + // Create a point light called "light" and insert it into the assembly. + asf::auto_release_ptr light( + asr::PointLightFactory().create( + "light", + asr::ParamArray() + .insert("intensity", "light_intensity"))); + light->set_transform( + asf::Transformd::from_local_to_parent( + asf::Matrix4d::make_translation(asf::Vector3d(0.6, 2.0, 1.0)))); + assembly->lights().insert(light); + + //------------------------------------------------------------------------ + // Assembly instance + //------------------------------------------------------------------------ + + // Create an instance of the assembly and insert it into the scene. + asf::auto_release_ptr assembly_instance( + asr::AssemblyInstanceFactory::create( + "assembly_inst", + asr::ParamArray(), + "assembly")); + assembly_instance + ->transform_sequence() + .set_transform( + 0.0f, + asf::Transformd::identity()); + scene->assembly_instances().insert(assembly_instance); + + // Insert the assembly into the scene. + scene->assemblies().insert(assembly); + + //------------------------------------------------------------------------ + // Environment + //------------------------------------------------------------------------ + + // Create a color called "sky_radiance" and insert it into the scene. + static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; + scene->colors().insert( + asr::ColorEntityFactory::create( + "sky_radiance", + asr::ParamArray() + .insert("color_space", "srgb") + .insert("multiplier", "0.5"), + asr::ColorValueArray(3, SkyRadiance))); + + // Create an environment EDF called "sky_edf" and insert it into the scene. + scene->environment_edfs().insert( + asr::ConstantEnvironmentEDFFactory().create( + "sky_edf", + asr::ParamArray() + .insert("radiance", "sky_radiance"))); + + // Create an environment shader called "sky_shader" and insert it into the scene. + scene->environment_shaders().insert( + asr::EDFEnvironmentShaderFactory().create( + "sky_shader", + asr::ParamArray() + .insert("environment_edf", "sky_edf"))); + + // Create an environment called "sky" and bind it to the scene. + scene->set_environment( + asr::EnvironmentFactory::create( + "sky", + asr::ParamArray() + .insert("environment_edf", "sky_edf") + .insert("environment_shader", "sky_shader"))); + + //------------------------------------------------------------------------ + // Camera + //------------------------------------------------------------------------ + + // Create a pinhole camera with film dimensions + bu_vls_sprintf(&dimensions, "%f %f", 0.08 * (double) width / height, 0.08); + asf::auto_release_ptr camera( + asr::PinholeCameraFactory().create( + "camera", + asr::ParamArray() + .insert("film_dimensions", bu_vls_cstr(&dimensions)) + .insert("focal_length", "0.035"))); + + // Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0) + // and are looking toward Z- (0.0, 0.0, -1.0). + camera->transform_sequence().set_transform( + 0.0f, + asf::Transformd::from_local_to_parent( + asf::Matrix4d::make_translation(asf::Vector3d(eye_model[0], eye_model[2], -eye_model[1])) * /* camera location */ + asf::Matrix4d::make_rotation(asf::Vector3d(0.0, 1.0, 0.0), asf::deg_to_rad(azimuth - 270)) * /* azimuth */ + asf::Matrix4d::make_rotation(asf::Vector3d(1.0, 0.0, 0.0), asf::deg_to_rad(-elevation)) /* elevation */ + )); + + // Bind the camera to the scene. + scene->cameras().insert(camera); + + //------------------------------------------------------------------------ + // Frame + //------------------------------------------------------------------------ + + // Create a frame and bind it to the project. + bu_vls_sprintf(&dimensions, "%zd %zd", width, height); + project->set_frame( + asr::FrameFactory::create( + "beauty", + asr::ParamArray() + .insert("camera", "camera") + .insert("resolution", bu_vls_cstr(&dimensions)))); + + // Bind the scene to the project. + project->set_scene(scene); + + return project; +} + + +int +main(int argc, char **argv) +{ + // Create a log target that outputs to stderr, and binds it to the renderer's global logger. + // Eventually you will probably want to redirect log messages to your own target. For this + // you will need to implement foundation::ILogTarget (foundation/utility/log/ilogtarget.h). + std::unique_ptr log_target(asf::create_console_log_target(stderr)); + asr::global_logger().add_target(log_target.get()); + + // Print appleseed's version string. + RENDERER_LOG_INFO("%s", asf::Appleseed::get_synthetic_version_string()); + + struct rt_i* rtip; + const char *title_file = NULL; + //const char *title_obj = NULL; /* name of file and first object */ + struct bu_vls str = BU_VLS_INIT_ZERO; + //int objs_free_argv = 0; + + bu_setprogname(argv[0]); + + /* Process command line options */ + int i = get_args(argc, (const char**)argv); + if (i < 0) { + //usage(argv[0], 0); + return 1; + } + else if (i == 0) { + //usage(argv[0], 100); + return 0; + } + + if (bu_optind >= argc) { + RENDERER_LOG_INFO("%s: BRL-CAD geometry database not specified\n", argv[0]); + //usage(argv[0], 0); + return 1; + } + + title_file = argv[bu_optind]; + //title_obj = argv[bu_optind + 1]; + if (!objv) { + objc = argc - bu_optind - 1; + if (objc) { + objv = (char **)&(argv[bu_optind+1]); + } else { + /* No objects in either input file or argv - try getting objs from + * command processing. Initialize the table. */ + BU_GET(cmd_objs, struct bu_ptbl); + bu_ptbl_init(cmd_objs, 8, "initialize cmdobjs table"); + + // log and gracefully exit for now + bu_exit(EXIT_FAILURE, "No Region specified\n"); + } + } else { + //objs_free_argv = 1; + } + + bu_vls_from_argv(&str, objc, (const char**)objv); + + resources = static_cast(bu_calloc(1, sizeof(resource) * MAX_PSW, "appleseed")); + char title[1024] = { 0 }; + + /* load the specified geometry database */ + rtip = rt_dirbuild(title_file, title, sizeof(title)); + if (rtip == RTI_NULL) + { + RENDERER_LOG_INFO("building the database directory for [%s] FAILED\n", title_file); + return -1; + } + + for (int ic = 0; ic < MAX_PSW; ic++) { + rt_init_resource(&resources[ic], ic, rtip); + RT_CK_RESOURCE(&resources[ic]); + } + + /* print optional title */ + if (title[0]) + { + RENDERER_LOG_INFO("database title: %s\n", title); + } + + /* include objects from database */ + if (rt_gettrees(rtip, objc, (const char**)objv, npsw) < 0) + { + RENDERER_LOG_INFO("loading the geometry for [%s...] FAILED\n", objv[0]); + return -1; + } + + /* prepare database for raytracing */ + if (rtip->needprep) + rt_prep_parallel(rtip, 1); + + /* initialize values in application struct */ + RT_APPLICATION_INIT(&APP); + + /* configure raytrace application */ + APP.a_rt_i = rtip; + APP.a_onehit = -1; + APP.a_hit = brlcad_hit; + APP.a_miss = brlcad_miss; + + do_ae(azimuth, elevation); + RENDERER_LOG_INFO("View model: (%f, %f, %f)", eye_model[0], -eye_model[2], eye_model[1]); + + // Build the project. + asf::auto_release_ptr project(build_project(title_file, bu_vls_cstr(&str))); + + // Create the master renderer. + asr::DefaultRendererController renderer_controller; + asf::SearchPaths resource_search_paths; + std::unique_ptr renderer( + new asr::MasterRenderer( + project.ref(), + project->configurations().get_by_name("final")->get_inherited_parameters(), + resource_search_paths)); + + // Render the frame. + renderer->render(renderer_controller); + + // Save the frame to disk. + char *default_out = bu_strdup("art.png"); + outputfile = default_out; + project->get_frame()->write_main_image(outputfile); + bu_free(default_out, "default name"); + + // Save the project to disk. + //asr::ProjectFileWriter::write(project.ref(), "output/objects.appleseed"); + + // Make sure to delete the master renderer before the project and the logger / log target. + renderer.reset(); + + return 0; +} + + +// Local Variables: +// tab-width: 8 +// mode: C++ +// c-basic-offset: 4 +// indent-tabs-mode: t +// c-file-style: "stroustrup" +// End: +// ex: shiftwidth=4 tabstop=8 diff --git a/src/art/art_test_static_model.cpp b/src/art/art_test_static_model.cpp new file mode 100644 index 00000000000..f91a1ffe2d0 --- /dev/null +++ b/src/art/art_test_static_model.cpp @@ -0,0 +1,469 @@ +// +// This source file is part of appleseed. +// Visit https://appleseedhq.net/ for additional information and resources. +// +// This software is released under the MIT license. +// +// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited +// Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#include "common.h" +/* avoid redefining the appleseed sleep function */ +#undef sleep + +#include +#include +#include +#include + +#include +#include +#include + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +#endif +#if defined(__clang__) +# pragma clang diagnostic push +#endif +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic ignored "-Wfloat-equal" +# pragma GCC diagnostic ignored "-Wunused-parameter" +# pragma GCC diagnostic ignored "-Wpedantic" +# pragma GCC diagnostic ignored "-Wignored-qualifiers" +# if (__GNUC__ >= 8) +# pragma GCC diagnostic ignored "-Wclass-memaccess" +# endif +#endif +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wfloat-equal" +# pragma clang diagnostic ignored "-Wunused-parameter" +# pragma clang diagnostic ignored "-Wpedantic" +# pragma clang diagnostic ignored "-Wignored-qualifiers" +#endif + + +// appleseed.renderer headers. Only include header files from renderer/api/. +#include "renderer/api/bsdf.h" +#include "renderer/api/camera.h" +#include "renderer/api/color.h" +#include "renderer/api/environment.h" +#include "renderer/api/environmentedf.h" +#include "renderer/api/environmentshader.h" +#include "renderer/api/frame.h" +#include "renderer/api/light.h" +#include "renderer/api/log.h" +#include "renderer/api/material.h" +#include "renderer/api/object.h" +#include "renderer/api/project.h" +#include "renderer/api/rendering.h" +#include "renderer/api/scene.h" +#include "renderer/api/surfaceshader.h" +#include "renderer/api/utility.h" +#include "renderer/api/shadergroup.h" + +// appleseed.foundation headers. +#include "foundation/core/appleseed.h" +#include "foundation/math/matrix.h" +#include "foundation/math/scalar.h" +#include "foundation/math/transform.h" +#include "foundation/math/vector.h" +#include "foundation/utility/containers/dictionary.h" +#include "foundation/utility/log/consolelogtarget.h" +#include "foundation/utility/autoreleaseptr.h" +#include "foundation/utility/searchpaths.h" + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + +#include "vmath.h" /* vector math macros */ +#include "raytrace.h" /* librt interface definitions */ +#include "bu/app.h" +#include "bu/getopt.h" +#include "bu/vls.h" +#include "art.h" + +struct application APP; +struct resource* resources; +extern "C" { + FILE* outfp = NULL; + int save_overlaps = 1; + size_t n_malloc; /* Totals at last check */ + size_t n_free; + size_t n_realloc; + mat_t view2model; + mat_t model2view; + struct icv_image* bif = NULL; +} + +/* NOTE: stub in empty rt_do_tab to satisfy ../rt/opt.c - this means + * we can't run the commands, but they are tied deeply into the various + * src/rt files and a significant refactor is in order to properly + * extract that functionality into a library... */ + +extern "C" { + struct command_tab rt_do_tab[] = { {NULL, NULL, NULL, 0, 0, 0} }; + void usage(const char* argv0, int verbose); + int get_args(int argc, const char* argv[]); + + extern char* outputfile; + extern int objc; + extern char** objv; + extern size_t npsw; + extern struct bu_ptbl* cmd_objs; + extern size_t width, height; + extern fastf_t azimuth, elevation; + extern point_t eye_model; /* model-space location of eye */ + extern fastf_t eye_backoff; /* dist from eye to center */ + extern mat_t Viewrotscale; + extern fastf_t viewsize; + extern fastf_t aspect; + + void grid_setup(); +} + +// Define shorter namespaces for convenience. +namespace asf = foundation; +namespace asr = renderer; + +asf::auto_release_ptr build_project() +{ + // Create an empty project. + asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); + project->search_paths().push_back_explicit_path("data"); + + // ***** add path for shaders + // the first two paths are for appleseed precomiled .oso shaders + // todo: make this dynamic to the project + project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/appleseed"); + project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/max"); + project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/src/appleseed"); + + + // Add default configurations to the project. + project->add_default_configurations(); + + // Set the number of samples. This is the main quality parameter: the higher the + // number of samples, the smoother the image but the longer the rendering time. + project->configurations() + .get_by_name("final")->get_parameters() + .insert_path("uniform_pixel_renderer.samples", "25"); + + // Create a scene. + asf::auto_release_ptr scene(asr::SceneFactory::create()); + + // Create an assembly. + asf::auto_release_ptr assembly( + asr::AssemblyFactory().create( + "assembly", + asr::ParamArray())); + + //------------------------------------------------------------------------ + // Materials + //------------------------------------------------------------------------ + + // Create a color called "gray" and insert it into the assembly. + // static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; + // assembly->colors().insert( + // asr::ColorEntityFactory::create( + // "gray", + // asr::ParamArray() + // .insert("color_space", "srgb"), + // asr::ColorValueArray(3, GrayReflectance))); + + // Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. + // assembly->bsdfs().insert( + // asr::LambertianBRDFFactory().create( + // "diffuse_gray_brdf", + // asr::ParamArray() + // .insert("reflectance", "gray"))); + + // create a shader group + asf::auto_release_ptr shader_grp( + asr::ShaderGroupFactory().create( + "Material_tree", + asr::ParamArray())); + + // THIS IS OUR INPUT SHADER - add to shader group + /* This uses an already created appleseed .oso shader + in the form of + type + shader name + layer + paramArray + */ + shader_grp->add_shader( + "shader", + "as_toon", + "OSL_in", + asr::ParamArray() + ); + + /* import generic .osl shader + in the form of + type + name + layer + source + paramArray + */ + // shader_grp->add_source_shader( + // "shader", + // "toon", + // "OSL_in", + // "as_toon", + // asr::ParamArray() + // ); + + // add material2surface so we can see the shader in action + shader_grp->add_shader( + "surface", + "as_closure2surface", + "close", + asr::ParamArray() + ); + + // connect the two shader nodes + shader_grp->add_connection( + "OSL_in", + "out_outColor", + "close", + "in_input" + ); + + // add the shader group to the assembly + assembly->shader_groups().insert( + shader_grp + ); + + // Create a physical surface shader and insert it into the assembly. + assembly->surface_shaders().insert( + asr::PhysicalSurfaceShaderFactory().create( + "Material_mat_surface_shader", + asr::ParamArray() + .insert("lighting_samples", "1"))); + + // Create a material called "gray_material" and insert it into the assembly. + assembly->materials().insert( + asr::OSLMaterialFactory().create( + "Material_mat", + asr::ParamArray() + .insert("osl_surface", "Material_tree"))); + + //------------------------------------------------------------------------ + // Geometry + //------------------------------------------------------------------------ + + // Load the scene geometry from disk. + asr::MeshObjectArray objects; + asr::MeshObjectReader::read( + project->search_paths(), + "cube", + asr::ParamArray() + .insert("filename", "scene.obj"), + objects); + + // Insert all the objects into the assembly. + for (size_t i = 0; i < objects.size(); ++i) + { + // Insert this object into the scene. + asr::MeshObject* object = objects[i]; + assembly->objects().insert(asf::auto_release_ptr(object)); + + // Create an instance of this object and insert it into the assembly. + const std::string instance_name = std::string(object->get_name()) + "_inst"; + assembly->object_instances().insert( + asr::ObjectInstanceFactory::create( + instance_name.c_str(), + asr::ParamArray(), + object->get_name(), + asf::Transformd::identity(), + asf::StringDictionary() + .insert("default", "Material_mat") + .insert("default2", "Material_mat") + )); + } + + //------------------------------------------------------------------------ + // Light + //------------------------------------------------------------------------ + + // Create a color called "light_intensity" and insert it into the assembly. + static const float LightRadiance[] = { 1.0f, 1.0f, 1.0f }; + assembly->colors().insert( + asr::ColorEntityFactory::create( + "light_intensity", + asr::ParamArray() + .insert("color_space", "srgb") + .insert("multiplier", "30.0"), + asr::ColorValueArray(3, LightRadiance))); + + // Create a point light called "light" and insert it into the assembly. + asf::auto_release_ptr light( + asr::PointLightFactory().create( + "light", + asr::ParamArray() + .insert("intensity", "light_intensity"))); + light->set_transform( + asf::Transformd::from_local_to_parent( + asf::Matrix4d::make_translation(asf::Vector3d(0.6, 2.0, 1.0)))); + assembly->lights().insert(light); + + //------------------------------------------------------------------------ + // Assembly instance + //------------------------------------------------------------------------ + + // Create an instance of the assembly and insert it into the scene. + asf::auto_release_ptr assembly_instance( + asr::AssemblyInstanceFactory::create( + "assembly_inst", + asr::ParamArray(), + "assembly")); + assembly_instance + ->transform_sequence() + .set_transform( + 0.0f, + asf::Transformd::identity()); + scene->assembly_instances().insert(assembly_instance); + + // Insert the assembly into the scene. + scene->assemblies().insert(assembly); + + //------------------------------------------------------------------------ + // Environment + //------------------------------------------------------------------------ + + // Create a color called "sky_radiance" and insert it into the scene. + // static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; + // scene->colors().insert( + // asr::ColorEntityFactory::create( + // "sky_radiance", + // asr::ParamArray() + // .insert("color_space", "srgb") + // .insert("multiplier", "0.5"), + // asr::ColorValueArray(3, SkyRadiance))); + + // Create an environment EDF called "sky_edf" and insert it into the scene. + // scene->environment_edfs().insert( + // asr::ConstantEnvironmentEDFFactory().create( + // "sky_edf", + // asr::ParamArray() + // .insert("radiance", "sky_radiance"))); + + // Create an environment shader called "sky_shader" and insert it into the scene. + // scene->environment_shaders().insert( + // asr::EDFEnvironmentShaderFactory().create( + // "sky_shader", + // asr::ParamArray() + // .insert("environment_edf", "sky_edf"))); + + // Create an environment called "sky" and bind it to the scene. + // updated: created a generic env with no parameters (ie no background color on render) + // todo: update the above commented out code to import environment background color + scene->set_environment( + asr::EnvironmentFactory::create( + "environment", + asr::ParamArray())); + + //------------------------------------------------------------------------ + // Camera + //------------------------------------------------------------------------ + + // Create a pinhole camera with film dimensions 0.980 x 0.735 in (24.892 x 18.669 mm). + asf::auto_release_ptr camera( + asr::PinholeCameraFactory().create( + "camera", + asr::ParamArray() + .insert("film_dimensions", "0.024892 0.018669") + .insert("focal_length", "0.035"))); + + // Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0) + // and are looking toward Z- (0.0, 0.0, -1.0). + camera->transform_sequence().set_transform( + 0.0f, + asf::Transformd::from_local_to_parent( + asf::Matrix4d::make_rotation(asf::Vector3d(1.0, 0.0, 0.0), asf::deg_to_rad(-20.0)) * + asf::Matrix4d::make_translation(asf::Vector3d(0.0, 0.8, 11.0)))); + + // Bind the camera to the scene. + scene->cameras().insert(camera); + + //------------------------------------------------------------------------ + // Frame + //------------------------------------------------------------------------ + + // Create a frame and bind it to the project. + project->set_frame( + asr::FrameFactory::create( + "beauty", + asr::ParamArray() + .insert("camera", "camera") + .insert("resolution", "640 480"))); + + // Bind the scene to the project. + project->set_scene(scene); + + return project; +} + +int main() +{ + // Create a log target that outputs to stderr, and binds it to the renderer's global logger. + // Eventually you will probably want to redirect log messages to your own target. For this + // you will need to implement foundation::ILogTarget (foundation/log/ilogtarget.h). + std::unique_ptr log_target(asf::create_console_log_target(stderr)); + asr::global_logger().add_target(log_target.get()); + + // Print appleseed's version string. + RENDERER_LOG_INFO("%s", asf::Appleseed::get_synthetic_version_string()); + + // Build the project. + asf::auto_release_ptr project(build_project()); + + // Create the master renderer. + asr::DefaultRendererController renderer_controller; + asf::SearchPaths resource_search_paths; + std::unique_ptr renderer( + new asr::MasterRenderer( + project.ref(), + project->configurations().get_by_name("final")->get_inherited_parameters(), + resource_search_paths)); + + // Render the frame. + renderer->render(renderer_controller); + + // Save the frame to disk. + project->get_frame()->write_main_image("output/test.png"); + + // Save the project to disk. + asr::ProjectFileWriter::write(project.ref(), "output/test.appleseed"); + + // Make sure to delete the master renderer before the project and the logger / log target. + renderer.reset(); + + return 0; +} From c8e809f6a67cf76e0ecc203bcd5746bc3ffcc0df Mon Sep 17 00:00:00 2001 From: f4alt Date: Tue, 9 Nov 2021 10:13:34 -0600 Subject: [PATCH 04/14] implement tree walk to itemize pieces of geometry and pull out rgb colors for now. ISSUE: with bounding boxes --- src/art/CMakeLists.txt | 2 + src/art/art.cpp | 465 ++++++++++++++++++++++++++++++--------- src/art/art.h | 2 + src/art/brlcadplugin.cpp | 22 +- 4 files changed, 377 insertions(+), 114 deletions(-) diff --git a/src/art/CMakeLists.txt b/src/art/CMakeLists.txt index 532fd76e6f0..eeba280c7b5 100644 --- a/src/art/CMakeLists.txt +++ b/src/art/CMakeLists.txt @@ -2,6 +2,7 @@ set(ART_INCLUDE_DIRS ${OPTICAL_INCLUDE_DIRS} ${FB_INCLUDE_DIRS} ${RT_INCLUDE_DIRS} + ${GED_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -10,6 +11,7 @@ BRLCAD_INCLUDE_DIRS(ART_INCLUDE_DIRS) set(RT_STD_LIBS Threads::Threads + libged librt libnmg libdm diff --git a/src/art/art.cpp b/src/art/art.cpp index cc8f34b4d80..b2a6ff61fcc 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -142,6 +142,10 @@ #include "bu/getopt.h" #include "bu/vls.h" #include "art.h" +#include "rt/tree.h" +#include "ged.h" +#include "ged/commands.h" +#include "ged/defines.h" struct application APP; struct resource* resources; @@ -182,6 +186,234 @@ extern "C" { void grid_setup(); } +// Define shorter namespaces for convenience. +namespace asf = foundation; +namespace asr = renderer; + +int register_region(struct db_tree_state* tsp __attribute__((unused)), + const struct db_full_path* pathp __attribute__((unused)), + const struct rt_comb_internal* combp __attribute__((unused)), + void* data) +{ + + struct directory* dp = DB_FULL_PATH_CUR_DIR(pathp); + struct ged* ged; + ged = ged_open("db", APP.a_rt_i->rti_dbip->dbi_filename, 1); + + // struct application local_app = APP; // struct copy + // struct rt_i* rtip = rt_new_rti(APP.a_rt_i->rti_dbip); + + char* name; + name = dp->d_namep; + + // char title[1024]; + // rtip = rt_dirbuild(APP.a_rt_i->rti_dbip->dbi_filename, title, sizeof(title)); + // rt_gettree(rtip, name); + + // local_app.a_rt_i = rtip; + // rt_prep(rtip); + + point_t min; + point_t max; + int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); + // int ac = 2; + // const char* av[3]; + // av[0] = (const char*)"bb"; + // av[1] = name; + // av[2] = NULL; + // ged_exec(&ged, ac, av); + bu_log("ged: %i | min: %f %f %f | max: %f %f %f\n", ret, V3ARGS(min), V3ARGS(max)); + + // struct bu_vls v = BU_VLS_INIT_ZERO; + // bu_vls_sprintf() + // std::string min = bu_vls_cstr(V3ARGS(min)); + + VMOVE(APP.a_uvec, min); + VMOVE(APP.a_vvec, max); + + + renderer::ParamArray geometry_parameters = asr::ParamArray() + .insert("database_path", name) + .insert("object_count", objc) + .insert("minX", min[0]) + .insert("minY", min[1]) + .insert("minZ", min[2]) + .insert("maxX", max[0]) + .insert("maxY", max[1]) + .insert("maxZ", max[2]); + + asf::auto_release_ptr brlcad_object( + new BrlcadObject{name, + // new BrlcadObject{"brlcad_object", + geometry_parameters, + &APP, resources}); + + asr::Scene* scene = static_cast(data); + // asf::auto_release_ptr assembly = static_cast>(data); + + std::string assembly_name = std::string(name) + "_object_assembly"; + asf::auto_release_ptr assembly( +asr::AssemblyFactory().create( + assembly_name.c_str(), + asr::ParamArray())); + + // create a shader group called "Material_tree" + std::string shader_name = std::string(name) + "_shader"; + asf::auto_release_ptr shader_grp( + asr::ShaderGroupFactory().create( + shader_name.c_str(), + asr::ParamArray())); + + // THIS IS OUR INPUT SHADER - add to shader group + /* This uses an already created appleseed .oso shader + in the form of + type + shader name + layer + paramArray + */ + struct bu_vls v=BU_VLS_INIT_ZERO; + bu_vls_printf(&v, "color %f %f %f", combp->rgb[0]/255.0, combp->rgb[1]/255.0, combp->rgb[2]/255.0); + const char* color = bu_vls_cstr(&v); + shader_grp->add_shader( + "shader", + "as_disney_material", + "shader_in", + asr::ParamArray() + .insert("in_color", color) + ); + bu_vls_free(&v); + + /* import generic .osl shader + in the form of + type + name + layer + source + paramArray + */ + // shader_grp->add_source_shader( + // "shader", + // "toon", + // "shader_in", + // "as_toon", + // asr::ParamArray() + // ); + + // add material2surface so we can see the shader in action + shader_grp->add_shader( + "surface", + "as_closure2surface", + "close", + asr::ParamArray() + ); + + // connect the two shader nodes + shader_grp->add_connection( + "shader_in", + "out_outColor", + "close", + "in_input" + ); + + // add the shader group to the assembly + assembly->shader_groups().insert( + shader_grp + ); + + // Create a physical surface shader and insert it into the assembly. + assembly->surface_shaders().insert( + asr::PhysicalSurfaceShaderFactory().create( + "Material_mat_surface_shader", + asr::ParamArray() + .insert("lighting_samples", "1"))); + + // Create a material called "gray_material" and insert it into the assembly. + // assembly->materials().insert( + // asr::GenericMaterialFactory().create( + // "gray_material", + // asr::ParamArray() + // .insert("surface_shader", "physical_surface_shader") + // .insert("bsdf", "diffuse_gray_brdf"))); + + // create a material called "Material_mat" with our shader_group + std::string material_mat = shader_name + "_mat"; + assembly->materials().insert( + asr::OSLMaterialFactory().create( + material_mat.c_str(), + asr::ParamArray() + .insert("osl_surface", shader_name.c_str()) + .insert("surface_shader", "Material_mat_surface_shader") + )); + + + assembly->objects().insert(brlcad_object); + + const std::string instance_name = std::string(assembly_name) + "_brlcad_inst"; + assembly->object_instances().insert( + asr::ObjectInstanceFactory::create( + instance_name.c_str(), + asr::ParamArray(), + name, + // "brlcad_object", + asf::Transformd::identity(), + asf::StringDictionary() + .insert("default", material_mat.c_str()) + .insert("default2", material_mat.c_str()) + )); + + // Create a color called "light_intensity" and insert it into the assembly. +// static const float LightRadiance[] = { 1.0f, 1.0f, 1.0f }; +// assembly->colors().insert( +// asr::ColorEntityFactory::create( +// "light_intensity", +// asr::ParamArray() +// .insert("color_space", "srgb") +// .insert("multiplier", "30.0"), +// asr::ColorValueArray(3, LightRadiance))); +// +// // Create a point light called "light" and insert it into the assembly. +// asf::auto_release_ptr light( +// asr::PointLightFactory().create( +// "light", +// asr::ParamArray() +// .insert("intensity", "light_intensity"))); +// light->set_transform( +// asf::Transformd::from_local_to_parent( +// asf::Matrix4d::make_translation(asf::Vector3d(0.6, 2.0, 1.0)))); +// assembly->lights().insert(light); + + scene->assemblies().insert(assembly); + + std::string assembly_inst_name = assembly_name + "_inst"; + asf::auto_release_ptr assembly_instance( + asr::AssemblyInstanceFactory::create( + assembly_inst_name.c_str(), + asr::ParamArray(), + assembly_name.c_str() + )); + assembly_instance + ->transform_sequence() + .set_transform( + 0.0f, + asf::Transformd::identity()); + scene->assembly_instances().insert(assembly_instance); + + + + + + // char* name; + // name = db_path_to_string(pathp); + // bu_log("region_start %s\n", name); + + + + + + return 0; +} + void do_ae(double azim, double elev) { @@ -256,11 +488,7 @@ do_ae(double azim, double elev) MAT4X3PNT(eye_model, view2model, temp); } -// Define shorter namespaces for convenience. -namespace asf = foundation; -namespace asr = renderer; - -asf::auto_release_ptr build_project(const char* file, const char* UNUSED(objects)) +asf::auto_release_ptr build_project(const char* UNUSED(file), const char* UNUSED(objects)) { /* If user gave no sizing info at all, use 512 as default */ struct bu_vls dimensions = BU_VLS_INIT_ZERO; @@ -293,6 +521,7 @@ asf::auto_release_ptr build_project(const char* file, const char* // Create a scene. asf::auto_release_ptr scene(asr::SceneFactory::create()); + // asr::Scene scene(asr::SceneFactory::create()); // Create an assembly. asf::auto_release_ptr assembly( @@ -321,123 +550,135 @@ asf::auto_release_ptr build_project(const char* file, const char* // .insert("reflectance", "gray"))); // create a shader group called "Material_tree" - asf::auto_release_ptr shader_grp( - asr::ShaderGroupFactory().create( - "Material_tree", - asr::ParamArray())); - - // THIS IS OUR INPUT SHADER - add to shader group - /* This uses an already created appleseed .oso shader - in the form of - type - shader name - layer - paramArray - */ - shader_grp->add_shader( - "shader", - "as_metal", - "shader_in", - asr::ParamArray() - ); - - /* import generic .osl shader - in the form of - type - name - layer - source - paramArray - */ - // shader_grp->add_source_shader( - // "shader", - // "toon", - // "shader_in", - // "as_toon", + // asf::auto_release_ptr shader_grp( + // asr::ShaderGroupFactory().create( + // "Material_tree", + // asr::ParamArray())); + // + // // THIS IS OUR INPUT SHADER - add to shader group + // /* This uses an already created appleseed .oso shader + // in the form of + // type + // shader name + // layer + // paramArray + // */ + // shader_grp->add_shader( + // "shader", + // "as_metal", + // "shader_in", + // asr::ParamArray() + // ); + // + // /* import generic .osl shader + // in the form of + // type + // name + // layer + // source + // paramArray + // */ + // // shader_grp->add_source_shader( + // // "shader", + // // "toon", + // // "shader_in", + // // "as_toon", + // // asr::ParamArray() + // // ); + // + // // add material2surface so we can see the shader in action + // shader_grp->add_shader( + // "surface", + // "as_closure2surface", + // "close", // asr::ParamArray() // ); - - // add material2surface so we can see the shader in action - shader_grp->add_shader( - "surface", - "as_closure2surface", - "close", - asr::ParamArray() - ); - - // connect the two shader nodes - shader_grp->add_connection( - "shader_in", - "out_outColor", - "close", - "in_input" - ); - - // add the shader group to the assembly - assembly->shader_groups().insert( - shader_grp - ); - - // Create a physical surface shader and insert it into the assembly. - assembly->surface_shaders().insert( - asr::PhysicalSurfaceShaderFactory().create( - "Material_mat_surface_shader", - asr::ParamArray() - .insert("lighting_samples", "1"))); - - // Create a material called "gray_material" and insert it into the assembly. - // assembly->materials().insert( - // asr::GenericMaterialFactory().create( - // "gray_material", + // + // // connect the two shader nodes + // shader_grp->add_connection( + // "shader_in", + // "out_outColor", + // "close", + // "in_input" + // ); + // + // // add the shader group to the assembly + // assembly->shader_groups().insert( + // shader_grp + // ); + // + // // Create a physical surface shader and insert it into the assembly. + // assembly->surface_shaders().insert( + // asr::PhysicalSurfaceShaderFactory().create( + // "Material_mat_surface_shader", // asr::ParamArray() - // .insert("surface_shader", "physical_surface_shader") - // .insert("bsdf", "diffuse_gray_brdf"))); - - // create a material called "Material_mat" with our shader_group - assembly->materials().insert( - asr::OSLMaterialFactory().create( - "Material_mat", - asr::ParamArray() - .insert("osl_surface", "Material_tree") - .insert("surface_shader", "Material_mat_surface_shader") - )); + // .insert("lighting_samples", "1"))); + // + // // Create a material called "gray_material" and insert it into the assembly. + // // assembly->materials().insert( + // // asr::GenericMaterialFactory().create( + // // "gray_material", + // // asr::ParamArray() + // // .insert("surface_shader", "physical_surface_shader") + // // .insert("bsdf", "diffuse_gray_brdf"))); + // + // // create a material called "Material_mat" with our shader_group + // assembly->materials().insert( + // asr::OSLMaterialFactory().create( + // "Material_mat", + // asr::ParamArray() + // .insert("osl_surface", "Material_tree") + // .insert("surface_shader", "Material_mat_surface_shader") + // )); //------------------------------------------------------------------------ // Geometry //------------------------------------------------------------------------ // Load the brlcad geometry - renderer::ParamArray geometry_parameters = asr::ParamArray() - .insert("database_path", file) - .insert("object_count", objc); - for (int i = 0; i < objc; i++) - { - std::string obj_num = std::string("object.") + std::to_string(i + 1); - std::string obj_name = std::string(objv[i]); - geometry_parameters.insert_path(obj_num, obj_name); -} - asf::auto_release_ptr brlcad_object( - // new BrlcadObject{obj_name.c_str(), - new BrlcadObject{"brlcad_object", - geometry_parameters, - &APP, resources}); - assembly->objects().insert(brlcad_object); +// renderer::ParamArray geometry_parameters = asr::ParamArray() +// .insert("database_path", file) +// .insert("object_count", objc); +// for (int i = 0; i < objc; i++) +// { +// std::string obj_num = std::string("object.") + std::to_string(i + 1); +// std::string obj_name = std::string(objv[i]); +// geometry_parameters.insert_path(obj_num, obj_name); +// } + struct db_tree_state state = rt_initial_tree_state; + state.ts_dbip = APP.a_rt_i->rti_dbip; + state.ts_resp = resources; + // rt_init_resource(&rt_uniresource, 0, NULL); - // const std::string instance_name = obj_name + "_brlcad_inst"; - const std::string instance_name = "_brlcad_inst"; - assembly->object_instances().insert( - asr::ObjectInstanceFactory::create( - instance_name.c_str(), - asr::ParamArray(), - // obj_name.c_str(), - "brlcad_object", - asf::Transformd::identity(), - asf::StringDictionary() - .insert("default", "Material_mat") - .insert("default2", "Material_mat"))); + db_walk_tree(APP.a_rt_i->rti_dbip, objc, (const char**)objv, 1, &state, register_region, NULL, NULL, reinterpret_cast(scene.get())); + + + + // asf::auto_release_ptr brlcad_object( + // // new BrlcadObject{obj_name.c_str(), + // new BrlcadObject{"brlcad_object", + // geometry_parameters, + // &APP, resources}); + // + // assembly->objects().insert(brlcad_object); + + + // const std::string instance_name = obj_name + "_brlcad_inst"; + // const std::string instance_name = "_brlcad_inst"; + // assembly->object_instances().insert( + // asr::ObjectInstanceFactory::create( + // instance_name.c_str(), + // asr::ParamArray(), + // // obj_name.c_str(), + // "brlcad_object", + // asf::Transformd::identity(), + // asf::StringDictionary() + // .insert("default", "Material_mat") + // .insert("default2", "Material_mat"))); + //------------------------------------------------------------------------ // Light //------------------------------------------------------------------------ @@ -664,7 +905,7 @@ main(int argc, char **argv) /* configure raytrace application */ APP.a_rt_i = rtip; - APP.a_onehit = -1; + APP.a_onehit = 1; APP.a_hit = brlcad_hit; APP.a_miss = brlcad_miss; @@ -674,6 +915,7 @@ main(int argc, char **argv) // Build the project. asf::auto_release_ptr project(build_project(title_file, bu_vls_cstr(&str))); + // Create the master renderer. asr::DefaultRendererController renderer_controller; asf::SearchPaths resource_search_paths; @@ -698,6 +940,9 @@ main(int argc, char **argv) // Make sure to delete the master renderer before the project and the logger / log target. renderer.reset(); + // clean up resources + bu_free(resources, "appleseed"); + return 0; } diff --git a/src/art/art.h b/src/art/art.h index e9e917f2d84..1076108f028 100644 --- a/src/art/art.h +++ b/src/art/art.h @@ -139,6 +139,8 @@ class APPLESEED_DLL_EXPORT BrlcadObject : public asr::ProceduralObject struct application* ap; struct rt_i* rtip; struct resource* resources; + point_t min; + point_t max; static int get_id(); diff --git a/src/art/brlcadplugin.cpp b/src/art/brlcadplugin.cpp index 4891aa737fe..2f333ef9a0e 100644 --- a/src/art/brlcadplugin.cpp +++ b/src/art/brlcadplugin.cpp @@ -190,6 +190,11 @@ BrlcadObject::BrlcadObject( : asr::ProceduralObject(name, params) { configure_raytrace_application(get_database().c_str(), get_object_count(), get_objects()); + VSET(min, m_params.get_required("minX"), m_params.get_required("minY"), m_params.get_required("minZ")); + // VMOVE(min, ap->a_uvec); + // VMOVE(max, ap->a_vvec); + VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); + } @@ -203,6 +208,8 @@ BrlcadObject:: BrlcadObject( this->ap = p_ap; this->rtip = p_ap->a_rt_i; this->resources = p_resources; + VMOVE(this->min, ap->a_uvec); + VMOVE(this->max, ap->a_vvec); } @@ -210,7 +217,7 @@ BrlcadObject:: BrlcadObject( void BrlcadObject::release() { - bu_free(resources, "appleseed"); + // bu_free(resources, "appleseed"); //bu_free(ap, "appleseed"); delete this; } @@ -248,10 +255,17 @@ BrlcadObject::compute_local_bbox() const if (l_rtip->needprep) rt_prep_parallel(l_rtip, 1); - fprintf(output, "Local Bounding Box: (%f, %f, %f) , (%f, %f, %f)\n", l_rtip->mdl_min[X], -l_rtip->mdl_min[Z], l_rtip->mdl_min[Y], l_rtip->mdl_max[X], -l_rtip->mdl_max[Z], l_rtip->mdl_max[Y]); + // point_t min; + // VSET(min, m_params.get_required("minX"), m_params.get_required("minY"), m_params.get_required("minZ")); + // VMOVE(min, ap->a_uvec); + // point_t max; + // VMOVE(max, ap->a_vvec); + // VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); + + fprintf(output, "Local Bounding Box: (%f, %f, %f) , (%f, %f, %f)\n", V3ARGS(min), V3ARGS(max)); fflush(output); - return asr::GAABB3(asr::GVector3(l_rtip->mdl_min[X], -l_rtip->mdl_min[Z], l_rtip->mdl_min[Y]), asr::GVector3(l_rtip->mdl_max[X], -l_rtip->mdl_max[Z], l_rtip->mdl_max[Y])); + return asr::GAABB3(asr::GVector3(V3ARGS(min)), asr::GVector3(V3ARGS(max))); // return asr::GAABB3(asr::GVector3(-r), asr::GVector3(r)); } @@ -328,7 +342,7 @@ BrlcadObject::intersect(const asr::ShadingRay& ray) const // Compute a front point, a back point and the geometric normal in object // instance space for a given ray with origin being a point on the surface -void +void BrlcadObject::refine_and_offset( const asf::Ray3d& obj_inst_ray, asf::Vector3d& obj_inst_front_point, From 14702661f9473876a643641c4c83f96c3451ad6c Mon Sep 17 00:00:00 2001 From: f4alt Date: Thu, 11 Nov 2021 16:04:37 -0600 Subject: [PATCH 05/14] debugging why render does not maintain orientation. Bounding box now gets object absolute size --- src/art/art.cpp | 43 +++++++++++++++++++++++++++++----------- src/art/brlcadplugin.cpp | 5 +++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/art/art.cpp b/src/art/art.cpp index b2a6ff61fcc..9faa4a52ac2 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -147,6 +147,11 @@ #include "ged/commands.h" #include "ged/defines.h" +struct name_color { + char* name; + char* color; +}; + struct application APP; struct resource* resources; extern "C" { @@ -206,6 +211,12 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), char* name; name = dp->d_namep; + const char* name_char; + std::string name_test = "all.g/" + std::string(name); + name_char = name_test.c_str(); + // + // bu_log("name: %s\n", name_test.c_str()); + // char title[1024]; // rtip = rt_dirbuild(APP.a_rt_i->rti_dbip->dbi_filename, title, sizeof(title)); // rt_gettree(rtip, name); @@ -215,13 +226,10 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), point_t min; point_t max; - int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); - // int ac = 2; - // const char* av[3]; - // av[0] = (const char*)"bb"; - // av[1] = name; - // av[2] = NULL; - // ged_exec(&ged, ac, av); + // int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); + int ret = ged_get_obj_bounds(ged, 1, (const char**)&name_char, 1, min, max); + // int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); + bu_log("ged: %i | min: %f %f %f | max: %f %f %f\n", ret, V3ARGS(min), V3ARGS(max)); // struct bu_vls v = BU_VLS_INIT_ZERO; @@ -233,7 +241,8 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), renderer::ParamArray geometry_parameters = asr::ParamArray() - .insert("database_path", name) + // .insert("database_path", name) + .insert("database_path", name_char) .insert("object_count", objc) .insert("minX", min[0]) .insert("minY", min[1]) @@ -242,8 +251,16 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), .insert("maxY", max[1]) .insert("maxZ", max[2]); + + // name = "/all.g/" + name; + // char* name_test = "/all.g/" + name; + + asf::auto_release_ptr brlcad_object( - new BrlcadObject{name, + new BrlcadObject{ + name, + // name_test.c_str(), + // name_char, // new BrlcadObject{"brlcad_object", geometry_parameters, &APP, resources}); @@ -252,6 +269,7 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), // asf::auto_release_ptr assembly = static_cast>(data); std::string assembly_name = std::string(name) + "_object_assembly"; + // std::string assembly_name = std::string(name_test) + "_object_assembly"; asf::auto_release_ptr assembly( asr::AssemblyFactory().create( assembly_name.c_str(), @@ -259,6 +277,7 @@ asr::AssemblyFactory().create( // create a shader group called "Material_tree" std::string shader_name = std::string(name) + "_shader"; + // std::string shader_name = std::string(name_test) + "_shader"; asf::auto_release_ptr shader_grp( asr::ShaderGroupFactory().create( shader_name.c_str(), @@ -355,6 +374,8 @@ asr::AssemblyFactory().create( instance_name.c_str(), asr::ParamArray(), name, + // name_char, + // name_test.c_str(), // "brlcad_object", asf::Transformd::identity(), asf::StringDictionary() @@ -410,7 +431,6 @@ asr::AssemblyFactory().create( - return 0; } @@ -652,8 +672,7 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // rt_init_resource(&rt_uniresource, 0, NULL); db_walk_tree(APP.a_rt_i->rti_dbip, objc, (const char**)objv, 1, &state, register_region, NULL, NULL, reinterpret_cast(scene.get())); - - + // db_walk_tree(APP.a_rt_i->rti_dbip, objc, (const char**)objv, 1, &state, register_region, NULL, NULL, ); diff --git a/src/art/brlcadplugin.cpp b/src/art/brlcadplugin.cpp index 2f333ef9a0e..e6143f2f67c 100644 --- a/src/art/brlcadplugin.cpp +++ b/src/art/brlcadplugin.cpp @@ -195,6 +195,8 @@ BrlcadObject::BrlcadObject( // VMOVE(max, ap->a_vvec); VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); + // fprintf(output, "constructor built here \n"); + // fflush(output); } @@ -210,6 +212,9 @@ BrlcadObject:: BrlcadObject( this->resources = p_resources; VMOVE(this->min, ap->a_uvec); VMOVE(this->max, ap->a_vvec); + + // fprintf(output, "other constructor built here \n"); + // fflush(output); } From 5c8e6c849897a324978f990446fd5dbd95fad16b Mon Sep 17 00:00:00 2001 From: f4alt Date: Mon, 15 Nov 2021 23:09:19 -0600 Subject: [PATCH 06/14] this got wrapped in here by mistake - removing --- src/libgcv/plugins/gltf/gltf_read.cpp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/libgcv/plugins/gltf/gltf_read.cpp diff --git a/src/libgcv/plugins/gltf/gltf_read.cpp b/src/libgcv/plugins/gltf/gltf_read.cpp deleted file mode 100644 index cbeb52dc3b5..00000000000 --- a/src/libgcv/plugins/gltf/gltf_read.cpp +++ /dev/null @@ -1 +0,0 @@ -// insert code here From c30ecc3f6e680a8dc00a83dfba71eaafbc3bb659 Mon Sep 17 00:00:00 2001 From: f4alt Date: Mon, 15 Nov 2021 23:14:40 -0600 Subject: [PATCH 07/14] this file was for testing - should never have been committed --- src/art/art_test_static_model.cpp | 469 ------------------------------ 1 file changed, 469 deletions(-) delete mode 100644 src/art/art_test_static_model.cpp diff --git a/src/art/art_test_static_model.cpp b/src/art/art_test_static_model.cpp deleted file mode 100644 index f91a1ffe2d0..00000000000 --- a/src/art/art_test_static_model.cpp +++ /dev/null @@ -1,469 +0,0 @@ -// -// This source file is part of appleseed. -// Visit https://appleseedhq.net/ for additional information and resources. -// -// This software is released under the MIT license. -// -// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited -// Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#include "common.h" -/* avoid redefining the appleseed sleep function */ -#undef sleep - -#include -#include -#include -#include - -#include -#include -#include - -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic push -#endif -#if defined(__clang__) -# pragma clang diagnostic push -#endif -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic ignored "-Wfloat-equal" -# pragma GCC diagnostic ignored "-Wunused-parameter" -# pragma GCC diagnostic ignored "-Wpedantic" -# pragma GCC diagnostic ignored "-Wignored-qualifiers" -# if (__GNUC__ >= 8) -# pragma GCC diagnostic ignored "-Wclass-memaccess" -# endif -#endif -#if defined(__clang__) -# pragma clang diagnostic ignored "-Wfloat-equal" -# pragma clang diagnostic ignored "-Wunused-parameter" -# pragma clang diagnostic ignored "-Wpedantic" -# pragma clang diagnostic ignored "-Wignored-qualifiers" -#endif - - -// appleseed.renderer headers. Only include header files from renderer/api/. -#include "renderer/api/bsdf.h" -#include "renderer/api/camera.h" -#include "renderer/api/color.h" -#include "renderer/api/environment.h" -#include "renderer/api/environmentedf.h" -#include "renderer/api/environmentshader.h" -#include "renderer/api/frame.h" -#include "renderer/api/light.h" -#include "renderer/api/log.h" -#include "renderer/api/material.h" -#include "renderer/api/object.h" -#include "renderer/api/project.h" -#include "renderer/api/rendering.h" -#include "renderer/api/scene.h" -#include "renderer/api/surfaceshader.h" -#include "renderer/api/utility.h" -#include "renderer/api/shadergroup.h" - -// appleseed.foundation headers. -#include "foundation/core/appleseed.h" -#include "foundation/math/matrix.h" -#include "foundation/math/scalar.h" -#include "foundation/math/transform.h" -#include "foundation/math/vector.h" -#include "foundation/utility/containers/dictionary.h" -#include "foundation/utility/log/consolelogtarget.h" -#include "foundation/utility/autoreleaseptr.h" -#include "foundation/utility/searchpaths.h" - -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic pop -#endif -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - - -#include "vmath.h" /* vector math macros */ -#include "raytrace.h" /* librt interface definitions */ -#include "bu/app.h" -#include "bu/getopt.h" -#include "bu/vls.h" -#include "art.h" - -struct application APP; -struct resource* resources; -extern "C" { - FILE* outfp = NULL; - int save_overlaps = 1; - size_t n_malloc; /* Totals at last check */ - size_t n_free; - size_t n_realloc; - mat_t view2model; - mat_t model2view; - struct icv_image* bif = NULL; -} - -/* NOTE: stub in empty rt_do_tab to satisfy ../rt/opt.c - this means - * we can't run the commands, but they are tied deeply into the various - * src/rt files and a significant refactor is in order to properly - * extract that functionality into a library... */ - -extern "C" { - struct command_tab rt_do_tab[] = { {NULL, NULL, NULL, 0, 0, 0} }; - void usage(const char* argv0, int verbose); - int get_args(int argc, const char* argv[]); - - extern char* outputfile; - extern int objc; - extern char** objv; - extern size_t npsw; - extern struct bu_ptbl* cmd_objs; - extern size_t width, height; - extern fastf_t azimuth, elevation; - extern point_t eye_model; /* model-space location of eye */ - extern fastf_t eye_backoff; /* dist from eye to center */ - extern mat_t Viewrotscale; - extern fastf_t viewsize; - extern fastf_t aspect; - - void grid_setup(); -} - -// Define shorter namespaces for convenience. -namespace asf = foundation; -namespace asr = renderer; - -asf::auto_release_ptr build_project() -{ - // Create an empty project. - asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); - project->search_paths().push_back_explicit_path("data"); - - // ***** add path for shaders - // the first two paths are for appleseed precomiled .oso shaders - // todo: make this dynamic to the project - project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/appleseed"); - project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/max"); - project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/src/appleseed"); - - - // Add default configurations to the project. - project->add_default_configurations(); - - // Set the number of samples. This is the main quality parameter: the higher the - // number of samples, the smoother the image but the longer the rendering time. - project->configurations() - .get_by_name("final")->get_parameters() - .insert_path("uniform_pixel_renderer.samples", "25"); - - // Create a scene. - asf::auto_release_ptr scene(asr::SceneFactory::create()); - - // Create an assembly. - asf::auto_release_ptr assembly( - asr::AssemblyFactory().create( - "assembly", - asr::ParamArray())); - - //------------------------------------------------------------------------ - // Materials - //------------------------------------------------------------------------ - - // Create a color called "gray" and insert it into the assembly. - // static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; - // assembly->colors().insert( - // asr::ColorEntityFactory::create( - // "gray", - // asr::ParamArray() - // .insert("color_space", "srgb"), - // asr::ColorValueArray(3, GrayReflectance))); - - // Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. - // assembly->bsdfs().insert( - // asr::LambertianBRDFFactory().create( - // "diffuse_gray_brdf", - // asr::ParamArray() - // .insert("reflectance", "gray"))); - - // create a shader group - asf::auto_release_ptr shader_grp( - asr::ShaderGroupFactory().create( - "Material_tree", - asr::ParamArray())); - - // THIS IS OUR INPUT SHADER - add to shader group - /* This uses an already created appleseed .oso shader - in the form of - type - shader name - layer - paramArray - */ - shader_grp->add_shader( - "shader", - "as_toon", - "OSL_in", - asr::ParamArray() - ); - - /* import generic .osl shader - in the form of - type - name - layer - source - paramArray - */ - // shader_grp->add_source_shader( - // "shader", - // "toon", - // "OSL_in", - // "as_toon", - // asr::ParamArray() - // ); - - // add material2surface so we can see the shader in action - shader_grp->add_shader( - "surface", - "as_closure2surface", - "close", - asr::ParamArray() - ); - - // connect the two shader nodes - shader_grp->add_connection( - "OSL_in", - "out_outColor", - "close", - "in_input" - ); - - // add the shader group to the assembly - assembly->shader_groups().insert( - shader_grp - ); - - // Create a physical surface shader and insert it into the assembly. - assembly->surface_shaders().insert( - asr::PhysicalSurfaceShaderFactory().create( - "Material_mat_surface_shader", - asr::ParamArray() - .insert("lighting_samples", "1"))); - - // Create a material called "gray_material" and insert it into the assembly. - assembly->materials().insert( - asr::OSLMaterialFactory().create( - "Material_mat", - asr::ParamArray() - .insert("osl_surface", "Material_tree"))); - - //------------------------------------------------------------------------ - // Geometry - //------------------------------------------------------------------------ - - // Load the scene geometry from disk. - asr::MeshObjectArray objects; - asr::MeshObjectReader::read( - project->search_paths(), - "cube", - asr::ParamArray() - .insert("filename", "scene.obj"), - objects); - - // Insert all the objects into the assembly. - for (size_t i = 0; i < objects.size(); ++i) - { - // Insert this object into the scene. - asr::MeshObject* object = objects[i]; - assembly->objects().insert(asf::auto_release_ptr(object)); - - // Create an instance of this object and insert it into the assembly. - const std::string instance_name = std::string(object->get_name()) + "_inst"; - assembly->object_instances().insert( - asr::ObjectInstanceFactory::create( - instance_name.c_str(), - asr::ParamArray(), - object->get_name(), - asf::Transformd::identity(), - asf::StringDictionary() - .insert("default", "Material_mat") - .insert("default2", "Material_mat") - )); - } - - //------------------------------------------------------------------------ - // Light - //------------------------------------------------------------------------ - - // Create a color called "light_intensity" and insert it into the assembly. - static const float LightRadiance[] = { 1.0f, 1.0f, 1.0f }; - assembly->colors().insert( - asr::ColorEntityFactory::create( - "light_intensity", - asr::ParamArray() - .insert("color_space", "srgb") - .insert("multiplier", "30.0"), - asr::ColorValueArray(3, LightRadiance))); - - // Create a point light called "light" and insert it into the assembly. - asf::auto_release_ptr light( - asr::PointLightFactory().create( - "light", - asr::ParamArray() - .insert("intensity", "light_intensity"))); - light->set_transform( - asf::Transformd::from_local_to_parent( - asf::Matrix4d::make_translation(asf::Vector3d(0.6, 2.0, 1.0)))); - assembly->lights().insert(light); - - //------------------------------------------------------------------------ - // Assembly instance - //------------------------------------------------------------------------ - - // Create an instance of the assembly and insert it into the scene. - asf::auto_release_ptr assembly_instance( - asr::AssemblyInstanceFactory::create( - "assembly_inst", - asr::ParamArray(), - "assembly")); - assembly_instance - ->transform_sequence() - .set_transform( - 0.0f, - asf::Transformd::identity()); - scene->assembly_instances().insert(assembly_instance); - - // Insert the assembly into the scene. - scene->assemblies().insert(assembly); - - //------------------------------------------------------------------------ - // Environment - //------------------------------------------------------------------------ - - // Create a color called "sky_radiance" and insert it into the scene. - // static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; - // scene->colors().insert( - // asr::ColorEntityFactory::create( - // "sky_radiance", - // asr::ParamArray() - // .insert("color_space", "srgb") - // .insert("multiplier", "0.5"), - // asr::ColorValueArray(3, SkyRadiance))); - - // Create an environment EDF called "sky_edf" and insert it into the scene. - // scene->environment_edfs().insert( - // asr::ConstantEnvironmentEDFFactory().create( - // "sky_edf", - // asr::ParamArray() - // .insert("radiance", "sky_radiance"))); - - // Create an environment shader called "sky_shader" and insert it into the scene. - // scene->environment_shaders().insert( - // asr::EDFEnvironmentShaderFactory().create( - // "sky_shader", - // asr::ParamArray() - // .insert("environment_edf", "sky_edf"))); - - // Create an environment called "sky" and bind it to the scene. - // updated: created a generic env with no parameters (ie no background color on render) - // todo: update the above commented out code to import environment background color - scene->set_environment( - asr::EnvironmentFactory::create( - "environment", - asr::ParamArray())); - - //------------------------------------------------------------------------ - // Camera - //------------------------------------------------------------------------ - - // Create a pinhole camera with film dimensions 0.980 x 0.735 in (24.892 x 18.669 mm). - asf::auto_release_ptr camera( - asr::PinholeCameraFactory().create( - "camera", - asr::ParamArray() - .insert("film_dimensions", "0.024892 0.018669") - .insert("focal_length", "0.035"))); - - // Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0) - // and are looking toward Z- (0.0, 0.0, -1.0). - camera->transform_sequence().set_transform( - 0.0f, - asf::Transformd::from_local_to_parent( - asf::Matrix4d::make_rotation(asf::Vector3d(1.0, 0.0, 0.0), asf::deg_to_rad(-20.0)) * - asf::Matrix4d::make_translation(asf::Vector3d(0.0, 0.8, 11.0)))); - - // Bind the camera to the scene. - scene->cameras().insert(camera); - - //------------------------------------------------------------------------ - // Frame - //------------------------------------------------------------------------ - - // Create a frame and bind it to the project. - project->set_frame( - asr::FrameFactory::create( - "beauty", - asr::ParamArray() - .insert("camera", "camera") - .insert("resolution", "640 480"))); - - // Bind the scene to the project. - project->set_scene(scene); - - return project; -} - -int main() -{ - // Create a log target that outputs to stderr, and binds it to the renderer's global logger. - // Eventually you will probably want to redirect log messages to your own target. For this - // you will need to implement foundation::ILogTarget (foundation/log/ilogtarget.h). - std::unique_ptr log_target(asf::create_console_log_target(stderr)); - asr::global_logger().add_target(log_target.get()); - - // Print appleseed's version string. - RENDERER_LOG_INFO("%s", asf::Appleseed::get_synthetic_version_string()); - - // Build the project. - asf::auto_release_ptr project(build_project()); - - // Create the master renderer. - asr::DefaultRendererController renderer_controller; - asf::SearchPaths resource_search_paths; - std::unique_ptr renderer( - new asr::MasterRenderer( - project.ref(), - project->configurations().get_by_name("final")->get_inherited_parameters(), - resource_search_paths)); - - // Render the frame. - renderer->render(renderer_controller); - - // Save the frame to disk. - project->get_frame()->write_main_image("output/test.png"); - - // Save the project to disk. - asr::ProjectFileWriter::write(project.ref(), "output/test.appleseed"); - - // Make sure to delete the master renderer before the project and the logger / log target. - renderer.reset(); - - return 0; -} From 12fa27e47b32cfe6f2712c0ce72dffc282d5abee Mon Sep 17 00:00:00 2001 From: f4alt Date: Mon, 15 Nov 2021 23:23:07 -0600 Subject: [PATCH 08/14] comment cleanup --- src/art/brlcadplugin.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/art/brlcadplugin.cpp b/src/art/brlcadplugin.cpp index e6143f2f67c..0b4e571e503 100644 --- a/src/art/brlcadplugin.cpp +++ b/src/art/brlcadplugin.cpp @@ -191,12 +191,9 @@ BrlcadObject::BrlcadObject( { configure_raytrace_application(get_database().c_str(), get_object_count(), get_objects()); VSET(min, m_params.get_required("minX"), m_params.get_required("minY"), m_params.get_required("minZ")); + VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); // VMOVE(min, ap->a_uvec); // VMOVE(max, ap->a_vvec); - VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); - - // fprintf(output, "constructor built here \n"); - // fflush(output); } @@ -212,9 +209,6 @@ BrlcadObject:: BrlcadObject( this->resources = p_resources; VMOVE(this->min, ap->a_uvec); VMOVE(this->max, ap->a_vvec); - - // fprintf(output, "other constructor built here \n"); - // fflush(output); } @@ -222,8 +216,6 @@ BrlcadObject:: BrlcadObject( void BrlcadObject::release() { - // bu_free(resources, "appleseed"); - //bu_free(ap, "appleseed"); delete this; } @@ -347,7 +339,7 @@ BrlcadObject::intersect(const asr::ShadingRay& ray) const // Compute a front point, a back point and the geometric normal in object // instance space for a given ray with origin being a point on the surface -void +void BrlcadObject::refine_and_offset( const asf::Ray3d& obj_inst_ray, asf::Vector3d& obj_inst_front_point, From f6608a3bc46e1b73fb62fdb0d4d9b2aa2b9a258a Mon Sep 17 00:00:00 2001 From: f4alt Date: Mon, 15 Nov 2021 23:24:45 -0600 Subject: [PATCH 09/14] Revert "comment cleanup" This reverts commit 12fa27e47b32cfe6f2712c0ce72dffc282d5abee. --- src/art/brlcadplugin.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/art/brlcadplugin.cpp b/src/art/brlcadplugin.cpp index 0b4e571e503..e6143f2f67c 100644 --- a/src/art/brlcadplugin.cpp +++ b/src/art/brlcadplugin.cpp @@ -191,9 +191,12 @@ BrlcadObject::BrlcadObject( { configure_raytrace_application(get_database().c_str(), get_object_count(), get_objects()); VSET(min, m_params.get_required("minX"), m_params.get_required("minY"), m_params.get_required("minZ")); - VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); // VMOVE(min, ap->a_uvec); // VMOVE(max, ap->a_vvec); + VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); + + // fprintf(output, "constructor built here \n"); + // fflush(output); } @@ -209,6 +212,9 @@ BrlcadObject:: BrlcadObject( this->resources = p_resources; VMOVE(this->min, ap->a_uvec); VMOVE(this->max, ap->a_vvec); + + // fprintf(output, "other constructor built here \n"); + // fflush(output); } @@ -216,6 +222,8 @@ BrlcadObject:: BrlcadObject( void BrlcadObject::release() { + // bu_free(resources, "appleseed"); + //bu_free(ap, "appleseed"); delete this; } @@ -339,7 +347,7 @@ BrlcadObject::intersect(const asr::ShadingRay& ray) const // Compute a front point, a back point and the geometric normal in object // instance space for a given ray with origin being a point on the surface -void +void BrlcadObject::refine_and_offset( const asf::Ray3d& obj_inst_ray, asf::Vector3d& obj_inst_front_point, From e1c789c90eda71bd8704acb64c5eac702b8403f2 Mon Sep 17 00:00:00 2001 From: f4alt Date: Tue, 16 Nov 2021 00:00:52 -0600 Subject: [PATCH 10/14] comment and spacing cleanup. Added use comments --- src/art/art.cpp | 455 ++++++++++++--------------------------- src/art/brlcadplugin.cpp | 10 +- 2 files changed, 135 insertions(+), 330 deletions(-) diff --git a/src/art/art.cpp b/src/art/art.cpp index 9faa4a52ac2..9b5650baab0 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -147,11 +147,6 @@ #include "ged/commands.h" #include "ged/defines.h" -struct name_color { - char* name; - char* color; -}; - struct application APP; struct resource* resources; extern "C" { @@ -200,49 +195,42 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), const struct rt_comb_internal* combp __attribute__((unused)), void* data) { - + // We open the db using the region path to get objects name struct directory* dp = DB_FULL_PATH_CUR_DIR(pathp); - struct ged* ged; - ged = ged_open("db", APP.a_rt_i->rti_dbip->dbi_filename, 1); - - // struct application local_app = APP; // struct copy - // struct rt_i* rtip = rt_new_rti(APP.a_rt_i->rti_dbip); char* name; name = dp->d_namep; - const char* name_char; - std::string name_test = "all.g/" + std::string(name); - name_char = name_test.c_str(); - // - // bu_log("name: %s\n", name_test.c_str()); - - // char title[1024]; - // rtip = rt_dirbuild(APP.a_rt_i->rti_dbip->dbi_filename, title, sizeof(title)); - // rt_gettree(rtip, name); - - // local_app.a_rt_i = rtip; - // rt_prep(rtip); + /* + this is for testing bounding box with the parent directory - using build/share/db/moss.g + eventually all comments using this will be deleted + */ + // const char* name_char; + // std::string name_test = "all.g/" + std::string(name); + // name_char = name_test.c_str(); + // bu_log("name: %s\n", APP.a_rt_i->rti_dbip->dbi_filename); + // get objects bounding box + struct ged* ged; + ged = ged_open("db", APP.a_rt_i->rti_dbip->dbi_filename, 1); point_t min; point_t max; - // int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); - int ret = ged_get_obj_bounds(ged, 1, (const char**)&name_char, 1, min, max); - // int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); + int ret = ged_get_obj_bounds(ged, 1, (const char**)&name, 1, min, max); + // int ret = ged_get_obj_bounds(ged, 1, (const char**)&name_char, 1, min, max); bu_log("ged: %i | min: %f %f %f | max: %f %f %f\n", ret, V3ARGS(min), V3ARGS(max)); - // struct bu_vls v = BU_VLS_INIT_ZERO; - // bu_vls_sprintf() - // std::string min = bu_vls_cstr(V3ARGS(min)); - VMOVE(APP.a_uvec, min); VMOVE(APP.a_vvec, max); + /* + create object paramArray to pass to constructor + note: we can likely remove min/max values from here if the above bounding box calculation works + */ renderer::ParamArray geometry_parameters = asr::ParamArray() - // .insert("database_path", name) - .insert("database_path", name_char) + .insert("database_path", name) + // .insert("database_path", name_char) .insert("object_count", objc) .insert("minX", min[0]) .insert("minY", min[1]) @@ -252,122 +240,114 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), .insert("maxZ", max[2]); - // name = "/all.g/" + name; - // char* name_test = "/all.g/" + name; - - asf::auto_release_ptr brlcad_object( new BrlcadObject{ name, - // name_test.c_str(), // name_char, - // new BrlcadObject{"brlcad_object", geometry_parameters, &APP, resources}); + // typecast our scene using the callback function 'data' asr::Scene* scene = static_cast(data); - // asf::auto_release_ptr assembly = static_cast>(data); + // create assembly for current object std::string assembly_name = std::string(name) + "_object_assembly"; // std::string assembly_name = std::string(name_test) + "_object_assembly"; asf::auto_release_ptr assembly( -asr::AssemblyFactory().create( - assembly_name.c_str(), - asr::ParamArray())); - - // create a shader group called "Material_tree" - std::string shader_name = std::string(name) + "_shader"; - // std::string shader_name = std::string(name_test) + "_shader"; - asf::auto_release_ptr shader_grp( - asr::ShaderGroupFactory().create( - shader_name.c_str(), - asr::ParamArray())); - - // THIS IS OUR INPUT SHADER - add to shader group - /* This uses an already created appleseed .oso shader - in the form of - type - shader name - layer - paramArray - */ - struct bu_vls v=BU_VLS_INIT_ZERO; - bu_vls_printf(&v, "color %f %f %f", combp->rgb[0]/255.0, combp->rgb[1]/255.0, combp->rgb[2]/255.0); - const char* color = bu_vls_cstr(&v); - shader_grp->add_shader( - "shader", - "as_disney_material", - "shader_in", - asr::ParamArray() - .insert("in_color", color) - ); - bu_vls_free(&v); - - /* import generic .osl shader - in the form of - type - name - layer - source - paramArray - */ - // shader_grp->add_source_shader( - // "shader", - // "toon", - // "shader_in", - // "as_toon", - // asr::ParamArray() - // ); - - // add material2surface so we can see the shader in action - shader_grp->add_shader( - "surface", - "as_closure2surface", - "close", - asr::ParamArray() - ); - - // connect the two shader nodes - shader_grp->add_connection( + asr::AssemblyFactory().create( + assembly_name.c_str(), + asr::ParamArray())); + + // create a shader group + std::string shader_name = std::string(name) + "_shader"; + // std::string shader_name = std::string(name_test) + "_shader"; + asf::auto_release_ptr shader_grp( + asr::ShaderGroupFactory().create( + shader_name.c_str(), + asr::ParamArray())); + + // THIS IS OUR INPUT SHADER - add to shader group + /* This uses an already created appleseed .oso shader + in the form of + type + shader name + layer + paramArray + */ + struct bu_vls v=BU_VLS_INIT_ZERO; + bu_vls_printf(&v, "color %f %f %f", combp->rgb[0]/255.0, combp->rgb[1]/255.0, combp->rgb[2]/255.0); + const char* color = bu_vls_cstr(&v); + shader_grp->add_shader( + "shader", + "as_disney_material", "shader_in", - "out_outColor", - "close", - "in_input" - ); - - // add the shader group to the assembly - assembly->shader_groups().insert( - shader_grp - ); - - // Create a physical surface shader and insert it into the assembly. - assembly->surface_shaders().insert( - asr::PhysicalSurfaceShaderFactory().create( - "Material_mat_surface_shader", asr::ParamArray() - .insert("lighting_samples", "1"))); - - // Create a material called "gray_material" and insert it into the assembly. - // assembly->materials().insert( - // asr::GenericMaterialFactory().create( - // "gray_material", - // asr::ParamArray() - // .insert("surface_shader", "physical_surface_shader") - // .insert("bsdf", "diffuse_gray_brdf"))); - - // create a material called "Material_mat" with our shader_group - std::string material_mat = shader_name + "_mat"; - assembly->materials().insert( - asr::OSLMaterialFactory().create( - material_mat.c_str(), - asr::ParamArray() - .insert("osl_surface", shader_name.c_str()) - .insert("surface_shader", "Material_mat_surface_shader") - )); - + .insert("in_color", color) + ); + bu_vls_free(&v); + + /* import non compiled .osl shader in the form of + type + name + layer + source + paramArray + note: this relies on appleseed triggering on osl compiler + */ + // shader_grp->add_source_shader( + // "shader", + // shader_name.c_str(), + // "shader_in", + // "shader_in", + // asr::ParamArray() + // ); + // add material2surface so we can map input shader to object surface + shader_grp->add_shader( + "surface", + "as_closure2surface", + "close", + asr::ParamArray() + ); + + // connect the two shader nodes within the group + shader_grp->add_connection( + "shader_in", + "out_outColor", + "close", + "in_input" + ); + + // add the shader group to the assembly + assembly->shader_groups().insert( + shader_grp + ); + + // Create a physical surface shader and insert it into the assembly. + // This is technically not needed with the current shader implementation + assembly->surface_shaders().insert( + asr::PhysicalSurfaceShaderFactory().create( + "Material_mat_surface_shader", + asr::ParamArray() + .insert("lighting_samples", "1") + ) + ); + + // create a material with our shader_group + std::string material_mat = shader_name + "_mat"; + assembly->materials().insert( + asr::OSLMaterialFactory().create( + material_mat.c_str(), + asr::ParamArray() + .insert("osl_surface", shader_name.c_str()) + .insert("surface_shader", "Material_mat_surface_shader") + ) + ); + + // insert object into object array in assembly assembly->objects().insert(brlcad_object); + // create an instance for our newly created object within the assembly const std::string instance_name = std::string(assembly_name) + "_brlcad_inst"; assembly->object_instances().insert( asr::ObjectInstanceFactory::create( @@ -375,63 +355,31 @@ asr::AssemblyFactory().create( asr::ParamArray(), name, // name_char, - // name_test.c_str(), - // "brlcad_object", asf::Transformd::identity(), asf::StringDictionary() .insert("default", material_mat.c_str()) .insert("default2", material_mat.c_str()) )); - // Create a color called "light_intensity" and insert it into the assembly. -// static const float LightRadiance[] = { 1.0f, 1.0f, 1.0f }; -// assembly->colors().insert( -// asr::ColorEntityFactory::create( -// "light_intensity", -// asr::ParamArray() -// .insert("color_space", "srgb") -// .insert("multiplier", "30.0"), -// asr::ColorValueArray(3, LightRadiance))); -// -// // Create a point light called "light" and insert it into the assembly. -// asf::auto_release_ptr light( -// asr::PointLightFactory().create( -// "light", -// asr::ParamArray() -// .insert("intensity", "light_intensity"))); -// light->set_transform( -// asf::Transformd::from_local_to_parent( -// asf::Matrix4d::make_translation(asf::Vector3d(0.6, 2.0, 1.0)))); -// assembly->lights().insert(light); - - scene->assemblies().insert(assembly); + // add assembly to assemblies array in scene + scene->assemblies().insert(assembly); - std::string assembly_inst_name = assembly_name + "_inst"; - asf::auto_release_ptr assembly_instance( - asr::AssemblyInstanceFactory::create( - assembly_inst_name.c_str(), - asr::ParamArray(), - assembly_name.c_str() - )); - assembly_instance - ->transform_sequence() + // finally, we add an instance to use the assembly in the render + std::string assembly_inst_name = assembly_name + "_inst"; + asf::auto_release_ptr assembly_instance( + asr::AssemblyInstanceFactory::create( + assembly_inst_name.c_str(), + asr::ParamArray(), + assembly_name.c_str() + ) + ); + assembly_instance->transform_sequence() .set_transform( - 0.0f, - asf::Transformd::identity()); - scene->assembly_instances().insert(assembly_instance); - - - - - - // char* name; - // name = db_path_to_string(pathp); - // bu_log("region_start %s\n", name); + 0.0f, + asf::Transformd::identity()); + scene->assembly_instances().insert(assembly_instance); - - - - return 0; + return 0; } void @@ -520,8 +468,8 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // Create an empty project. asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); project->search_paths().push_back_explicit_path("build/Debug"); - // ***** add path for shaders - // todo: make this dynamic to the project + // ***** add precompiled shaders path + // TODO: make this dynamic to the project project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/appleseed"); project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/max"); @@ -530,6 +478,7 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // Set the number of samples. This is the main quality parameter: the higher the // number of samples, the smoother the image but the longer the rendering time. + // TODO: create -samples flag on run to update this without recompiling project->configurations() .get_by_name("final")->get_parameters() .insert_path("uniform_pixel_renderer.samples", "25") @@ -553,150 +502,12 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // Materials //------------------------------------------------------------------------ - // Create a color called "gray" and insert it into the assembly. - // static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; - // assembly->colors().insert( - // asr::ColorEntityFactory::create( - // "gray", - // asr::ParamArray() - // .insert("color_space", "srgb"), - // asr::ColorValueArray(3, GrayReflectance))); - - // Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. - // assembly->bsdfs().insert( - // asr::LambertianBRDFFactory().create( - // "diffuse_gray_brdf", - // asr::ParamArray() - // .insert("reflectance", "gray"))); - - // create a shader group called "Material_tree" - // asf::auto_release_ptr shader_grp( - // asr::ShaderGroupFactory().create( - // "Material_tree", - // asr::ParamArray())); - // - // // THIS IS OUR INPUT SHADER - add to shader group - // /* This uses an already created appleseed .oso shader - // in the form of - // type - // shader name - // layer - // paramArray - // */ - // shader_grp->add_shader( - // "shader", - // "as_metal", - // "shader_in", - // asr::ParamArray() - // ); - // - // /* import generic .osl shader - // in the form of - // type - // name - // layer - // source - // paramArray - // */ - // // shader_grp->add_source_shader( - // // "shader", - // // "toon", - // // "shader_in", - // // "as_toon", - // // asr::ParamArray() - // // ); - // - // // add material2surface so we can see the shader in action - // shader_grp->add_shader( - // "surface", - // "as_closure2surface", - // "close", - // asr::ParamArray() - // ); - // - // // connect the two shader nodes - // shader_grp->add_connection( - // "shader_in", - // "out_outColor", - // "close", - // "in_input" - // ); - // - // // add the shader group to the assembly - // assembly->shader_groups().insert( - // shader_grp - // ); - // - // // Create a physical surface shader and insert it into the assembly. - // assembly->surface_shaders().insert( - // asr::PhysicalSurfaceShaderFactory().create( - // "Material_mat_surface_shader", - // asr::ParamArray() - // .insert("lighting_samples", "1"))); - // - // // Create a material called "gray_material" and insert it into the assembly. - // // assembly->materials().insert( - // // asr::GenericMaterialFactory().create( - // // "gray_material", - // // asr::ParamArray() - // // .insert("surface_shader", "physical_surface_shader") - // // .insert("bsdf", "diffuse_gray_brdf"))); - // - // // create a material called "Material_mat" with our shader_group - // assembly->materials().insert( - // asr::OSLMaterialFactory().create( - // "Material_mat", - // asr::ParamArray() - // .insert("osl_surface", "Material_tree") - // .insert("surface_shader", "Material_mat_surface_shader") - // )); - - //------------------------------------------------------------------------ - // Geometry - //------------------------------------------------------------------------ - - // Load the brlcad geometry -// renderer::ParamArray geometry_parameters = asr::ParamArray() -// .insert("database_path", file) -// .insert("object_count", objc); -// for (int i = 0; i < objc; i++) -// { -// std::string obj_num = std::string("object.") + std::to_string(i + 1); -// std::string obj_name = std::string(objv[i]); -// geometry_parameters.insert_path(obj_num, obj_name); -// } - + // walk the db to register all regions struct db_tree_state state = rt_initial_tree_state; state.ts_dbip = APP.a_rt_i->rti_dbip; state.ts_resp = resources; - // rt_init_resource(&rt_uniresource, 0, NULL); db_walk_tree(APP.a_rt_i->rti_dbip, objc, (const char**)objv, 1, &state, register_region, NULL, NULL, reinterpret_cast(scene.get())); - // db_walk_tree(APP.a_rt_i->rti_dbip, objc, (const char**)objv, 1, &state, register_region, NULL, NULL, ); - - - - // asf::auto_release_ptr brlcad_object( - // // new BrlcadObject{obj_name.c_str(), - // new BrlcadObject{"brlcad_object", - // geometry_parameters, - // &APP, resources}); - // - // assembly->objects().insert(brlcad_object); - - - // const std::string instance_name = obj_name + "_brlcad_inst"; - // const std::string instance_name = "_brlcad_inst"; - // assembly->object_instances().insert( - // asr::ObjectInstanceFactory::create( - // instance_name.c_str(), - // asr::ParamArray(), - // // obj_name.c_str(), - // "brlcad_object", - // asf::Transformd::identity(), - // asf::StringDictionary() - // .insert("default", "Material_mat") - // .insert("default2", "Material_mat"))); //------------------------------------------------------------------------ // Light @@ -747,10 +558,10 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // Environment //------------------------------------------------------------------------ - // OPTIONAL: this creates a blue background color - // Create a color called "sky_radiance" and insert it into the scene. + // OPTIONAL: this creates a background color // static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; // statically making this 'white' for now so we don't blue wash the image + // Create a color called "sky_radiance" and insert it into the scene. static const float SkyRadiance[] = { 1.0f, 1.0f, 1.0f }; scene->colors().insert( asr::ColorEntityFactory::create( diff --git a/src/art/brlcadplugin.cpp b/src/art/brlcadplugin.cpp index e6143f2f67c..c1d0625ab8c 100644 --- a/src/art/brlcadplugin.cpp +++ b/src/art/brlcadplugin.cpp @@ -191,12 +191,9 @@ BrlcadObject::BrlcadObject( { configure_raytrace_application(get_database().c_str(), get_object_count(), get_objects()); VSET(min, m_params.get_required("minX"), m_params.get_required("minY"), m_params.get_required("minZ")); + VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); // VMOVE(min, ap->a_uvec); // VMOVE(max, ap->a_vvec); - VSET(max, m_params.get_required("maxX"), m_params.get_required("maxY"), m_params.get_required("maxZ")); - - // fprintf(output, "constructor built here \n"); - // fflush(output); } @@ -212,9 +209,6 @@ BrlcadObject:: BrlcadObject( this->resources = p_resources; VMOVE(this->min, ap->a_uvec); VMOVE(this->max, ap->a_vvec); - - // fprintf(output, "other constructor built here \n"); - // fflush(output); } @@ -223,7 +217,7 @@ void BrlcadObject::release() { // bu_free(resources, "appleseed"); - //bu_free(ap, "appleseed"); + // bu_free(ap, "appleseed"); delete this; } From 00f1a64d07d45339d95a5f6857e8cbe33d9e457a Mon Sep 17 00:00:00 2001 From: f4alt Date: Wed, 17 Nov 2021 18:31:39 -0600 Subject: [PATCH 11/14] include usage.cpp and stub minimal tables to support -c set samples=x --- src/art/CMakeLists.txt | 1 + src/art/art.cpp | 59 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/art/CMakeLists.txt b/src/art/CMakeLists.txt index eeba280c7b5..dfde455b2e6 100644 --- a/src/art/CMakeLists.txt +++ b/src/art/CMakeLists.txt @@ -46,6 +46,7 @@ if(Appleseed_FOUND) art.cpp brlcadplugin.cpp ../rt/opt.c + ../rt/usage.cpp ) BRLCAD_ADDEXEC(art "${ART_SRCS}" "${RT_STD_LIBS};${Appleseed_LIBRARIES};${Appleseed_BOOST_SYSTEM_LIB};${Appleseed_OPENIMAGEIO_LIB}" TEST_USESDATA) diff --git a/src/art/art.cpp b/src/art/art.cpp index 9b5650baab0..05038f1d9a3 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -149,6 +149,8 @@ struct application APP; struct resource* resources; +int samples = 0; + extern "C" { FILE* outfp = NULL; int save_overlaps = 1; @@ -166,7 +168,8 @@ extern "C" { * extract that functionality into a library... */ extern "C" { - struct command_tab rt_do_tab[] = { {NULL, NULL, NULL, 0, 0, 0} }; + // struct command_tab rt_do_tab[] = { {NULL, NULL, NULL, 0, 0, 0} }; + void option(const char *cat, const char *opt, const char *des, int verbose); void usage(const char* argv0, int verbose); int get_args(int argc, const char* argv[]); @@ -186,6 +189,56 @@ extern "C" { void grid_setup(); } +struct bu_structparse view_parse[] = { + {"%d", 1, "samples", 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL}, + {"%d", 1, "s", 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL}, + {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL } +}; + +struct bu_structparse set_parse[] = { + {"%d", 1, "samples", bu_byteoffset(samples), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }, + {"%p", 1, "Application-Specific Parameters", bu_byteoffset(view_parse[0]), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }, + {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL } +}; + +int cm_set(const int argc, const char **argv) +{ + struct bu_vls str = BU_VLS_INIT_ZERO; + + if (argc <= 1) { + bu_struct_print("Generic and Application-Specific Parameter Values", + set_parse, (char *)0); + return 0; + } + + bu_vls_from_argv(&str, argc-1, (const char **)argv+1); + if (bu_struct_parse(&str, set_parse, (char *)0, NULL) < 0) { + bu_vls_free(&str); + return -1; + } + bu_vls_free(&str); + return 0; +} + +struct command_tab rt_do_tab[] = { + {"set", "", "show or set parameters", + cm_set, 1, 999}, + {(char *)0, (char *)0, (char *)0, + 0, 0, 0 /* END */} +}; + +void init_options(void) { + /* Set the byte offsets at run time */ + view_parse[ 0].sp_offset = bu_byteoffset(samples); + view_parse[ 1].sp_offset = bu_byteoffset(samples); + + + // for now, just support -c set samples=x and -? + // TODO: update to support most of what rt/usage.cpp has + option("", "-c \"command\"", "Customize behavior (see rtedge manual)", 1); + option("", "-? or -h", "Display help", 1); +} + // Define shorter namespaces for convenience. namespace asf = foundation; namespace asr = renderer; @@ -642,6 +695,10 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons int main(int argc, char **argv) { + + init_options(); + // usage(argv[0], 0); + // Create a log target that outputs to stderr, and binds it to the renderer's global logger. // Eventually you will probably want to redirect log messages to your own target. For this // you will need to implement foundation::ILogTarget (foundation/utility/log/ilogtarget.h). From 15f4283b3c76d5f10670e04f8d5aecc993581dac Mon Sep 17 00:00:00 2001 From: f4alt Date: Thu, 18 Nov 2021 21:01:55 -0600 Subject: [PATCH 12/14] support set command to specify samples when running. Option menu from rt is reformatted to show usable options here --- src/art/art.cpp | 80 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/src/art/art.cpp b/src/art/art.cpp index 05038f1d9a3..f3d301c041d 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -149,7 +149,7 @@ struct application APP; struct resource* resources; -int samples = 0; +size_t samples = 25; extern "C" { FILE* outfp = NULL; @@ -173,6 +173,7 @@ extern "C" { void usage(const char* argv0, int verbose); int get_args(int argc, const char* argv[]); + extern char* outputfile; extern int objc; extern char** objv; @@ -189,18 +190,21 @@ extern "C" { void grid_setup(); } +// holds application specific paramaters struct bu_structparse view_parse[] = { {"%d", 1, "samples", 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL}, {"%d", 1, "s", 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL}, {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL } }; +// holds regular parse variables struct bu_structparse set_parse[] = { - {"%d", 1, "samples", bu_byteoffset(samples), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }, + /* daisy-chain to additional app-specific parameters */ {"%p", 1, "Application-Specific Parameters", bu_byteoffset(view_parse[0]), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }, {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL } }; +// set callback function int cm_set(const int argc, const char **argv) { struct bu_vls str = BU_VLS_INIT_ZERO; @@ -214,8 +218,10 @@ int cm_set(const int argc, const char **argv) bu_vls_from_argv(&str, argc-1, (const char **)argv+1); if (bu_struct_parse(&str, set_parse, (char *)0, NULL) < 0) { bu_vls_free(&str); + bu_log("ERROR HERE"); return -1; } + // bu_log("str: %s", bu_vls_cstr(&str)); bu_vls_free(&str); return 0; } @@ -227,22 +233,66 @@ struct command_tab rt_do_tab[] = { 0, 0, 0 /* END */} }; +/* Initializes module specific options + * NOTE: to have an accurate usage() menu, we overwrite the indexes of all the + * options from rt/usage.cpp which we don't support + */ void init_options(void) { /* Set the byte offsets at run time */ view_parse[ 0].sp_offset = bu_byteoffset(samples); view_parse[ 1].sp_offset = bu_byteoffset(samples); - // for now, just support -c set samples=x and -? - // TODO: update to support most of what rt/usage.cpp has - option("", "-c \"command\"", "Customize behavior (see rtedge manual)", 1); + // for now, just support -c set samples=x + // TODO: update to support more options + option("", "-o filename", "Render to specified image file (e.g., image.png or image.pix)", 0); + option("", "-F framebuffer", "Render to a framebuffer (defaults to a window)", 100); + option("", "-s #", "Square image size (default: 512 - implies 512x512 image)", 100); + option("", "-w # -n #", "Image pixel dimensions as width and height", 100); + // option("", "-C #/#/#", "Set background image color to R/G/B values (default: 0/0/1)", 0); + // option("", "-W", "Set background image color to white", 0); + option("", "-R", "Disable reporting of overlaps", 100); option("", "-? or -h", "Display help", 1); + + option("Raytrace", "-a # -e #", "Azimuth and elevation in degrees (default: -a 35 -e 25)", 100); + option("Raytrace", "-p #", "Perspective angle, degrees side to side (0 <= # < 180)", 100); + option("Raytrace", "-E #", "Set perspective eye distance from model (default: 1.414)", 100); + option("Raytrace", "-H #", "Specify number of hypersample rays per pixel (default: 0)", 100); + option("Raytrace", "-J #", "Specify a \"jitter\" pattern (default: 0 - no jitter)", 100); + option("Raytrace", "-P #", "Specify number of processors to use (default: all available)", 100); + option("Raytrace", "-T # or -T #/#", "Tolerance as distance or distance/angular", 100); + + option("Advanced", "-c \"command\"", "[eventually will] Run a semicolon-separated list of commands (just samples for now)", 0); + option("Advanced", "-M", "Read matrix + commands on stdin (RT 'saveview' scripts)", 100); + option("Advanced", "-D #", "Specify starting frame number (ending is specified via -K #)", 100); + option("Advanced", "-K #", "Specify ending frame number (starting is specified via -D #)", 100); + option("Advanced", "-g #", "Specify grid cell (pixel) width, in millimeters", 100); + option("Advanced", "-G #", "Specify grid cell (pixel) height, in millimeters", 100); + option("Advanced", "-S", "Enable stereo rendering", 100); + option("Advanced", "-U #", "Turn on air region rendering (default: 0 - off)", 100); + option("Advanced", "-V #", "View (pixel) aspect ratio (width/height)", 100); + option("Advanced", "-j xmin,xmax,ymin,ymax", "Only render pixels within the specified sub-rectangle", 100); + option("Advanced", "-k xdir,ydir,zdir,dist", "Specify a cutting plane for the entire render scene", 100); + + option("Developer", "-v [#]", "Specify or increase RT verbosity", 100); + option("Developer", "-X #", "Specify RT debugging flags", 100); + option("Developer", "-x #", "Specify librt debugging flags", 100); + option("Developer", "-N #", "Specify libnmg debugging flags", 100); + option("Developer", "-! #", "Specify libbu debugging flags", 100); + option("Developer", "-, #", "Specify space partitioning algorithm", 100); + option("Developer", "-B", "Disable randomness for \"benchmark\"-style repeatability", 100); + option("Developer", "-b \"x y\"", "Only shoot one ray at pixel coordinates (quotes required)", 100); + option("Developer", "-Q x,y", "Shoot one pixel with debugging; compute others without", 100); } // Define shorter namespaces for convenience. namespace asf = foundation; namespace asr = renderer; +/* db_walk_tree() callback to register all regions within the scene + * using either legacy rgb sets and phong shaders or specified material OSL + * optical shader + */ int register_region(struct db_tree_state* tsp __attribute__((unused)), const struct db_full_path* pathp __attribute__((unused)), const struct rt_comb_internal* combp __attribute__((unused)), @@ -279,7 +329,7 @@ int register_region(struct db_tree_state* tsp __attribute__((unused)), /* create object paramArray to pass to constructor - note: we can likely remove min/max values from here if the above bounding box calculation works + NOTE: we can likely remove min/max values from here if the above bounding box calculation works */ renderer::ParamArray geometry_parameters = asr::ParamArray() .insert("database_path", name) @@ -531,10 +581,10 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // Set the number of samples. This is the main quality parameter: the higher the // number of samples, the smoother the image but the longer the rendering time. - // TODO: create -samples flag on run to update this without recompiling + // we overwrite via command line -c "set" project->configurations() .get_by_name("final")->get_parameters() - .insert_path("uniform_pixel_renderer.samples", "25") + .insert_path("uniform_pixel_renderer.samples", samples) .insert_path("rendering_threads", "1"); /* multithreading not supported yet */ project->configurations() @@ -695,10 +745,6 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons int main(int argc, char **argv) { - - init_options(); - // usage(argv[0], 0); - // Create a log target that outputs to stderr, and binds it to the renderer's global logger. // Eventually you will probably want to redirect log messages to your own target. For this // you will need to implement foundation::ILogTarget (foundation/utility/log/ilogtarget.h). @@ -716,20 +762,24 @@ main(int argc, char **argv) bu_setprogname(argv[0]); + // initialize options and overload menu before parsing + init_options(); + /* Process command line options */ int i = get_args(argc, (const char**)argv); if (i < 0) { - //usage(argv[0], 0); + usage(argv[0], 0); return 1; } + // explicitly asking for help else if (i == 0) { - //usage(argv[0], 100); + usage(argv[0], 99); return 0; } if (bu_optind >= argc) { RENDERER_LOG_INFO("%s: BRL-CAD geometry database not specified\n", argv[0]); - //usage(argv[0], 0); + usage(argv[0], 0); return 1; } From 8eeba1aa485c2b3b5c9e483ed400c59bb3e7ed01 Mon Sep 17 00:00:00 2001 From: f4alt Date: Fri, 19 Nov 2021 16:17:40 -0600 Subject: [PATCH 13/14] remove redundant file --- src/art/art.cpp.old | 633 -------------------------------------------- 1 file changed, 633 deletions(-) delete mode 100644 src/art/art.cpp.old diff --git a/src/art/art.cpp.old b/src/art/art.cpp.old deleted file mode 100644 index 8cc86a34d1a..00000000000 --- a/src/art/art.cpp.old +++ /dev/null @@ -1,633 +0,0 @@ -/* A R T . C P P - * BRL-CAD - * - * Copyright (c) 2004-2021 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ -/** @file art/art.cpp - * - * Once you have appleseed installed, run BRL-CAD's CMake with APPLESEED_ROOT - * set to enable this program: - * - * cmake .. -DAPPLESEED_ROOT=/path/to/appleseed -DBRLCAD_PNG=SYSTEM -DBRLCAD_ZLIB=SYSTEM - * - * (the appleseed root path should contain bin, lib and include directories) - * - * On Linux, if using the prebuilt binary you'll need to set LD_LIBRARY_PATH: - * export LD_LIBRARY_PATH=/path/to/appleseed/lib - * - * - * The example scene object used by helloworld is found at: - * https://raw.githubusercontent.com/appleseedhq/appleseed/master/sandbox/examples/cpp/helloworld/data/scene.obj - * - * basic example helloworld code from - * https://github.com/appleseedhq/appleseed/blob/master/sandbox/examples/cpp/helloworld/helloworld.cpp - * has the following license: - * - * This software is released under the MIT license. - * - * Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited - * Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#include "common.h" -/* avoid redefining the appleseed sleep function */ -#undef sleep - -#include -#include -#include -#include - -#include -#include -#include - -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic push -#endif -#if defined(__clang__) -# pragma clang diagnostic push -#endif -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic ignored "-Wfloat-equal" -# pragma GCC diagnostic ignored "-Wunused-parameter" -# pragma GCC diagnostic ignored "-Wpedantic" -# pragma GCC diagnostic ignored "-Wignored-qualifiers" -# if (__GNUC__ >= 8) -# pragma GCC diagnostic ignored "-Wclass-memaccess" -# endif -#endif -#if defined(__clang__) -# pragma clang diagnostic ignored "-Wfloat-equal" -# pragma clang diagnostic ignored "-Wunused-parameter" -# pragma clang diagnostic ignored "-Wpedantic" -# pragma clang diagnostic ignored "-Wignored-qualifiers" -#endif - - -// appleseed.renderer headers. Only include header files from renderer/api/. -#include "renderer/api/bsdf.h" -#include "renderer/api/camera.h" -#include "renderer/api/color.h" -#include "renderer/api/environment.h" -#include "renderer/api/environmentedf.h" -#include "renderer/api/environmentshader.h" -#include "renderer/api/frame.h" -#include "renderer/api/light.h" -#include "renderer/api/log.h" -#include "renderer/api/material.h" -#include "renderer/api/object.h" -#include "renderer/api/project.h" -#include "renderer/api/rendering.h" -#include "renderer/api/scene.h" -#include "renderer/api/surfaceshader.h" -#include "renderer/api/utility.h" - -// appleseed.foundation headers. -#include "foundation/core/appleseed.h" -#include "foundation/math/matrix.h" -#include "foundation/math/scalar.h" -#include "foundation/math/transform.h" -#include "foundation/math/vector.h" -#include "foundation/utility/containers/dictionary.h" -#include "foundation/utility/log/consolelogtarget.h" -#include "foundation/utility/autoreleaseptr.h" -#include "foundation/utility/searchpaths.h" - -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic pop -#endif -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - - -#include "vmath.h" /* vector math macros */ -#include "raytrace.h" /* librt interface definitions */ -#include "bu/app.h" -#include "bu/getopt.h" -#include "bu/vls.h" -#include "art.h" - -struct application APP; -struct resource* resources; -extern "C" { - FILE* outfp = NULL; - int save_overlaps = 1; - size_t n_malloc; /* Totals at last check */ - size_t n_free; - size_t n_realloc; - mat_t view2model; - mat_t model2view; - struct icv_image* bif = NULL; -} - -/* NOTE: stub in empty rt_do_tab to satisfy ../rt/opt.c - this means - * we can't run the commands, but they are tied deeply into the various - * src/rt files and a significant refactor is in order to properly - * extract that functionality into a library... */ - -extern "C" { - struct command_tab rt_do_tab[] = { {NULL, NULL, NULL, 0, 0, 0} }; - void usage(const char* argv0, int verbose); - int get_args(int argc, const char* argv[]); - - extern char* outputfile; - extern int objc; - extern char** objv; - extern size_t npsw; - extern struct bu_ptbl* cmd_objs; - extern size_t width, height; - extern fastf_t azimuth, elevation; - extern point_t eye_model; /* model-space location of eye */ - extern fastf_t eye_backoff; /* dist from eye to center */ - extern mat_t Viewrotscale; - extern fastf_t viewsize; - extern fastf_t aspect; - - void grid_setup(); -} - -void -do_ae(double azim, double elev) -{ - vect_t temp; - vect_t diag; - mat_t toEye; - struct rt_i* rtip = APP.a_rt_i; - - if (rtip == NULL) - return; - - if (rtip->nsolids <= 0) - bu_exit(EXIT_FAILURE, "ERROR: no primitives active\n"); - - if (rtip->nregions <= 0) - bu_exit(EXIT_FAILURE, "ERROR: no regions active\n"); - - if (rtip->mdl_max[X] >= INFINITY) { - bu_log("do_ae: infinite model bounds? setting a unit minimum\n"); - VSETALL(rtip->mdl_min, -1); - } - if (rtip->mdl_max[X] <= -INFINITY) { - bu_log("do_ae: infinite model bounds? setting a unit maximum\n"); - VSETALL(rtip->mdl_max, 1); - } - - /* - * Enlarge the model RPP just slightly, to avoid nasty effects - * with a solid's face being exactly on the edge NOTE: This code - * is duplicated out of librt/tree.c/rt_prep(), and has to appear - * here to enable the viewsize calculation to match the final RPP. - */ - rtip->mdl_min[X] = floor(rtip->mdl_min[X]); - rtip->mdl_min[Y] = floor(rtip->mdl_min[Y]); - rtip->mdl_min[Z] = floor(rtip->mdl_min[Z]); - rtip->mdl_max[X] = ceil(rtip->mdl_max[X]); - rtip->mdl_max[Y] = ceil(rtip->mdl_max[Y]); - rtip->mdl_max[Z] = ceil(rtip->mdl_max[Z]); - - MAT_IDN(Viewrotscale); - bn_mat_angles(Viewrotscale, 270.0 + elev, 0.0, 270.0 - azim); - - /* Look at the center of the model */ - MAT_IDN(toEye); - toEye[MDX] = -((rtip->mdl_max[X] + rtip->mdl_min[X]) / 2.0); - toEye[MDY] = -((rtip->mdl_max[Y] + rtip->mdl_min[Y]) / 2.0); - toEye[MDZ] = -((rtip->mdl_max[Z] + rtip->mdl_min[Z]) / 2.0); - - /* Fit a sphere to the model RPP, diameter is viewsize, unless - * viewsize command used to override. - */ - if (viewsize <= 0) { - VSUB2(diag, rtip->mdl_max, rtip->mdl_min); - viewsize = MAGNITUDE(diag); - if (aspect > 1) { - /* don't clip any of the image when autoscaling */ - viewsize *= aspect; - } - } - - /* sanity check: make sure viewsize still isn't zero in case - * bounding box is empty, otherwise bn_mat_int() will bomb. - */ - if (viewsize < 0 || ZERO(viewsize)) { - viewsize = 2.0; /* arbitrary so Viewrotscale is normal */ - } - - Viewrotscale[15] = 0.5 * viewsize; /* Viewscale */ - bn_mat_mul(model2view, Viewrotscale, toEye); - bn_mat_inv(view2model, model2view); - VSET(temp, 0, 0, eye_backoff); - MAT4X3PNT(eye_model, view2model, temp); -} - -// Define shorter namespaces for convenience. -namespace asf = foundation; -namespace asr = renderer; - -asf::auto_release_ptr build_project(const char* file, const char* UNUSED(objects)) -{ - /* If user gave no sizing info at all, use 512 as default */ - struct bu_vls dimensions = BU_VLS_INIT_ZERO; - if (width <= 0) - width = 512; - if (height <= 0) - height = 512; - - // Create an empty project. - asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); - project->search_paths().push_back_explicit_path("build/Debug"); - - // Add default configurations to the project. - project->add_default_configurations(); - - // Set the number of samples. This is the main quality parameter: the higher the - // number of samples, the smoother the image but the longer the rendering time. - project->configurations() - .get_by_name("final")->get_parameters() - .insert_path("uniform_pixel_renderer.samples", "25") - .insert_path("rendering_threads", "1"); /* multithreading not supported yet */ - - project->configurations() - .get_by_name("interactive")->get_parameters() - .insert_path("rendering_threads", "1"); /* no multithreading - for debug rendering on appleseed */ - - // Create a scene. - asf::auto_release_ptr scene(asr::SceneFactory::create()); - - // Create an assembly. - asf::auto_release_ptr assembly( - asr::AssemblyFactory().create( - "assembly", - asr::ParamArray())); - - //------------------------------------------------------------------------ - // Materials - //------------------------------------------------------------------------ - - // Create a color called "gray" and insert it into the assembly. - static const float GrayReflectance[] = { 0.5f, 0.5f, 0.5f }; - assembly->colors().insert( - asr::ColorEntityFactory::create( - "gray", - asr::ParamArray() - .insert("color_space", "srgb"), - asr::ColorValueArray(3, GrayReflectance))); - - // Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly. - assembly->bsdfs().insert( - asr::LambertianBRDFFactory().create( - "diffuse_gray_brdf", - asr::ParamArray() - .insert("reflectance", "gray"))); - - // Create a physical surface shader and insert it into the assembly. - assembly->surface_shaders().insert( - asr::PhysicalSurfaceShaderFactory().create( - "physical_surface_shader", - asr::ParamArray())); - - // Create a material called "gray_material" and insert it into the assembly. - assembly->materials().insert( - asr::GenericMaterialFactory().create( - "gray_material", - asr::ParamArray() - .insert("surface_shader", "physical_surface_shader") - .insert("bsdf", "diffuse_gray_brdf"))); - - //------------------------------------------------------------------------ - // Geometry - //------------------------------------------------------------------------ - - // Load the brlcad geometry - renderer::ParamArray geometry_parameters = asr::ParamArray() - .insert("database_path", file) - .insert("object_count", objc); - for (int i = 0; i < objc; i++) - { - std::string obj_num = std::string("object.") + std::to_string(i + 1); - std::string obj_name = std::string(objv[i]); - geometry_parameters.insert_path(obj_num, obj_name); - } - - asf::auto_release_ptr brlcad_object( - new BrlcadObject{"brlcad geometry", - geometry_parameters, - &APP, resources}); - assembly->objects().insert(brlcad_object); - - const std::string instance_name = "brlcad_inst"; - assembly->object_instances().insert( - asr::ObjectInstanceFactory::create( - instance_name.c_str(), - asr::ParamArray(), - "brlcad geometry", - asf::Transformd::identity(), - asf::StringDictionary() - .insert("default", "gray_material") - .insert("default2", "gray_material"))); - - - //------------------------------------------------------------------------ - // Light - //------------------------------------------------------------------------ - - // Create a color called "light_intensity" and insert it into the assembly. - static const float LightRadiance[] = { 1.0f, 1.0f, 1.0f }; - assembly->colors().insert( - asr::ColorEntityFactory::create( - "light_intensity", - asr::ParamArray() - .insert("color_space", "srgb") - .insert("multiplier", "30.0"), - asr::ColorValueArray(3, LightRadiance))); - - // Create a point light called "light" and insert it into the assembly. - asf::auto_release_ptr light( - asr::PointLightFactory().create( - "light", - asr::ParamArray() - .insert("intensity", "light_intensity"))); - light->set_transform( - asf::Transformd::from_local_to_parent( - asf::Matrix4d::make_translation(asf::Vector3d(0.6, 2.0, 1.0)))); - assembly->lights().insert(light); - - //------------------------------------------------------------------------ - // Assembly instance - //------------------------------------------------------------------------ - - // Create an instance of the assembly and insert it into the scene. - asf::auto_release_ptr assembly_instance( - asr::AssemblyInstanceFactory::create( - "assembly_inst", - asr::ParamArray(), - "assembly")); - assembly_instance - ->transform_sequence() - .set_transform( - 0.0f, - asf::Transformd::identity()); - scene->assembly_instances().insert(assembly_instance); - - // Insert the assembly into the scene. - scene->assemblies().insert(assembly); - - //------------------------------------------------------------------------ - // Environment - //------------------------------------------------------------------------ - - // Create a color called "sky_radiance" and insert it into the scene. - static const float SkyRadiance[] = { 0.75f, 0.80f, 1.0f }; - scene->colors().insert( - asr::ColorEntityFactory::create( - "sky_radiance", - asr::ParamArray() - .insert("color_space", "srgb") - .insert("multiplier", "0.5"), - asr::ColorValueArray(3, SkyRadiance))); - - // Create an environment EDF called "sky_edf" and insert it into the scene. - scene->environment_edfs().insert( - asr::ConstantEnvironmentEDFFactory().create( - "sky_edf", - asr::ParamArray() - .insert("radiance", "sky_radiance"))); - - // Create an environment shader called "sky_shader" and insert it into the scene. - scene->environment_shaders().insert( - asr::EDFEnvironmentShaderFactory().create( - "sky_shader", - asr::ParamArray() - .insert("environment_edf", "sky_edf"))); - - // Create an environment called "sky" and bind it to the scene. - scene->set_environment( - asr::EnvironmentFactory::create( - "sky", - asr::ParamArray() - .insert("environment_edf", "sky_edf") - .insert("environment_shader", "sky_shader"))); - - //------------------------------------------------------------------------ - // Camera - //------------------------------------------------------------------------ - - // Create a pinhole camera with film dimensions - bu_vls_sprintf(&dimensions, "%f %f", 0.08 * (double) width / height, 0.08); - asf::auto_release_ptr camera( - asr::PinholeCameraFactory().create( - "camera", - asr::ParamArray() - .insert("film_dimensions", bu_vls_cstr(&dimensions)) - .insert("focal_length", "0.035"))); - - // Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0) - // and are looking toward Z- (0.0, 0.0, -1.0). - camera->transform_sequence().set_transform( - 0.0f, - asf::Transformd::from_local_to_parent( - asf::Matrix4d::make_translation(asf::Vector3d(eye_model[0], eye_model[2], -eye_model[1])) * /* camera location */ - asf::Matrix4d::make_rotation(asf::Vector3d(0.0, 1.0, 0.0), asf::deg_to_rad(azimuth - 270)) * /* azimuth */ - asf::Matrix4d::make_rotation(asf::Vector3d(1.0, 0.0, 0.0), asf::deg_to_rad(-elevation)) /* elevation */ - )); - - // Bind the camera to the scene. - scene->cameras().insert(camera); - - //------------------------------------------------------------------------ - // Frame - //------------------------------------------------------------------------ - - // Create a frame and bind it to the project. - bu_vls_sprintf(&dimensions, "%zd %zd", width, height); - project->set_frame( - asr::FrameFactory::create( - "beauty", - asr::ParamArray() - .insert("camera", "camera") - .insert("resolution", bu_vls_cstr(&dimensions)))); - - // Bind the scene to the project. - project->set_scene(scene); - - return project; -} - - -int -main(int argc, char **argv) -{ - // Create a log target that outputs to stderr, and binds it to the renderer's global logger. - // Eventually you will probably want to redirect log messages to your own target. For this - // you will need to implement foundation::ILogTarget (foundation/utility/log/ilogtarget.h). - std::unique_ptr log_target(asf::create_console_log_target(stderr)); - asr::global_logger().add_target(log_target.get()); - - // Print appleseed's version string. - RENDERER_LOG_INFO("%s", asf::Appleseed::get_synthetic_version_string()); - - struct rt_i* rtip; - const char *title_file = NULL; - //const char *title_obj = NULL; /* name of file and first object */ - struct bu_vls str = BU_VLS_INIT_ZERO; - //int objs_free_argv = 0; - - bu_setprogname(argv[0]); - - /* Process command line options */ - int i = get_args(argc, (const char**)argv); - if (i < 0) { - //usage(argv[0], 0); - return 1; - } - else if (i == 0) { - //usage(argv[0], 100); - return 0; - } - - if (bu_optind >= argc) { - RENDERER_LOG_INFO("%s: BRL-CAD geometry database not specified\n", argv[0]); - //usage(argv[0], 0); - return 1; - } - - title_file = argv[bu_optind]; - //title_obj = argv[bu_optind + 1]; - if (!objv) { - objc = argc - bu_optind - 1; - if (objc) { - objv = (char **)&(argv[bu_optind+1]); - } else { - /* No objects in either input file or argv - try getting objs from - * command processing. Initialize the table. */ - BU_GET(cmd_objs, struct bu_ptbl); - bu_ptbl_init(cmd_objs, 8, "initialize cmdobjs table"); - - // log and gracefully exit for now - bu_exit(EXIT_FAILURE, "No Region specified\n"); - } - } else { - //objs_free_argv = 1; - } - - bu_vls_from_argv(&str, objc, (const char**)objv); - - resources = static_cast(bu_calloc(1, sizeof(resource) * MAX_PSW, "appleseed")); - char title[1024] = { 0 }; - - /* load the specified geometry database */ - rtip = rt_dirbuild(title_file, title, sizeof(title)); - if (rtip == RTI_NULL) - { - RENDERER_LOG_INFO("building the database directory for [%s] FAILED\n", title_file); - return -1; - } - - for (int ic = 0; ic < MAX_PSW; ic++) { - rt_init_resource(&resources[ic], ic, rtip); - RT_CK_RESOURCE(&resources[ic]); - } - - /* print optional title */ - if (title[0]) - { - RENDERER_LOG_INFO("database title: %s\n", title); - } - - /* include objects from database */ - if (rt_gettrees(rtip, objc, (const char**)objv, npsw) < 0) - { - RENDERER_LOG_INFO("loading the geometry for [%s...] FAILED\n", objv[0]); - return -1; - } - - /* prepare database for raytracing */ - if (rtip->needprep) - rt_prep_parallel(rtip, 1); - - /* initialize values in application struct */ - RT_APPLICATION_INIT(&APP); - - /* configure raytrace application */ - APP.a_rt_i = rtip; - APP.a_onehit = -1; - APP.a_hit = brlcad_hit; - APP.a_miss = brlcad_miss; - - do_ae(azimuth, elevation); - RENDERER_LOG_INFO("View model: (%f, %f, %f)", eye_model[0], -eye_model[2], eye_model[1]); - - // Build the project. - asf::auto_release_ptr project(build_project(title_file, bu_vls_cstr(&str))); - - // Create the master renderer. - asr::DefaultRendererController renderer_controller; - asf::SearchPaths resource_search_paths; - std::unique_ptr renderer( - new asr::MasterRenderer( - project.ref(), - project->configurations().get_by_name("final")->get_inherited_parameters(), - resource_search_paths)); - - // Render the frame. - renderer->render(renderer_controller); - - // Save the frame to disk. - char *default_out = bu_strdup("art.png"); - outputfile = default_out; - project->get_frame()->write_main_image(outputfile); - bu_free(default_out, "default name"); - - // Save the project to disk. - //asr::ProjectFileWriter::write(project.ref(), "output/objects.appleseed"); - - // Make sure to delete the master renderer before the project and the logger / log target. - renderer.reset(); - - return 0; -} - - -// Local Variables: -// tab-width: 8 -// mode: C++ -// c-basic-offset: 4 -// indent-tabs-mode: t -// c-file-style: "stroustrup" -// End: -// ex: shiftwidth=4 tabstop=8 From 50e5cda410093cd728d4831e1d92103384318350 Mon Sep 17 00:00:00 2001 From: f4alt Date: Fri, 19 Nov 2021 16:19:21 -0600 Subject: [PATCH 14/14] update cmake to set a APPLESEED_ROOT var when successfully compiling with appleseed. We now use this path to add compiled shaders for art --- misc/CMake/FindAppleseed.cmake | 1 + src/art/art.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/misc/CMake/FindAppleseed.cmake b/misc/CMake/FindAppleseed.cmake index ebe8f319f8f..03f89d1665a 100644 --- a/misc/CMake/FindAppleseed.cmake +++ b/misc/CMake/FindAppleseed.cmake @@ -70,6 +70,7 @@ find_package_handle_standard_args (Appleseed DEFAULT_MSG if (Appleseed_FOUND) set (Appleseed_INCLUDE_DIRS ${Appleseed_INCLUDE_DIR}) set (Appleseed_LIBRARIES ${Appleseed_LIBRARY}) + CONFIG_H_APPEND(BRLCAD "#define APPLESEED_ROOT \"${Appleseed_ROOT}\"\n") else () set (Appleseed_INCLUDE_DIRS) set (Appleseed_LIBRARIES) diff --git a/src/art/art.cpp b/src/art/art.cpp index f3d301c041d..76c2f1f024a 100644 --- a/src/art/art.cpp +++ b/src/art/art.cpp @@ -571,10 +571,10 @@ asf::auto_release_ptr build_project(const char* UNUSED(file), cons // Create an empty project. asf::auto_release_ptr project(asr::ProjectFactory::create("test project")); project->search_paths().push_back_explicit_path("build/Debug"); - // ***** add precompiled shaders path - // TODO: make this dynamic to the project - project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/appleseed"); - project->search_paths().push_back_explicit_path("/Users/christopher/Workspace/appleseed/shaders/max"); + // ***** add precompiled shaders from appleseed + char root[MAXPATHLEN]; + project->search_paths().push_back_explicit_path(bu_dir(root, MAXPATHLEN, APPLESEED_ROOT, "shaders/appleseed", NULL)); + project->search_paths().push_back_explicit_path(bu_dir(root, MAXPATHLEN, APPLESEED_ROOT, "shaders/max", NULL)); // Add default configurations to the project. project->add_default_configurations();