assimp / assimp

The official Open-Asset-Importer-Library Repository. Loads 40+ 3D-file-formats into one unified and clean data structure.
https://www.assimp.org
Other
10.96k stars 2.91k forks source link

Material property IsTwoSided not work #2900

Open renanfaccin opened 4 years ago

renanfaccin commented 4 years ago

When I export a WPF 3D model to GLB format, and to open it later in a viewer like Babylon.JS/glTF Viewer some sides are hidden it when rotate camera. The Assimp library (AssimpNet) has a property for enable double side, IsTwoSided property, however, is not work when I set true value.

Code snippet: 3863116168-image 1

Follows the evidence of the problem:

Original model 3863116168-image 1

Model opened in Babylon.JS viewer 3863116168-image 1

Would appreciate if you can help me.

andersonnichele commented 4 years ago

I have the same problem. When you set IsTwoSided as true, AssimpNet calls the code above:

            set
            {
                MaterialProperty prop = GetProperty(AiMatKeys.TWOSIDED);

                if(prop == null)
                {
                    prop = new MaterialProperty(AiMatKeys.TWOSIDED_BASE, value);
                    AddProperty(prop);
                }

                prop.SetBooleanValue(value);
            }

The value of AiMatKeys.TWOSIDED_BASE is "$mat.twosided".

A glTF/GLB material with value twosided as true should define the backside color.

swx2k commented 4 years ago

export of doubleSided does not work since the exporter uses a boolean variable instead of an integer. Since there is no handling of boolean property values it is treated as a buffer instead which causes the Get function to fail. A simple workaround could be to do: int doubleSided = 0; mat->Get(AI_MATKEY_TWOSIDED, doubleSided); m->doubleSided = doubleSided != 0;