Skip to content

Commit

Permalink
NodeからParent/Root Node取得 (#258)
Browse files Browse the repository at this point in the history
* node add parent node

* ModelでNodeのparent,root設定を行う

* mesh extractorにassignNodeHier追加

* granularity converterにassign node 追加

* rej削除

* 注釈追加
  • Loading branch information
sevendev authored Aug 7, 2024
1 parent d8fcb65 commit 01dca33
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/plateau/polygon_mesh/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace plateau::polygonMesh {
Node& getRootNodeAt(size_t index);
const Node& getRootNodeAt(size_t index) const;

/// 各ノードのペアレント、ルートを設定します。
void assignNodeHierarchy();

/// 子もメッシュもないノードを削除します。
void eraseEmptyNodes();

Expand Down
12 changes: 12 additions & 0 deletions include/plateau/polygon_mesh/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ namespace plateau::polygonMesh {
Node& getChildAt(unsigned int index);
const Node& getChildAt(unsigned int index) const;

/// Parent Node設定
void setParentNode(Node* node);
const Node& getParentNode() const; //Model.assignNodeHierarchyを呼ぶことで取得可能になります。
const bool hasParentNode() const;

/// Root Node設定
void setRootNode(Node* node);
const Node& getRootNode() const; //Model.assignNodeHierarchyを呼ぶことで取得可能になります。
const bool hasRootNode() const;

/**
* 子のうち、子もなくメッシュもないノードを削除します。再帰的に行われます。
*/
Expand All @@ -76,6 +86,8 @@ namespace plateau::polygonMesh {
private:
std::string name_;
std::vector<Node> child_nodes_;
Node* parent_node_;
Node* root_node_;
std::unique_ptr<Mesh> mesh_;
bool is_primary_; // GranularityConverterでのみ利用します。

Expand Down
1 change: 1 addition & 0 deletions src/granularity_convert/granularity_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace plateau::granularityConvert {
next_dst = converter->convert(next_src);
next_src = &next_dst;
}
next_dst.assignNodeHierarchy();
return next_dst;
}
}
1 change: 1 addition & 0 deletions src/polygon_mesh/mesh_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ namespace {
out_model.addNode(std::move(lod_node));
}
out_model.eraseEmptyNodes();
out_model.assignNodeHierarchy();

// テクスチャを結合します。
if (options.enable_texture_packing) {
Expand Down
17 changes: 17 additions & 0 deletions src/polygon_mesh/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ namespace plateau::polygonMesh {
return meshes;
}

namespace {
void assignNodeHierarchyRecursive(Node* node, Node* root) {
for (int i = 0; i < node->getChildCount(); i++) {
auto& child = node->getChildAt(i);
child.setParentNode(node);
child.setRootNode(root);
assignNodeHierarchyRecursive(&child, root);
}
}
}

void Model::assignNodeHierarchy() {
for (auto& node : root_nodes_) {
assignNodeHierarchyRecursive(&node, &node);
}
}

void Model::reserveRootNodes(size_t reserve_count) {
root_nodes_.reserve(reserve_count);
}
Expand Down
34 changes: 32 additions & 2 deletions src/polygon_mesh/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace plateau::polygonMesh {
mesh_(nullptr),
is_primary_(false),
is_active_(true),
local_transform_(Transform())
local_transform_(Transform()),
parent_node_(nullptr),
root_node_(nullptr)
{
}

Expand All @@ -20,7 +22,7 @@ namespace plateau::polygonMesh {

Node& Node::addChildNode(Node&& node) {
child_nodes_.push_back(std::forward<Node>(node));
return child_nodes_.at(child_nodes_.size()-1);
return child_nodes_.at(child_nodes_.size() - 1);
}

void Node::setChildNodes(std::vector<Node>&& child_nodes) {
Expand All @@ -31,6 +33,34 @@ namespace plateau::polygonMesh {
return child_nodes_.emplace_back(name);
}

void Node::setParentNode(Node* node) {
parent_node_ = node;
}

const Node& Node::getParentNode() const {
if(hasParentNode())
return *parent_node_;
return *this;
}

const bool Node::hasParentNode() const {
return parent_node_ != nullptr;
}

void Node::setRootNode(Node* node) {
root_node_ = node;
}

const Node& Node::getRootNode() const {
if(hasRootNode())
return *root_node_;
return *this;
}

const bool Node::hasRootNode() const {
return root_node_ != nullptr;
}

const std::string& Node::getName() const {
return name_;
}
Expand Down

0 comments on commit 01dca33

Please sign in to comment.