Update to CMake, tweaks & dds
[convexer.git] / __init__.py
index 06abec08bd453a79936d117129a203d42d6e153f..7ba2584dbb5c0482840656d7441536f9f2b90ffb 100644 (file)
@@ -216,7 +216,8 @@ libcxr = None
 class cxr_edge(Structure):
    _fields_ = [("i0",c_int32),
                ("i1",c_int32),
-               ("freestyle",c_int32)]
+               ("freestyle",c_int32),
+               ("sharp",c_int32)]
 
 class cxr_static_loop(Structure):
    _fields_ = [("index",c_int32),
@@ -254,14 +255,20 @@ class cxr_tri_mesh(Structure):
                ("indices_count",c_int32),
                ("vertex_count",c_int32)]
 
+class cxr_visgroup(Structure):
+   _fields_ = [("name",c_char_p)]
+
 class cxr_vmf_context(Structure):
    _fields_ = [("mapversion",c_int32),
                ("skyname",c_char_p),
                ("detailvbsp",c_char_p),
                ("detailmaterial",c_char_p),
+               ("visgroups",POINTER(cxr_visgroup)),
+               ("visgroup_count",c_int32),
                ("scale",c_double),
                ("offset",c_double *3),
                ("lightmap_scale",c_int32),
+               ("visgroupid",c_int32),
                ("brush_count",c_int32),
                ("entity_count",c_int32),
                ("face_count",c_int32)]
@@ -327,6 +334,7 @@ def mesh_cxr_format(obj):
       edge_data[i].i0 = edge.vertices[0]
       edge_data[i].i1 = edge.vertices[1]
       edge_data[i].freestyle = edge.use_freestyle_mark
+      edge_data[i].sharp = edge.use_edge_sharp
 
    material_data = (cxr_material*len(obj.material_slots))()
 
@@ -554,6 +562,16 @@ def cxr_baseclass(classes, other):
       base.update(x.copy())
    return base
 
+def ent_soundscape(context):
+   obj = context['object']
+   kvs = cxr_baseclass([ent_origin],\
+   {
+      "radius": obj.scale.x * bpy.context.scene.cxr_data.scale_factor,
+      "soundscape": {"type":"string","default":""}
+   })
+
+   return kvs
+
 # EEVEE Light component converter -> Source 1
 #
 def ent_lights(context):
@@ -596,7 +614,7 @@ def ent_lights(context):
    elif obj.data.type == 'POINT':
       kvs['_light'] = [ int(x) for x in light_base]
       kvs['_quadratic_attn'] = 1.0
-      kvs['_linear_attn'] = 0.0
+      kvs['_linear_attn'] = 1.0
    
    elif obj.data.type == 'SUN':
       light_base[3] *= 300.0 * 5
@@ -614,24 +632,43 @@ def ent_lights(context):
    return kvs
 
 def ent_prop(context):
-   kvs = {}
    if isinstance( context['object'], bpy.types.Collection ):
-      kvs['angles'] = [0,180,0]
-      kvs['enablelightbounce'] = 1
-      kvs['disableshadows'] = 0
-      kvs['fademindist'] = -1
-      kvs['fadescale'] = 1
-      kvs['model'] = F"{asset_path('models',context['object'])}.mdl".lower()
-      kvs['renderamt'] = 255
-      kvs['rendercolor'] = [255, 255, 255]
-      kvs['skin'] = 0
-      kvs['solid'] = 6
-      kvs['uniformscale'] = 1.0
-
+      kvs = {}
+      target = context['object']
       pos = mathutils.Vector(context['origin'])
       pos += mathutils.Vector(context['transform']['offset'])
 
       kvs['origin'] = [pos[1],-pos[0],pos[2]]
+      kvs['angles'] = [0,180,0]
+      kvs['uniformscale'] = 1.0
+   else:
+      kvs = cxr_baseclass([ent_origin],{})
+      target = context['object'].instance_collection
+
+      obj = context['object']
+      euler = [ a*57.295779513 for a in obj.rotation_euler ]
+      angle = [0,0,0]
+      angle[0] = euler[1]
+      angle[1] = euler[2] + 180.0 # Dunno...
+      angle[2] = euler[0]
+      
+      kvs['angles'] = angle
+      kvs['uniformscale'] = obj.scale[0]
+   
+   if target.cxr_data.shadow_caster:
+      kvs['enablelightbounce'] = 1
+      kvs['disableshadows'] = 0
+   else:
+      kvs['enablelightbounce'] = 0
+      kvs['disableshadows'] = 1
+
+   kvs['fademindist'] = -1
+   kvs['fadescale'] = 1
+   kvs['model'] = F"{asset_path('models',target)}.mdl".lower()
+   kvs['renderamt'] = 255
+   kvs['rendercolor'] = [255, 255, 255]
+   kvs['skin'] = 0
+   kvs['solid'] = 6
 
    return kvs
 
