Jump to content

Selecting reference node object by intersection


photo

Recommended Posts

Posted

Hello,

I am looking for some guidance on the best way to select a node from the view in Unigine when using reference nodes.
We are trying to modify a world by placing and moving predefined assets.

We are running a C++ Unigine Sim 2.18.1 engine (not the editor),  automatic reference node unpacking disabled.

We have a c++ plugin that is allowing us to select objects in the scene, when an object is selected we are rendering the bounding box or mesh to show the selection.
When the object is part of a reference node, we want to select and visualise the reference node itself (as we want to be able to move it and save the new position to the world)
Basically we want that same sort of functionality provided in the editor (clicking a mesh that is part of a reference node will select the node reference in the nodes tree).

The current code uses a WorldIntersection from the current mouse position and player position and this works fine.
When we get the intersection from a mesh inside a node reference this was giving us the reference target, which we do not want to be interacting with.

Currently the code is checking if the node has a possessor node->getPossessor(), and getting this if so, but this only works if the mesh is the root node of the reference (as documented).

Some of our reference nodes are to a dummy node containing multiple children, and some of those children may also be references.
In these cases what is the best way to get the top level reference node?

Do we need to iterate up the hierarchy and check each parent if it has a possessor to see if we need to get it.
Or just iterate to the root node (given we have unpacking disabled) and check that. 

I am presuming for nested references, each nested reference target will be added at the root as well?

The documentation is not overly clear on what the node tree looks like for nested references, perhaps an example could be added to the diagrams e.g. https://developer.unigine.com/en/docs/2.18.1/api/library/nodes/class.nodereference?rlang=cpp&autotranslate=en#unpacking_disabled

Cheers,
Chris

Posted

Hi Chris,

Quote

Do we need to iterate up the hierarchy and check each parent if it has a possessor to see if we need to get it.
Or just iterate to the root node (given we have unpacking disabled) and check that. 

For your use-case the only valid way is to iterate manually up the hierarchy and check. We have similar code in our Editor as well:

Spoiler
NodePtr findSelectionNode(const NodePtr &node_form_intersection)
{
	NodePtr node = node_form_intersection;
	if (node->isShowInEditorEnabledSelf())
	{
		return node;
	}

	while (node->getParent())
	{
		node = node->getParent();
	}

	if (!node->getPossessor())
	{
		return nullptr;
	}

	NodePtr possessor = std::move(node);
	while (possessor->getPossessor())
	{
		possessor = possessor->getPossessor();
	}

	if (possessor->isShowInEditorEnabledSelf())
	{
		return possessor;
	}
	else
	{
		// select for NodeReference inside another NodeReference
		while (possessor)
		{
			if (possessor->isShowInEditorEnabledSelf())
			{
				return possessor;
			}

			if (possessor->getPossessor())
			{
				possessor = possessor->getPossessor();
			}
			else
			{
				NodePtr parent = possessor->getParent();
				if (!parent)
				{
					break;
				}
				while (parent->getParent())
				{
					parent = parent->getParent();
				}

				possessor = parent->getPossessor();
			}
		}
	}

	return nullptr;
}

 

We will try to make documentation a bit more detailed in this part, thanks for the signal!

  • Thanks 1

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

Posted

Thanks a bunch Silent, 

That is pretty much how I was expecting it to go, but was definitely worth the question.

I had not realised the isShowInEditorEnabledSelf() function was working in the runtime engine as well (given the name I was apprehensive.
That makes it a lot simpler to check if the candidate is not a reference target and hence valid for selection. 

I have taken your snippet and so far looks to be working great!

 

Out of interest is the same logic ok with automatic unpacking enabled as well? (I don't have any immediate plans to enable this, this but curious).

Cheers,
Chris

 

×
×
  • Create New...