Jump to content
AggrorJorn

C++ - finding entities in a scene

Recommended Posts

Does anybody know how to search entities that are loaded via map? LE2 LoadScene() gave back all entities but the current LoadMap function only returns a boolean.

Share this post


Link to post

I didn't think LE 2 load scene returned anything, but once done, you could then do CountChildren() on the scene (everything it loaded was a child) and then use GetChild for each of these children to access each entity (GetChild returned a TEntity type)

 

Obviously have no idea how this translates into Leadwerks 3 but in LE 2, LoadScene returned nothing. However there was a tutorial where it guided you through the process of writing a ProcessScene() function to get the children.

 

 

Edit: Actually no, I lie, You passed it a string, it returned a TScene object, which you then called CountChildren() on

Share this post


Link to post

I don't think we can at the moment, which is insane, but in another thread Josh was talking about ways of allowing this probably a week ago or so.

Share this post


Link to post

Well I am looking in to the entire scene. Of course the bounding box could be set to 10000000. But that would be very clumsy in my opinion.

Share this post


Link to post

just looking at the LE3 documentation here, it appears a list is created for a world's entities... can you not access that list like how it was done in LE2?

LE2: fw.main.world.entities or fw.main.world.meshes or fw.main.world.emitters...etc...

Share this post


Link to post

After the map is loaded, the only thing I see under self.world is ambientlight (via the lua editor that shows the current state).

Share this post


Link to post

Hey Macklebee! good to see you again.

 

Yes we can access this list but there is nothing in there that can be used. In the image below I have loaded a scene which contains 1 csg brush and a directionalLight. If I iterate through this world list and try GetKeyName("DirectionalLight1") nothing is returned. Also note how the errors are displayed by the entity list.

 

entities.jpg

Share this post


Link to post

Hi Aggror,

 

This may help you it iterates over the entities when the level is loaded. From there I can wrap the entities in classes and/or store them in a list...

 

void StoreWorldPointsCallBack(Entity* entity, Object* extra)
{        
       std::string text = entity->GetKeyValue("name");

       if(text.compare("playerSpawn") == 0)
       {
               TheGame->AddPlayerSpawnPoint(entity);
       }
}


//Load the map somewhere in your code
if(Map::Load((const char*)(path), StoreWorldPointsCallBack))
{
}

Share this post


Link to post

Each scripted entity will have the Start() function, for Lua. That takes care of most usage.

Share this post


Link to post

That's if you choose to attach a script to it. I don't think being able to loop over all loaded entities is much to ask really. Pretty common task.

Share this post


Link to post

Here's a way :

 

function Callback(entity)
  App.entities[entity] = entity
end

 

function App:Start()
  self.entities = {}
..
  --Load the starting map
  local mapfilename=System:GetProperty("map","Maps/start.map")
  if Map:Load(mapfilename,"Callback")==false then return false end

  -- Find camera from map
  for k, v in next, App.entities do
  if v:GetClass()==Object.CameraClass then
	 self.camera=v
  end
  end
...
end

Share this post


Link to post

void StoreWorldPointsCallBack(Entity* entity, Object* extra)
{
std::string text = entity->GetKeyValue("name");

if(text.compare("playerSpawn") == 0)
{
TheGame->AddPlayerSpawnPoint(entity);
}
}


//Load the map somewhere in your code
if(Map::Load((const char*)(path), StoreWorldPointsCallBack))
{
}

 

Just a little detail for when you use a callback to iterate over all the entities loaded:

 

Lights and models trigger the callback, but CSG objects by default don't. So if you would want to save CSG objects in to a class then you either have to attach a script or set a mass.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...