Ejemplo n.º 1
0
        void VisualiseModel(ModelBase model)
        {
            Model = new MeshGeometry3D()
            {
                Positions          = model.Positions,
                Indices            = model.Indices,
                Normals            = model.Normals,
                TextureCoordinates = null,
                Tangents           = null,
                BiTangents         = null,
            };

            // визуализация граней
            //var inxs = new IntCollection();
            //model.Edges.ForEach(x => inxs.AddAll(x.Indices));
            //Edges = new LineGeometry3D { Positions = model.Positions, Indices = inxs };

            // визуализация граней Face
            var inxs2 = new IntCollection();

            model.Faces.ForEach(x => x.Edges.ForEach(x2 => inxs2.AddAll(x2.Indices)));
            Edges = new LineGeometry3D {
                Positions = model.Positions, Indices = inxs2
            };
            EdgesColor = Colors.Red;
        }
Ejemplo n.º 2
0
        public void VisualizeFigure(BaseModel m)
        {
            // визуализируем исходный контур
            var(points, inxs) = GetContourPointAndInx(m);
            LineGeometry3D      lineGeom0 = new() { Positions = points, Indices = inxs, };
            LineGeometryModel3D lines     = new() { Geometry = lineGeom0, Color = Colors.Red, Thickness = 3 };

            viewport.Items.Add(lines);

            // визуализируем фигуру
            m.Update();
            var tmp = ToGeometry(m);
            MeshGeometryModel3D model = new() { Geometry = tmp };

            if (m.Error)
            {
                MessageBoxResult result = MessageBox.Show(m.ErrorStr);
            }
            else
            {
                // определяем различные цвета
                var colorAlpha = 0.5f;
                var material   = blueOnlyCheckBox.IsChecked == true
                    ? PhongMaterials.Blue
                    : materials[rnd.Next(0, materials.Count - 1)];
                material.DiffuseColor = new Color4(material.DiffuseColor.ToVector3(), colorAlpha);
                model.Material        = material;
                //model.CullMode = CullMode.Back;
                model.IsTransparent = true;
                viewport.Items.Add(model);
            }

            // визуализируем ребра
            var inxs2 = new IntCollection();

            m.Edges.ForEach(x2 => inxs2.AddAll(x2.Indices));
            m.Faces.ForEach(x => x.Edges.ForEach(x2 => inxs2.AddAll(x2.Indices)));
            LineGeometry3D      lineGeom = new() { Positions = m.Positions, Indices = inxs2, };
            LineGeometryModel3D edge     = new() { Geometry = lineGeom, Color = Colors.Black };

            viewport.Items.Add(edge);
        }

        private MeshGeometry3D ToGeometry(BaseModel m)
        {
            var model = new MeshGeometry3D()
            {
                Positions          = m.Positions,
                Indices            = m.Indices,
                Normals            = m.Normals,
                TextureCoordinates = null,
                Tangents           = null,
                BiTangents         = null,
            };

            return(model);
        }

        private OrthographicCamera _ortoCam = new OrthographicCamera()
        {
            Position = new Point3D(100, 100, 100), LookDirection = new Vector3D(-100, -100, -100), UpDirection = new Vector3D(0, 0, 1), Width = 200, FarPlaneDistance = 1000
        };