Jump to content

Help with picking entities in scenes


Quan
 Share

Recommended Posts

I have moved onto using scene files and the LE Editor to build my levels but I am struggling to work out how I can pick a entity and change its properties from inside Blitzmax on the fly.

 

I have a directional light called sunlight which I would like to rotate and turn on / off etc. In the past I have just been creating a light in Blitzmax which is fine because I know what it is called but I can't seem to work out how I would find the sunlight entity from inside the loaded scene.

 

Can anyone help me or point me to a example on the wiki.

 

Thanks

BMax 1.38 * Leadwerks 2.4 * Unity 3.0 Pro * Intel Core 2 Duo 6600 - Win7 64bit - ATI 4870

Link to comment
Share on other sites

After scene = LoadScene(....) call a function that uses an iterator to go through all the entities and process them as you wish. The following code (not tested as I hacked it out from a failing memory) should be enough to demonstrate one solution.

 

It goes through all the scene entities, finds one that's called 'light_directional_1' (use any name you have assigned in the editor), it creates a pivot object and parents the directional light to it. You can then rotate the pivot to rotate the light, hence move the apparent sun position across the sky.

 

 


' CREATE A PIVOT FOR ROTATING THE SUN ENTITY '
Global sunpivot:TPivot

' ASSUMES scene IS GLOBAL AND MAP HAS BEEN LOADED '
Function ProcessSceneInfo(scene:TEntity)

Local entity:TEntity
Local name:String;

For entity = EachIn scene.kids
	name = entity.GetKey("name", "")
	Select name
		' FIND OR SUN USE THE NAME OF THE DIRECTIONAL LIGHT HERE '
		Case "light_directional_1"   
			sunpivot = CreatePivot() ;
			entity.SetParent(sunpivot) ;
	End Select
Next
End Function

 

And you can use this as the basis to do other useful things.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Works like a charm, thanks again.

 

I still have a load more questions but I'll have a play for a bit and see what I can work out first.

BMax 1.38 * Leadwerks 2.4 * Unity 3.0 Pro * Intel Core 2 Duo 6600 - Win7 64bit - ATI 4870

Link to comment
Share on other sites

I am still a bit stuck when it comes to changing a entities properties inside a scene from Blitz max. Working with the sun idea, what I would like to do is change the colors during the day.

 

I have tried doing e.color = Vec4(1,0,0,1) inside the selection loop but this ended up changing nothing visually and is probably going about it the wrong way.

BMax 1.38 * Leadwerks 2.4 * Unity 3.0 Pro * Intel Core 2 Duo 6600 - Win7 64bit - ATI 4870

Link to comment
Share on other sites

After playing some more I have changed the code a bit by making sunlight:TEntity = e after which I can turn the sunlight, hide it etc. But I still can't seem to change its color with EntityColor. I think I know why because its now a TEntity instead of a TLight but I have no idea how to convert it.

 

But my understanding of how things work increasing quite quickly.

BMax 1.38 * Leadwerks 2.4 * Unity 3.0 Pro * Intel Core 2 Duo 6600 - Win7 64bit - ATI 4870

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