Jump to content

[SOLVED] Understanding and using IG Interface plugin


photo

Recommended Posts

Hi.

For our latest project in our company, we need to make use of DIS protocol and the IG Interface plugin from Unigine.

At the moment, we managed to initialize and stop the plugin without problems. But we are having a few problems trying to understand how to use it correctly.

Here is an example of how we have configured it:

<!-- :::::::::::: ig_config.xml ::::::::::::::::::::::::::: -->
<!-- database and dis_configuration made correctly -->
<entity_types>
  <entity id="100" name="testcube">
    <path>ig/entities/e_test/testcube.node</path> <!-- File contains a node with a cube, correctly defined -->
  </entity>
</entity_types>

 

/////:::::::::::: CPP :::::::::::::::::::::::::::::::::::::

void SomeFunction(){

  IG::ManagerInterface* manager = GetIGManager();

  int id = manager->findEntityType("testcube"); // -> 100
  //auto fileName = manager->getConfigPath(); // -> ig_config.xml

  IG::IEntity* entity = manager->getEntity(id);
  NodePtr entityNode = entity->getNode();
  // -> creates a new, empty node. Shouldn't create a new node with the data
  // from the .node file??

}

void SomeOtherFunction() {

  IG::ManagerInterface* manager = GetIGManager();

  // Existing node in the world
  NodePtr sceneNode = Editor::get()->getNodeByName("testcube");

  IG::Entity* entity = manager->findEntity(sceneNode);
  // -> returns NULL

}

 

The objective we seek is to understand how we can go from the entity definition to the node with the correct data, and vice versa, reach the entity from the node.

We are also trying to figure how to manage several instances of an entity in the scene, and if this is doable through the plugin or if we have to code/create or own manager for this purpose.