@@ -694,7 +731,7 @@ def asset_uid(asset):
    name = ""
 
    if v == 0:
-      name = "A"
+      name = "a"
    else:
       dig = []
       
@@ -1015,6 +1052,12 @@ def cxr_export_vmf(sceneinfo, output_vmf):
       vmfinfo.entity_count = 0
       vmfinfo.face_count = 0
       
+      visgroups = (cxr_visgroup*len(cxr_visgroups))()
+      for i, vg in enumerate(cxr_visgroups):
+         visgroups[i].name = vg.encode('utf-8')
+      vmfinfo.visgroups = cast(visgroups, POINTER(cxr_visgroup))
+      vmfinfo.visgroup_count = len(cxr_visgroups)
+      
       libcxr_begin_vmf.call( pointer(vmfinfo), m.fp )
 
       def _buildsolid( cmd ):
@@ -1035,6 +1078,11 @@ def cxr_export_vmf(sceneinfo, output_vmf):
          vmfinfo.offset[1] = offset[1]
          vmfinfo.offset[2] = offset[2]
 
+         if cmd['object'].cxr_data.lightmap_override > 0:
+            vmfinfo.lightmap_scale = cmd['object'].cxr_data.lightmap_override
+         else:
+            vmfinfo.lightmap_scale = bpy.context.scene.cxr_data.lightmap_scale
+
          libcxr_push_world_vmf.call( world, pointer(vmfinfo), m.fp )
          libcxr_free_world.call( world )
 
@@ -1042,10 +1090,12 @@ def cxr_export_vmf(sceneinfo, output_vmf):
 
       # World geometry
       for brush in sceneinfo['geo']:
+         vmfinfo.visgroupid = int(brush['object'].cxr_data.visgroup)
          if not _buildsolid( brush ):
             cxr_batch_lines()
             scene_redraw()
             return False
+      vmfinfo.visgroupid = 0
 
       libcxr_vmf_begin_entities.call(pointer(vmfinfo), m.fp)
       
@@ -1069,12 +1119,21 @@ def cxr_export_vmf(sceneinfo, output_vmf):
             pass
          elif not isinstance( obj, bpy.types.Collection ):
             if obj.type == 'MESH':
+               vmfinfo.visgroupid = int(obj.cxr_data.visgroup)
                if not _buildsolid( ent ):
                   cxr_batch_lines()
                   scene_redraw()
                   return False
 
+         if obj != None:
+            m.node( 'editor' )
+            m.kv( 'visgroupid', str(obj.cxr_data.visgroup) )
+            m.kv( 'visgroupshown', '1' )
+            m.kv( 'visgroupautoshown', '1' )
+            m.edon()
+
          m.edon()
+      vmfinfo.visgroupid = 0
 
    print( "Done" )
    return True
@@ -1221,6 +1280,12 @@ def compile_material(mat):
       vmt.edon()
    return props
 
+def cxr_modelsrc_vphys( mdl ):
+   for obj in mdl.objects:
+      if obj.name == F"{mdl.name}_phy":
+         return obj
+   return None
+
 def cxr_export_modelsrc( mdl, origin, asset_dir, project_name, transform ):
    dgraph = bpy.context.evaluated_depsgraph_get()
 
@@ -1324,8 +1389,16 @@ def cxr_export_modelsrc( mdl, origin, asset_dir, project_name, transform ):
       o.write(F'$scale {transform["scale"]/100.0}\n')
       o.write(F'$body _ "{uid}_ref.fbx"\n')
       o.write(F'$staticprop\n')
-      o.write(F'$origin {origin[0]} {origin[1]} {origin[2]}\n')
+      o.write(F'$origin {origin[0]:.6f} {origin[1]:.6f} {origin[2]:.6f}\n')
       
