Beispiel #1
1
        public Cube()
        {
            var b1 = new HelixToolkit.Wpf.SharpDX.MeshBuilder();

            b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1);
            Geometry = b1.ToMeshGeometry3D();
        }
Beispiel #2
0
        public MainViewModel()
        {
            this.Title = "Environment Mapping Demo";
            this.SubTitle = "HelixToolkitDX";                        

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

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

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

            this.Model = b1.ToMeshGeometry3D();
            this.ModelTransform = new Media3D.TranslateTransform3D();
            this.ModelMaterial = PhongMaterials.Copper;

            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);
        }
Beispiel #3
0
        public Cube(double x, double y, double z)
        {
            var b1 = new HelixToolkit.Wpf.SharpDX.MeshBuilder();

            b1.AddBox(new Vector3(0, 0, 0), x, y, z);
            Geometry = b1.ToMeshGeometry3D();
        }
        public MainViewModel()
        {
            Title = "ImageViewDemo";
            SubTitle = "WPF & SharpDX";

            this.OpenCommand = new RelayCommand((x) => OnOpenClick());

            // camera setup
            this.defaultPerspectiveCamera = new PerspectiveCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0), NearPlaneDistance = 0.5, FarPlaneDistance = 150 };
            this.defaultOrthographicCamera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0), NearPlaneDistance = 0, FarPlaneDistance = 100 };
            this.Camera = defaultPerspectiveCamera;

            // setup lighting            
            this.AmbientLightColor = new Color4(0f, 0f, 0f, 0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-0, -0, -10);

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

            // plane
            var b2 = new MeshBuilder();
            b2.AddBox(new Vector3(0, 0, 0), 10, 10, 0, BoxFaces.PositiveZ);
            this.Plane = b2.ToMeshGeometry3D();
            this.PlaneMaterial = PhongMaterials.Blue;
            this.PlaneTransform = new Media3D.TranslateTransform3D(-0, -0, -0);            
            //this.PlaneMaterial.ReflectiveColor = Color.Black;
            this.PlaneTransform = new Media3D.TranslateTransform3D(0, 0, 0);

            this.RenderTechnique = Techniques.RenderBlinn;
        }
        public static Geometry3D GetProbePointModel(Point3D position, double radius)
        {
            var builder = new MeshBuilder();

            builder.AddSphere(position.ToVector3(), radius);

            return(builder.ToMesh());
        }
Beispiel #6
0
        public void CreateBall()
        {
            var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder();

            ballContainer.AddSphere(BallCenter, 1.5);

            Geometry = ballContainer.ToMeshGeometry3D();

            this.Material = PhongMaterials.White;
        }
 /// <summary>
 /// Called when geometry has been changed.
 /// </summary>
 protected override void OnModelChanged()
 {            
     var mb = new MeshBuilder();
     var p0 = this.Offset;// new Vector3(0, 0, 0);
     var d = this.Direction;
     d.Normalize();
     var p1 = p0 + (d * (float)this.Length);
     mb.AddArrow(p0, p1, this.Diameter, 2, 64);
     this.Geometry = mb.ToMeshGeometry3D();            
 }
Beispiel #8
0
        public SingleCylinder(double radius)
        {
            Radius = radius;
            var b1 = new HelixToolkit.Wpf.SharpDX.MeshBuilder();

            b1.AddCylinder(new Vector3(-1, 0, 0), new Vector3(1, 0, 0), radius, 32, true, true);

            b1.AddCylinder(new Vector3(-1.1f, 0, 0), new Vector3(1.1f, 0, 0), 0.05d, 32, true, true);

            Geometry = b1.ToMeshGeometry3D();
        }
Beispiel #9
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;            
        }
 public void Setup()
 {
     closePoint = InitializePointWithId("closePoint");
     farPoint = InitializePointWithId("farPoint", new Vector3(10000, 10000, 10000));
     var builder = new MeshBuilder();
     builder.AddBox(new Vector3(-10000, -10000, -5000), 5, 5, 5, BoxFaces.All);
     var boxGeom = builder.ToMeshGeometry3D();
     cube = new MeshGeometryModel3D()
     {
         Geometry = boxGeom,
         Name = "cube"
     };
 }
Beispiel #11
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);

            Title = "Shadow Map Demo";
            SubTitle = "WPF & SharpDX";

            // setup lighting            
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection = new Vector3(-0, -1, -1);
            this.LightDirectionTransform = CreateAnimatedTransform(-DirectionalLightDirection.ToVector3D(), new Vector3D(0, 1, -1), 24);
            this.ShadowMapResolution = new Vector2(2048, 2048);

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

            // floor plane grid
            //Grid = LineBuilder.GenerateGrid();
            //GridColor = SharpDX.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.25, 2, BoxFaces.All);
            Model = b1.ToMeshGeometry3D();
            //Instances = new[] { Matrix.Translation(0, 0, -1.5f), Matrix.Translation(0, 0, 1.5f) };

            var b2 = new MeshBuilder();
            b2.AddBox(new Vector3(0, 0, 0), 10, 0, 10, BoxFaces.PositiveY);
            Plane = b2.ToMeshGeometry3D();
            PlaneTransform = new Media3D.TranslateTransform3D(-0, -2, -0);
            GrayMaterial = PhongMaterials.LightGray;
            //GrayMaterial.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); 

            // lines model3d            
            Lines = LineBuilder.GenerateBoundingBox(Model);

            // model trafos
            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.Glass;
            GreenMaterial = PhongMaterials.Green;
            BlueMaterial = PhongMaterials.Blue;
        }
Beispiel #12
0
        public void LoadBalls()
        {
            try
            {
                string   fileContent  = File.ReadAllText("./data/balldata.txt");
                string[] contentArray = fileContent.Split((string[])null, StringSplitOptions.RemoveEmptyEntries);

                MainViewModel.ProjData.BallCollection.Clear();

                for (int i = 0; i < contentArray.Length; i += 5)
                {
                    BallModel ball = new BallModel();

                    var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder();
                    ball.BallCenter = new Vector3(Convert.ToSingle(contentArray[i]), Convert.ToSingle(contentArray[i + 1]), Convert.ToSingle(contentArray[i + 2]));
                    ball.BallName   = contentArray[i + 3];
                    ballContainer.AddSphere(ball.BallCenter, 1.5);
                    ball.Geometry = ballContainer.ToMeshGeometry3D();
                    ball.Material = PhongMaterials.White;
                    if (contentArray[i + 4].Equals("MovedMaxilla"))
                    {
                        ball.ModelType = ModelType.MovedMaxilla;
                    }
                    else if (contentArray[i + 4].Equals("MovedMandible"))
                    {
                        ball.ModelType = ModelType.MovedMandible;
                    }


                    foreach (BoneModel modeltem in MainViewModel.ProjData.BoneCollection)
                    {
                        if (modeltem.ModelType.Equals(ball.ModelType))
                        {
                            ball.ModelType = modeltem.ModelType;
                            System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Transform");
                            binding.Source = modeltem;
                            binding.Mode   = BindingMode.OneWay;
                            BindingOperations.SetBinding(ball, HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, binding);
                        }
                    }



                    MainViewModel.ProjData.BallCollection.Add(ball);
                }
            }
            catch
            {
                System.Windows.MessageBox.Show("Load檔案失敗");
            }
        }
Beispiel #13
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;                        
        }
Beispiel #14
0
        private IMachineElementViewModel CreateInjectElement(Point3D position, Vector3D direction)
        {
            var builder = new HelixToolkit.Wpf.SharpDX.MeshBuilder();

            builder.AddCone((position + direction * 20.0).ToVector3(),
                            position.ToVector3(),
                            4.0,
                            true,
                            20);
            return(new InserterObjectViewModel()
            {
                Geometry = builder.ToMesh(), Material = Material, Visible = true
            });
        }
Beispiel #15
0
        public static void ExtrudeText(this HelixToolkit.Wpf.SharpDX.MeshBuilder builder, string text, string font, FontStyle fontStyle, FontWeight fontWeight, double fontSize, Vector3D textDirection, Point3D p0, Point3D p1)
        {
            var outlineList = GetTextOutlines(text, font, fontStyle, fontWeight, fontSize);

            // Build the polygon to mesh (using Triangle.NET to triangulate)
            var polygon = new TriangleNet.Geometry.Polygon();
            int marker  = 0;

            foreach (var outlines in outlineList)
            {
                var outerOutline = outlines.OrderBy(x => x.AreaOfSegment()).Last();

                for (int i = 0; i < outlines.Count; i++)
                {
                    var outline = outlines[i];
                    var isHole  = i != outlines.Count - 1 && IsPointInPolygon(outerOutline, outline[0]);
                    polygon.AddContour(outline.Select(p => new Vertex(p.X, p.Y)), marker++, isHole);
                    builder.AddExtrudedSegments(outline.ToSegments().Select(x => new SharpDX.Vector2((float)x.X, (float)x.Y)).ToList(),
                                                textDirection, p0, p1);
                }
            }

            var mesher  = new GenericMesher();
            var options = new ConstraintOptions();
            var mesh    = mesher.Triangulate(polygon, options);

            var u = textDirection;

            u.Normalize();
            var z = p1 - p0;

            z.Normalize();
            var v = Vector3D.Cross(z, u);

            // Convert the triangles
            foreach (var t in mesh.Triangles)
            {
                var v0 = t.GetVertex(2);
                var v1 = t.GetVertex(1);
                var v2 = t.GetVertex(0);

                // Add the top triangle.
                // Project the X/Y vertices onto a plane defined by textdirection, p0 and p1.
                builder.AddTriangle(v0.Project(p0, u, v, z, 1), v1.Project(p0, u, v, z, 1), v2.Project(p0, u, v, z, 1));

                // Add the bottom triangle.
                builder.AddTriangle(v2.Project(p0, u, v, z, 0), v1.Project(p0, u, v, z, 0), v0.Project(p0, u, v, z, 0));
            }
        }
        public Watch3DxControl()
        {
            InitializeComponent();
            // DataContext = this;

            // titles
            view1.Title = "Watch3DxNode";
            view1.SubTitle = "SharpDX";

            // camera setup
            view1.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
            view1.RenderTechniquesManager = new DefaultRenderTechniquesManager();
            view1.RenderTechnique = view1.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Phong];
            view1.EffectsManager = new DefaultEffectsManager(view1.RenderTechniquesManager);

            // Setup lights
            var directionalLight3D = new DirectionalLight3D
            {
                Color = Color.White,
                Direction = new Vector3(-2, -5, -2)
            };

            var ambientLight3D = new AmbientLight3D {Color = Color.White};

            view1.Items.Add(ambientLight3D);
            view1.Items.Add(directionalLight3D);

            // Geometry
            var mb = new MeshBuilder();
            mb.AddSphere(new Vector3(0, 0, 0), 0.5);
            mb.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);
            var meshGeometry = mb.ToMeshGeometry3D();

            var meshGeomModel = new MeshGeometryModel3D
            {
                Geometry = meshGeometry,
                Material = PhongMaterials.Red
            };
            // Add the Model to the viewport
            view1.Items.Add(meshGeomModel);
        }
        public void HighlightBounds(SharpDX.BoundingBox bounds)
        {
            var r3d = new Media3D.Rect3D(bounds.Minimum.ToPoint3D(), bounds.Size.ToSize3D());
            var b   = new Helix.MeshBuilder();

            b.AddBoundingBox(r3d, 0.1);
            b.AddSphere(bounds.Center, 0.1);
            var geom = b.ToMeshGeometry3D();

            box.Geometry = geom;
            if (!Viewport.Items.Contains(box))
            {
                Viewport.Items.Add(box);
            }
        }
Beispiel #18
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);
        }
        static InteractionHandle3D()
        {
            var b1 = new MeshBuilder();
            b1.AddSphere(new Vector3(0.0f, 0.0f, 0), 0.135);
            NodeGeometry = b1.ToMeshGeometry3D();

            var b2 = new MeshBuilder();
            b2.AddCylinder(new Vector3(0, 0, 0), new Vector3(1, 0, 0), 0.05, 32, true, true);
            EdgeHGeometry = b2.ToMeshGeometry3D();

            var b3 = new MeshBuilder();
            b3.AddCylinder(new Vector3(0, 0, 0), new Vector3(0, 1, 0), 0.05, 32, true, true);
            EdgeVGeometry = b3.ToMeshGeometry3D();

            var b4 = new MeshBuilder();
            b4.AddBox(new Vector3(0, 0, 0), 0.175, 0.175, 0.175);
            BoxGeometry = b4.ToMeshGeometry3D();
        }
Beispiel #20
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);
        }
Beispiel #21
0
        private IProcedural GenerateMesh()
        {
            //GenerateMaterialProperties();

            //GenerateCubeFaces();

            //while (Material == null) { Debug.WriteLine($"Waiting for material - {Id}"); }

            //Debug.WriteLine($"Got material - {Id}");

            HelixToolkit.Wpf.SharpDX.MeshBuilder b = new HelixToolkit.Wpf.SharpDX.MeshBuilder();

            foreach (var f in Faces)
            {
                var face = f.Value;
                b.AddCubeFace(face.CubeCenter, face.Normal, face.Up, face.Distance, face.Width, face.Height);
            }

            var m = new MeshGeometryModel3D
            {
                Geometry = b.ToMesh(),
                CullMode = SharpDX.Direct3D11.CullMode.Back
            };

            var scale     = new ScaleTransform3D(1, 1, 1);
            var translate = new TranslateTransform3D(0, 0, 0);
            var group     = new Transform3DGroup();

            group.Children.Add(scale);
            group.Children.Add(translate);
            m.Transform = group;

            m.Material = PhysicalMaterial;
            if (PhysicalMaterial.DiffuseColor.Alpha < 1)
            {
                m.IsTransparent = true;
            }

            Mesh = m;

            return(this);
        }
Beispiel #22
0
        /// <summary>
        /// Updates the model in the 3D viewport
        /// </summary>
        /// <param name="mdlData">The model data</param>
        /// <param name="textureDataDictionary">The texture dictionary for the model</param>
        public void UpdateModel(XivMdl mdlData, Dictionary <int, ModelTextureData> textureDataDictionary)
        {
            SharpDX.BoundingBox?boundingBox = null;

            var totalMeshCount = mdlData.LoDList[0].MeshCount + mdlData.LoDList[0].ExtraMeshCount;

            for (var i = 0; i < totalMeshCount; i++)
            {
                var meshData = mdlData.LoDList[0].MeshDataList[i].VertexData;

                var meshGeometry3D = new MeshGeometry3D
                {
                    Positions          = meshData.Positions,
                    Normals            = meshData.Normals,
                    Indices            = meshData.Indices,
                    TextureCoordinates = meshData.TextureCoordinates0,
                };

                try
                {
                    MeshBuilder.ComputeTangents(meshGeometry3D);
                }
                catch
                {
                    Debug.WriteLine($"Unable to compute tangents for mesh {i}");
                }

                if (meshData.BiNormals != null && meshData.BiNormals.Count > 0)
                {
                    meshGeometry3D.BiTangents = meshData.BiNormals;
                }

                var textureData = textureDataDictionary[mdlData.LoDList[0].MeshDataList[i].MeshInfo.MaterialIndex];

                Stream diffuse = null, specular = null, normal = null, alpha = null, emissive = null;

                var pixelSettings =
                    new PixelReadSettings(textureData.Width, textureData.Height, StorageType.Char, PixelMapping.RGBA);

                if (textureData.Diffuse != null && textureData.Diffuse.Length > 0)
                {
                    using (var image = new MagickImage(textureData.Diffuse, pixelSettings))
                    {
                        diffuse = new MemoryStream(image.ToByteArray(MagickFormat.Bmp));
                    }
                }

                if (textureData.Specular != null && textureData.Specular.Length > 0)
                {
                    using (var image = new MagickImage(textureData.Specular, pixelSettings))
                    {
                        specular = new MemoryStream(image.ToByteArray(MagickFormat.Bmp));
                    }
                }

                if (textureData.Normal != null && textureData.Normal.Length > 0)
                {
                    using (var image = new MagickImage(textureData.Normal, pixelSettings))
                    {
                        normal = new MemoryStream(image.ToByteArray(MagickFormat.Bmp));
                    }
                }

                if (textureData.Alpha != null && textureData.Alpha.Length > 0)
                {
                    using (var image = new MagickImage(textureData.Alpha, pixelSettings))
                    {
                        alpha = new MemoryStream(image.ToByteArray(MagickFormat.Bmp));
                    }
                }

                if (textureData.Emissive != null && textureData.Emissive.Length > 0)
                {
                    using (var image = new MagickImage(textureData.Emissive, pixelSettings))
                    {
                        emissive = new MemoryStream(image.ToByteArray(MagickFormat.Bmp));
                    }
                }


                var material = new PhongMaterial
                {
                    DiffuseColor      = PhongMaterials.ToColor(1, 1, 1, 1),
                    SpecularShininess = 1f,
                    DiffuseMap        = diffuse,
                    DiffuseAlphaMap   = alpha,
                    SpecularColorMap  = specular,
                    NormalMap         = normal,
                    EmissiveMap       = emissive
                };

                var mgm3d = new CustomMeshGeometryModel3D
                {
                    Geometry = meshGeometry3D,
                    Material = material,
                    IsBody   = mdlData.LoDList[0].MeshDataList[i].IsBody
                };

                boundingBox = meshGeometry3D.Bound;

                mgm3d.CullMode = Properties.Settings.Default.Cull_Mode.Equals("None") ? CullMode.None : CullMode.Back;


                Models.Add(mgm3d);
            }

            SpecularShine = 1;

            var center = boundingBox.GetValueOrDefault().Center;

            _lightX = center.X;
            _lightY = center.Y;
            _lightZ = center.Z;

            Light3Direction = new Vector3D(_lightX, _lightY, _lightZ);

            Camera.UpDirection = new Vector3D(0, 1, 0);
            Camera.CameraInternal.PropertyChanged += CameraInternal_PropertyChanged;
        }
        public override void Calculate()
        {
            if (InputPorts[0].Data == null)
                return;

            // Use Tesselation Render Technique
            _control.view1.RenderTechniquesManager = new TessellationTechniquesManager();
            _control.view1.RenderTechnique = _control.view1.RenderTechniquesManager.RenderTechniques[TessellationRenderTechniqueNames.PNTriangles];
            _control.view1.EffectsManager = new TessellationEffectsManager(_control.view1.RenderTechniquesManager);

            // _control.view1.RenderTechniquesManager = new DefaultRenderTechniquesManager();
            // _control.view1.RenderTechnique = _control.view1.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            // _control.view1.EffectsManager = new DefaultEffectsManager(_control.view1.RenderTechniquesManager);

            _control.RemoveGeometryModels();

            // Input is of Type GenericElement
            if (InputPorts[0].Data != null && InputPorts[0].Data.GetType() == typeof(List<DtObject>))
            {
                var elements = InputPorts[0].Data as List<DtObject>;

                // Loop the items of each list
                foreach (var item in elements)
                {
                    // Init the MeshBuilde
                    var mb = new MeshBuilder();

                    var points = item.AttributeGroups["geometry"].GetProperty("threejspoints") as List<Point3D>;
                    var indices = item.AttributeGroups["geometry"].GetProperty("geometryindices") as List<uint>;
                    var color = item.AttributeGroups["geometry"].GetProperty("color") is System.Drawing.Color
                        ? (System.Drawing.Color) item.AttributeGroups["geometry"].GetProperty("color")
                        : new System.Drawing.Color();

                    var listIndices = indices.Select(value => (int) value).ToList();

                    for (var i = 0; i < indices.Count; i++)
                    {
                        switch (indices[i])
                        {
                            case 0:
                                mb.AddPolygon(new List<Vector3> {
                                    new Vector3((float)points[listIndices[i]].X, (float)points[listIndices[i]].Y, (float)points[listIndices[i]].Z),
                                    new Vector3((float)points[listIndices[i + 1]].X, (float)points[listIndices[i + 1]].Y, (float)points[listIndices[i + 1]].Z),
                                    new Vector3((float)points[listIndices[i + 2]].X, (float)points[listIndices[i + 2]].Y, (float)points[listIndices[i + 2]].Z)
                                });
                                i = i + 3;
                                break;
                            case 1:
                                mb.AddPolygon(new List<Vector3> {
                                    new Vector3((float)points[listIndices[i]].X, (float)points[listIndices[i]].Y, (float)points[listIndices[i]].Z),
                                    new Vector3((float)points[listIndices[i + 1]].X, (float)points[listIndices[i + 1]].Y, (float)points[listIndices[i + 1]].Z),
                                    new Vector3((float)points[listIndices[i + 2]].X, (float)points[listIndices[i + 2]].Y, (float)points[listIndices[i + 2]].Z),
                                    new Vector3((float)points[listIndices[i + 3]].X, (float)points[listIndices[i + 3]].Y, (float)points[listIndices[i + 3]].Z)
                                });
                                i = i + 4;
                                break;
                        }
                    }


                    // for (var i = 0; i < indices.Count; i++)
                    // {
                    //     switch (indices[i])
                    //     {
                    //         case 0:
                    //             mb.AddTriangle(
                    //                 new Vector3((float)points[(int)indices[i]].X, (float)points[(int)indices[i]].Y, (float)points[(int)indices[i]].Z),
                    //                 new Vector3((float)points[(int)indices[i + 1]].X, (float)points[(int)indices[i + 1]].Y, (float)points[(int)indices[i + 1]].Z),
                    //                 new Vector3((float)points[(int)indices[i + 2]].X, (float)points[(int)indices[i + 2]].Y, (float)points[(int)indices[i + 2]].Z));
                    //             i = i + 3;
                    //             break;
                    //         case 1:
                    //             mb.AddQuad(
                    //                 new Vector3((float)points[(int)indices[i]].X, (float)points[(int)indices[i]].Y, (float)points[(int)indices[i]].Z),
                    //                 new Vector3((float)points[(int)indices[i + 1]].X, (float)points[(int)indices[i + 1]].Y, (float)points[(int)indices[i + 1]].Z),
                    //                 new Vector3((float)points[(int)indices[i + 2]].X, (float)points[(int)indices[i + 2]].Y, (float)points[(int)indices[i + 2]].Z),
                    //                 new Vector3((float)points[(int)indices[i + 3]].X, (float)points[(int)indices[i + 3]].Y, (float)points[(int)indices[i + 3]].Z));
                    //             i = i + 4;
                    //             break;
                    //     }
                    // }

                    mb.ComputeNormalsAndTangents(MeshFaces.QuadPatches, true);
                    var meshGeometry = mb.ToMeshGeometry3D();
                    var meshGeomModel = new MeshGeometryModel3D
                    {
                        Geometry = meshGeometry,
                        Material = PhongMaterials.Red,
                        // Material = new PhongMaterial
                        // {
                        //     AmbientColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G },
                        //     // DiffuseColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G },
                        //     // SpecularColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G },
                        //     // EmissiveColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G },
                        //     // SpecularShininess = 89.6f,
                        // },
                        Transform = new TranslateTransform3D()
                    };

                    // Add the Model to the viewport
                    base.VisualizeMesh(meshGeomModel);
                }
            }
            else
            {
                base.Calculate();
            }

        }
Beispiel #24
0
        /// <summary>
        /// Updates the model in the 3D viewport
        /// </summary>
        /// <param name="mdlData">The model data</param>
        /// <param name="textureDataDictionary">The texture dictionary for the model</param>
        public void UpdateModel(XivMdl mdlData, Dictionary <int, ModelTextureData> textureDataDictionary)
        {
            SharpDX.BoundingBox?boundingBox = null;

            var totalMeshCount = mdlData.LoDList[0].MeshCount + mdlData.LoDList[0].ExtraMeshCount;

            for (var i = 0; i < totalMeshCount; i++)
            {
                var meshData = mdlData.LoDList[0].MeshDataList[i].VertexData;

                var meshGeometry3D = new MeshGeometry3D
                {
                    Positions          = new Vector3Collection(meshData.Positions),
                    Normals            = new Vector3Collection(meshData.Normals),
                    Indices            = new IntCollection(meshData.Indices),
                    Colors             = new Color4Collection(meshData.Colors4),
                    TextureCoordinates = new Vector2Collection(meshData.TextureCoordinates0),
                };

                try
                {
                    MeshBuilder.ComputeTangents(meshGeometry3D);
                }
                catch
                {
                    Debug.WriteLine($"Unable to compute tangents for mesh {i}");
                }

                if (meshData.BiNormals != null && meshData.BiNormals.Count > 0)
                {
                    meshGeometry3D.BiTangents = new Vector3Collection(meshData.BiNormals);
                }

                var textureData = textureDataDictionary[mdlData.LoDList[0].MeshDataList[i].MeshInfo.MaterialIndex];

                Stream diffuse = null, specular = null, normal = null, alpha = null, emissive = null;

                if (textureData.Diffuse != null && textureData.Diffuse.Length > 0)
                {
                    using (var img = Image.LoadPixelData <Rgba32>(textureData.Diffuse, textureData.Width, textureData.Height))
                    {
                        diffuse = new MemoryStream();
                        img.Save(diffuse, new PngEncoder());
                    }

                    streamList.Add(diffuse);
                }

                if (textureData.Specular != null && textureData.Specular.Length > 0)
                {
                    using (var img = Image.LoadPixelData <Rgba32>(textureData.Specular, textureData.Width, textureData.Height))
                    {
                        specular = new MemoryStream();
                        img.Save(specular, new PngEncoder());
                    }

                    streamList.Add(specular);
                }

                if (textureData.Normal != null && textureData.Normal.Length > 0)
                {
                    using (var img = Image.LoadPixelData <Rgba32>(textureData.Normal, textureData.Width, textureData.Height))
                    {
                        normal = new MemoryStream();
                        img.Save(normal, new PngEncoder());
                    }

                    streamList.Add(normal);
                }

                if (textureData.Alpha != null && textureData.Alpha.Length > 0)
                {
                    using (var img = Image.LoadPixelData <Rgba32>(textureData.Alpha, textureData.Width, textureData.Height))
                    {
                        alpha = new MemoryStream();
                        img.Save(alpha, new PngEncoder());
                    }

                    streamList.Add(alpha);
                }

                if (textureData.Emissive != null && textureData.Emissive.Length > 0)
                {
                    using (var img = Image.LoadPixelData <Rgba32>(textureData.Emissive, textureData.Width, textureData.Height))
                    {
                        emissive = new MemoryStream();
                        img.Save(emissive, new PngEncoder());
                    }

                    streamList.Add(emissive);
                }

                var material = new PhongMaterial
                {
                    DiffuseColor      = PhongMaterials.ToColor(1, 1, 1, 1),
                    SpecularShininess = 1f,
                    DiffuseMap        = diffuse,
                    DiffuseAlphaMap   = alpha,
                    SpecularColorMap  = specular,
                    NormalMap         = normal,
                    EmissiveMap       = emissive
                };

                var mgm3d = new CustomMeshGeometryModel3D
                {
                    Geometry = meshGeometry3D,
                    Material = material,
                    IsBody   = mdlData.LoDList[0].MeshDataList[i].IsBody
                };

                boundingBox = meshGeometry3D.Bound;

                mgm3d.CullMode = Properties.Settings.Default.Cull_Mode.Equals("None") ? CullMode.None : CullMode.Back;

                Models.Add(mgm3d);
            }

            SpecularShine = 1;

            var center = boundingBox.GetValueOrDefault().Center;

            _lightX = center.X;
            _lightY = center.Y;
            _lightZ = center.Z;

            Light3Direction    = new Vector3D(_lightX, _lightY, _lightZ);
            Camera.UpDirection = new Vector3D(0, 1, 0);
            Camera.CameraInternal.PropertyChanged += CameraInternal_PropertyChanged;
        }
        /// <summary>
        /// Called when geometry has been changed.
        /// </summary>
        protected override void OnModelChanged()
        {
            var mb = new MeshBuilder();
            var p0 = this.Offset; //new Vector3(0, 0, 0);
            if (this.InnerDiameter >= this.OuterDiameter)
                this.OuterDiameter = this.InnerDiameter + 0.3;

            var d = this.Axis;
            d.Normalize();
            var p1 = p0 - (d * (float)this.Length * 0.5f);
            var p2 = p0 + (d * (float)this.Length * 0.5f);
            mb.AddPipe(p1, p2, this.InnerDiameter, this.OuterDiameter, 64);
            this.Geometry = mb.ToMeshGeometry3D();
        }
Beispiel #26
0
 /// <summary>
 /// Adds a mesh.
 /// </summary>
 public void AddMesh()
 {
     var meshBuilder = new MeshBuilder(true, true);
     this.meshBuilders.Add(meshBuilder);
     this.materials.Add(PhongMaterials.Green);
 }
Beispiel #27
0
        public MainViewModel(Viewport3DX viewport, TreeView treeview)
        {
            // ----------------------------------------------
            // titles
            this.Title = "Ifc Viewer";
            this.SubTitle = "By LinJiarui";

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

            // ----------------------------------------------
            // setup scene
            this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f);

            this.RenderLight1 = true;
            this.RenderLight2 = false;
            this.RenderLight3 = false;
            this.RenderLight4 = true;

            this.Light1Color = (Color4)Color.White;
            this.Light2Color = (Color4)Color.Red;
            this.Light3Color = (Color4)Color.LightYellow;
            this.Light4Color = (Color4)Color.LightBlue;

            this.Light2Attenuation = new Vector3(1.0f, 0.5f, 0.10f);
            this.Light3Attenuation = new Vector3(1.0f, 0.1f, 0.05f);
            this.Light4Attenuation = new Vector3(1.0f, 0.2f, 0.0f);

            this.Light1Direction = new Vector3(0, -10, -10);
            this.Light1Transform = new TranslateTransform3D(-Light1Direction.ToVector3D());
            //            this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction.ToVector3D(), new Vector3D(0, 1, -1), 24);

            //            this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-4, 0, 0), new Vector3D(0, 0, 1), 3);
            //            this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 0, 4), new Vector3D(0, 1, 0), 5);

            this.Light4Direction = new Vector3(0, -5, 0);
            this.Light4Transform = new TranslateTransform3D(-Light4Direction.ToVector3D());
            //            this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction.ToVector3D(), new Vector3D(1, 0, 0), 12);

            // ----------------------------------------------
            // light model3d
            var sphere = new MeshBuilder();
            sphere.AddSphere(new Vector3(0, 0, 0), 0.2);
            Sphere = sphere.ToMeshGeometry3D();
            this.LightModelMaterial = new PhongMaterial {
                AmbientColor = Color.Gray,
                DiffuseColor = Color.Gray,
                EmissiveColor = Color.Yellow,
                SpecularColor = Color.Black,
            };

            viewController = new ViewController();
            Model = new Element3DCollection();
            viewController.InitGraphics(viewport, Model, treeview);
        }
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.renderTechnique = Techniques.RenderCubeMap;
            base.Attach(host);

            /// --- get variables               
            this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// -- attach cube map 
            if (this.Filename != null)
            {
                /// -- attach texture
                using (var texture = Texture2D.FromFile<Texture2D>(this.Device, this.Filename))
                {
                    this.texCubeMapView = new ShaderResourceView(this.Device, texture);
                }
                this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource();
                this.texCubeMap.SetResource(this.texCubeMapView);
                this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar();
                this.bHasCubeMap.Set(true);

                /// --- set up geometry
                var sphere = new MeshBuilder(false,true,false);
                sphere.AddSphere(new Vector3(0, 0, 0));
                this.geometry = sphere.ToMeshGeometry3D();

                /// --- set up vertex buffer
                this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex() { Position = new Vector4(x, 1f) }).ToArray());

                /// --- set up index buffer
                this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.Array);

                /// --- set up rasterizer states
                var rasterStateDesc = new RasterizerStateDescription()
                {
                    FillMode = FillMode.Solid,
                    CullMode = CullMode.Back,
                    IsMultisampleEnabled = true,
                    IsAntialiasedLineEnabled = true,
                    IsFrontCounterClockwise = false,
                };
                this.rasterState = new RasterizerState(this.Device, rasterStateDesc);

                /// --- set up depth stencil state
                var depthStencilDesc = new DepthStencilStateDescription()
                {
                    DepthComparison = Comparison.LessEqual,
                    DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All,
                    IsDepthEnabled = true,
                };
                this.depthStencilState = new DepthStencilState(this.Device, depthStencilDesc);
            }

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
Beispiel #29
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());
        }
Beispiel #30
0
        /// <summary>
        /// Constructor of the MainViewModel
        /// </summary>
        public MainViewModel()
        {
            // titles
            this.Title = "Deferred Shading Demo";
            this.SubTitle = "WPF & SharpDX";

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

            // deferred render technique
            RenderTechniquesManager = new DeferredTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.Deferred];
            EffectsManager = new DeferredEffectsManager(RenderTechniquesManager);
            SupportDeferredRender = true;

            //load model
            var reader = new ObjReader();
            var objModel = reader.Read(@"./Media/bunny.obj");
            this.Model = objModel[0].Geometry as MeshGeometry3D;
            var scale = 2.0;

            // model trafos
            var transf1 = new Transform3DGroup();
            transf1.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf1.Children.Add(new RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 40), 0.0, 0.0, 0.0));
            transf1.Children.Add(new TranslateTransform3D(0, -2, 3));
            this.Model1Transform = transf1;

            var transf2 = new Transform3DGroup();
            transf2.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf2.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 66), 0.0, 0.0, 0.0));
            transf2.Children.Add(new Media3D.TranslateTransform3D(-3.0, -2, -2.5));
            this.Model2Transform = transf2;

            var transf3 = new Transform3DGroup();
            transf3.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf3.Children.Add(new TranslateTransform3D(+3.5, -2, -1.0));
            this.Model3Transform = transf3;

            // floor plane
            var meshBuilder = new MeshBuilder();
            meshBuilder.AddBox(new Vector3(0, 0, 0), 100, 0.0, 100, BoxFaces.PositiveY);
            this.Plane = meshBuilder.ToMeshGeometry3D();
            this.PlaneTransform = new TranslateTransform3D(0, -1.05, 0);

            // model materials
            this.RedMaterial = PhongMaterials.Red;
            this.GreenMaterial = PhongMaterials.Green;
            this.BlueMaterial = PhongMaterials.Blue;
            this.PlaneMaterial = PhongMaterials.DefaultVRML;
            this.PlaneMaterial.DiffuseMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute));
            this.PlaneMaterial.NormalMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute));

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

            this.PointLightColor = (Color4)Color.White;
            this.PointLightAttenuation = new Vector3(0.0f, 0.0f, 0.18f); //1/0/0 ; 0.1, 0.2, 0.3
            this.PointLightTransform1 = new TranslateTransform3D(new Vector3D(0, 1, 0));
            this.PointLightTransform2 = new TranslateTransform3D(new Vector3D(6, 1, 3));
            this.PointLightTransform3 = new TranslateTransform3D(new Vector3D(-3, 1, -6));

            this.SpotLightColor = (Color4)Color.AntiqueWhite;
            this.SpotLightAttenuation = new Vector3(1.0f, 0.1f, 0.01f);

            // light collection
            this.PointLightCollection = new Element3DCollection();
            this.PointLightCount = 7;
            this.PointLightSpread = 100;

            // spotlight collection
            this.SpotLightCollection = new Element3DCollection();
            this.SpotLightCount = 7;
            this.SpotLightSpread = 100;
        }
Beispiel #31
0
 static Sphere()
 {
     var b1 = new MeshBuilder();
     b1.AddSphere(new Vector3(0, 0, 0), 0.5);
     geometry = b1.ToMeshGeometry3D();
 }
        /// <summary>
        /// Cuts the mesh with the specified plane. (Modified from HelixToolkit.Wpf version)
        /// </summary>
        /// <param name="mesh">
        /// The mesh.
        /// </param>
        /// <param name="plane">
        /// The plane origin.
        /// </param>
        /// <param name="normal">
        /// The plane normal.
        /// </param>
        /// <returns>
        /// The <see cref="MeshGeometry3D"/>.
        /// </returns>
        public static MeshGeometry3D CutMesh(this MeshGeometry3D mesh, Media3D.Point3D plane, Vector3 normal)
        {
            var hasTextureCoordinates = mesh.TextureCoordinates != null && mesh.TextureCoordinates.Count > 0;
            var hasNormals = mesh.Normals != null && mesh.Normals.Count > 0;
            var meshBuilder = new MeshBuilder(hasNormals, hasTextureCoordinates);
            var contourHelper = new HelixToolkit.Wpf.SharpDX.Helpers.ContourHelperDX(plane, normal, mesh);
            foreach (var position in mesh.Positions)
            {
                meshBuilder.Positions.Add(position);
            }

            if (hasTextureCoordinates)
            {
                foreach (var textureCoordinate in mesh.TextureCoordinates)
                {
                    meshBuilder.TextureCoordinates.Add(textureCoordinate);
                }
            }

            if (hasNormals)
            {
                foreach (var n in mesh.Normals)
                {
                    meshBuilder.Normals.Add(n);
                }
            }

            for (var i = 0; i < mesh.Indices.Count; i += 3)
            {
                var index0 = mesh.Indices[i];
                var index1 = mesh.Indices[i + 1];
                var index2 = mesh.Indices[i + 2];

                Vector3[] positions;
                Vector3[] normals;
                Vector2[] textureCoordinates;
                int[] triangleIndices;

                contourHelper.ContourFacet(index0, index1, index2, out positions, out normals, out textureCoordinates, out triangleIndices);

                foreach (var p in positions)
                {
                    meshBuilder.Positions.Add(p);
                }

                foreach (var tc in textureCoordinates)
                {
                    meshBuilder.TextureCoordinates.Add(tc);
                }

                foreach (var n in normals)
                {
                    meshBuilder.Normals.Add(n);
                }

                foreach (var ti in triangleIndices)
                {
                    meshBuilder.TriangleIndices.Add(ti);
                }
            }

            return meshBuilder.ToMeshGeometry3D();
        }
        public void ComputeBoundsForSelectedNodeGeometry_OnePointOneCubeSelected_BoundingBoxIsCorrect()
        {
            var pointA = InitializePointWithId("A");

            var builder = new MeshBuilder();
            builder.AddBox(new Vector3(1000000, 1000000, 1000000), 5, 5, 5, BoxFaces.All);
            var boxGeom = builder.ToMeshGeometry3D();
            var boxB = new MeshGeometryModel3D()
            {
                Geometry = boxGeom,
                Name = "B"
            };

            var bounds = HelixWatch3DViewModel.ComputeBoundsForGeometry(new GeometryModel3D[] { pointA, boxB });
            Assert.AreEqual(bounds.Minimum, pointA.Bounds().Minimum);
            Assert.AreEqual(bounds.Maximum, boxB.Bounds().Maximum);
        }
Beispiel #34
0
        public Watch3DNodeDx(Core.VplControl hostCanvas) : base(hostCanvas)
        {
            // Add Control s
            _control = new Watch3DxControl();
            AddControlToNode(_control);

            // Set Node resizable ...
            IsResizeable = true;

            // Add Control s
            _control = new Watch3DxControl();

            /*
             * {
             *  ViewPort3D =
             *  {
             *
             *      Background = new SolidColorBrush(Colors.White),
             *      Camera =
             *          new PerspectiveCamera
             *          {
             *              Position = new Point3D(0, 0, 0),
             *              NearPlaneDistance = 0.1,
             *              FarPlaneDistance = double.PositiveInfinity,
             *              LookDirection = new Vector3D(-3, -3, -5),
             *              UpDirection = new Vector3D(0, 1, 0)
             *          },
             *      RenderTechnique = Techniques.RenderBlinn,
             *      MaximumFieldOfView = 45,
             *      MinimumFieldOfView = 20
             *
             *  }
             * };
             */

            // ViewPort3D = _control.ViewPort3D;

            var mb = new MeshBuilder();

            for (var i = 0; i < 1000; i++)
            {
                mb.AddBox(new Vector3(i + 15, i + 15, i + 15), 100, 100, 100, BoxFaces.All);
            }

            // _control.meshModel.Material = PhongMaterials.Orange;
            // _control.meshModel.Geometry = mb.ToMeshGeometry3D();
            //_control.meshModel.Visibility = Visibility.Visible;

            var model = new MeshGeometryModel3D();

            model.Geometry = mb.ToMeshGeometry3D();
            model.Material = PhongMaterials.Orange;

            // {Geometry = mb.ToMeshGeometry3D(), Material = PhongMaterials.Orange, Visibility = Visibility.Visible};
            _control.ViewPort3D.Items.Add(model);

            _control.ViewPort3D.Items.Add(new AmbientLight3D {
                Color = Color4.White
            });
            // control.ViewPort3D.Items.Add(new DirectionalLight3D() { Color = Color4.White , Direction = new Vector3(0,0,1)});

            // _control.ViewPort3D.ShowTriangleCountInfo = true;
            // _control.ViewPort3D.ShowFieldOfView = true;

            AddControlToNode(_control);

            AddInputPortToNode("Elements", typeof(object));
        }
Beispiel #35
0
        /// <summary>
        /// Creates a MeshGeometry3D object from the loaded file. Polygons are triangulated using triangle fans.
        /// </summary>
        /// <returns>
        /// A MeshGeometry3D.
        /// </returns>
        public MeshGeometry3D CreateMeshGeometry3D(ModelInfo info = default(ModelInfo))
        {
            var mb = new MeshBuilder(info.Normals, info.Tangents);
            foreach (var p in this.Vertices)
            {
                mb.Positions.Add(p);
            }

            foreach (var face in this.Faces)
            {
                mb.AddTriangleFan(face);
            }
            mb.ComputeNormalsAndTangents(info.Faces);
            return mb.ToMeshGeometry3D();
        }
Beispiel #36
0
        private void CreateFaceModels(IFCItem item, Vector3D center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0)
                {
                    var positions = new List<Vector3>();
                    var normals = new List<Vector3>();
                    if (item.verticesForFaces != null)
                    {
                        for (int i = 0; i < item.noVerticesForFaces; i++)
                        {
                            var point = new Point3D(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z);
                            var normal = new Vector3D(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5]);
                            positions.Add(new Vector3((float)point.X, (float)point.Y, (float)point.Z));
                            normals.Add(new Vector3((float)normal.X, (float)normal.Y, (float)normal.Z));
                        }

                        Debug.Assert(item.verticesForFaces.Length == item.noVerticesForFaces * 6);
                    }

                    var indices = new Int32Collection();
                    if (item.indicesForFaces != null)
                    {
                        for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++)
                        {
                            indices.Add(item.indicesForFaces[i]);
                        }
                    }

                    List<Vector2> textureCoords = positions.Select(o => new Vector2(o.X, o.Y)).ToList();

                    var meshBuilder = new MeshBuilder();
                    meshBuilder.Append(positions, indices,normals,textureCoords);
                    MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = meshBuilder.ToMeshGeometry3D() };
                    item.Mesh3d = mesh;
                    _meshToIfcItems[mesh] = item;
            #if DEBUG
                    //OutputObj(item.ifcID.ToString(), mesh);
            #endif
                    FillMeshByIfcColor(item);

                    model.Add(mesh);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
        /// <summary>
        /// Appends the specified mesh.
        /// </summary>
        /// <param name="mesh">
        /// The mesh.
        /// </param>
        public void Append(MeshBuilder mesh)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException("mesh");
            }

            this.Append(mesh.positions, mesh.triangleIndices, mesh.normals, mesh.textureCoordinates);
        }
        public MainViewModel()
        {
            // ----------------------------------------------
            // titles
            this.Title = "Lighting Demo";
            this.SubTitle = "WPF & SharpDX";

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

            // ----------------------------------------------
            // setup scene
            this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f);

            this.RenderLight1 = true;
            this.RenderLight2 = true;
            this.RenderLight3 = true;
            this.RenderLight4 = true;

            this.Light1Color = (Color4)Color.White;
            this.Light2Color = (Color4)Color.Red;
            this.Light3Color = (Color4)Color.LightYellow;
            this.Light4Color = (Color4)Color.LightBlue;

            this.Light2Attenuation = new Vector3(1.0f, 0.5f, 0.10f);
            this.Light3Attenuation = new Vector3(1.0f, 0.1f, 0.05f);
            this.Light4Attenuation = new Vector3(1.0f, 0.2f, 0.0f);

            this.Light1Direction = new Vector3(0, -10, -10);
            this.Light1Transform = new TranslateTransform3D(-Light1Direction.ToVector3D());
            this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction.ToVector3D(), new Vector3D(0, 1, -1), 24);

            this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-4, 0, 0), new Vector3D(0, 0, 1), 3);
            this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 0, 4), new Vector3D(0, 1, 0), 5);

            this.Light4Direction = new Vector3(0, -5, 0);
            this.Light4Transform = new TranslateTransform3D(-Light4Direction.ToVector3D());
            this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction.ToVector3D(), new Vector3D(1, 0, 0), 12); 
            
            // ----------------------------------------------
            // light model3d
            var sphere = new MeshBuilder();
            sphere.AddSphere(new Vector3(0, 0, 0), 0.2);
            Sphere = sphere.ToMeshGeometry3D();
            this.LightModelMaterial = new PhongMaterial
            {
                AmbientColor = Color.Gray,
                DiffuseColor = Color.Gray,
                EmissiveColor = Color.Yellow,
                SpecularColor = Color.Black,
            };

            // ----------------------------------------------
            // scene model3d
            var b1 = new MeshBuilder(true, true, true);
            b1.AddSphere(new Vector3(0.25f, 0.25f, 0.25f), 0.75, 64, 64);
            b1.AddBox(-new Vector3(0.25f, 0.25f, 0.25f), 1, 1, 1, BoxFaces.All);
            b1.AddBox(-new Vector3(5.0f, 0.0f, 0.0f), 1, 1, 1, BoxFaces.All);
            b1.AddSphere(new Vector3(5f, 0f, 0f), 0.75, 64, 64);
            b1.AddCylinder(new Vector3(0f, -3f, -5f), new Vector3(0f, 3f, -5f), 1.2, 64);

            this.Model = b1.ToMeshGeometry3D();
            this.ModelTransform = new Media3D.TranslateTransform3D(0, 0, 0);
            this.ModelMaterial = PhongMaterials.Chrome;
            //this.ModelMaterial.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute));
            this.ModelMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute));
            //odelMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureNoise1_dot3.jpg", System.UriKind.RelativeOrAbsolute));


            // ----------------------------------------------
            // floor model3d
            var b2 = new MeshBuilder(true, true, true);
            b2.AddBox(new Vector3(0.0f, -5.0f, 0.0f), 15, 0.1, 15, BoxFaces.All);
            b2.AddSphere(new Vector3(-5.0f, -5.0f, 5.0f), 4, 64, 64);
            b2.AddCone(new Vector3(6f, -9f, -6f), new Vector3(6f, -1f, -6f), 4f, true, 64);
            this.Floor = b2.ToMeshGeometry3D();
            this.FloorTransform = new Media3D.TranslateTransform3D(0, 0, 0);
            this.FloorMaterial = new PhongMaterial
            {
                AmbientColor = Color.Gray,
                DiffuseColor = new Color4(0.75f, 0.75f, 0.75f, 1.0f), 
                SpecularColor = Color.White,
                SpecularShininess = 100f,
                DiffuseMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)),
                NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)),
            };            
        }
        /// <summary>
        /// Gets a unit sphere from the cache.
        /// </summary>
        /// <param name="subdivisions">
        /// The number of subdivisions.
        /// </param>
        /// <returns>
        /// A unit sphere mesh.
        /// </returns>
        private static MeshGeometry3D GetUnitSphere(int subdivisions)
        {
            if (UnitSphereCache.ContainsKey(subdivisions))
            {
                return UnitSphereCache[subdivisions];
            }

            var mb = new MeshBuilder(false, false);
            mb.AddRegularIcosahedron(new Vector3(), 1, false);
            for (int i = 0; i < subdivisions; i++)
            {
                mb.SubdivideLinear();
            }

            for (int i = 0; i < mb.positions.Count; i++)
            {
                var v = mb.positions[i];
                v.Normalize();
                mb.positions[i] = v;
            }

            var mesh = mb.ToMeshGeometry3D();
            UnitSphereCache[subdivisions] = mesh;
            return mesh;
        }
Beispiel #40
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)));
                }
            }
        }
Beispiel #41
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;
        }
Beispiel #42
0
        private static MeshGeometry3D DrawTestMesh()
        {
            var b1 = new MeshBuilder();
            for (var x = 0; x < 4; x++)
            {
                for (var y = 0; y < 4; y++)
                {
                    for (var z = 0; z < 4; z++)
                    {
                        b1.AddBox(new Vector3(x, y, z), 0.5, 0.5, 0.5, BoxFaces.All);
                    }
                }
            }
            var mesh = b1.ToMeshGeometry3D();
            
            mesh.Colors = new Color4Collection();
            foreach (var v in mesh.Positions)
            {
                mesh.Colors.Add(new Color4(1f,0f,0f,1f));
            }

            return mesh;
        }
Beispiel #43
0
        //用來輸入文字文件,然後輸出球的模型檔案
        private void SaveBall()
        {
            string path = "D:\\Desktop\\新文字文件.txt";

            try
            {
                string   fileContent  = File.ReadAllText(path);
                string[] contentArray = fileContent.Split((string[])null, StringSplitOptions.RemoveEmptyEntries);
                float[]  pointInfo    = Array.ConvertAll(contentArray, float.Parse);
                if (pointInfo.Length % 3 != 0)
                {
                    throw new Exception();
                }

                var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder();
                for (int i = 0; i < pointInfo.Length / 3; i++)
                {
                    ballContainer.AddSphere(new Vector3(pointInfo[i * 3], pointInfo[i * 3 + 1], pointInfo[i * 3 + 2]), 1.5);
                }

                System.Windows.Media.Media3D.MeshGeometry3D ballMesh = new System.Windows.Media.Media3D.MeshGeometry3D
                {
                    Positions       = new Point3DCollection(),
                    Normals         = new Vector3DCollection(),
                    TriangleIndices = new Int32Collection()
                };
                HelixToolkit.Wpf.SharpDX.MeshGeometry3D geometry = ballContainer.ToMeshGeometry3D();

                foreach (Vector3 position in geometry.Positions)
                {
                    ballMesh.Positions.Add(new Point3D(position.X, position.Y, position.Z));
                }
                foreach (Vector3 normal in geometry.Normals)
                {
                    ballMesh.Normals.Add(new Vector3D(normal.X, normal.Y, normal.Z));
                }
                foreach (int triangleindice in geometry.TriangleIndices)
                {
                    ballMesh.TriangleIndices.Add(triangleindice);
                }

                System.Windows.Media.Media3D.GeometryModel3D ballModel = new System.Windows.Media.Media3D.GeometryModel3D
                {
                    Geometry = ballMesh,
                };

                Model3DGroup ballGroup = new Model3DGroup();


                ballGroup.Children.Add(ballModel);

                StlExporter export1 = new StlExporter();
                string      name1   = "ball.stl";
                using (var fileStream = File.Create("D:\\Desktop\\" + name1))
                {
                    export1.Export(ballGroup, fileStream);
                }
            }
            catch
            {
                System.Windows.MessageBox.Show("點的讀取錯誤");
            }
        }
        public Watch3DNodeDx(Core.VplControl hostCanvas) : base(hostCanvas)
        {
            // Add Control s
            _control = new Watch3DxControl();
            AddControlToNode(_control);

            // Set Node resizable ...
            IsResizeable = true;

            // Add Control s
            _control = new Watch3DxControl();
            /*
            {
                ViewPort3D =
                {
                    
                    Background = new SolidColorBrush(Colors.White),
                    Camera =
                        new PerspectiveCamera
                        {
                            Position = new Point3D(0, 0, 0),
                            NearPlaneDistance = 0.1,
                            FarPlaneDistance = double.PositiveInfinity,
                            LookDirection = new Vector3D(-3, -3, -5),
                            UpDirection = new Vector3D(0, 1, 0)
                        },
                    RenderTechnique = Techniques.RenderBlinn,
                    MaximumFieldOfView = 45,
                    MinimumFieldOfView = 20
                    
                }
            };
            */

            // ViewPort3D = _control.ViewPort3D;

            var mb = new MeshBuilder();
            for (var i = 0; i < 1000; i++)
            {
                mb.AddBox(new Vector3(i + 15, i + 15, i + 15), 100, 100, 100, BoxFaces.All);
            }

            // _control.meshModel.Material = PhongMaterials.Orange;
            // _control.meshModel.Geometry = mb.ToMeshGeometry3D();
            //_control.meshModel.Visibility = Visibility.Visible;

            var model = new MeshGeometryModel3D();
            model.Geometry = mb.ToMeshGeometry3D();
            model.Material = PhongMaterials.Orange;

            // {Geometry = mb.ToMeshGeometry3D(), Material = PhongMaterials.Orange, Visibility = Visibility.Visible};
            _control.ViewPort3D.Items.Add(model);

            _control.ViewPort3D.Items.Add(new AmbientLight3D {Color = Color4.White});
            // control.ViewPort3D.Items.Add(new DirectionalLight3D() { Color = Color4.White , Direction = new Vector3(0,0,1)});

            // _control.ViewPort3D.ShowTriangleCountInfo = true;
            // _control.ViewPort3D.ShowFieldOfView = true;

            AddControlToNode(_control);

            AddInputPortToNode("Elements", typeof (object));
        }
Beispiel #45
0
        /// <summary>
        /// 連續點擊兩下產生出球
        /// </summary>
        public void OnMouseDoubleClickHandler(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //如果當前可點擊的狀態為否則直接return
            if (!MainViewModel.ProjData.CanSelectPoints)
            {
                return;
            }

            Viewport3DX viewport = sender as Viewport3DX;

            if (viewport == null)
            {
                return;
            }
            var point    = e.GetPosition(viewport);
            var hitTests = viewport.FindHits(point);

            //null或是點到的東西為少於零個
            if (hitTests == null || hitTests.Count <= 0)
            {
                return;
            }

            foreach (var hit in hitTests)
            {
                //有可能點到對稱面,不是BoneModel的話換下一個模型
                if (!(hit.ModelHit is BoneModel))
                {
                    continue;
                }

                BallModel ball = new BallModel
                {
                    BallName = "Ball",
                };

                //這邊很怪 拿不到該有的屬性資訊只有一些基底類別的資訊
                BoneModel model = hit.ModelHit as BoneModel;
                foreach (BoneModel modeltem in MainViewModel.ProjData.BoneCollection)
                {
                    //先找出當前點到的BoneModel是哪個,並將點擊的球的ModelType設定成跟該Model一樣
                    if (modeltem.Geometry.Positions.Count == model.Geometry.Positions.Count)
                    {
                        ball.ModelType = modeltem.ModelType;
                        Binding binding = new Binding("Transform");
                        binding.Source = modeltem;
                        binding.Mode   = BindingMode.OneWay;
                        BindingOperations.SetBinding(ball, HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, binding);
                    }
                }


                var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder();
                ball.BallCenter = new Vector3(Convert.ToSingle(hit.PointHit.X), Convert.ToSingle(hit.PointHit.Y), Convert.ToSingle(hit.PointHit.Z));
                ballContainer.AddSphere(ball.BallCenter, 1.5);
                ball.Geometry = ballContainer.ToMeshGeometry3D();
                ball.Material = PhongMaterials.White;

                MainViewModel.ProjData.BallCollection.Add(ball);

                break;
            }
        }