0

FileModelVisual3D and opacity

Anonymous 6 years ago 0
This discussion was imported from CodePlex

regha wrote at 2013-09-20 18:42:

Hi,
I don't know how to change the opacity of an FileModelVisual3D object.
Somebody can help me...

objo wrote at 2013-09-29 10:03:

Try to traverse the visual tree below the FileModelVisual3D and replace the materials in the GeometryModel3D objects.

regha wrote at 2013-09-29 10:55:

thanks for your answer but I don't know how 'to traverse the visual tree'...
I can access to children of viewport but after... I don't know...

regha wrote at 2014-07-30 14:59:

Hi,
Anybody knows how to retrieve geometryModel3D from FileModelVisual3D ?

everytimer wrote at 2014-07-30 19:24:

I've never worked with FileModelVisual3D but I'm sure that the way is to try to cast its Content as GeometryModel3D and Model3DGroup:
   Model3DGroup grupo = (Model3DGroup)myFileModelVisual3D.Content;

            foreach (var modelo in grupo.Children.OfType<GeometryModel3D>())
            {
                GeometryModel3D model = (GeometryModel3D)modelo;
                var mat1 = modelo.Material.Clone();
                var mat2 = modelo.BackMaterial.Clone();
                MaterialHelper.ChangeOpacity(mat1, SliderVerifyOpacity.Value);
                MaterialHelper.ChangeOpacity(mat2, SliderVerifyOpacity.Value);

                model.Material = mat1;
                model.BackMaterial = mat2;
            }

            foreach (var group in grupo.Children.OfType<Model3DGroup>())
            {
                Model3DGroup grupoModel = (Model3DGroup)group;
                foreach (var modelo in grupoModel.Children.OfType<GeometryModel3D>())
                {
                    GeometryModel3D model = (GeometryModel3D)modelo;

                    var mat1 = modelo.Material.Clone();
                    var mat2 = modelo.BackMaterial.Clone();
                    MaterialHelper.ChangeOpacity(mat1, SliderVerifyOpacity.Value);
                    MaterialHelper.ChangeOpacity(mat2, SliderVerifyOpacity.Value);

                    model.Material = mat1;
                    model.BackMaterial = mat2;
                }
            }
In this example the opacity is controlled by a Slider, change to a specific value if you want it so.
Good luck.