Skip to content

Commit

Permalink
write number of point_lights
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeneren committed Jan 5, 2020
1 parent 29e6831 commit 6df9b6f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 74 deletions.
1 change: 1 addition & 0 deletions instancer_hda/file_IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); ) {
Expand Down
157 changes: 83 additions & 74 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ CUfunction cuTestGeometryKernel;
std::vector<GPU_VDB> unique_vdb_files;
std::vector<GPU_VDB> instances;
std::vector<vdb_instance> volume_files;
std::vector<point_light> point_lights;

static int num_volumes = 3; // TODO: read number of instances from json file
BVH_Builder bvh_builder;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6df9b6f

Please sign in to comment.