Ok to sum it up you'll need to set an array for the objects and textures and use copyentity aswell as paintbrush for the prefab parts. This basically takes a Light type and creates lm lights in yal. Good luck, the system this is pulled out of is rather cluttered and im too busy to make it a lib... the general concept is here, and im sure you can figure out how to make your own system. You need yal of course.
Types etc...
Type obj
Field entity
Field part%
Field zone
Field texture%
Field selected
Field group$
Field x#,y#;,z#
Field rx#,ry#,rz#
End Type
Type lm_obj
Field entity
Field part%
Field zone
Field texture%
Field selected
Field group$
Field x#,y#;,z#
Field rx#,ry#,rz#
End Type
Type light
Field entity
Field entity_o
Field ent_range
Field ent_brightness
Field X#,Y#,Z#
Field R%,G%,B%
Field zone%
Field range%
Field brightness%
Field selected
End Type
Type section
Field number%
Field name$
Field visible$
Field mesh
End Type
Dim brush_texture(Total_textures%)
Dim texture(Total_textures%)
Dim block(Total_block_parts%)
The following are used for occlusion etc.
For secload=1 To 100
sec.section=New section
sec\number% = secload
sec\name$ = ""
sec\visible$ = Str$(secload)
sec\mesh = CreateCube()
EntityAlpha sec\mesh,0.0
HideEntity sec\mesh
Next
;Create collision mesh based on parts then hide them, only displaying the lightmapped final mesh.
For o.obj = Each obj
EntityType O\entity,type_ground
EntityAlpha O\entity,0
; FreeEntity O\entity
; Delete o
Next
Here is the function... good luck.
Function light_map(section%)
first_selection = False
For O.obj=Each obj
If O\zone% = section% Then
LM.lm_obj=New lm_obj
LM\entity = CopyMesh (block(O\part%))
LM\X# = O\X#
LM\Y# = O\Y#
LM\Z# = O\Z#
LM\RX# = O\RX#
LM\RY# = O\RY#
LM\RZ# = O\RZ#
LM\texture% = O\texture%
EntityFX LM\entity,1
PaintMesh LM\entity,brush_texture( LM\texture% )
RotateMesh LM\entity, LM\RX#, LM\RY#, LM\RZ#
PositionMesh LM\entity, LM\X#, LM\Y#, LM\Z#
EntityPickMode LM\entity,2
If first_selection = False Then
PositionEntity temp_piv,EntityX(O\entity),EntityY(O\entity),EntityZ(O\entity)
first_selection = True
End If
last_x# = O\X#
last_y# = O\y#
last_z# = O\z#
End If
Next
If first_selection=False Then Return
For S.section = Each section
If S\number% = section% Then
FreeEntity S\mesh
S\mesh = CreateMesh()
NameEntity( S\mesh, S\number% )
For N.lm_obj = Each lm_obj
AddMesh N\entity,S\mesh
Next
ThisObscurer.LMObscurer = New LMObscurer
ThisObscurer\Entity = S\mesh
BeginLightMap(Ambient_r%, Ambient_g%, Ambient_b%)
For L.light= Each light
If L\zone% = section%
CreateLMLight( L\X#, L\Y#, L\Z#, L\R%,L\G%,L\B%, L\range%, False, L\brightness%)
End If
Next
tex = LightMapMesh(S\mesh, 2.0, 256, 0, "Lightmapping " + EntityName(S\mesh))
lm_folder$ = "maps\" + map_name$ + "\"
If tex
SaveLightMap(S\mesh, tex, lm_folder$ + EntityName(S\mesh) + ".bmp", lm_folder$ + EntityName(S\mesh) + ".luv")
ApplyLightMap(S\mesh, tex)
EndIf
EndLightMap()
For R.lm_obj=Each lm_obj
FreeEntity R\entity
Delete R
Next
For M.LMLight= Each LMLight
Delete M
Next
End If
Next
End Function
|