From 6df9b6f529e9781981dcfceb81895f13d045f58f Mon Sep 17 00:00:00 2001 From: Sergen Eren Date: Sun, 5 Jan 2020 17:16:21 +0300 Subject: [PATCH] write number of point_lights --- instancer_hda/file_IO.cpp | 1 + source/main.cpp | 157 ++++++++++++++++++++------------------ 2 files changed, 84 insertions(+), 74 deletions(-) diff --git a/instancer_hda/file_IO.cpp b/instancer_hda/file_IO.cpp index 9fa0917..e0d402c 100644 --- a/instancer_hda/file_IO.cpp +++ b/instancer_hda/file_IO.cpp @@ -197,6 +197,7 @@ namespace vpt_instance { file << "light" << std::endl; + file << gdp->getNumPoints() << std::endl; GA_Offset lcl_start, lcl_end, ptoff; for (GA_Iterator lcl_it(gdp->getPointRange()); lcl_it.blockAdvance(lcl_start, lcl_end); ) { diff --git a/source/main.cpp b/source/main.cpp index cd51438..11b943b 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -109,6 +109,7 @@ CUfunction cuTestGeometryKernel; std::vector unique_vdb_files; std::vector instances; std::vector volume_files; +std::vector point_lights; static int num_volumes = 3; // TODO: read number of instances from json file BVH_Builder bvh_builder; @@ -980,94 +981,102 @@ static void read_instance_file(std::string file_name) { std::string num_vdbs; std::getline(stream, num_vdbs); - std::istringstream iss(num_vdbs); - int num_volumes; - iss >> num_volumes; - log("number of vdbs: " + num_volumes, LOG); - volume_files.resize(num_volumes); + if (num_vdbs == "light") { + log("instancing lights", LOG); + int num_lights; + + + } + else { - for (int i = 0; i < num_volumes; ++i) { + std::istringstream iss(num_vdbs); + int num_volumes; + iss >> num_volumes; + log("number of vdbs: " + num_volumes, LOG); + volume_files.resize(num_volumes); + + for (int i = 0; i < num_volumes; ++i) { + + std::string vdb_file_name; + std::getline(stream, vdb_file_name); + volume_files.at(i).vdb_file = vdb_file_name; + std::string num_instances; + std::getline(stream, num_instances); + std::istringstream nis(num_instances); + nis >> volume_files.at(i).num_instances; + volume_files.at(i).instances.resize(volume_files.at(i).num_instances); + + for (unsigned int x = 0; x < volume_files.at(i).num_instances; ++x) { + + std::string instance_parameters; + std::getline(stream, instance_parameters); + std::istringstream params(instance_parameters); + double p1, p2, p3, r1, r2, r3, r4, s; + params >> p1 >> p2 >> p3 >> r1 >> r2 >> r3 >> r4 >> s; + volume_files.at(i).instances.at(x).position[0] = p1; + volume_files.at(i).instances.at(x).position[1] = p2; + volume_files.at(i).instances.at(x).position[2] = p3; + + volume_files.at(i).instances.at(x).rotation[0] = r1; + volume_files.at(i).instances.at(x).rotation[1] = r2; + volume_files.at(i).instances.at(x).rotation[2] = r3; + volume_files.at(i).instances.at(x).rotation[3] = r4; + + volume_files.at(i).instances.at(x).scale = s; + } + } - std::string vdb_file_name; - std::getline(stream, vdb_file_name); - volume_files.at(i).vdb_file = vdb_file_name; - std::string num_instances; - std::getline(stream, num_instances); - std::istringstream nis(num_instances); - nis >> volume_files.at(i).num_instances; - volume_files.at(i).instances.resize(volume_files.at(i).num_instances); + stream.close(); - for (unsigned int x = 0; x < volume_files.at(i).num_instances; ++x) { - - std::string instance_parameters; - std::getline(stream, instance_parameters); - std::istringstream params(instance_parameters); - double p1, p2, p3, r1, r2, r3, r4, s; - params >> p1 >> p2 >> p3 >> r1 >> r2 >> r3 >> r4 >> s; - volume_files.at(i).instances.at(x).position[0] = p1; - volume_files.at(i).instances.at(x).position[1] = p2; - volume_files.at(i).instances.at(x).position[2] = p3; - - volume_files.at(i).instances.at(x).rotation[0] = r1; - volume_files.at(i).instances.at(x).rotation[1] = r2; - volume_files.at(i).instances.at(x).rotation[2] = r3; - volume_files.at(i).instances.at(x).rotation[3] = r4; - - volume_files.at(i).instances.at(x).scale = s; - } - } + for (int i = 0; i < volume_files.size(); ++i) { - stream.close(); + unique_vdb_files.push_back(GPU_VDB()); + unique_vdb_files.at(i).loadVDB(volume_files.at(i).vdb_file, "density", "heat", "Cd"); - for (int i = 0; i < volume_files.size(); ++i) { + for (unsigned int x = 0; x < volume_files.at(i).num_instances; ++x) { - unique_vdb_files.push_back(GPU_VDB()); - unique_vdb_files.at(i).loadVDB(volume_files.at(i).vdb_file, "density", "heat", "Cd"); + GPU_VDB new_instance(GPU_VDB(unique_vdb_files.at(i))); - for (unsigned int x = 0; x < volume_files.at(i).num_instances; ++x) { - - GPU_VDB new_instance(GPU_VDB(unique_vdb_files.at(i))); - - mat4 xform = unique_vdb_files.at(i).get_xform(); - - // Set translation vector to 0 if it's coming from houdini - xform.translate(-xform.extract_translate()); - - // Set scale - xform.scale(make_float3(volume_files.at(i).instances.at(x).scale)); - - - // Apply instance rotation + mat4 xform = unique_vdb_files.at(i).get_xform(); - float3 euler = quaternion_to_euler( - volume_files.at(i).instances.at(x).rotation[0], - volume_files.at(i).instances.at(x).rotation[1], - volume_files.at(i).instances.at(x).rotation[2], - volume_files.at(i).instances.at(x).rotation[3]); + // Set translation vector to 0 if it's coming from houdini + xform.translate(-xform.extract_translate()); - mat4 rotation_matrix = quaternion_to_mat4( - volume_files.at(i).instances.at(x).rotation[0], - volume_files.at(i).instances.at(x).rotation[1], - volume_files.at(i).instances.at(x).rotation[2], - volume_files.at(i).instances.at(x).rotation[3]); + // Set scale + xform.scale(make_float3(volume_files.at(i).instances.at(x).scale)); - xform = rotation_matrix * xform; - - // Translate with instance position - xform.translate(make_float3( - volume_files.at(i).instances.at(x).position[0], - volume_files.at(i).instances.at(x).position[1], - volume_files.at(i).instances.at(x).position[2])); - - - new_instance.set_xform(xform); - instances.push_back(new_instance); + // Apply instance rotation + + float3 euler = quaternion_to_euler( + volume_files.at(i).instances.at(x).rotation[0], + volume_files.at(i).instances.at(x).rotation[1], + volume_files.at(i).instances.at(x).rotation[2], + volume_files.at(i).instances.at(x).rotation[3]); + + mat4 rotation_matrix = quaternion_to_mat4( + volume_files.at(i).instances.at(x).rotation[0], + volume_files.at(i).instances.at(x).rotation[1], + volume_files.at(i).instances.at(x).rotation[2], + volume_files.at(i).instances.at(x).rotation[3]); + + xform = rotation_matrix * xform; + // Translate with instance position + + xform.translate(make_float3( + volume_files.at(i).instances.at(x).position[0], + volume_files.at(i).instances.at(x).position[1], + volume_files.at(i).instances.at(x).position[2])); + + + new_instance.set_xform(xform); + instances.push_back(new_instance); + + } } } - } // Process camera movement. @@ -1275,7 +1284,7 @@ int main(const int argc, const char* argv[]) if(!proc_vol.create_volume(proc_box_min, proc_box_max, 1.0f, 0, 0.1f)) return 0; //instances.clear(); - //instances.push_back(proc_vol); + instances.push_back(proc_vol); // Send volume instances to gpu