Day/night cycle sun movement, artist driven camera pos override from blender

main
parent 3972edb455
commit 206a855170

@ -6,6 +6,7 @@ import struct
from mathutils import *; from math import *
from bpy_extras.io_utils import (axis_conversion)
from dataclasses import dataclass
import cProfile
C = bpy.context
D = bpy.data
@ -300,7 +301,7 @@ def collect_and_validate_mesh_objects(collection_with_only_mesh_objects):
return to_return
def get_startswith(name_of_overarching_thing, iterable, starts_with):
def get_startswith(name_of_overarching_thing, iterable, starts_with, required = True):
"""
Gets the thing in iterable that starts with starts with, and makes sure there's only *one* thing that starts with starts with
name_of_overarching_thing is for the error message, for reporting in what collection things went wrong in.
@ -310,7 +311,7 @@ def get_startswith(name_of_overarching_thing, iterable, starts_with):
if thing.name.startswith(starts_with):
assert to_return == None, f"Duplicate thing that starts with '{starts_with}' found in {name_of_overarching_thing} called {thing.name}"
to_return = thing
assert to_return != None, f"Couldn't find thing that starts with '{starts_with}' as a child of '{name_of_overarching_thing}', but one is required"
if required: assert to_return != None, f"Couldn't find thing that starts with '{starts_with}' as a child of '{name_of_overarching_thing}', but one is required"
return to_return
def no_hidden(objects):
@ -373,6 +374,17 @@ def export_meshes_and_levels():
assert o.rotation_euler.order == 'XYZ', f"Invalid rotation euler order for object of name '{o.name}', it's {o.rotation_euler.order} but must be XYZ"
placed_entities.append((name_despite_copied(o.name), mapping @ o.location, o.rotation_euler, o.scale))
camera_override = None
if True:
camera_object = get_startswith(room_collection.name, room_collection.objects, "Camera", required = False)
if camera_object:
camera_override = mapping @ camera_object.location
write_b8(f, camera_override != None)
if camera_override:
write_f32(f, camera_override.x)
write_f32(f, camera_override.y)
write_f32(f, camera_override.z)
write_u64(f, len(placed_meshes))
for p in placed_meshes:
@ -454,5 +466,8 @@ def export_meshes_and_levels():
print("Success!")
export_armatures()
export_meshes_and_levels()
def export_everything():
export_armatures()
export_meshes_and_levels()
export_everything()
#cProfile.run("export_everything") # gave up optimizing this because after reading this output I'm not sure what the best direction is, it seems like it's just a lot of data, specifically the images, is why it's slow... I could hash them and only write if the hash changes but whatever

Binary file not shown.

@ -1251,6 +1251,8 @@ typedef struct Room
{
struct Room *next;
bool camera_offset_is_overridden;
Vec3 camera_offset;
String8 name;
PlacedMesh *placed_mesh_list;
CollisionCylinder *collision_list;
@ -1326,6 +1328,12 @@ ThreeDeeLevel load_level(Arena *arena, String8 binary_file)
Room *new_room = PushArray(arena, Room, 1);
ser_String8(&ser, &new_room->name, arena);
ser_bool(&ser, &new_room->camera_offset_is_overridden);
if(new_room->camera_offset_is_overridden)
{
ser_Vec3(&ser, &new_room->camera_offset);
}
// placed meshes
{
u64 num_placed = 0;
@ -5813,6 +5821,10 @@ void frame(void)
away_from_player = V3(x, y, 0.0);
}
away_from_player = MulM4V4(Rotate_RH(-PI32/3.0f + PI32, V3(0,1,0)), IsPoint(away_from_player)).xyz;
if(get_cur_room(&gs, &level_threedee)->camera_offset_is_overridden)
{
away_from_player = get_cur_room(&gs, &level_threedee)->camera_offset;
}
Vec3 cam_pos = AddV3(player_pos, away_from_player);
Vec2 movement = { 0 };
@ -5839,17 +5851,11 @@ void frame(void)
Vec3 light_dir;
{
float spin_factor = 0.0f;
float t = (float)elapsed_time * spin_factor;
float x = cosf(t);
float z = sinf(t);
light_dir = NormV3(V3(x, -0.5f, z));
float t = (float)(elapsed_time/3.0f - floor(elapsed_time/3.0f));
Vec3 sun_vector = V3(2.0f*t - 1.0f, sinf(t*PI32), 0.8f); // where the sun is pointing from
light_dir = NormV3(MulV3F(sun_vector, -1.0f));
}
// make movement relative to camera forward
Vec3 facing = NormV3(SubV3(player_pos, cam_pos));
Vec3 right = Cross(facing, V3(0,1,0));
@ -5949,11 +5955,6 @@ void frame(void)
break;
}
if (it->killed)
{
assert(false);
break;
}
if (it->killed)
{
to_use->go_to_animation = S8Lit("Die Backwards");
to_use->next_animation_isnt_looping = true;

@ -65,9 +65,9 @@
//Rendering
#define FIELD_OF_VIEW (PI32/4.0f)
#define FIELD_OF_VIEW (0.6911112070083618) // FOV
#define NEAR_PLANE_DISTANCE (0.01f)
#define FAR_PLANE_DISTANCE (45.0f)
#define FAR_PLANE_DISTANCE (70.0f)
#define SHADOW_MAP_DIMENSION (2048)
// Post-processing

Loading…
Cancel
Save