Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Pycharm settings
.idea
44 changes: 44 additions & 0 deletions blender_bindings/source2/vwrld/entities/cs2_entity_handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

import bpy

from SourceIO.library.source2.data_types.keyvalues3.types import NullObject
Expand Down Expand Up @@ -195,3 +197,45 @@ def handle_light_rect(self, entity: light_rect, entity_raw: dict):

self._set_entity_data(lamp, {'entity': entity_raw})
self._put_into_collection('light_rect', lamp, 'lights')

def handle_light_omni2(self, entity: light_omni2, entity_raw: dict):
name = self._get_entity_name(entity)

# Could also be < 180, but I personally believe we should only count spots that can be implemented in blender
is_spot = entity.outer_angle <= 90

lamp_data = None
lamp = None
angles = []

# TODO: This should probably take in all axes into account
light_source_radius = float(entity.size_params[0]) * self.scale

if is_spot:
lamp_data = bpy.data.lights.new(name + "_DATA", 'SPOT')
lamp = bpy.data.objects.new(name, lamp_data)
# light_omni2 as a spotlight in cs2 is oriented differently to light_spot in hla
# could it be beneficial to re orient the light either way?
angles = get_angles(entity_raw)
angles[0] -= 90

# TODO: I think there should be a better way of correcting outer_angle
lamp_data.spot_size = math.radians(entity.outer_angle * 2)
lamp_data.spot_blend = np.clip(light_source_radius, 0, 1)
else:
lamp_data = bpy.data.lights.new(name + "_DATA", 'POINT')
lamp = bpy.data.objects.new(name, lamp_data)
angles = get_angles(entity_raw)

self._set_location_and_scale(lamp, get_origin(entity_raw))
self._set_rotation(lamp, angles)
scale_vec = get_scale(entity_raw)

color = np.divide(entity.color, 255.0)
brightness = float(entity.brightness)
lamp_data.energy = brightness * 10000 * scale_vec[0] * self.scale
lamp_data.color = color[:3]
lamp_data.shadow_soft_size = light_source_radius

self._set_entity_data(lamp, {'entity': entity_raw})
self._put_into_collection('light_omni2', lamp, 'lights')