Jump to content

C++ - finding entities in a scene


AggrorJorn
 Share

Recommended Posts

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

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

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...

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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))
{
}

  • Upvote 3
trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Link to comment
Share on other sites

  • 1 month later...

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

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...