Skip to content

Commit

Permalink
v5
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Aug 26, 2019
1 parent 6800f67 commit aea05aa
Show file tree
Hide file tree
Showing 9 changed files with 570 additions and 309 deletions.
1 change: 1 addition & 0 deletions bakeryoptix/bake_ao_optix_prime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ void bake::ao_optix_prime(
{
const auto sample_offset = batch_idx * batch_size;
const auto num_samples = std::min(batch_size, ao_samples.num_samples - sample_offset);
if (num_samples == 0) continue;

// Copy all necessary data to device
const auto buffer_type = use_cuda ? RTP_BUFFER_TYPE_CUDA_LINEAR : RTP_BUFFER_TYPE_HOST;
Expand Down
48 changes: 28 additions & 20 deletions bakeryoptix/bake_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bool Mesh::matches(const std::string& query) const

void Bone::solve(const std::shared_ptr<Node>& root)
{
node = root->find_node(name);
node = root->find_node(Filter({name}));
}

Vec3 skinned_pos(const Vec3& pos, const Vec4& weight, const Vec4& bone_id, const std::vector<Matrix4x4>& bones, const Node* node)
Expand Down Expand Up @@ -224,7 +224,7 @@ void SkinnedMesh::resolve(const Node* node)
for (auto i = 0U; i < bones.size(); i++)
{
auto& b = bones[i];
b.node = node->find_node(b.name);
b.node = node->find_node(Filter({b.name}));
if (b.node)
{
bones_[i] = to_matrix(b.node->matrix * b.tranform).transpose();
Expand All @@ -240,6 +240,8 @@ void SkinnedMesh::resolve(const Node* node)
{
vertices[i] = skinned_pos(vertices_orig[i], weights[i], bone_ids[i], bones_, node);
}

matrix = NodeTransformation::identity();
}

Node::Node(const std::string& name, const NodeTransformation& matrix)
Expand Down Expand Up @@ -273,7 +275,7 @@ std::shared_ptr<Mesh> Node::find_mesh(const std::string& name)
return nullptr;
}

static void find_meshes_inner(Node* node, std::vector<std::shared_ptr<Mesh>>& result, const std::vector<std::string>& names)
static void find_meshes_inner(const Node* node, std::vector<std::shared_ptr<Mesh>>& result, const Filter& names)
{
for (const auto& c : node->children)
{
Expand All @@ -287,7 +289,7 @@ static void find_meshes_inner(Node* node, std::vector<std::shared_ptr<Mesh>>& re
auto m = std::dynamic_pointer_cast<Mesh>(c);
if (m)
{
for (const auto& name : names)
for (const auto& name : names.items)
{
if (m && m->matches(name))
{
Expand All @@ -300,14 +302,14 @@ static void find_meshes_inner(Node* node, std::vector<std::shared_ptr<Mesh>>& re
}
}

std::vector<std::shared_ptr<Mesh>> Node::find_meshes(const std::vector<std::string>& names)
std::vector<std::shared_ptr<Mesh>> Node::find_meshes(const Filter& names) const
{
std::vector<std::shared_ptr<Mesh>> result;
find_meshes_inner(this, result, names);
return result;
}

std::vector<std::shared_ptr<Mesh>> Node::find_any_meshes(const std::vector<std::string>& names)
std::vector<std::shared_ptr<Mesh>> Node::find_any_meshes(const Filter& names) const
{
auto result = find_meshes(names);
for (const auto& n : find_nodes(names))
Expand All @@ -317,7 +319,7 @@ std::vector<std::shared_ptr<Mesh>> Node::find_any_meshes(const std::vector<std::
return result;
}

std::shared_ptr<Node> Node::find_node(const std::string& name) const
/*std::shared_ptr<Node> Node::find_node(const std::string& name) const
{
for (const auto& c : children)
{
Expand All @@ -342,16 +344,16 @@ std::shared_ptr<Node> Node::find_node(const std::string& name) const
}
}
return nullptr;
}
}*/

static void find_nodes_inner(Node* node, std::vector<std::shared_ptr<Node>>& result, const std::vector<std::string>& names)
static void find_nodes_inner(const Node* node, std::vector<std::shared_ptr<Node>>& result, const Filter& names)
{
for (const auto& c : node->children)
{
auto n = std::dynamic_pointer_cast<Node>(c);
if (n)
{
for (const auto& name : names)
for (const auto& name : names.items)
{
if (std_ext::match(name, n->name))
{
Expand All @@ -373,14 +375,14 @@ static void find_nodes_inner(Node* node, std::vector<std::shared_ptr<Node>>& res
}
}

std::vector<std::shared_ptr<Node>> Node::find_nodes(const std::vector<std::string>& names)
std::vector<std::shared_ptr<Node>> Node::find_nodes(const Filter& names) const
{
std::vector<std::shared_ptr<Node>> result;
find_nodes_inner(this, result, names);
return result;
}

bool Node::set_active(const std::vector<std::string>& names, const bool value)
bool Node::set_active(const Filter& names, const bool value) const
{
auto any = false;
for (const auto& n : find_nodes(names))
Expand Down Expand Up @@ -498,7 +500,7 @@ void Animation::init(const std::shared_ptr<Node>& root)
{
for (auto& e : entries)
{
e.node = root->find_node(e.name);
e.node = root->find_node(Filter({e.name}));
}
last_root_ = root.get();
}
Expand Down Expand Up @@ -562,26 +564,32 @@ Scene::Scene(const std::vector<std::shared_ptr<Node>>& nodes)
}
}

void HierarchyNode::align(const std::shared_ptr<Node>& root)
void align_hierarchy(const HierarchyNode* that, const std::shared_ptr<Node>& root, const NodeTransformation& offset)
{
auto target = root->name == name ? root : root->find_node(name);
auto target = root->name == that->name ? root : root->find_node(Filter({that->name}));
if (target)
{
target->matrix_local = target->matrix_local_orig = matrix_local;
for (const auto& c : children)
target->matrix_local = target->matrix_local_orig = that->matrix_local * offset;
for (const auto& c : that->children)
{
c->align(target);
align_hierarchy(c.get(), target, offset);
}
}
else
{
for (const auto& c : children)
const auto offset_c = that->matrix_local * offset;
for (const auto& c : that->children)
{
c->align(root);
align_hierarchy(c.get(), root, offset_c);
}
}
}

void HierarchyNode::align(const std::shared_ptr<Node>& root) const
{
align_hierarchy(this, root, NodeTransformation::identity());
}

void bake::map_ao_to_vertices(
const Scene& scene,
const size_t* num_samples_per_instance,
Expand Down
23 changes: 17 additions & 6 deletions bakeryoptix/bake_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,28 @@ namespace bake
void resolve(const Node* node);
};

struct Filter
{
std::vector<std::string> items;
explicit Filter(std::vector<std::string> items) : items(std::move(items)) { }
};

struct Node : NodeBase
{
Node(const std::string& name, const NodeTransformation& matrix = NodeTransformation::identity());
std::shared_ptr<Mesh> find_mesh(const std::string& name);
std::vector<std::shared_ptr<Mesh>> find_meshes(const std::vector<std::string>& names);
std::vector<std::shared_ptr<Mesh>> find_any_meshes(const std::vector<std::string>& names);
std::shared_ptr<Node> find_node(const std::string& name) const;
std::vector<std::shared_ptr<Node>> find_nodes(const std::vector<std::string>& names);
bool set_active(const std::vector<std::string>& names, const bool value);
std::vector<std::shared_ptr<Mesh>> find_meshes(const Filter& names) const;
std::vector<std::shared_ptr<Mesh>> find_any_meshes(const Filter& names) const;
std::vector<std::shared_ptr<Node>> find_nodes(const Filter& names) const;
bool set_active(const Filter& names, const bool value) const;
void add_child(const std::shared_ptr<NodeBase>& node);

std::shared_ptr<Node> find_node(const Filter& filter) const
{
const auto nodes = find_nodes(filter);
return nodes.empty() ? nullptr : nodes[0];
}

NodeTransformation matrix_local;
NodeTransformation matrix_local_orig;
std::vector<std::shared_ptr<NodeBase>> children;
Expand Down Expand Up @@ -250,7 +261,7 @@ namespace bake
: name(std::move(name)), matrix_local(matrix)
{ }

void align(const std::shared_ptr<bake::Node>& root);
void align(const std::shared_ptr<bake::Node>& root) const;
};

struct AILanePoint
Expand Down
5 changes: 2 additions & 3 deletions bakeryoptix/bake_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ void sample_instance(
{
// Setup access to mesh data
const auto xform_invtrans = xform.inverse().transpose();
assert(ao_samples.num_samples >= mesh->num_triangles*min_samples_per_triangle);
assert(mesh->vertices);
assert(mesh->num_vertices);
assert(ao_samples.num_samples >= mesh->triangles.size()*min_samples_per_triangle);
assert(mesh->vertices.size());
assert(ao_samples.sample_positions);
assert(ao_samples.sample_normals);
assert(ao_samples.sample_infos);
Expand Down
2 changes: 2 additions & 0 deletions bakeryoptix/bakeryoptix.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<ClCompile Include="bake_wrap.cpp" />
<ClCompile Include="utils\alphanum.cpp" />
<ClCompile Include="utils\binary_reader.cpp" />
<ClCompile Include="utils\custom_crash_handler.cpp" />
<ClCompile Include="utils\filesystem.cpp" />
<ClCompile Include="utils\ini_file.cpp" />
<ClCompile Include="utils\load_util.cpp" />
Expand Down Expand Up @@ -445,6 +446,7 @@
<ClInclude Include="eigen\Eigen\src\UmfPackSupport\UmfPackSupport.h" />
<ClInclude Include="utils\alphanum.h" />
<ClInclude Include="utils\binary_reader.h" />
<ClInclude Include="utils\custom_crash_handler.h" />
<ClInclude Include="utils\dbg_output.h" />
<ClInclude Include="utils\filesystem.h" />
<ClInclude Include="utils\half.h" />
Expand Down
6 changes: 6 additions & 0 deletions bakeryoptix/bakeryoptix.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<ClCompile Include="utils\alphanum.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utils\custom_crash_handler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="bake_ao_optix_prime.h">
Expand Down Expand Up @@ -920,6 +923,9 @@
<ClInclude Include="utils\alphanum.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utils\custom_crash_handler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="bake_kernels.cu" />
Expand Down
Loading

0 comments on commit aea05aa

Please sign in to comment.