diff --git a/core/entity.jai b/core/entity.jai index cdf04ce..9cfd41b 100644 --- a/core/entity.jai +++ b/core/entity.jai @@ -162,6 +162,11 @@ get_node_world_position :: (e: *Entity, node_name: string) -> Vector3 { } load_model_into_entity :: (e: *Entity, handle: Model_Handle) { + if handle == 0 { + log_error("MODEL: Attempted to load model into entity of type %, but the model handle is zero. This probably means that the model has not been loaded properly.\n", e.type); + return; + } + model := get_model_by_handle(handle); e.renderable.type = .MODEL; diff --git a/editor/editor_ui.jai b/editor/editor_ui.jai index b762dcf..a8182ad 100644 --- a/editor/editor_ui.jai +++ b/editor/editor_ui.jai @@ -167,7 +167,9 @@ base_editor_update :: () { } camera := *engine.editor.camera; - blocking_input := ImGui.GetIO().WantCaptureMouse || ImGui.GetIO().WantCaptureKeyboard; + + capture_mouse := ImGui.GetIO().WantCaptureMouse; + capture_keyboard := ImGui.GetIO().WantCaptureKeyboard; if engine.editor.focused_widget == null && engine.mode == .EDITING { engine.editor.should_check_entities = true; @@ -184,14 +186,14 @@ base_editor_update :: () { //coordinates := Vector2.{engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.y}; ray := normalized_screen_to_ray(engine.editor.camera, coordinates); - if !blocking_input { + if !capture_mouse { if update_transform_gizmo(ray, coordinates) { engine.editor.should_check_entities = false; } } } - if !blocking_input { + if !capture_keyboard { if key_pressed(.CTRL) && key_down(.Z) { undo(); } diff --git a/physics/physx.jai b/physics/physx.jai index 6893bb4..ba44bd0 100644 --- a/physics/physx.jai +++ b/physics/physx.jai @@ -172,7 +172,6 @@ add_physx_capsule :: (entity: *Entity, half_height: float, radius: float) -> Phy shape := PhysX.PxPhysics_createShape(physics, *geo, material, false, PHYSX_DEFAULT_SHAPE_FLAGS); PhysX.PxRigidActor_attachShape(actor, shape); - PhysX.PxRigidBodyExt_updateMassAndInertia(actor, 0.1, null, false); PhysX.PxScene_addActor(entity.scene.physx_scene.scene, actor, null); @@ -188,9 +187,10 @@ add_physx_capsule :: (entity: *Entity, half_height: float, radius: float) -> Phy return entity.physx_handle; } -add_physx_box :: (entity: *Entity, half_extent: Vector3) -> PhysX_Handle { +add_physx_box :: (entity: *Entity, half_extent: Vector3, offset: Vector3 = .{}) -> PhysX_Handle { shape := PhysX.PxPhysics_createShape(physics, PhysX.PxBoxGeometry_new(half_extent), material, false, PHYSX_DEFAULT_SHAPE_FLAGS); - t := PhysX.PxTransform_new(*entity.transform.position); + pos := entity.transform.position + offset; + t := PhysX.PxTransform_new(*pos, *entity.transform.orientation); body := PhysX.PxPhysics_createRigidStatic(physics, *t); PhysX.PxRigidActor_attachShape(body, shape); diff --git a/renderer/model.jai b/renderer/model.jai index 0f2b3bc..1d0e845 100644 --- a/renderer/model.jai +++ b/renderer/model.jai @@ -293,7 +293,7 @@ parse_fbx_node :: (model: *Model, fbx_node: *ufbx_node) { num_vertices := ufbx_generate_indices(streams.data, num_streams, indices.data, num_indices, null, *error); if error.type != .UFBX_ERROR_NONE { - log_error("Failed to generate index buffer\n"); + log_error("FBX_LOADING: Failed to generate index buffer\n"); } array_reserve(*mesh.indices, xx num_indices); @@ -603,7 +603,12 @@ load_fbx :: (path: string) -> Model_Handle, bool { scene := ufbx_load_file(to_temp_c_string(path), *opts, *error); if scene == null { - log_error("FBX '%' could not be loaded", path); + log_error("FBX_LOADING: FBX '%' could not be loaded.\n", path); + return 0, false; + } + + if scene.materials.count == 0 { + log_error("FBX_LOADING: FBX '%' doesn't contain any material data. Currently Coven only supports fbx files that have materials on every mesh.\n", path); return 0, false; } @@ -613,35 +618,49 @@ load_fbx :: (path: string) -> Model_Handle, bool { model.name = copy_string(path); // Materials - for i: 0..scene.materials.count - 1 { - mat := scene.materials.data[i]; - model_material : Model_Material; - model_material.textures.base_color = load_fbx_texture(mat.pbr.base_color, format=.R8G8B8A8_UNORM_SRGB); - model_material.textures.normal = load_fbx_texture(mat.pbr.normal_map, format=.R8G8B8A8_UNORM); + if scene.materials.count > 0 { + for i: 0..scene.materials.count - 1 { + model_material : Model_Material; + model_material.base_color.x = 0.3; + model_material.base_color.y = 0.3; + model_material.base_color.z = 0.3; + model_material.base_color.w = 1.0; - for 0..mat.props.props.count-1 { - prop := mat.props.props.data[it]; - prop_name := to_string(prop.name.data,, allocator=temp); - if prop_name == "DiffuseColor" { - model_material.base_color.x = xx prop.value_vec3.x; - model_material.base_color.y = xx prop.value_vec3.y; - model_material.base_color.z = xx prop.value_vec3.z; - model_material.base_color.w = 1.0; + mat := scene.materials.data[i]; + model_material.textures.base_color = load_fbx_texture(mat.pbr.base_color, format=.R8G8B8A8_UNORM_SRGB); + model_material.textures.normal = load_fbx_texture(mat.pbr.normal_map, format=.R8G8B8A8_UNORM); + + for 0..mat.props.props.count-1 { + prop := mat.props.props.data[it]; + prop_name := to_string(prop.name.data,, allocator=temp); + if prop_name == "DiffuseColor" { + model_material.base_color.x = xx prop.value_vec3.x; + model_material.base_color.y = xx prop.value_vec3.y; + model_material.base_color.z = xx prop.value_vec3.z; + model_material.base_color.w = 1.0; + } } + //mat.pbr.base_factor; + //create_texture :: (using renderer: *Renderer, data: *void, width: u32, height: u32, channels: u32, path: string = "", generate_mips: bool = true) -> Texture_Handle { + //Material &dst = materials[i + 1]; + //dst.base_factor.value.x = 1.0f; + //setup_texture(dst.base_factor, mat->pbr.base_factor); + //setup_texture(dst.base_color, mat->pbr.base_color); + //setup_texture(dst.roughness, mat->pbr.roughness); + //setup_texture(dst.metallic, mat->pbr.metalness); + //setup_texture(dst.emission_factor, mat->pbr.emission_factor); + //setup_texture(dst.emission_color, mat->pbr.emission_color); + //dst.base_color.image.srgb = true; + //dst.emission_color.image.srgb = true; + array_add(*model.materials, model_material); } + } else { + model_material : Model_Material; + model_material.base_color.x = 0.3; + model_material.base_color.y = 0.3; + model_material.base_color.z = 0.3; + model_material.base_color.w = 1.0; - //mat.pbr.base_factor; - //create_texture :: (using renderer: *Renderer, data: *void, width: u32, height: u32, channels: u32, path: string = "", generate_mips: bool = true) -> Texture_Handle { - //Material &dst = materials[i + 1]; - //dst.base_factor.value.x = 1.0f; - //setup_texture(dst.base_factor, mat->pbr.base_factor); - //setup_texture(dst.base_color, mat->pbr.base_color); - //setup_texture(dst.roughness, mat->pbr.roughness); - //setup_texture(dst.metallic, mat->pbr.metalness); - //setup_texture(dst.emission_factor, mat->pbr.emission_factor); - //setup_texture(dst.emission_color, mat->pbr.emission_color); - //dst.base_color.image.srgb = true; - //dst.emission_color.image.srgb = true; array_add(*model.materials, model_material); }