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...
#
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
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})
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"
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)
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
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()
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':
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
# ------------------------------------------------------------------------------
_.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" )
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
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",\
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