+      if mdl.cxr_data.preserve_order:
+         o.write(F"$preservetriangleorder\n")
+
+      if mdl.cxr_data.texture_shadows:
+         o.write(F"$casttextureshadows\n")
+
+      o.write(F"$surfaceprop {mdl.cxr_data.surfaceprop}\n")
+
       if vphys != None:
          o.write(F'$collisionmodel "{uid}_phy.fbx"\n')
          o.write("{\n")
@@ -1419,7 +1492,8 @@ class CXR_PREVIEW_OPERATOR(bpy.types.Operator):
                "Internal-Fail",\
                "Non-Coplanar",\
                "Non-Convex Polygon",\
-               "Bad Result"]\
+               "Bad Result",\
+               "Invalid-Input"]\
                [err.value]
 
          if static.RUNNING:
@@ -1481,6 +1555,17 @@ class CXR_DETECT_COMPILERS(bpy.types.Operator):
 
       return {'FINISHED'}
 
+def cxr_compiler_path( compiler ):
+   settings = bpy.context.scene.cxr_data
+   subdir = settings.subdir
+   path = os.path.normpath(F'{subdir}/../bin/{compiler}.exe')
+   
+   if os.path.exists( path ): return path
+   else: return None
+
+def cxr_winepath( path ):
+   return 'z:'+path.replace('/','\\')
+
 # Main compile function
 #
 class CXR_COMPILER_CHAIN(bpy.types.Operator):
@@ -1601,150 +1686,210 @@ class CXR_COMPILER_CHAIN(bpy.types.Operator):
       static = _.__class__
       wm = context.window_manager
       
-      if static.TIMER == None:
-         print("Launching compiler toolchain")
+      if static.TIMER != None:
+         print("Chain exiting...")
+         static.USER_EXIT=True
+         return {'RUNNING_MODAL'}
 
-         # Run static compilation units now (collect, vmt..)
-         filepath = bpy.data.filepath
-         directory = os.path.dirname(filepath)
-         settings = bpy.context.scene.cxr_data
-   
-         asset_dir = F"{directory}/modelsrc"
-         material_dir = F"{settings.subdir}/materials/{settings.project_name}"
-         model_dir = F"{settings.subdir}/models/{settings.project_name}"
-         output_vmf = F"{directory}/{settings.project_name}.vmf"
-
-         os.makedirs( asset_dir, exist_ok=True )
-         os.makedirs( material_dir, exist_ok=True )
-         os.makedirs( model_dir, exist_ok=True )
-         
-         static.FILE = open(F"/tmp/convexer_compile_log.txt","w")
-         static.LOG = []
+      print("Launching compiler toolchain")
 
-         sceneinfo = cxr_scene_collect()
-         image_jobs = []
-         qc_jobs = []
+      # Run static compilation units now (collect, vmt..)
+      filepath = bpy.data.filepath
+      directory = os.path.dirname(filepath)
+      settings = bpy.context.scene.cxr_data
+
+      asset_dir = F"{directory}/modelsrc"
+      material_dir = F"{settings.subdir}/materials/{settings.project_name}"
+      model_dir = F"{settings.subdir}/models/{settings.project_name}"
+      output_vmf = F"{directory}/{settings.project_name}.vmf"
 
-         # Collect materials
-         a_materials = set()
-         for brush in sceneinfo['geo']:
-            for ms in brush['object'].material_slots:
+      bsp_local = F"{directory}/{settings.project_name}.bsp"
+      bsp_remote = F"{settings.subdir}/maps/{settings.project_name}.bsp"
+      bsp_packed = F"{settings.subdir}/maps/{settings.project_name}_pack.bsp"
+      packlist = F"{directory}/{settings.project_name}_assets.txt"
+
+      os.makedirs( asset_dir, exist_ok=True )
+      os.makedirs( material_dir, exist_ok=True )
+      os.makedirs( model_dir, exist_ok=True )
+      
+      static.FILE = open(F"/tmp/convexer_compile_log.txt","w")
+      static.LOG = []
+
+      sceneinfo = cxr_scene_collect()
+      image_jobs = []
+      qc_jobs = []
+
+      # Collect materials
+      a_materials = set()
+      for brush in sceneinfo['geo']:
+         for ms in brush['object'].material_slots:
+            a_materials.add( ms.material )
+            if ms.material.cxr_data.shader == 'VertexLitGeneric':
+               errmat = ms.material.name
+               errnam = brush['object'].name
+               print( F"Vertex shader {errmat} used on {errnam}")
+               return {'CANCELLED'}
+      
+      a_models = set()
+      model_jobs = []
+      for ent in sceneinfo['entities']:
+         if ent['object'] == None: continue
+
+         if ent['classname'] == 'prop_static':
+            obj = ent['object']
+            if isinstance(obj,bpy.types.Collection):
+               target = obj
+               a_models.add( target )
+               model_jobs += [(target, ent['origin'], asset_dir, \
+                              settings.project_name, ent['transform'])]
+            else:
+               target = obj.instance_collection
+               if target in a_models:
+                  continue
+               a_models.add( target )
+               
+               # TODO: Should take into account collection instancing offset
+               model_jobs += [(target, [0,0,0], asset_dir, \
+                              settings.project_name, ent['transform'])]
+      
+         elif ent['object'].type == 'MESH':
+            for ms in ent['object'].material_slots:
                a_materials.add( ms.material )
