Пример #1
0
        public static TreeViewItem GetTreeItems(IStreamable data, GeometryModel3D[] models)
        {
            if (data == null)
            {
                return(null);
            }

            var t = data.GetType();


            if (t == typeof(IfcViewerWrapper))
            {
                return(IfcVisualizer.GetTreeItems((IfcViewerWrapper)data, models));
            }
            else if (t == typeof(Pointcloud))
            {
                return(PointcloudVisualizer.GetTreeItems((Pointcloud)data, models));
            }
            else
            {
                return(GetStandardTreeItems(data, models));
            }
        }
Пример #2
0
        public static GeometryModel3D[] GetModels(object data)
        {
            if (data == null)
            {
                return(null);
            }

            var t = data.GetType();

            if (t == typeof(List <GeometryModel3D>))
            {
                return(((List <GeometryModel3D>)data).ToArray());
            }

            if (t == typeof(NViewMatch))
            {
                return(NViewMatchVisualizer.GetModels((NViewMatch)data));
            }

            if (t == typeof(NViewMatch[]))
            {
                return(NViewMatchVisualizer.GetModels((NViewMatch[])data));
            }

            if (t == typeof(List <CameraPosition>))
            {
                return(NViewMatchVisualizer.GetModels(new NViewMatch()
                {
                    CameraPositions = (List <CameraPosition>)data
                }));
            }

            if (t == typeof(IfcViewerWrapper))
            {
                return(IfcVisualizer.GetModels((IfcViewerWrapper)data));
            }

            if (t == typeof(Pointcloud))
            {
                return(PointcloudVisualizer.GetModels((Pointcloud)data));
            }

            if (t == typeof(PointGeometry3D))
            {
                return(PointcloudVisualizer.GetModels((PointGeometry3D)data));
            }

            if (t == typeof(CoordinateSystem))
            {
                return(CoordinateSystemVisualizer.GetModels((CoordinateSystem)data));
            }

            if (t == typeof(Model3DGroup))
            {
                var r = new List <MeshGeometryModel3D>();

                var d = (Model3DGroup)data;

                foreach (var dChild in d.Children)
                {
                    var l  = new MeshGeometryModel3D();
                    var gm = (System.Windows.Media.Media3D.GeometryModel3D)dChild;
                    var m  = gm.Geometry as MeshGeometry3D;

                    var geo = new HelixToolkit.Wpf.SharpDX.MeshGeometry3D()
                    {
                        Positions          = new Vector3Collection(),
                        Normals            = new Vector3Collection(),
                        Indices            = new IntCollection(),
                        TextureCoordinates = new Vector2Collection()
                    };

                    foreach (var mPosition in m.Positions)
                    {
                        geo.Positions.Add(new Vector3((float)mPosition.X, (float)mPosition.Y, (float)mPosition.Z));
                    }

                    foreach (var mTriangles in m.TriangleIndices)
                    {
                        geo.Indices.Add(mTriangles);
                    }

                    foreach (var mTriangles in m.TextureCoordinates)
                    {
                        geo.TextureCoordinates.Add(new Vector2((float)mTriangles.X, (float)mTriangles.Y));
                    }

                    foreach (var mNormals in m.Normals)
                    {
                        geo.Normals.Add(new Vector3((float)mNormals.X, (float)mNormals.Y, (float)mNormals.Z));
                    }

                    l.Geometry = geo;

                    var diffuse =
                        (DiffuseMaterial)((MaterialGroup)gm.Material).Children.First(ob => ob is DiffuseMaterial);
                    var specular =
                        (SpecularMaterial)((MaterialGroup)gm.Material).Children.First(ob => ob is SpecularMaterial);


                    l.Material = new PhongMaterial()
                    {
                        AmbientColor  = new Color4(diffuse.AmbientColor.R, diffuse.AmbientColor.G, diffuse.AmbientColor.B, diffuse.AmbientColor.A),
                        DiffuseColor  = new Color4(diffuse.Color.R, diffuse.Color.G, diffuse.Color.B, diffuse.Color.A),
                        SpecularColor = new Color4(specular.Color.R, specular.Color.G, specular.Color.B, specular.Color.A)
                    };

                    if (diffuse.Color.R == 0xFF && diffuse.Color.G == 0xFF && diffuse.Color.B == 0xFF)
                    {
                        l.Material = PhongMaterials.LightGray;
                    }

                    r.Add(l);
                }

                return(r.ToArray());
            }

            return(null);
        }