Greetings, again!
I would like to create lots of instances of my mesh but also randomize the material applied to the mesh. Code posted below, if anyone can point me to the right direction I would appreciate it, thanks.
Secondly, TEntity? If I Load a mesh using either of the Load commands i.e. LoadMeshGMF, LoadMesh etc, am I right in thinking they inherit from TEntity automatically?
If not then how would I go about using LoadMeshGMF or LoadMesh and create its TEntity?
Thanks!
SuperStrict
Framework leadwerks.ENGINE
Local world:TWorld
Local gbuffer:TBuffer
Local camera:TCamera
Local Light:TLight
GCSetMode(2)
RegisterAbstractPath( "C:/Apps/Coding/Leadwerks Engine SDK" )
RegisterAbstractPath("Y:/Coding/Leadwerks/GunGore/data/models")
AppTitle = "Test
Graphics(800, 600)
SeedRnd MilliSecs()
Type tZombie
Field v:TVec3
Field m:TMesh
Field te:TEntity
Field dead:Int
Field mat:Int
Field mat1:TMaterial = LoadMaterial("abstract::zombie_1.mat")
Field mat2:TMaterial = LoadMaterial("abstract::zombie_2.mat")
Field mat3:TMaterial = LoadMaterial("abstract::zombie_3.mat")
Field mat4:TMaterial = LoadMaterial("abstract::zombie_4.mat")
Field mat5:TMaterial = LoadMaterial("abstract::zombie_5.mat")
Global zList:TList
Function CreateZombie(xloc:Float, yloc:Float, zloc:Float, maxzombies:Int)
If Not zList:TList Then zList:TList = CreateList()
For Local xi:Int = 0 Until maxzombies
Local z:tZombie = New tZombie
z.m = LoadMeshGMF("abstract::zombie1.gmf")
z.mat = Rand(1, 5)
If z.mat = 1 Then PaintEntity(z.m, z.mat1)
If z.mat = 2 Then PaintEntity(z.m, z.mat2)
If z.mat = 3 Then PaintEntity(z.m, z.mat3)
If z.mat = 4 Then PaintEntity(z.m, z.mat4)
If z.mat = 5 Then PaintEntity(z.m, z.mat5)
z.v = New TVec3
z.dead = 0
z.v.x = xloc
z.v.y = yloc
z.v.z = zloc
zList.AddLast(z)
Next
End Function
Method SetZPosition()
PositionEntity(m, [v.x, v.y, v.z])
End Method
End Type
world=CreateWorld()
If Not world RuntimeError "Failed to create world."
gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2)
camera = CreateCamera()
PositionEntity camera, [0.0, 5.0, -2.0]
Light = CreateDirectionalLight()
RotateEntity Light, [45.0, 45.0, 45.0]
SetLightRange(Light, 100.0)
tZombie.CreateZombie(Rnd(-10.0, 10.0), 0.0, Rnd(0.0, 20.0), 10)
For Local z:tZombie = EachIn tZombie.zList
z.SetZPosition
Next
Repeat
If KeyHit(KEY_ESCAPE) Exit
If AppTerminate() Exit
UpdateAppTime()
UpdateWorld(AppSpeed())
SetBuffer(gbuffer)
RenderWorld()
SetBuffer(BackBuffer())
RenderLights(gbuffer)
Flip(0)
Forever
gbuffer=Null
FreeEntity light
GCCollect()
End