Skip to content

Commit

Permalink
Ensure light exists
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Dec 4, 2024
1 parent 0ff48f4 commit 99e3275
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 12 additions & 4 deletions base/sources/util_render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ function util_render_make_material_preview() {
let saved_fov: f32 = scene_camera.data.fov;
scene_camera.data.fov = 0.92;
viewport_update_camera_type(camera_type_t.PERSPECTIVE);
let light: light_object_t = scene_lights[0];
let _light_strength: f32 = light.data.strength;

let light: light_object_t = scene_lights.length > 0 ? scene_lights[0]: null;
let _light_strength: f32 = light != null ? light.data.strength : 0.0;
if (light != null) {
light.data.strength = 0;
}

let probe: world_data_t = scene_world;
let _probe_strength: f32 = probe.strength;
light.data.strength = 0;
probe.strength = 7;
let _envmap_angle: f32 = context_raw.envmap_angle;
context_raw.envmap_angle = 6.0;
Expand Down Expand Up @@ -69,7 +73,11 @@ function util_render_make_material_preview() {
scene_camera.data.fov = saved_fov;
camera_object_build_proj(scene_camera);
camera_object_build_mat(scene_camera);
light.data.strength = _light_strength;

if (light != null) {
light.data.strength = _light_strength;
}

probe.strength = _probe_strength;
context_raw.envmap_angle = _envmap_angle;
context_raw.brush_scale = _brush_scale;
Expand Down
10 changes: 7 additions & 3 deletions base/sources/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ function viewport_zoom(f: f32) {

function viewport_update_camera_type(camera_type: i32) {
let cam: camera_object_t = scene_cameras[0];
let light: light_object_t = scene_lights[0];
let light: light_object_t = scene_lights.length > 0 ? scene_lights[0] : null;
if (camera_type == camera_type_t.PERSPECTIVE) {
cam.data.ortho = null;
light.base.visible = true;
if (light != null) {
light.base.visible = true;
}
}
else {
let f32a: f32_array_t = f32_array_create(4);
Expand All @@ -90,7 +92,9 @@ function viewport_update_camera_type(camera_type: i32) {
f32a[2] = -2 * f * (app_h() / app_w());
f32a[3] = 2 * f * (app_h() / app_w());
cam.data.ortho = f32a;
light.base.visible = false;
if (light != null) {
light.base.visible = false;
}
}
camera_object_build_proj(cam);
context_raw.ddirty = 2;
Expand Down

0 comments on commit 99e3275

Please sign in to comment.