create a scene/map from scratch

16 views
Skip to first unread message

Mathieu MARACHE

unread,
May 16, 2012, 5:48:11 AM5/16/12
to dtenti...@googlegroups.com
Hi Martin,

I'm trying (and not very successfully) to create a scene from my
application that generates an osg::Node to be viewed by a dtEntity
application.
What are the steps I need to follow ? Here is an excerpt of my code
but its creates only empty scene/map :

bool exportScene()
{
   dtEntity::EntityManager em;
   dtEntity::AddDefaultEntitySystemsAndFactories(0, 0, em);

   dtEntity::MapSystem* mSystem;
   if ( !em.GetEntitySystem(dtEntity::MapComponent::TYPE, mSystem) )
   {
       LOG4CPLUS_WARN(logger, "Unable to get a MapComponent from the
EntityManager");
       return false;
   }

   mSystem->AddEmptyMap(scenepath.toStdString(), "myMap.dtemap");

   {
       dtEntity::Entity* entity;
       em.CreateEntity(entity);

       dtEntity::MapComponent* mapcomp;
       entity->CreateComponent(mapcomp);
       mapcomp->SetMapName(mapname);
       mapcomp->SetUniqueId("myId");
       mapcomp->SetEntityName("myName");
       mapcomp->Finished();
       em.AddToScene(entity->GetId());
   }

   {
       dtEntity::Entity* entity;
       em.CreateEntity(entity);

       dtEntity::StaticMeshComponent* nComponent;
       if ( !entity->CreateComponent(nComponent))
       {
           LOG4CPLUS_WARN(logger, "Unable to create a NodeComponent");
           return false;
       }

       nComponent->SetMesh("cow.osgt");

       nComponent->Finished();
       em.AddToScene(entity->GetId());
   }

   return mSystem->SaveScene("myScene.dtscene",true);
}


the scene :

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<scene>
<libraries/>
<maps>
<map path="myMap.dtemap"/>
</maps>
</scene>

and the map :

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<map>
<entity>
<component type="Map">
<stringproperty name="MapName">myMap.dtemap</stringproperty>
<stringproperty name="UniqueId">myId</stringproperty>
</component>
</entity>
</map>

--
Mathieu

Martin Scheffler

unread,
May 16, 2012, 8:21:58 AM5/16/12
to dtenti...@googlegroups.com
Hi Mathieu,

you create an entity that only has a map component. That won't do anything.
The other entity has a single static mesh component, to attach it you
have to add a layer component that has layer set to "default" and
attached component to "StaticMesh".

You will have to add an OSG camera, either by hand or by creating an
entity with a CameraComponent and setting its ContextId to 0.
Maybe you can take a look at testEntity, it shows how to set things up.

Cheers,
Martin

2012/5/16 Mathieu MARACHE <mathieu...@gmail.com>:

emeric....@gmail.com

unread,
Jan 6, 2015, 12:08:30 PM1/6/15
to dtenti...@googlegroups.com, martins...@googlemail.com
Hi Martin,
 
Le mercredi 16 mai 2012 14:21:58 UTC+2, Martin Scheffler a écrit :
Hi Mathieu,

you create an entity that only has a map component. That won't do anything.
The other entity has a single static mesh component, to attach it you
have to add a layer component that has layer set to "default" and
attached component to "StaticMesh".

You will have to add an OSG camera, either by hand or by creating an
entity with a  CameraComponent and setting its ContextId to 0.
Maybe you can take a look at testEntity, it shows how to set things up.

Cheers,
Martin
 
I'm in the same boat than Mathieu :-P
But to me, the testEntity isn't that simple ;-) Indeed, it relies upon external scene/map resources and makes use of Spawner the exact purpose is obscure to me.
 
If I want to create a scene/map really from scratch the dtEntity way, i.e. simply by loading an OSG-supported mesh without relying any external scene/map resources, is the code below supposed to work (I've followed the advice you gave to Mathieu at the time):
 
void cOSG::InitSceneGraph(void)
{
    // Init the main Root Node/Group
    mRoot  = new osg::Group; // mRoot is an osg::ref_ptr<osg::Group> member variable
    // mViewer is an osgViewer::Viewer member variable
    // em is a dtEntity::EntityManager member variable
    dtEntityOSG::SetupSceneGraph(*mViewer, em, mRoot.get());
 
    dtEntity::StartSystemMessage msg;
    em.EnqueueMessage(msg);

    // Create new entity
    dtEntity::Entity* entity = NULL;
    VERIFY(em.CreateEntity(entity));
    if (!entity) return;

    // Load the Model from the model name
    dtEntityOSG::StaticMeshComponent* meshcomp = NULL;
    VERIFY(entity->CreateComponent(meshcomp));
    if (!meshcomp) return;
    meshcomp->SetMesh(m_ModelName); // m_ModelName is a std::string member variable
 
    // Create camera component
    dtEntityOSG::CameraComponent* camcomp = NULL;
    VERIFY(entity->CreateComponent(camcomp));
    if (!camcomp) return;
    camcomp->SetContextId(0);
 
    // Create map component
    dtEntity::MapComponent* mapcomp = NULL;
    VERIFY(entity->CreateComponent(mapcomp));

    // Add the model to the scene
    dtEntity::MapSystem* mapsys = NULL;
    VERIFY(em.GetEntitySystem(dtEntity::MapComponent::TYPE, mapsys));
    if (!mapsys) return;
    VERIFY(mapsys->AddToScene(entity->GetId()));
}
I'm getting _nothing_ (i.e. no background color, no stats handler, nothing) in my application window with the above code.
If I remove the camera component, the viewer seems to be initialized correctly as I can see the classical dark blue OSG background in my application window. And the stats handler reports one camera with one view, but no PrimitiveSet, so I can't see my loaded mesh. And yes, I've checked that it loads fine in the SetMesh call.
What am I missing? Except for the dtEntityOSG::DoScreenSetup that I had to "override" in order to use an existing window on Windows (rather than creating a new one), I'm having the equivalent code sequence to dtEntityOSG::InitOSGViewer, so am getting the default dtEntityOSG::CameraSystem, dtEntityOSG::LayerSystem, dtEntity::MapSystem and dtEntityOSG::LayerAttachPointSystem at load.
 
Alternatively, isn't there a simpler example than testEntity that shows how to simply load a supported OSG mesh/image file the dtEntity way (without using external scene/map resources to make it simple at first)?
 
Thanks,
 
     Emeric
Reply all
Reply to author
Forward
0 new messages