FileModelVisual3D and opacity

Sep 20, 2013 at 4:42 PM
Hi,
I don't know how to change the opacity of an FileModelVisual3D object.
Somebody can help me...
Coordinator
Sep 29, 2013 at 8:03 AM
Try to traverse the visual tree below the FileModelVisual3D and replace the materials in the GeometryModel3D objects.
Sep 29, 2013 at 8:55 AM
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...
Jul 30, 2014 at 12:59 PM
Hi,
Anybody knows how to retrieve geometryModel3D from FileModelVisual3D ?
Jul 30, 2014 at 5:24 PM
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.