Removed crash, when fbx has no material. Added rotation + offset to physx boxes

This commit is contained in:
2025-07-18 16:55:31 +02:00
parent 602dd870df
commit 1b339f087b
4 changed files with 59 additions and 33 deletions

View File

@@ -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);
}