-               if ms.material.cxr_data.shader == 'VertexLitGeneric':
+         
+      for mdl in a_models:
+         uid = asset_uid(mdl)
+         qc_jobs += [F'{uid}.qc']
+
+         for obj in mdl.objects:
+            for ms in obj.material_slots:
+               a_materials.add( ms.material )
+               if ms.material.cxr_data.shader == 'LightMappedGeneric' or \
+                  ms.material.cxr_data.shader == 'WorldVertexTransition':
+
                   errmat = ms.material.name
-                  errnam = brush['object'].name
-                  print( F"Vertex shader {errmat} used on {errnam}")
+                  errnam = obj.name
+                  print( F"Lightmapped shader {errmat} used on {errnam}")
                   return {'CANCELLED'}
-         
-         for ent in sceneinfo['entities']:
-            if ent['object'] == None: continue
-            if isinstance(ent['object'],bpy.types.Collection): continue
+      
+      # Collect images
+      for mat in a_materials:
+         for pair in compile_material(mat):
+            decl = pair[0]
+            pdef = pair[1]
+            prop = pair[2]
+
+            if isinstance(prop,bpy.types.Image):
+               flags = 0
+               if 'flags' in pdef: flags = pdef['flags']
+               if prop not in image_jobs:
+                  image_jobs += [(prop,)]
+                  prop.cxr_data.flags = flags
+
+      # Create packlist
+      with open( packlist, "w" ) as fp:
 
-            if ent['object'].type == 'MESH':
-               for ms in ent['object'].material_slots:
-                  a_materials.add( ms.material )
-         
-         # TODO.. this  should just be in the entity loop
-         for hero in sceneinfo['heros']:
-            uid = asset_uid(hero['collection'])
-            qc_jobs += [F'{uid}.qc']
-            for obj in hero['collection'].objects:
-               for ms in obj.material_slots:
-                  a_materials.add( ms.material )
-                  if ms.material.cxr_data.shader == 'LightMappedGeneric' or \
-                     ms.material.cxr_data.shader == 'WorldVertexTransition':
-
-                     errmat = ms.material.name
-                     errnam = obj.name
-                     print( F"Lightmapped shader {errmat} used on {errnam}")
-                     return {'CANCELLED'}
-         
-         # Collect images
          for mat in a_materials:
