Jump to content

Add node to world at run-time (C++)


photo

Recommended Posts

Hello,

 

I need to create a node (i.e. ObjectMeshStatic) at run-time and want to add it to list of nodes of already loaded world.

 

So far, I've succeeded in creating the ObjectMeshStatic node. But when adding to nodes' list through Unigine::Editor::addNode method, node is not visible (not rendering).

Also, I'm able to get the list of nodes in the current world with the newly created node's entry in the list.

 

Here's the code for adding node dynamically (C++):

bool createNodeRunTime()
{
    Unigine::ObjectMeshStaticPtr pOMS = Unigine::ObjectMeshStatic::create("core/meshes/material_ball.mesh", 1 /*unique=1*/);
    if (!pOMS)
        return false;

    pOMS->setMeshName("core/meshes/material_ball.mesh");    //relative path to data dir.
    pOMS->setMaterial("material_ball", 0);
    pOMS->release();

    Unigine::NodePtr newNode = pOMS->getNode();
    if (!newNode)
        return false;
    Unigine::Editor::get()->addNode(newNode);

    m_vecNodes.append(newNode);    // Unigine::Vector<Unigine::NodePtr>  m_vecNodes;

    Unigine::Console::get()->run("world_save");

    return true;
}

 

after executing world_save command, there's entry in world file as follows:

<node type="ObjectMeshStatic" id="19595027" prefab_id="190089851" name="new_node">
	<mesh_name>core/meshes/material_ball.mesh</mesh_name>
	<surface name="material_ball_mat" material="material_ball"/>
	<transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 1 1 1 1.0</transform>
</node>

When I'm starting the application and loading the same world file through config file, I'm able to see the node (i.e. ObjectMeshStatic) which was added earlier.

 

I want to see the added node immediately in the rendering view.

 

I don't know what and where I'm missing something...

 

Any help greatly appreciated.

Link to comment

Hi Punit,


We've checked your code - it's working fine in our case.

 

Could you please send us a minimal test project from SDK Browser? Also if you can provide some screenshots where you can' see your node - it would be very helpful. Right now we are not completely clear what is the current behavior and expected.

 

Thanks!

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

Link to comment

Hello,

 

I'd implemented it slightly other way....& achieved it.

 

I've called that function (i.e. createNodeRunTime()) from update() of class derived from SystemLogic.

Being a multi-threaded environment, there's use of events. So, as per the samples of SDK browser, it's not possible to have that function called from init() of SystemLogic or WorldLogic derived classes. Creation of nodes at run-time may happen any time throughout the life time of the application.

 

So, my next question is...

"Is it acceptable and optimized way to create run-time nodes in update() method, provided there's a multi-threaded environment for hosting application ?"

Link to comment
×
×
  • Create New...