(Our testing project is built following the steps of the IG Template: https://developer.unigine.com/en/docs/2.8/ig/?rlang=cpp )

 

All help you can provide will be much appreciated.

Thanks for your time.

 

 

 

 

Link to comment

Hello, Enrique! 

In the config you specify TypeID not EntityID. See also these topics:

 


in these topics you can find a code snippet to create an entity.

 

14 hours ago, enrique.trilles said:

We are also trying to figure how to manage several instances of an entity in the scene, and if this is doable through the plugin or if we have to code/create or own manager for this purpose

in DISConnector you can subscribe to receive packages, but you will have to process most of the data yourself. (by default we process EntityState PDU packages with  AIRCRAFT appearance). 

Link to comment

Hi.

I've been checking the topics you mentioned and made some changes to our code, but still can't manage to createa new entity.

Our code looks something like this:

using namespace KDIS;
using namespace PDU;
using namespace DATA_TYPE;

void onDISrcv(Header* pdu){
  
  if(pdu->GetPDUType() == ENUMS::CreateEntityPDU){

    Create_Entity_PDU* cepdu = static_cast<Create_Entity_PDU*>(pdu);
    IG::ManagerInterface* manager = GetIGManager();
    // manager->getConfigPath(); // -> returns our config.xml file. Everything ok.

    int entityType = 100; // cepdu->GetReceivingEntityID().GetEntityID();
    IG::IEntity* entity = manager->getEntity(entityType);
    NodePtr node = entity->getNode(); // -> empty node
    // <- Set entity and/or node starting location
    // <- Set entity and/or node starting rotation
    // etc...

  }

}

ig_config.xml file:

<entity_types>
  <entity id="100" name="testcube">
    <path>ig/entities/e_test/testcube.node</path>
  </entity>
</entity_types>

 

I'm forcing the entity type value to the same on our config file (100), but I'm still missing something. Also, the call:

int entityType = manager->findEntityType("testcube");

Returns the correct value assigned in the config file (100).

 

Any idea about what am I doing wrong?

Thanks.

Link to comment
int entityid = 0;
int entityType = 100;
IG::IEntity* entity = manager->getEntity(entityid); // unique entity identifier
entity->setType(entityType); // type of entity (aircraft/ship/bicycle)

do not confuse entityid and typeid
 


also you can set DIS-style type ID
for convert DIS type to normal IG type you can use ig_manager->getEntityType(uint8_t kind, uint8_t domain, uint16_t country, uint8_t cat, uint8_t subcat, uint8_t spec, uint8_t extra)

<entity_types>
  <entity id="1.2.222.4.14.0.0" name="testcube">
    <path>ig/entities/e_test/testcube.node</path>
  </entity>
</entity_types>

 

Link to comment

Perfect, I added your changes and now the entity is being created correctly!

 

The only piece we are missing for now is how to remove entities from the scene (For the RemoveEntity PDU). It doesn't seem to exist a function on the manager to do so.

Is there any function or workaround to do so?

 

Thanks.

Link to comment
58 minutes ago, enrique.trilles said:

The only piece we are missing for now is how to remove entities from the scene (For the RemoveEntity PDU). It doesn't seem to exist a function on the manager to do so.

Is there any function or workaround to do so?

only through reset type

entity->setType(0)

there is no remove method, as well as the create method.

Link to comment

Again, thanks for your help. Setting the entity type to 0 removed correctly the entity.

We've been advancing on our testing of the plugin; We are 'toying around' with the Entity's state behavior and modification:

void onDISrcv(Header* pdu){
  
  if(pdu->GetPDUType() == ENUMS::EntityStatePDU){

    Entity_State_PDU* cepdu = static_cast<Entity_State_PDU*>(pdu);
    IG::ManagerInterface* manager = GetIGManager();
    // manager->getConfigPath(); // -> returns our config.xml file. Everything ok.

    int id = GetEntityID(cepdu);
    if(manager->isEntity(id)){
      IG::IEntity* entity = manager->getEntity(id);
      NodePtr node = entity->getNode(); // -> empty node

      // Handling position
      Math::Vec3 wpos = Math::Vec3(15.0f, 30.0f, 5.0f);

      IG::IConverter* c = manager->getConverter();

      entity->setGeoPosition(c->worldToGeodetic(newpos));

      // Handling rotation
      enetity->setRotationEuler(Math::vec3( 50.0f * deg2rad, 30.0f * deg2rad, 0.0f * deg2rad));

      // Modifing node parameters
      NodePtr node = entity->getNode();
      node->setName("AnotherName");

      // etc...

    }
  }

}

The thing is, the functions entity->setGeoPosition() and setRotationEuler() seems to do nothing to the entity.

Any insight on how use this features of the plugin correctly?

EDIT: After a bit of debuging, we checked the state in memory of the entity after the calls to the get methods (Image attached)

cap.thumb.png.932cdcdf82b73837f100e56fbab59a26.png

It seems the functions did something, but its not reflected in the scene's entity...

Thanks.

Edited by enrique.trilles
Link to comment

try this 

entity->setInterpolation(0);

 

but ... one moment: entity movement should work in the DISConnector out of the box. 
DISConnector automatically process the parameters entity_id, entity_type, entity_location, entity_orientation.

processing looks like this (this is sample code, it may not compile!):

	KDIS::PDU::Entity_State_PDU *packet = static_cast<KDIS::PDU::Entity_State_PDU *>(pdu);
	auto dis_entity_id = packet->GetEntityIdentifier();
	
	if (dis_entity_id.GetApplicationID() == app_id || dis_entity_id.GetSiteID() != site_id) 
		return;
	
	int entity_id = Connector::getInternalEntityID(dis_entity_id.GetApplicationID(), dis_entity_id.GetEntityID());
	IEntity * entity = ig_manager->getEntity(entity_id);
	
	auto dis_type = packet->GetEntityType();
	int type = Connector::getInternalEntityType(dis_type.GetEntityKind(), dis_type.GetDomain(), dis_type.GetCountry(), dis_type.GetCategory(), dis_type.GetSubCategory(), dis_type.GetSpecific(), dis_type.GetExtra());
	if (!type) 
	{
		dis_type = packet->GetAltEntityType();
		type = Connector::getInternalEntityType(dis_type.GetEntityKind(), dis_type.GetDomain(), dis_type.GetCountry(), dis_type.GetCategory(), dis_type.GetSubCategory(), dis_type.GetSpecific(), dis_type.GetExtra());
	}
	entity->setType(type);
	
	entity->setInterpolation(0);

	auto location = packet->GetEntityLocation();
	
	double lat = 0, lon = 0,  alt = 0;
	DISGeocentricToGeodetic<double>(location.GetX(), location.GetY(), location.GetZ(), lat, lon, alt, KDIS::UTILS::WGS_1984);
	entity->setGeoPosition(Vec3(lat, lon, alt));

	auto orient = packet->GetEntityOrientation();
	entity->setRotationEuler(vec3(orient.GetPhiInDegrees(), orient.GetPsiInDegrees(), orient.GetThetaInDegrees()));

Is this the right approach? 
It is difficult to make a general approach to processing dis packages, because many companies use customized dis.

Link to comment

If the dis connector is processing the transform parameters by default that explains why the function calls were doing nothing.

It's exactly as you said, we have to work with a customized version of dis, so we need to add a new layer of processing to several pdu's...

 

After the call to setInterpolation(0) everything seems to work as it should :)

 

With all these questions solved, we have enough information to continue with the project for a good amount of time. Feel free to mark as solved/clossed the topic.

If in the future we have more questions we will open another topic.

 

Thanks for all the answers!

Link to comment
  • silent changed the title to [SOLVED] Understanding and using IG Interface plugin
×
×
  • Create New...