Jump to content

I am placing a node in viewport using UnigineEditor::ViewportManager::placeNode(), is there any callback function for placeNode()?


photo

Recommended Posts

Posted

Hi team,
I am using Unigine editor 2.19 for windows. I am placing a node in viewport using UnigineEditor::ViewportManager::placeNode() and I want to execute some functionality on the same node once it is placed, so is there any callback function for placeNode() or is there any other way to achieve this?

 

  • 2 weeks later...
Posted

Hi Siddhant,

I'm afraid there is no such functionality available in the Editor API right now.

I will create an internal ticket with new feature request and it will be added in the future versions.

My colleague will post a code that you can use to achieve similar behavior with using only the existing 2.19.x API.

Thank you!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Hi Silent,

Thank you for the clarification and for creating an internal feature request.

I appreciate that. I’ll wait for the sample code from your colleague to see how similar behavior can be achieved using the existing 2.19.x API.

Thanks again for the support.

Posted

Hello Siddhant,

Below is similar code from Editor what we use to get nodes what Editor will place. Note `get_flatten_hierarchy` function has an overloaded version, if you would like to call ViewportManager::placeNodesList

void your_function_which_calls_place_nodes()
{
  NodePtr node = ...;	// You've got it from somewhere
  UnigineEditor::ViewportManager::placeNode(node);

  // It's a vector of nodes what UnigineEditor will place
  Vector<NodePtr> root_nodes = Helpers::topmost_only(Helpers::get_flatten_hierarchy(node));
}


namespace Helpers
{

void run_hierarchy(Vector<NodePtr> &result, const NodePtr &node)
{
	if (!node)
	{
		return;
	}

	result.append(node);

	for (int i = 0, n = node->getNumChildren(); i < n; ++i)
	{
		NodePtr child = node->getChild(i);
		run_hierarchy(result, child);
	}

	if (node->getType() == Node::NODE_REFERENCE)
	{
		NodeReferencePtr reference = static_ptr_cast<NodeReference>(node);
		NodePtr instance = reference->getReference();
		run_hierarchy(result, instance);
	}
}

NodePtr get_node_owner(const NodePtr &node)
{
	NodePtr result = node->getParent();
	if (!result)
	{
		result = node->getPossessor();
	}

	return result;
}

Vector<NodePtr> topmost_only(const Vector<NodePtr> &nodes)
{
	const HashSet<NodePtr> node_set = HashSet<NodePtr>::fromKeys(nodes);

	Vector<NodePtr> topmost; // We want to keep order intact.
	for (const NodePtr &node : nodes)
	{
		if (!node)
		{
			continue;
		}

		bool skip = false;
		NodePtr owner = get_node_owner(node);
		while (owner && !skip)
		{
			skip = node_set.contains(owner);
			owner = get_node_owner(owner);
		}

		if (!skip)
		{
			topmost.append(node);
		}
	}

	return topmost;
}

Vector<NodePtr> get_flatten_hierarchy(const Vector<NodePtr> &nodes)
{
	Vector<NodePtr> result;
	result.reserve(nodes.size());
	for (const auto &n : nodes)
	{
		run_hierarchy(result, n);
	}
	return result;
}

Vector<NodePtr> get_flatten_hierarchy(const NodePtr &node)
{
	Vector<NodePtr> result;
	run_hierarchy(result, node);
	return result;
}

} // namespace Helpers

 

×
×
  • Create New...