Exemplo n.º 1
0
        public static LineGeometry3D CreatePathLines(this IList <BoundingBox> path)
        {
            Vector3[] verts   = new Vector3[8];
            var       builder = new LineBuilder();

            foreach (var box in path)
            {
                verts[0] = box.Minimum;
                verts[1] = new Vector3(box.Minimum.X, box.Minimum.Y, box.Maximum.Z); //Z
                verts[2] = new Vector3(box.Minimum.X, box.Maximum.Y, box.Minimum.Z); //Y
                verts[3] = new Vector3(box.Maximum.X, box.Minimum.Y, box.Minimum.Z); //X

                verts[7] = box.Maximum;
                verts[4] = new Vector3(box.Maximum.X, box.Maximum.Y, box.Minimum.Z); //Z
                verts[5] = new Vector3(box.Maximum.X, box.Minimum.Y, box.Maximum.Z); //Y
                verts[6] = new Vector3(box.Minimum.X, box.Maximum.Y, box.Maximum.Z); //X
                builder.AddLine(verts[0], verts[1]);
                builder.AddLine(verts[0], verts[2]);
                builder.AddLine(verts[0], verts[3]);
                builder.AddLine(verts[7], verts[4]);
                builder.AddLine(verts[7], verts[5]);
                builder.AddLine(verts[7], verts[6]);

                builder.AddLine(verts[1], verts[6]);
                builder.AddLine(verts[1], verts[5]);
                builder.AddLine(verts[4], verts[2]);
                builder.AddLine(verts[4], verts[3]);
                builder.AddLine(verts[2], verts[6]);
                builder.AddLine(verts[3], verts[5]);
            }
            return(builder.ToLineGeometry3D());
        }
Exemplo n.º 2
0
        public static LineGeometry3D CreateOctreeLineModel(this IOctree tree)
        {
            var builder = new LineBuilder();

            CreateOctreeLineModel(tree, builder);
            return(builder.ToLineGeometry3D());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates a square grid with a step of 1.0
        /// </summary>
        /// <returns></returns>
        public static LineGeometry3D GenerateGrid(Vector3 plane, int min = 0, int max = 10)
        {
            var grid = new LineBuilder();

            //int width = max - min;
            if (plane == Vector3.UnitX)
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(0, i, min), new Vector3(0, i, max));
                    grid.AddLine(new Vector3(0, min, i), new Vector3(0, max, i));
                }
            }
            else if (plane == Vector3.UnitY)
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(i, 0, min), new Vector3(i, 0, max));
                    grid.AddLine(new Vector3(min, 0, i), new Vector3(max, 0, i));
                }
            }
            else
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(i, min, 0), new Vector3(i, max, 0));
                    grid.AddLine(new Vector3(min, i, 0), new Vector3(max, i, 0));
                }
            }

            return(grid.ToLineGeometry3D());
        }
Exemplo n.º 4
0
        public CameraModel3D()
        {
            var b1 = new MeshBuilder();

            b1.AddBox(new Vector3(), 1f, 1f, 1.2f, BoxFaces.All);
            var body = new MeshGeometryModel3D()
            {
                CullMode = CullMode.Back
            };

            body.Geometry = b1.ToMeshGeometry3D();
            body.Material = PhongMaterials.Gray;
            body.SceneNode.OnSetRenderTechnique = (h) => { return(h.EffectsManager[DefaultRenderTechniqueNames.Diffuse]); };
            this.Children.Add(body);
            b1 = new MeshBuilder();
            b1.AddCone(new Vector3(0, 0, -1.2f), new Vector3(0, 0f, 0), 0.4f, true, 12);
            var lens = new MeshGeometryModel3D()
            {
                CullMode = CullMode.Back
            };

            lens.Geometry = b1.ToMeshGeometry3D();
            lens.Material = PhongMaterials.Yellow;
            lens.SceneNode.OnSetRenderTechnique = (h) => { return(h.EffectsManager[DefaultRenderTechniqueNames.Diffuse]); };
            this.Children.Add(lens);

            var builder = new LineBuilder();

            builder.AddLine(Vector3.Zero, new Vector3(2, 0, 0));
            builder.AddLine(Vector3.Zero, new Vector3(0, 2, 0));
            builder.AddLine(Vector3.Zero, new Vector3(0, 0, -2));

            var mesh           = builder.ToLineGeometry3D();
            var arrowMeshModel = new LineGeometryModel3D();

            arrowMeshModel.Geometry         = mesh;
            arrowMeshModel.Color            = System.Windows.Media.Colors.White;
            arrowMeshModel.IsHitTestVisible = false;
            int segment = mesh.Positions.Count / 3;
            var colors  = new Core.Color4Collection(Enumerable.Repeat <Color4>(Color.Black, mesh.Positions.Count));
            int i       = 0;

            for (; i < segment; ++i)
            {
                colors[i] = Color.Red;
            }
            for (; i < segment * 2; ++i)
            {
                colors[i] = Color.Green;
            }
            for (; i < segment * 3; ++i)
            {
                colors[i] = Color.Blue;
            }
            mesh.Colors = colors;
            this.Children.Add(arrowMeshModel);
            SceneNode.OnTransformChanged += SceneNode_OnTransformChanged;
        }
Exemplo n.º 5
0
        public MainViewModel()
        {
            // titles
            this.Title = "Simple Demo (Workitem 10043)";
            this.SubTitle = "Please switch to Viewport 2 and then back to Viewport 1";

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) };

            if (this.RenderTechniquesManager != null)
            {
                // default render technique
                this.RenderTechnique = RenderTechniquesManager.RenderTechniques.Get(DefaultRenderTechniqueNames.Blinn);
            }

            // setup lighting            
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            // floor plane grid
            this.Grid = LineBuilder.GenerateGrid();
            this.GridColor = SharpDX.Color.Black;
            this.GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5);

            // scene model3d
            var b1 = new MeshBuilder();            
            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);
           
            var meshGeometry = b1.ToMeshGeometry3D();
            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            this.Model = meshGeometry;

            // lines model3d
            var e1 = new LineBuilder();
            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);
            this.Lines = e1.ToLineGeometry3D();

            // model trafos
            this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);
            
            // model materials
            this.RedMaterial = PhongMaterials.Red;
            this.GreenMaterial = PhongMaterials.Green;
            this.BlueMaterial = PhongMaterials.Blue;
            //var diffColor = this.RedMaterial.DiffuseColor;
            //diffColor.Alpha = 0.5f;
            //this.RedMaterial.DiffuseColor = diffColor;            
        }
Exemplo n.º 6
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);

            this.Title = "Line Shading Demo (HelixToolkitDX)";
            this.SubTitle = null;

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(0, 5, 5), LookDirection = new Vector3D(-0, -5, -5), UpDirection = new Vector3D(0, 1, 0) };

            // setup lighting            
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            // floor plane grid
            this.Grid = LineBuilder.GenerateGrid();
            this.GridColor = SharpDX.Color.Black;
            this.GridTransform = new TranslateTransform3D(-5, -1, -5);

            // scene model3d
            var b1 = new MeshBuilder();
            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);
            this.Model = b1.ToMeshGeometry3D();

            // lines model3d
            var e1 = new LineBuilder();
            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);
            //e1.AddLine(new Vector3(-1, 0, 0), new Vector3(1, 0, 0));
            this.Lines = e1.ToLineGeometry3D();

            // lines params
            this.LineThickness = 2;
            this.LineSmoothness = 2.0;
            this.LinesEnabled = true;
            this.GridEnabled = true;

            // model trafos
            this.Model1Transform = new TranslateTransform3D(0, 0, 0);
            this.Model2Transform = new TranslateTransform3D(-2, 0, 0);
            this.Model3Transform = new TranslateTransform3D(+2, 0, 0);

            // model materials
            this.Material1 = PhongMaterials.PolishedGold;
            this.Material2 = PhongMaterials.Copper;
            this.Material3 = PhongMaterials.Glass;                        
        }
Exemplo n.º 7
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);

            this.Title = "Manipulator Demo";
            this.SubTitle = null;

            // camera setup
            this.Camera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0) };

            // setup lighting            
            this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            // floor plane grid
            this.Grid = LineBuilder.GenerateGrid();
            this.GridColor = SharpDX.Color.Black;
            this.GridTransform = new TranslateTransform3D(-5, -1, -5);

            // scene model3d
            var b1 = new MeshBuilder();
            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5, BoxFaces.All);
            this.Model = b1.ToMeshGeometry3D();

            // lines model3d
            var e1 = new LineBuilder();
            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5);
            this.Lines = e1.ToLineGeometry3D();

            // model trafos
            this.Model1Transform = CreateAnimatedTransform(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1), 20);
            this.Model2Transform = new TranslateTransform3D(-3, 0, 0);
            this.Model3Transform = new TranslateTransform3D(+3, 0, 0);

            // model materials
            this.Material1 = PhongMaterials.Orange;
            this.Material2 = PhongMaterials.Orange;
            this.Material3 = PhongMaterials.Red;

            var dr = Color.DarkRed;
            Console.WriteLine(dr);
        }
Exemplo n.º 8
0
        public MainViewModel()
        {
            Title = "Instancing Demo";            

            // camera setup
            Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) };

            // setup lighting            
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = (Color4)Color.White;
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            // scene model3d
            var b1 = new MeshBuilder(); 
            b1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5, BoxFaces.All);
            Model = b1.ToMeshGeometry3D();

            var l1 = new LineBuilder();
            l1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5);
            Lines = l1.ToLineGeometry3D();   

            int num = 10;
            var instances = new List<Matrix>();
            for (int i = -num; i < num; i++)
            {
                for (int j = -num; j < num; j++)
                {
                    instances.Add(Matrix.Translation(new Vector3(i / 1.0f, j / 1.0f, 0f)));
                }
            }
            ModelInstances = instances;
            SubTitle = "Number of Instances: " + instances.Count.ToString();

            // model trafo
            ModelTransform = Media3D.Transform3D.Identity;// new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 45));

            // model material
            ModelMaterial = PhongMaterials.Glass;

            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);
        }
Exemplo n.º 9
0
        public static LineGeometry3D GenerateGrid(Vector3 plane, int min0 = 0, int max0 = 10, int min1 = 0, int max1 = 10, int sizew = 1, int sizeh = 1)
        {
            var grid = new LineBuilder();

            //int width = max - min;
            if (plane == Vector3.UnitX)
            {
                for (int i = min0; i <= max0; i += sizew)
                {
                    grid.AddLine(new Vector3(0, i, min1), new Vector3(0, i, max1));
                }
                for (int i = min1; i <= max1; i += sizeh)
                {
                    grid.AddLine(new Vector3(0, min0, i), new Vector3(0, max0, i));
                }
            }
            else if (plane == Vector3.UnitY)
            {
                for (int i = min0; i <= max0; i += sizew)
                {
                    grid.AddLine(new Vector3(i, 0, min1), new Vector3(i, 0, max1));
                }
                for (int i = min1; i <= max1; i += sizeh)
                {
                    grid.AddLine(new Vector3(min0, 0, i), new Vector3(max0, 0, i));
                }
            }
            else
            {
                for (int i = min0; i <= max0; i += sizew)
                {
                    grid.AddLine(new Vector3(i, min1, 0), new Vector3(i, max1, 0));
                }
                for (int i = min1; i <= max1; i += sizeh)
                {
                    grid.AddLine(new Vector3(min0, i, 0), new Vector3(max0, i, 0));
                }
            }

            return(grid.ToLineGeometry3D());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a line geometry of the axis-aligned bounding-box of the given mesh.
        /// </summary>
        /// <param name="mesh">Input mesh for the computation of the b-box</param>
        /// <returns></returns>
        public static LineGeometry3D GenerateBoundingBox(global::SharpDX.BoundingBox bb)
        {
            var cc = bb.GetCorners();
            var ll = new LineBuilder();

            ll.AddLine(cc[0], cc[1]);
            ll.AddLine(cc[1], cc[2]);
            ll.AddLine(cc[2], cc[3]);
            ll.AddLine(cc[3], cc[0]);

            ll.AddLine(cc[4], cc[5]);
            ll.AddLine(cc[5], cc[6]);
            ll.AddLine(cc[6], cc[7]);
            ll.AddLine(cc[7], cc[4]);

            ll.AddLine(cc[0], cc[4]);
            ll.AddLine(cc[1], cc[5]);
            ll.AddLine(cc[2], cc[6]);
            ll.AddLine(cc[3], cc[7]);
            return(ll.ToLineGeometry3D());
        }
Exemplo n.º 11
0
        public LineGeometryModel3D GetGrid()
        {
            var lineBilder = new LineBuilder();

            for (int x = -1000; x < 1000; x += 100)
            {
                lineBilder.AddLine(new Vector3(x, 0, -1000), new Vector3(x, 0, 1000));
            }

            for (int z = -1000; z < 1000; z += 100)
            {
                lineBilder.AddLine(new Vector3(-1000, 0, z), new Vector3(1000, 0, z));
            }

            LineGeometryModel3D m = new LineGeometryModel3D();
            m.Geometry = lineBilder.ToLineGeometry3D();
            m.Color = Color.Black;
            m.Transform = new TranslateTransform3D(new Vector3D(0, 0, 0));
            m.Attach(Viewport.RenderHost);

            return m;
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="plane"></param>
        /// <param name="radius"></param>
        /// <param name="segments"></param>
        /// <returns></returns>
        public static LineGeometry3D GenerateCircle(Vector3 plane, float radius, int segments)
        {
            if (segments < 3)
            {
                throw new ArgumentNullException("too few segments, at least 3");
            }

            var circle = new LineBuilder();

            float sectionAngle = (float)(2.0 * Math.PI / segments);

            if (plane == Vector3.UnitX)
            {
                Point3D start   = new Point3D(0.0f, 0.0f, radius);
                Point3D current = new Point3D(0.0f, 0.0f, radius);
                Point3D next    = new Point3D(0.0f, 0.0f, 0.0f);

                for (int i = 1; i < segments; i++)
                {
                    next.Z = radius * (float)Math.Cos(i * sectionAngle);
                    next.Y = radius * (float)Math.Sin(i * sectionAngle);

                    circle.AddLine(current, next);

                    current = next;
                }

                circle.AddLine(current, start);
            }
            else if (plane == Vector3.UnitY)
            {
                Point3D start   = new Point3D(radius, 0.0f, 0.0f);
                Point3D current = new Point3D(radius, 0.0f, 0.0f);
                Point3D next    = new Point3D(0.0f, 0.0f, 0.0f);

                for (int i = 1; i < segments; i++)
                {
                    next.X = radius * (float)Math.Cos(i * sectionAngle);
                    next.Z = radius * (float)Math.Sin(i * sectionAngle);

                    circle.AddLine(current, next);

                    current = next;
                }

                circle.AddLine(current, start);
            }
            else
            {
                Point3D start   = new Point3D(0.0f, radius, 0.0f);
                Point3D current = new Point3D(0.0f, radius, 0.0f);
                Point3D next    = new Point3D(0.0f, 0.0f, 0.0f);

                for (int i = 1; i < segments; i++)
                {
                    next.Y = radius * (float)Math.Cos(i * sectionAngle);
                    next.X = radius * (float)Math.Sin(i * sectionAngle);

                    circle.AddLine(current, next);

                    current = next;
                }

                circle.AddLine(current, start);
            }

            return(circle.ToLineGeometry3D());
        }
Exemplo n.º 13
0
        public MainViewModel()
        {
            // titles
            Title = "Simple Demo";
            SubTitle = "WPF & SharpDX";

            // camera setup
            Camera = new PerspectiveCamera { 
                Position = new Point3D(3, 3, 5), 
                LookDirection = new Vector3D(-3, -3, -5), 
                UpDirection = new Vector3D(0, 1, 0),
                FarPlaneDistance = 5000000
            };

            // Create a custom render techniques manager that 
            // only supports Phong and Blinn
            RenderTechniquesManager = new CustomRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques["RenderCustom"];
            EffectsManager = new CustomEffectsManager(RenderTechniquesManager);

            // setup lighting            
            AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            DirectionalLightColor = Color.White;
            DirectionalLightDirection = new Vector3(-2, -5, -2);

            // floor plane grid
            Grid = LineBuilder.GenerateGrid();
            GridColor = Color.Black;
            GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5);

            // scene model3d
            var b1 = new MeshBuilder();            
            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);
           
            var meshGeometry = b1.ToMeshGeometry3D();
            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            Model = meshGeometry;

            // lines model3d
            var e1 = new LineBuilder();
            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);
            Lines = e1.ToLineGeometry3D();

            // model transform
            Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);

            // model materials
            RedMaterial = PhongMaterials.Red;
            GreenMaterial = PhongMaterials.Green;
            BlueMaterial = PhongMaterials.Blue;

            Points = new PointGeometry3D();
            var ptPos = new Vector3Collection();
            var ptIdx = new IntCollection();

            Text = new BillboardText3D();

            for (int x = -5; x <= 5; x++)
            {
                for (int y = -5; y <= 5; y++)
                {
                    ptIdx.Add(ptPos.Count);
                    ptPos.Add(new Vector3(x, -1, y));
                    Text.TextInfo.Add(new TextInfo(string.Format("{0}:{1}", x, y), new Vector3(x, -1, y)));
                }
            }

            Points.Positions = ptPos;
            Points.Indices = ptIdx;
        }
Exemplo n.º 14
0
        public CameraModel3D()
        {
            var b1 = new MeshBuilder();

            b1.AddBox(new Vector3(), 1f, 1f, 1.2f, BoxFaces.All);
            var body = new MeshGeometryModel3D()
            {
                CullMode = CullMode.Back
            };

            body.Geometry = b1.ToMeshGeometry3D();
            body.Material = new DiffuseMaterial()
            {
                DiffuseColor = Color.Gray
            };
            this.Children.Add(body);
            b1 = new MeshBuilder();
            b1.AddCone(new Vector3(0, 0, -1.2f), new Vector3(0, 0f, 0), 0.4f, true, 12);
            var lens = new MeshGeometryModel3D()
            {
                CullMode = CullMode.Back
            };

            lens.Geometry = b1.ToMeshGeometry3D();
            lens.Material = new DiffuseMaterial()
            {
                DiffuseColor = Color.Yellow
            };
            this.Children.Add(lens);

            var builder = new LineBuilder();

            builder.AddLine(Vector3.Zero, new Vector3(2, 0, 0));
            builder.AddLine(Vector3.Zero, new Vector3(0, 2, 0));
            builder.AddLine(Vector3.Zero, new Vector3(0, 0, -2));

            var mesh           = builder.ToLineGeometry3D();
            var arrowMeshModel = new LineGeometryModel3D
            {
                Geometry         = mesh,
                Color            = System.Windows.Media.Colors.White,
                IsHitTestVisible = false
            };
            int segment = mesh.Positions.Count / 3;
            var colors  = new Color4Collection(Enumerable.Repeat <Color4>(Color.Black, mesh.Positions.Count));
            int i       = 0;

            for (; i < segment; ++i)
            {
                colors[i] = Color.Red;
            }
            for (; i < segment * 2; ++i)
            {
                colors[i] = Color.Green;
            }
            for (; i < segment * 3; ++i)
            {
                colors[i] = Color.Blue;
            }
            mesh.Colors = colors;
            this.Children.Add(arrowMeshModel);
            SceneNode.TransformChanged += SceneNode_OnTransformChanged;
        }
Exemplo n.º 15
0
        private void CreateWireFrameModels(IFCItem item, Vector3D center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0)
                {
                    var points = new Vector3Collection();
                    Vector3Collection positions;
                    if (item.verticesForWireFrame != null)
                    {
                        for (int i = 0; i < item.noVerticesForWireFrame; i++)
                        {
                            points.Add(new Vector3((float)(item.verticesForWireFrame[3 * i + 0] - center.X), (float)(item.verticesForWireFrame[3 * i + 1] - center.Y), (float)(item.verticesForWireFrame[3 * i + 2] - center.Z)));
                        }
                    }

                    if (item.indicesForWireFrameLineParts != null)
                    {
                        positions = new Vector3Collection();
                        for (int i = 0; i < item.noPrimitivesForWireFrame; i++)
                        {
                            var idx = item.indicesForWireFrameLineParts[2 * i + 0];
                            positions.Add(points[idx]);
                            idx = item.indicesForWireFrameLineParts[2 * i + 1];
                            positions.Add(points[idx]);
                        }
                    }
                    else {
                        positions = points;
                    }

                    var lineBuilder = new LineBuilder();
                    lineBuilder.Add(false,positions.ToArray());
                    LineGeometryModel3D line = new LineGeometryModel3D();
                    line.Geometry = lineBuilder.ToLineGeometry3D();
                    line.Color = new SharpDX.Color(0,0,0,0);
                    item.Wireframe = line;
                    model.Add(line as Element3D);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
Exemplo n.º 16
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);

            // titles
            this.Title = "Mouse Drag Demo";
            this.SubTitle = "WPF & SharpDX";

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(0, 0, 9), LookDirection = new Vector3D(-0, -0, -9), UpDirection = new Vector3D(0, 1, 0) };

            // default render technique
            this.RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];

            // setup lighting            
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            // floor plane grid
            this.Grid = LineBuilder.GenerateGrid(Vector3.UnitZ, -5, 5);
            this.GridColor = SharpDX.Color.Black;
            this.GridTransform = new Media3D.TranslateTransform3D(-0, -0, -0);

            // scene model3d
            var b1 = new MeshBuilder();
            b1.AddSphere(new Vector3(0, 0, 0), 0.65);
            b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1);
            var meshGeometry = b1.ToMeshGeometry3D();
            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            this.MeshGeometry = meshGeometry;
            this.Model1Instances = new List<Matrix>();
            for (int i = 0; i < 5; i++)
            {
                this.Model1Instances.Add(Matrix.Translation(0, i, 0));
            }

            // lines model3d
            var e1 = new LineBuilder();
            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);
            this.Lines = e1.ToLineGeometry3D();

            // model trafos
            this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0.0);
            this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);

            // model materials
            this.RedMaterial = PhongMaterials.Red;
            this.GreenMaterial = PhongMaterials.Green;
            this.BlueMaterial = PhongMaterials.Blue;

            // ---
            this.Shape3DCollection = new ObservableCollection<Shape3D>
            {
                new Shape3D()
                {
                    Geometry = this.MeshGeometry,
                    Material = this.BlueMaterial,
                    Transform = this.Model3Transform,
                    Instances = new List<Matrix>{Matrix.Identity},
                    DragZ = false,
                },
                new Shape3D()
                {
                    Geometry = this.MeshGeometry,
                    Material = this.RedMaterial,
                    Transform = this.Model1Transform,
                    Instances = new List<Matrix>{Matrix.Identity},
                    DragZ = true,
                },
            };

            this.Element3DCollection = new ObservableCollection<Element3D>()
            {
                new DraggableGeometryModel3D()
                {
                    Geometry = this.MeshGeometry,
                    Material = this.BlueMaterial,
                    Transform = this.Model3Transform,
                },
                                
                new DraggableGeometryModel3D()
                {
                    Geometry = this.MeshGeometry,
                    Material = this.RedMaterial,
                    Transform = this.Model1Transform,
                },
            };

            this.AddCmd = new RelayCommand((o) => AddShape());
            this.DelCmd = new RelayCommand((o) => DelShape());
        }
Exemplo n.º 17
0
        /// <summary>
        /// The on children changed.
        /// </summary>
        protected virtual void OnChildrenChanged()
        {
            this.translateXL.Length = 0.5;
            this.translateYL.Length = 0.5;
            this.translateZL.Length = 0.5;
            this.translateXR.Length = 0.5;
            this.translateYR.Length = 0.5;
            this.translateZR.Length = 0.5;

            this.Children.Clear();

            if (this.CanTranslateX)
            {
                this.Children.Add(this.translateXL);
                this.Children.Add(this.translateXR);
            }

            if (this.CanTranslateY)
            {
                this.Children.Add(this.translateYL);
                this.Children.Add(this.translateYR);
            }

            if (this.CanTranslateZ)
            {
                this.Children.Add(this.translateZL);
                this.Children.Add(this.translateZR);
            }


            {
                var g = new LineBuilder();
                g.AddLine(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
                g.AddLine(new Vector3(1, 0, 0), new Vector3(1, 1, 0));
                g.AddLine(new Vector3(1, 1, 0), new Vector3(0, 1, 0));
                g.AddLine(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
                this.selectionBounds = new LineGeometryModel3D()
                {
                    Thickness = 3,
                    Smoothness = 2,
                    Color = Color.Red,
                    IsThrowingShadow = false,
                    Geometry = g.ToLineGeometry3D(),
                };
                this.Children.Add(this.selectionBounds);
            }            
        }
Exemplo n.º 18
0
        /// <summary>
        /// Generate a simple Polygon and then triangulate it.
        /// The Result is then Displayed.
        /// </summary>
        /// <param name="sender">The Sender (i.e. the Button)</param>
        /// <param name="e">The routet Event Args</param>
        private void generatePolygonButton_Click(object sender, RoutedEventArgs e)
        {
            // Generate random Polygon
            var random = new Random();
            var cnt = mViewModel.PointCount;
            mPolygonPoints = new List<Vector2>();
            var angle = 0f;
            var angleDiff = 2f * (Single)Math.PI / cnt;
            var radius = 4f;
            // Random Radii for the Polygon
            var radii = new List<float>();
            var innerRadii = new List<float>();
            for (int i = 0; i < cnt; i++)
            {
                radii.Add(random.NextFloat(radius * 0.9f, radius * 1.1f));
                innerRadii.Add(random.NextFloat(radius * 0.2f, radius * 0.3f));
            }
            var hole1 = new List<Vector2>();
            var hole2 = new List<Vector2>();
            var holeDistance = 2f;
            var holeAngle = random.NextFloat(0, (float)Math.PI * 2);
            var cos = (float)Math.Cos(holeAngle);
            var sin = (float)Math.Sin(holeAngle);
            var offset1 = new Vector2(holeDistance * cos, holeDistance * sin);
            var offset2 = new Vector2(-holeDistance * cos, -holeDistance * sin);
            for (int i = 0; i < cnt; i++)
            {
                // Flatten a bit
                var radiusUse = radii[i];
                mPolygonPoints.Add(new Vector2(radii[i] * (Single)Math.Cos(angle), radii[i] * (Single)Math.Sin(angle)));
                hole1.Add(offset1 + new Vector2(innerRadii[i] * (Single)Math.Cos(-angle), innerRadii[i] * (Single)Math.Sin(-angle)));
                hole2.Add(offset2 + new Vector2(innerRadii[i] * (Single)Math.Cos(-angle), innerRadii[i] * (Single)Math.Sin(-angle)));
                angle += angleDiff;
            }

            var holes = new List<List<Vector2>>() { hole1, hole2 };

            // Triangulate and measure the Time needed for the Triangulation
            var before = DateTime.Now;
            var sLTI = SweepLinePolygonTriangulator.Triangulate(mPolygonPoints, holes);
            var after = DateTime.Now;

            // Generate the Output
            var geometry = new HelixToolkit.Wpf.SharpDX.MeshGeometry3D();
            geometry.Positions = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
            geometry.Normals = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
            foreach (var point in mPolygonPoints.Union(holes.SelectMany(h => h)))
            {
                geometry.Positions.Add(new Vector3(point.X, 0, point.Y + 5));
                geometry.Normals.Add(new Vector3(0, 1, 0));
            }
            geometry.Indices = new HelixToolkit.Wpf.SharpDX.Core.IntCollection(sLTI);
            triangulatedPolygon.Geometry = geometry;

            var lb = new LineBuilder();
            for (int i = 0; i < sLTI.Count; i += 3)
            {
                lb.AddLine(geometry.Positions[sLTI[i]], geometry.Positions[sLTI[i + 1]]);
                lb.AddLine(geometry.Positions[sLTI[i + 1]], geometry.Positions[sLTI[i + 2]]);
                lb.AddLine(geometry.Positions[sLTI[i + 2]], geometry.Positions[sLTI[i]]);
            }
            mViewModel.LineGeometry  = lb.ToLineGeometry3D();

            // Set the Lines if activated
            if (mViewModel.ShowTriangleLines)
            {
                lineTriangulatedPolygon.Geometry = mViewModel.LineGeometry;
            }
            else
            {
                lineTriangulatedPolygon.Geometry = null;
            }

            // Set the InfoLabel Text
            var timeNeeded = (after - before).TotalMilliseconds;
            infoLabel.Content = String.Format("Last triangulation of {0} Points took {1:0.##} Milliseconds!", triangulatedPolygon.Geometry.Positions.Count, timeNeeded);
        }
Exemplo n.º 19
0
        public MainViewModel()
        {
            // titles
            this.Title = "Simple Demo";
            this.SubTitle = "WPF & SharpDX";

            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = new Point3D(3, 3, 5),
                LookDirection = new Vector3D(-3, -3, -5),
                UpDirection = new Vector3D(0, 1, 0),
                FarPlaneDistance = 5000000
            };

            // default render technique
            this.RenderTechnique = Techniques.RenderBlinn;

            // setup lighting
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            // floor plane grid
            this.Grid = LineBuilder.GenerateGrid();
            this.GridColor = SharpDX.Color.Black;
            this.GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5);

            // scene model3d
            var b1 = new MeshBuilder();
            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);

            var meshGeometry = b1.ToMeshGeometry3D();
            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            this.Model = meshGeometry;

            // lines model3d
            var e1 = new LineBuilder();
            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);
            this.Lines = e1.ToLineGeometry3D();

            // model trafos
            this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);

            // model materials
            this.RedMaterial = PhongMaterials.Red;
            this.GreenMaterial = PhongMaterials.Green;
            this.BlueMaterial = PhongMaterials.Blue;
            //var diffColor = this.RedMaterial.DiffuseColor;
            //diffColor.Alpha = 0.5f;
            //this.RedMaterial.DiffuseColor = diffColor;

            Points = new PointGeometry3D();
            var ptPos = new Vector3Collection();
            var ptIdx = new IntCollection();

            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    for (int z = 0; z < 10; z++)
                    {
                        ptIdx.Add(ptPos.Count);
                        ptPos.Add(new Vector3(x, y, z));
                    }
                }
            }

            Points.Positions = ptPos;
            Points.Indices = ptIdx;

            Text = new BillboardText3D();

            for (var i = 0; i < 50; i++)
            {
                for (var j = 0; j < 50; j++)
                {
                    Text.TextInfo.Add(new TextInfo("Hello World", new Vector3(i,j,0)));
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Generates a square grid with a step of 1.0 
        /// </summary>
        /// <returns></returns>
        public static LineGeometry3D GenerateGrid(Vector3 plane, int min = 0, int max = 10)
        {
            var grid = new LineBuilder();
            //int width = max - min;
            if (plane == Vector3.UnitX)
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(0, i, min), new Vector3(0, i, max));
                    grid.AddLine(new Vector3(0, min, i), new Vector3(0, max, i));
                }
            }
            else if (plane == Vector3.UnitY)
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(i, 0, min), new Vector3(i, 0, max));
                    grid.AddLine(new Vector3(min, 0, i), new Vector3(max, 0, i));
                }
            }
            else
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(i, min, 0), new Vector3(i, max, 0));
                    grid.AddLine(new Vector3(min, i, 0), new Vector3(max, i, 0));
                }
            }

            return grid.ToLineGeometry3D();
        }
Exemplo n.º 21
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="plane"></param>
        /// <param name="radius"></param>
        /// <param name="segments"></param>
        /// <returns></returns>
        public static LineGeometry3D GenerateCircle(Vector3 plane, float radius, int segments)
        {
            if (segments < 3)
            {
                throw new ArgumentNullException("too few segments, at least 3");
            }

            var circle = new LineBuilder();

            float sectionAngle = (float)(2.0 * Math.PI / segments);

            if (plane == Vector3.UnitX)
            {
                Point3D start = new Point3D(0.0f, 0.0f, radius);
                Point3D current = new Point3D(0.0f, 0.0f, radius);
                Point3D next = new Point3D(0.0f, 0.0f, 0.0f);

                for (int i = 1; i < segments; i++)
                {
                    next.Z = radius * (float)Math.Cos(i * sectionAngle);
                    next.Y = radius * (float)Math.Sin(i * sectionAngle);

                    circle.AddLine(current, next);

                    current = next;
                }

                circle.AddLine(current, start);
            }
            else if (plane == Vector3.UnitY)
            {
                Point3D start = new Point3D(radius, 0.0f, 0.0f);
                Point3D current = new Point3D(radius, 0.0f, 0.0f);
                Point3D next = new Point3D(0.0f, 0.0f, 0.0f);

                for (int i = 1; i < segments; i++)
                {
                    next.X = radius * (float)Math.Cos(i * sectionAngle);
                    next.Z = radius * (float)Math.Sin(i * sectionAngle);

                    circle.AddLine(current, next);

                    current = next;
                }

                circle.AddLine(current, start);
            }
            else
            {
                Point3D start = new Point3D(0.0f, radius, 0.0f);
                Point3D current = new Point3D(0.0f, radius, 0.0f);
                Point3D next = new Point3D(0.0f, 0.0f, 0.0f);

                for (int i = 1; i < segments; i++)
                {
                    next.Y = radius * (float)Math.Cos(i * sectionAngle);
                    next.X = radius * (float)Math.Sin(i * sectionAngle);

                    circle.AddLine(current, next);

                    current = next;
                }

                circle.AddLine(current, start);
            }

            return circle.ToLineGeometry3D();
        }
Exemplo n.º 22
0
        /// <summary>
        /// Returns a line geometry of the axis-aligned bounding-box of the given mesh.
        /// </summary>
        /// <param name="mesh">Input mesh for the computation of the b-box</param>
        /// <returns></returns>
        public static LineGeometry3D GenerateBoundingBox(global::SharpDX.BoundingBox bb)
        {            
            var cc = bb.GetCorners();
            var ll = new LineBuilder();
            ll.AddLine(cc[0], cc[1]);
            ll.AddLine(cc[1], cc[2]);
            ll.AddLine(cc[2], cc[3]);
            ll.AddLine(cc[3], cc[0]);

            ll.AddLine(cc[4], cc[5]);
            ll.AddLine(cc[5], cc[6]);
            ll.AddLine(cc[6], cc[7]);
            ll.AddLine(cc[7], cc[4]);

            ll.AddLine(cc[0], cc[4]);
            ll.AddLine(cc[1], cc[5]);
            ll.AddLine(cc[2], cc[6]);
            ll.AddLine(cc[3], cc[7]);
            return ll.ToLineGeometry3D();
        }