From: hgn Date: Fri, 15 Apr 2022 09:58:25 +0000 (+0100) Subject: targets, recompile op, sun ent X-Git-Url: https://harrygodden.com/git/?p=convexer.git;a=commitdiff_plain;h=6bbe81afdebbac6738c625a82dc9010569da0fe6 targets, recompile op, sun ent --- diff --git a/__init__.py b/__init__.py index 4fc3eed..06abec0 100644 --- a/__init__.py +++ b/__init__.py @@ -561,26 +561,31 @@ def ent_lights(context): kvs = cxr_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)], "_lightHDR": '-1 -1 -1 1', "_lightscaleHDR": 1 }) - - if obj.data.type == 'SPOT': - kvs['_cone'] = obj.data.spot_size*(57.295779513/2.0) - kvs['_inner_cone'] = (1.0-obj.data.spot_blend)*kvs['_cone'] - # Blenders spotlights are -z forward + light_base = [(pow(obj.data.color[i],1.0/2.2)*255.0) for i in range(3)] +\ + [obj.data.energy * bpy.context.scene.cxr_data.light_scale] + + if obj.data.type == 'SPOT' or obj.data.type == 'SUN': + # Blenders directional lights are -z forward # Source is +x, however, it seems to use a completely different system. # Since we dont care about roll for spotlights, we just take the # pitch and yaw via trig _,mtx_rot,_ = obj.matrix_world.decompose() fwd = mtx_rot @ mathutils.Vector((0,0,-1)) + dir_pitch = math.asin(fwd[2]) * 57.295779513 + dir_yaw = math.atan2(fwd[1],fwd[0]) * 57.295779513 + + if obj.data.type == 'SPOT': + kvs['_light'] = [ int(x) for x in light_base ] + kvs['_cone'] = obj.data.spot_size*(57.295779513/2.0) + kvs['_inner_cone'] = (1.0-obj.data.spot_blend)*kvs['_cone'] - kvs['pitch'] = math.asin(fwd[2]) * 57.295779513 - kvs['angles'] = [ 0.0, math.atan2(fwd[1],fwd[0]) * 57.295779513, 0.0 ] + kvs['pitch'] = dir_pitch + kvs['angles'] = [ 0, dir_yaw, 0 ] kvs['_quadratic_attn'] = 0.0 # Source spotlights + quadratic falloff look # Really bad... # @@ -589,11 +594,22 @@ def ent_lights(context): kvs['_linear_attn'] = 1.0 elif obj.data.type == 'POINT': + kvs['_light'] = [ int(x) for x in light_base] kvs['_quadratic_attn'] = 1.0 kvs['_linear_attn'] = 0.0 elif obj.data.type == 'SUN': - pass # TODO + light_base[3] *= 300.0 * 5 + kvs['_light'] = [ int(x) for x in light_base ] + + ambient = bpy.context.scene.world.color + kvs['_ambient'] = [int(pow(ambient[i],1.0/2.2)*255.0) for i in range(3)] +\ + [80 * 5] + kvs['_ambientHDR'] = [-1,-1,-1,1] + kvs['_AmbientScaleHDR'] = 1 + kvs['pitch'] = dir_pitch + kvs['angles'] = [ dir_pitch, dir_yaw, 0.0 ] + kvs['SunSpreadAngle'] = 0 return kvs @@ -619,6 +635,24 @@ def ent_prop(context): return kvs +def ent_sky_camera(context): + settings = bpy.context.scene.cxr_data + scale = settings.scale_factor / settings.skybox_scale_factor + + kvs = { + "origin": [_ for _ in context['transform']['offset']], + "angles": [ 0, 0, 0 ], + "fogcolor": [255, 255, 255], + "fogcolor2": [255, 255, 255], + "fogdir": [1,0,0], + "fogend": 2000.0, + "fogmaxdensity": 1, + "fogstart": 500.0, + "HDRColorScale": 1.0, + "scale": scale + } + return kvs + def ent_cubemap(context): obj = context['object'] return cxr_baseclass([ent_origin], {"cubemapsize": obj.data.cxr_data.size}) @@ -697,7 +731,7 @@ def cxr_intrinsic_classname(obj): return { 'SPOT': "light_spot", 'POINT': "light", - 'SUN': "light_directional" }[ obj.data.type ] + 'SUN': "light_environment" }[ obj.data.type ] elif obj.type == 'LIGHT_PROBE': return "env_cubemap" @@ -952,6 +986,12 @@ def cxr_scene_collect(): if 'skybox' in bpy.data.collections: _collect( bpy.data.collections['skybox'], transform_sky ) + sceneinfo['entities'] += [{ + "object": None, + "transform": transform_sky, + "classname": "sky_camera" + }] + return sceneinfo # Write VMF out to file (JOB HANDLER) @@ -966,7 +1006,7 @@ def cxr_export_vmf(sceneinfo, output_vmf): vmfinfo.mapversion = 4 #TODO: These need to be in options... - vmfinfo.skyname = b"sky_csgo_night02b" + vmfinfo.skyname = bpy.context.scene.cxr_data.skyname.encode('utf-8') vmfinfo.detailvbsp = b"detail.vbsp" vmfinfo.detailmaterial = b"detail/detailsprites" vmfinfo.lightmap_scale = 12 @@ -1025,7 +1065,9 @@ def cxr_export_vmf(sceneinfo, output_vmf): m.kv( kv[0], ' '.join([str(_) for _ in kv[2]]) ) else: m.kv( kv[0], str(kv[2]) ) - if not isinstance( obj, bpy.types.Collection ): + if obj == None: + pass + elif not isinstance( obj, bpy.types.Collection ): if obj.type == 'MESH': if not _buildsolid( ent ): cxr_batch_lines() @@ -1595,6 +1637,7 @@ class CXR_COMPILER_CHAIN(bpy.types.Operator): return {'CANCELLED'} for ent in sceneinfo['entities']: + if ent['object'] == None: continue if isinstance(ent['object'],bpy.types.Collection): continue if ent['object'].type == 'MESH': @@ -1748,6 +1791,40 @@ class CXR_RESET_HASHES(bpy.types.Operator): return {'FINISHED'} +class CXR_COMPILE_MATERIAL(bpy.types.Operator): + bl_idname="convexer.matcomp" + bl_label="Recompile Material" + + def execute(_,context): + active_obj = bpy.context.active_object + active_mat = active_obj.active_material + + #TODO: reduce code dupe (L1663) + for pair in compile_material(active_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'] + prop.cxr_data.flags = flags + + compile_image( prop ) + + settings = bpy.context.scene.cxr_data + with open(F'{settings.subdir}/cfg/convexer_mat_update.cfg','w') as o: + o.write(F'mat_reloadmaterial {asset_name(active_mat)}') + + # TODO: Move this + with open(F'{settings.subdir}/cfg/convexer.cfg','w') as o: + o.write('sv_cheats 1\n') + o.write('mp_warmup_pausetimer 1\n') + o.write('bot_kick\n') + o.write('alias cxr_reload "exec convexer_mat_update"\n') + + return {'FINISHED'} + # Convexer panels # ------------------------------------------------------------------------------ @@ -1793,6 +1870,8 @@ class CXR_INTERFACE(bpy.types.Panel): _.layout.prop(settings, "debug") _.layout.prop(settings, "scale_factor") + _.layout.prop(settings, "skybox_scale_factor") + _.layout.prop(settings, "skyname" ) _.layout.prop(settings, "lightmap_scale") _.layout.prop(settings, "light_scale" ) _.layout.prop(settings, "image_quality" ) @@ -1841,10 +1920,11 @@ class CXR_MATERIAL_PANEL(bpy.types.Panel): info = material_info( active_material ) _.layout.label(text=F"{info['name']} @{info['res'][0]}x{info['res'][1]}") - _.layout.prop( properties, "shader" ) + row = _.layout.row() + row.prop( properties, "shader" ) + row.operator( "convexer.matcomp" ) - for xk in info: - _.layout.label(text=F"{xk}:={info[xk]}") + #for xk in info: _.layout.label(text=F"{xk}:={info[xk]}") def _mtex( name, img, uiParent ): nonlocal properties @@ -2108,14 +2188,15 @@ class CXR_SCENE_SETTINGS(bpy.types.PropertyGroup): exe_vvis: bpy.props.StringProperty( name="vvis" ) opt_vvis: bpy.props.StringProperty( name="args" ) exe_vrad: bpy.props.StringProperty( name="vrad" ) - opt_vrad: bpy.props.StringProperty( name="args" ) + opt_vrad: bpy.props.StringProperty( name="args", \ + default="-reflectivityScale 0.35 -aoscale 1.4 -final -textureshadows -hdr -StaticPropLighting -StaticPropPolys" ) 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) - + skyname: bpy.props.StringProperty(name="Skyname",default="sky_csgo_night02b") skybox_offset: bpy.props.FloatProperty(name="Sky offset",default=-4096.0) light_scale: bpy.props.FloatProperty(name="Light Scale",default=1.0/5.0) include_names: bpy.props.BoolProperty(name="Append original file names",\ @@ -2135,7 +2216,8 @@ classes = [ CXR_RELOAD, CXR_DEV_OPERATOR, CXR_INTERFACE, \ CXR_MODEL_SETTINGS, CXR_ENTITY_SETTINGS, CXR_CUBEMAP_SETTINGS,\ 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_VIEW3D, CXR_COMPILER_CHAIN, CXR_RESET_HASHES,\ + CXR_COMPILE_MATERIAL] vmt_param_dynamic_class = None diff --git a/config.py b/config.py index 438c044..9ac6b9f 100644 --- a/config.py +++ b/config.py @@ -216,8 +216,10 @@ cxr_entities = \ # Builtin/intrinsic entities, you probably dont want to modify these "light": { "keyvalues": ent_lights }, "light_spot": { "keyvalues": ent_lights }, + "light_environment": { "keyvalues": ent_lights }, "env_cubemap": { "keyvalues": ent_cubemap }, "prop_static": { "keyvalues": ent_prop }, + "sky_camera": { "keyvalues": ent_sky_camera }, # CSGO.fgd # -------- @@ -252,6 +254,11 @@ cxr_entities = \ "TeamNum": {"type": "int", "default": 0 } } }, + "func_bomb_target": + { + "allow": ('MESH',), + "keyvalues": {} + }, "func_detail": { "allow": ('MESH',),