-            for pair in compile_material(mat):
-               decl = pair[0]
-               pdef = pair[1]
-               prop = pair[2]
-
-               if isinstance(prop,bpy.types.Image):
-                  flags = 0
-                  if 'flags' in pdef: flags = pdef['flags']
-                  if prop not in image_jobs:
-                     image_jobs += [(prop,)]
-                     prop.cxr_data.flags = flags
-         
-         # Convexer jobs
-         static.JOBID = 0
-         static.JOBINFO = []
-         
-         if settings.comp_vmf:
-            static.JOBINFO += [{ 
-               "title": "Convexer",
+            if mat.cxr_data.shader == 'Builtin': continue
+            fp.write(F"{asset_path('materials',mat)}.vmt\n")
+            fp.write(F"{cxr_winepath(asset_full_path('materials',mat))}.vmt\n")
+
+         for img_job in image_jobs:
+            img = img_job[0]
+            fp.write(F"{asset_path('materials',img)}.vtf\n")
+            fp.write(F"{cxr_winepath(asset_full_path('materials',img))}.vtf\n")
+
+         for mdl in a_models:
+            local = asset_path('models',mdl)
+            winep = cxr_winepath(asset_full_path('models',mdl))
+
+            fp.write(F"{local}.vvd\n")
+            fp.write(F"{winep}.vvd\n")
+            fp.write(F"{local}.dx90.vtx\n")
+            fp.write(F"{winep}.dx90.vtx\n")
+            fp.write(F"{local}.mdl\n")
+            fp.write(F"{winep}.mdl\n")
+            fp.write(F"{local}.vvd\n")
+            fp.write(F"{winep}.vvd\n")
+
+            if cxr_modelsrc_vphys(mdl):
+               fp.write(F"{local}.phy\n")
+               fp.write(F"{winep}.phy\n")
+      
+      # Convexer jobs
+      static.JOBID = 0
+      static.JOBINFO = []
+      
+      if settings.comp_vmf:
+         static.JOBINFO += [{ 
+            "title": "Convexer",
+            "w": 20,
+            "colour": (1.0,0.3,0.1,1.0),
+            "exec": cxr_export_vmf,
+            "jobs": [(sceneinfo,output_vmf)]
+         }]
+      
+      if settings.comp_textures:
+         if len(image_jobs) > 0:
+            static.JOBINFO += [{
+               "title": "Textures",
+               "w": 40,
+               "colour": (0.1,1.0,0.3,1.0),
+               "exec": compile_image,
+               "jobs": image_jobs
+            }]
+
+      game = cxr_winepath( settings.subdir )
+      args = [ \
+          '-game', game, settings.project_name
+      ]
+
+      # FBX stage
+      if settings.comp_models:
+         if len(model_jobs) > 0:
+            static.JOBINFO += [{
+               "title": "Batches",
+               "w": 25,
+               "colour": (0.5,0.5,1.0,1.0),
+               "exec": cxr_export_modelsrc,
+               "jobs": model_jobs
+            }]
+      
+         if len(qc_jobs) > 0:
+            static.JOBINFO += [{
+               "title": "StudioMDL",
                "w": 20,
-               "colour": (1.0,0.3,0.1,1.0),
-               "exec": cxr_export_vmf,
-               "jobs": [(sceneinfo,output_vmf)]
+               "colour": (0.8,0.1,0.1,1.0),
+               "exec": "studiomdl",
+               "jobs": [[settings[F'exe_studiomdl']] + [\
+                     '-nop4', '-game', game, qc] for qc in qc_jobs],
+               "cwd": asset_dir
             }]
-         
-         if settings.comp_textures:
-            if len(image_jobs) > 0:
-               static.JOBINFO += [{
-                  "title": "Textures",
-                  "w": 40,
-                  "colour": (0.1,1.0,0.3,1.0),
-                  "exec": compile_image,
-                  "jobs": image_jobs
-               }]
-
-         game = 'z:'+settings.subdir.replace('/','\\')
-         args = [ \
-             '-game', game, settings.project_name
-         ]
-
-         # FBX stage
-         if settings.comp_models:
-            if len(sceneinfo['heros']) > 0:
-               static.JOBINFO += [{
-                  "title": "Batches",
-                  "w": 25,
-                  "colour": (0.5,0.5,1.0,1.0),
-                  "exec": cxr_export_modelsrc,
-                  "jobs": [(h['collection'], h['origin'], asset_dir, \
-                        settings.project_name, h['transform']) for h in \
-                        sceneinfo['heros']]
-               }]
-         
-            if len(qc_jobs) > 0:
-               static.JOBINFO += [{
-                  "title": "StudioMDL",
-                  "w": 20,
-                  "colour": (0.8,0.1,0.1,1.0),
-                  "exec": "studiomdl",
-                  "jobs": [[settings[F'exe_studiomdl']] + [\
-                        '-nop4', '-game', game, qc] for qc in qc_jobs],
-                  "cwd": asset_dir
-               }]
-
-         # VBSP stage
-         if settings.comp_compile:
+
+      # VBSP stage
+      if settings.comp_compile:
+         if not settings.opt_vbsp.startswith( 'disable' ):
+            vbsp_opt = settings.opt_vbsp.split()
             static.JOBINFO += [{
                "title": "VBSP",
                "w": 25,
                "colour": (0.1,0.2,1.0,1.0),
                "exec": "vbsp",
-               "jobs": [[settings[F'exe_vbsp']] + args],
+               "jobs": [[settings[F'exe_vbsp']] + vbsp_opt + args],
                "cwd": directory
             }]
-            
+         
+         if not settings.opt_vvis.startswith( 'disable' ):
+            vvis_opt = settings.opt_vvis.split()
             static.JOBINFO += [{
                "title": "VVIS",
                "w": 25,
                "colour": (0.9,0.5,0.5,1.0),
                "exec": "vvis",
-               "jobs": [[settings[F'exe_vvis']] + ['-fast'] + args ],
+               "jobs": [[settings[F'exe_vvis']] + vvis_opt + args ],
                "cwd": directory
             }]
-            
+         
+         if not settings.opt_vrad.startswith( 'disable' ):
             vrad_opt = settings.opt_vrad.split()
             static.JOBINFO += [{
                "title": "VRAD",
@@ -1755,25 +1900,36 @@ class CXR_COMPILER_CHAIN(bpy.types.Operator):
                "cwd": directory
             }]
 
-            static.JOBINFO += [{
-               "title": "CXR",
-               "w": 5,
-               "colour": (0.0,1.0,0.4,1.0),
-               "exec": cxr_patchmap,
-               "jobs": [(F"{directory}/{settings.project_name}.bsp",\
-                         F"{settings.subdir}/maps/{settings.project_name}.bsp")]
-            }]
+         static.JOBINFO += [{
+            "title": "CXR",
+            "w": 5,
+            "colour": (0.0,1.0,0.4,1.0),
+            "exec": cxr_patchmap,
+            "jobs": [(bsp_local,bsp_remote)]
+         }]
+
+      if settings.comp_pack:
+         static.JOBINFO += [{
+            "title": "Pack",
+            "w": 5,
+            "colour": (0.2,0.2,0.2,1.0),
+            "exec": "bspzip",
+            "jobs": [[cxr_compiler_path("bspzip"), '-addlist', \
+                  cxr_winepath(bsp_remote), 
+                  cxr_winepath(packlist),
+                  cxr_winepath(bsp_packed) ]],
+            "cwd": directory
+         }]
 
-         static.USER_EXIT=False
-         static.TIMER=wm.event_timer_add(0.1,window=context.window)
-         wm.modal_handler_add(_)
+      if len(static.JOBINFO) == 0:
+         return {'CANCELLED'}
 
-         cxr_jobs_update_graph( static.JOBINFO )
-         scene_redraw()
-         return {'RUNNING_MODAL'}
+      static.USER_EXIT=False
+      static.TIMER=wm.event_timer_add(0.1,window=context.window)
+      wm.modal_handler_add(_)
 
-      print("Chain exiting...")
-      static.USER_EXIT=True
+      cxr_jobs_update_graph( static.JOBINFO )
+      scene_redraw()
       return {'RUNNING_MODAL'}
 
 class CXR_RESET_HASHES(bpy.types.Operator):
@@ -1885,7 +2041,11 @@ class CXR_INTERFACE(bpy.types.Panel):
       box.operator("convexer.detect_compilers")
       box.prop(settings, "exe_studiomdl")
       box.prop(settings, "exe_vbsp")
+      box.prop(settings, "opt_vbsp")
+
       box.prop(settings, "exe_vvis")
+      box.prop(settings, "opt_vvis")
+
       box.prop(settings, "exe_vrad")
       box.prop(settings, "opt_vrad")
 
@@ -1895,6 +2055,7 @@ class CXR_INTERFACE(bpy.types.Panel):
       row.prop(settings,"comp_textures")
       row.prop(settings,"comp_models")
       row.prop(settings,"comp_compile")
+      row.prop(settings,"comp_pack")
       
       text = "Compile" if CXR_COMPILER_CHAIN.TIMER == None else "Cancel"
       row = box.row()
@@ -2018,7 +2179,7 @@ def cxr_entity_changeclass(_,context):
       entdef = cxr_entities[classname]
 
       kvs = entdef['keyvalues']
-      if callable(kvs): kvs = kvs(active_object)
+      if callable(kvs): kvs = kvs( {'object': active_object} )
 
       for k in kvs:
          kv = kvs[k]
@@ -2056,6 +2217,9 @@ class CXR_ENTITY_PANEL(bpy.types.Panel):
             _.layout.prop( active_object.cxr_data, 'brushclass' )
          else: _.layout.prop( active_object.cxr_data, 'classname' )
 
+         _.layout.prop( active_object.cxr_data, 'visgroup' )
+         _.layout.prop( active_object.cxr_data, 'lightmap_override' )
+
          if classname == 'NONE':
             return
       else: 
@@ -2104,6 +2268,26 @@ class CXR_LIGHT_PANEL(bpy.types.Panel):
          elif active_object.type == 'LIGHT_PROBE':
             layout.prop( properties, "size" )
 
+class CXR_COLLECTION_PANEL(bpy.types.Panel):
+   bl_label = "Source Settings"
+   bl_idname = "COL_PT_cxr"
+   bl_space_type = 'PROPERTIES'
+   bl_region_type = 'WINDOW'
+   bl_context = "collection"
+   
+   def draw(self, context):
+      layout = self.layout
+      scene = context.scene
+      
+      active_collection = bpy.context.collection
+      
+      if active_collection != None:
+         layout.prop( active_collection.cxr_data, "shadow_caster" )
+         layout.prop( active_collection.cxr_data, "texture_shadows" )
+         layout.prop( active_collection.cxr_data, "preserve_order" )
+         layout.prop( active_collection.cxr_data, "surfaceprop" )
+         layout.prop( active_collection.cxr_data, "visgroup" )
+
 # Settings groups
 # ------------------------------------------------------------------------------
 
@@ -2173,10 +2357,25 @@ class CXR_ENTITY_SETTINGS(bpy.types.PropertyGroup):
 
    brushclass: bpy.props.EnumProperty(items=enum_brushents, name="Class", \
          update=cxr_entity_changeclass, default='NONE' )
+   
+   enum_classes = [('0',"None","")]
+   for i, vg in enumerate(cxr_visgroups):
+      enum_classes += [(str(i+1),vg,"")]
+   visgroup: bpy.props.EnumProperty(name="visgroup",items=enum_classes,default=0)
+   lightmap_override: bpy.props.IntProperty(name="Lightmap Override",default=0)
 
 class CXR_MODEL_SETTINGS(bpy.types.PropertyGroup):
    last_hash: bpy.props.StringProperty( name="" )
    asset_id: bpy.props.IntProperty(name="vmf_settings",default=0)
+   shadow_caster: bpy.props.BoolProperty( name="Shadow caster", default=True )
+   texture_shadows: bpy.props.BoolProperty( name="Texture Shadows", default=False )
+   preserve_order: bpy.props.BoolProperty( name="Preserve Order", default=False )
+   surfaceprop: bpy.props.StringProperty( name="Suface prop",default="default" )
+
+   enum_classes = [('0',"None","")]
+   for i, vg in enumerate(cxr_visgroups):
+      enum_classes += [(str(i+1),vg,"")]
+   visgroup: bpy.props.EnumProperty(name="visgroup",items=enum_classes,default=0)
 
 class CXR_SCENE_SETTINGS(bpy.types.PropertyGroup):
    project_name: bpy.props.StringProperty( name="Project Name" )
@@ -2210,6 +2409,7 @@ class CXR_SCENE_SETTINGS(bpy.types.PropertyGroup):
    comp_models: bpy.props.BoolProperty(name="Models",default=True)
    comp_textures: bpy.props.BoolProperty(name="Textures",default=True)
    comp_compile: bpy.props.BoolProperty(name="Compile",default=True)
+   comp_pack: bpy.props.BoolProperty(name="Pack",default=False)
 
 classes = [ CXR_RELOAD, CXR_DEV_OPERATOR, CXR_INTERFACE, \
             CXR_MATERIAL_PANEL, CXR_IMAGE_SETTINGS,\
@@ -2217,7 +2417,7 @@ classes = [ CXR_RELOAD, CXR_DEV_OPERATOR, CXR_INTERFACE, \
             CXR_LIGHT_SETTINGS, CXR_SCENE_SETTINGS, CXR_DETECT_COMPILERS,\
             CXR_ENTITY_PANEL, CXR_LIGHT_PANEL, CXR_PREVIEW_OPERATOR,\
             CXR_VIEW3D, CXR_COMPILER_CHAIN, CXR_RESET_HASHES,\
-            CXR_COMPILE_MATERIAL]
+            CXR_COMPILE_MATERIAL, CXR_COLLECTION_PANEL ]
 
 vmt_param_dynamic_class = None