Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COLLADA - Materials missing not None in Scene #67

Open
EtaLoop opened this issue Oct 15, 2024 · 2 comments
Open

COLLADA - Materials missing not None in Scene #67

EtaLoop opened this issue Oct 15, 2024 · 2 comments

Comments

@EtaLoop
Copy link
Contributor

EtaLoop commented Oct 15, 2024

If some materials are omitted, there are not set to None in Scene. Instead there are Some with default values.
I don't know if that's the behavior wanted. If that the case, it would be nice to see that in the documentation ;-)

Example :

let cube = r##"<?xml version="1.0" encoding="utf-8"?>
    <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <asset>
        <contributor>
        <author>Blender User</author>
        <authoring_tool>Blender 2.79.0 commit date:2018-03-22, commit time:14:10, hash:f4dc9f9d68b</authoring_tool>
        </contributor>
        <created>2018-11-19T22:54:36</created>
        <modified>2018-11-19T22:54:36</modified>
        <unit name="meter" meter="1"/>
        <up_axis>Z_UP</up_axis>
    </asset>
    <library_images/>
    <library_effects>
        <effect id="Material-effect">
        <profile_COMMON>
            <technique sid="common">
            <phong>
                <specular>
                <color sid="specular">0.5 0.5 0.5 1</color>
                </specular>
            </phong>
            </technique>
        </profile_COMMON>
        </effect>
    </library_effects>
    <library_materials>
        <material id="Material-material" name="Material">
            <instance_effect url="#Material-effect"/>
        </material>
    </library_materials>
    <library_geometries>
        <geometry id="Cube_001-mesh" name="Cube.001">
        <mesh>
            <source id="Cube_001-mesh-positions">
            <float_array id="Cube_001-mesh-positions-array" count="24">-0.5 -0.5 -0.5 -0.5 -0.5 0.5 -0.5 0.5 -0.5 -0.5 0.5 0.5 0.5 -0.5 -0.5 0.5 -0.5 0.5 0.5 0.5 -0.5 0.5 0.5 0.5</float_array>
            <technique_common>
                <accessor source="#Cube_001-mesh-positions-array" count="8" stride="3">
                <param name="X" type="float"/>
                <param name="Y" type="float"/>
                <param name="Z" type="float"/>
                </accessor>
            </technique_common>
            </source>
            <source id="Cube_001-mesh-normals">
            <float_array id="Cube_001-mesh-normals-array" count="18">-1 0 0 0 1 0 1 0 0 0 -1 0 0 0 -1 0 0 1</float_array>
            <technique_common>
                <accessor source="#Cube_001-mesh-normals-array" count="6" stride="3">
                <param name="X" type="float"/>
                <param name="Y" type="float"/>
                <param name="Z" type="float"/>
                </accessor>
            </technique_common>
            </source>
            <vertices id="Cube_001-mesh-vertices">
            <input semantic="POSITION" source="#Cube_001-mesh-positions"/>
            </vertices>
            <triangles material="Material-material" count="12">
            <input semantic="VERTEX" source="#Cube_001-mesh-vertices" offset="0"/>
            <input semantic="NORMAL" source="#Cube_001-mesh-normals" offset="1"/>
            <p>1 0 2 0 0 0 3 1 6 1 2 1 7 2 4 2 6 2 5 3 0 3 4 3 6 4 0 4 2 4 3 5 5 5 7 5 1 0 3 0 2 0 3 1 7 1 6 1 7 2 5 2 4 2 5 3 1 3 0 3 6 4 4 4 0 4 3 5 1 5 5 5</p>
            </triangles>
        </mesh>
        </geometry>
    </library_geometries>
    <library_controllers/>
    <library_visual_scenes>
        <visual_scene id="Scene" name="Scene">
        <node id="Cube" name="Cube" type="NODE">
            <matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
            <instance_geometry url="#Cube_001-mesh" name="Cube">
            <bind_material>
                <technique_common>
                <instance_material symbol="Material-material" target="#Material-material"/>
                </technique_common>
            </bind_material>
            </instance_geometry>
        </node>
        </visual_scene>
    </library_visual_scenes>
    <scene>
        <instance_visual_scene url="#Scene"/>
    </scene>
    </COLLADA>
    "##;

    let scene = mesh_loader::collada::from_str(&cube);

    if let Ok(scene) = scene {
        println!("mat : {:?}", scene.materials);
        assert_eq!(scene.materials[0].color.emissive, None);
        assert_eq!(scene.materials[0].color.ambient, None);
        assert_eq!(scene.materials[0].index_of_refraction, None);
        assert_eq!(scene.materials[0].color.diffuse, None);
        assert_eq!(scene.materials[0].shininess, None);
    }
@taiki-e
Copy link
Contributor

taiki-e commented Oct 15, 2024

The relevant code is here, and IIRC the behavior here is mostly refers that of assimp. (However, some of it is specified in the spec.)

emission: ColorAndTexture::new([0.0, 0.0, 0.0, 1.0]),
ambient: ColorAndTexture::new([0.1, 0.1, 0.1, 1.0]),
diffuse: ColorAndTexture::new([0.6, 0.6, 0.6, 1.0]),
specular: ColorAndTexture::new([0.4, 0.4, 0.4, 1.0]),
// refs: https://www.khronos.org/files/collada_spec_1_5.pdf#page=250
transparent: ColorAndTexture::new([1.0, 1.0, 1.0, 1.0]),
reflective: ColorAndTexture::new([0.0, 0.0, 0.0, 1.0]),
shininess: 10.0,
index_of_refraction: 1.0,
reflectivity: 0.0,
// refs: https://www.khronos.org/files/collada_spec_1_5.pdf#page=250
transparency: 1.0,

We refer to the behavior of assimp because this library was started to replace the use of assimp in our other projects, and it was more convenient to have the same behavior. And the STL parser has a similar behavior.

mesh-loader/src/stl/mod.rs

Lines 147 to 148 in 44ad136

// Use the same default color (light gray) as assimp: https://github.com/assimp/assimp/blob/v5.3.1/code/AssetLib/STL/STLLoader.cpp#L183-L184
let mut default_color = [0.6, 0.6, 0.6, 0.6];

That said, the OBJ parser, which was added later than these two parsers, does not have this behavior (defaults to None), and in fact, it may make sense to all parsers do the same as the OBJ parser (aside from the default value specified in the spec).

mesh-loader/src/obj/mod.rs

Lines 1189 to 1205 in 44ad136

// Colors
ambient: Option<[f32; 3]>,
diffuse: Option<[f32; 3]>,
specular: Option<[f32; 3]>,
emissive: Option<[f32; 3]>,
alpha: Option<f32>,
shininess: Option<f32>,
illumination_model: Option<u8>,
index_of_refraction: Option<f32>,
transparent: Option<[f32; 3]>,
roughness: Option<f32>,
metallic: Option<f32>,
sheen: Option<[f32; 3]>,
clearcoat_thickness: Option<f32>,
clearcoat_roughness: Option<f32>,
anisotropy: Option<f32>,

@EtaLoop
Copy link
Contributor Author

EtaLoop commented Oct 15, 2024

Ok I understand 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants