Refactor el big #2
[convexer.git] / __init__.py
index 624bce098f7740768c3f6e2204ff5c4b25e67bdb..8cc9638c943c8d88247529c9640eda238b4049ab 100644 (file)
@@ -33,7 +33,7 @@ libc_dlclose.argtypes = [c_void_p]
 c_libcxr_log_callback = None
 c_libcxr_line_callback = None
 
-libcxr_decompose = None
+libcxr_write_test_data = None
 libcxr_context_reset = None
 libcxr_set_offset = None
 libcxr_set_scale_factor = None
@@ -223,14 +223,13 @@ class CXR_RELOAD(bpy.types.Operator):
       print( F"libcxr build time: {build_time.value}" )
    
       # Public API
-      global libcxr_decompose
-      global libcxr_convert_mesh_to_vmf
+      global libcxr_write_test_data, libcxr_convert_mesh_to_vmf
 
-      libcxr_decompose = libcxr.cxr_decompose
-      libcxr_decompose.argtypes = [\
+      libcxr_write_test_data = libcxr.cxr_write_test_data
+      libcxr_write_test_data.argtypes = [\
          POINTER(cxr_input_mesh)
       ]
-      libcxr_decompose.restype = c_int32
+      libcxr_write_test_data.restype = c_int32
 
       libcxr_convert_mesh_to_vmf = libcxr.cxr_convert_mesh_to_vmf
       libcxr_convert_mesh_to_vmf.argtypes = [\
@@ -587,8 +586,8 @@ def ent_lights(obj,context):
    kvs = ent_baseclass([ent_origin],\
    {
       "_distance": (0.0 if obj.data.cxr_data.realtime else -1.0),
-      "_light": [int(pow(obj.data.color[i],1.0/2.2)*255.0) for i in range(3)] + \
-                [int(obj.data.energy * bpy.context.scene.cxr_data.light_scale) ],
+      "_light": [int(pow(obj.data.color[i],1.0/2.2)*255.0) for i in range(3)] +\
+                [int(obj.data.energy * bpy.context.scene.cxr_data.light_scale)],
       "_lightHDR": '-1 -1 -1 1',
       "_lightscaleHDR": 1
    })
@@ -607,9 +606,11 @@ def ent_lights(obj,context):
       
       kvs['pitch'] = math.asin(fwd[2]) * 57.295779513
       kvs['angles'] = [ 0.0, math.atan2(fwd[1],fwd[0]) * 57.295779513, 0.0 ]
-      kvs['_quadratic_attn'] = 0.0  # Source spotlights + quadratic falloff look awful.
-                                    # Blender's default has a much more 'accurate' look
-                                    # They appear correct when using linear scale.
+      kvs['_quadratic_attn'] = 0.0  # Source spotlights + quadratic falloff look
+                                    # Really bad...
+                                    #
+                                    # Blender's default has a much more 'nice'
+                                    # look.
       kvs['_linear_attn'] = 1.0
    
    elif obj.data.type == 'POINT':
@@ -993,9 +994,12 @@ class CXR_WRITE_VMF(bpy.types.Operator):
          _collect.geo = []
          _collect.heros = []
 
-         transform_main = cxr_object_context( context.scene.cxr_data.scale_factor, 0.0 )
-         transform_sky = cxr_object_context( context.scene.cxr_data.skybox_scale_factor, \
-                                             context.scene.cxr_data.skybox_offset )
+         transform_main = cxr_object_context( \
+               context.scene.cxr_data.scale_factor, 0.0 )
+
+         transform_sky = cxr_object_context( \
+               context.scene.cxr_data.skybox_scale_factor, \
+               context.scene.cxr_data.skybox_offset )
          
          if 'main' in bpy.data.collections:
             _collect( bpy.data.collections['main'], transform_main )
@@ -1047,9 +1051,9 @@ class CXR_WRITE_VMF(bpy.types.Operator):
 
       return {'FINISHED'}
 
-class CXR_DECOMPOSE_SOLID(bpy.types.Operator):
-   bl_idname="convexer.decompose_solid"
-   bl_label="Decompose Solid"
+class CXR_DEV_OPERATOR(bpy.types.Operator):
+   bl_idname="convexer.dev_test"
+   bl_label="Export development data"
 
    def execute(_,context):
       libcxr_use()
@@ -1058,7 +1062,7 @@ class CXR_DECOMPOSE_SOLID(bpy.types.Operator):
       mesh_src = mesh_cxr_format(context.active_object)
       
       libcxr_reset_debug_lines()
-      libcxr_decompose( pointer(mesh_src) )
+      libcxr_write_test_data( pointer(mesh_src) )
       libcxr_batch_debug_lines()
          
       scene_redraw()
@@ -1073,7 +1077,7 @@ class CXR_INTERFACE(bpy.types.Panel):
 
    def draw(_,context):
       _.layout.operator("convexer.reload")
-      _.layout.operator("convexer.decompose_solid")
+      _.layout.operator("convexer.dev_test")
       _.layout.operator("convexer.write_vmf")
 
       settings = context.scene.cxr_data
@@ -1299,7 +1303,8 @@ class CXR_MATERIAL_PANEL(bpy.types.Panel):
                expandview = True
                drawthis = True
 
-               if 'shaders' in pdef and properties.shader not in pdef['shaders']:
+               if ('shaders' in pdef) and \
+                  (properties.shader not in pdef['shaders']):
                   continue
 
                if ptype == 'intrinsic':
@@ -1325,7 +1330,7 @@ class CXR_MATERIAL_PANEL(bpy.types.Panel):
                      else:
                         # hidden intrinsic value.
                         # Means its a float array or something not an image
-                        thisnode.label( text=F"-- hidden intrinsic '{decl}' --" )
+                        thisnode.label(text=F"-- hidden intrinsic '{decl}' --")
                   else:
                      thisnode.prop(properties,decl)
                   if expandview: _mview(pdef,thisnode)
@@ -1368,12 +1373,15 @@ class CXR_ENTITY_PANEL(bpy.types.Panel):
 
       if active_object == None: return
       
-      default_context = cxr_object_context( bpy.context.scene.cxr_data.scale_factor, 0.0 )
+      default_context = cxr_object_context( \
+            bpy.context.scene.cxr_data.scale_factor, 0.0 )
+
       ecn = cxr_intrinsic_classname( active_object )
       classname = cxr_custom_class( active_object )
 
       if ecn == None: 
-         if active_object.type == 'MESH': _.layout.prop( active_object.cxr_data, 'brushclass' )
+         if active_object.type == 'MESH': 
+            _.layout.prop( active_object.cxr_data, 'brushclass' )
          else: _.layout.prop( active_object.cxr_data, 'classname' )
 
          if classname == 'NONE':
@@ -1502,13 +1510,17 @@ class CXR_SCENE_SETTINGS(bpy.types.PropertyGroup):
    opt_vrad: bpy.props.StringProperty( name="args" )
 
    debug: bpy.props.BoolProperty(name="Debug",default=False)
-   scale_factor: bpy.props.FloatProperty(name="VMF Scale factor",default=32.0,min=1.0)
-   skybox_scale_factor: bpy.props.FloatProperty(name="Sky Scale factor",default=1.0,min=0.01)
+   scale_factor: bpy.props.FloatProperty( name="VMF Scale factor", \
+         default=32.0,min=1.0)
+   skybox_scale_factor: bpy.props.FloatProperty( name="Sky Scale factor", \
+         default=1.0,min=0.01)
+
    skybox_offset: bpy.props.FloatProperty(name="Sky offset",default=-4096.0)
    light_scale: bpy.props.FloatProperty(name="Light Scale",default=1.0/5.0)
-   displacement_cardinal: bpy.props.BoolProperty(name="Cardinal displacements",default=True)
-   include_names: bpy.props.BoolProperty(name="Append original file names",default=True)
-   lightmap_scale: bpy.props.IntProperty(name="Global Lightmap Scale",default=12)
+   include_names: bpy.props.BoolProperty(name="Append original file names",\
+         default=True)
+   lightmap_scale: bpy.props.IntProperty(name="Global Lightmap Scale",\
+         default=12)
 
 class CXR_DETECT_COMPILERS(bpy.types.Operator):
    bl_idname="convexer.detect_compilers"
@@ -1526,7 +1538,7 @@ class CXR_DETECT_COMPILERS(bpy.types.Operator):
 
       return {'FINISHED'}
 
-classes = [ CXR_RELOAD, CXR_DECOMPOSE_SOLID, CXR_INTERFACE, \
+classes = [ CXR_RELOAD, CXR_DEV_OPERATOR, CXR_INTERFACE, \
             CXR_WRITE_VMF, CXR_MATERIAL_PANEL, CXR_IMAGE_SETTINGS,\
             CXR_MODEL_SETTINGS, CXR_ENTITY_SETTINGS, CXR_CUBEMAP_SETTINGS,\
             CXR_LIGHT_SETTINGS, CXR_SCENE_SETTINGS, CXR_DETECT_COMPILERS,\
@@ -1596,7 +1608,8 @@ def register():
                  '') for _ in cxr_shaders],\
       default = next(iter(cxr_shaders)))
    
-   annotations_dict["asset_id"] = bpy.props.IntProperty(name="intl_assetid",default=0)
+   annotations_dict["asset_id"] = bpy.props.IntProperty(name="intl_assetid",\
+         default=0)
 
    _dvmt_propogate( cxr_shader_params )
    vmt_param_dynamic_class = type(