Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            var modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);
            meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            // Create some materials
            var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);
            var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
            var blueMaterial = MaterialHelper.CreateMaterial(Colors.Blue);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });

            // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            this.Model = modelGroup;
        }
Exemplo n.º 2
0
        private ModelVisual3D CreateDice()
        {
            var diceMesh = new MeshBuilder();
            diceMesh.AddBox(new Point3D(0, 0, 0), 1, 1, 1);
            for (int i = 0; i < 2; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 2; k++)
                    {
                        var points = new List<Point3D>();
                        diceMesh.ChamferCorner(new Point3D(i - 0.5, j - 0.5, k - 0.5), 0.1, 1e-6, points);
                        //foreach (var p in points)
                        //    b.ChamferCorner(p, 0.03);
                    }

            return new ModelVisual3D { Content = new GeometryModel3D { Geometry = diceMesh.ToMesh(), Material = Materials.White } };
        }
Exemplo n.º 3
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique         = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager          = new DefaultEffectsManager(RenderTechniquesManager);

            // ----------------------------------------------
            // 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.NormalMap = LoadFileToMemory(new System.Uri(SelectedNormalTexture, System.UriKind.RelativeOrAbsolute).ToString());

            // ----------------------------------------------
            // 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        = LoadFileToMemory(new System.Uri(SelectedDiffuseTexture, System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap         = ModelMaterial.NormalMap
            };
            ModelMaterial.DiffuseMap = FloorMaterial.DiffuseMap;
        }
Exemplo n.º 4
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.º 5
0
        public MainViewModel()
        {
            // titles
            Title = "Watch3DxNode";
            // SubTitle = "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
            };

            // default render technique
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique         = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager          = new DefaultEffectsManager(RenderTechniquesManager);


            // Init
            RedMaterial = PhongMaterials.Red;

            // Choose the device -> BestAdapter is chosen here.
            // var text = EffectsManager.Device.DebugName;

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

            var b1 = new MeshBuilder();


            b1.AddSphere(new Vector3(0, 0, 0), 0.5);                                                               // floor plane grid
            // Grid = LineBuilder.GenerateGrid();
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);                                              // GridColor = Color.Black;
            // GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5);
            var meshGeometry = b1.ToMeshGeometry3D();                                                              //

            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); // scene model3d
            Model = meshGeometry;

            // 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 trafos
            // Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            // Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            // Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);
            //
            // // model materials

            // GreenMaterial = PhongMaterials.Green;
            // BlueMaterial = PhongMaterials.Blue;
            //
            // // var mat = new PhongMaterial();
            // // mat.AmbientColor = new Color4(new Color3());
            //
            // //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 < 100; x++)
            // {
            //     for (int y = 0; y < 100; y++)
            //     {
            //         for (int z = 0; z < 100; 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)));
            //     }
            // }
        }
        private void CreateArea(RoamArea area)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();
            if (_mapping.ContainsKey(area))
            {
                foreach (Model3D model in _mapping[area])
                {
                    group.Children.Remove(model);
                }
            }

            foreach (var vertex in area.Vertices)
            {
                MeshBuilder builder = new MeshBuilder();
                Point3D p1 = new Point3D(vertex.X, vertex.Y, area.MaxZ);
                Point3D p2 = new Point3D(vertex.X, vertex.Y, area.MinZ);

                //if (Clipping != null && !Clipping.DrawPoint(p)) continue;

                builder.AddBox(p1, 4, 4, 4);
                builder.AddBox(p2, 4, 4, 4);
                builder.AddPipe(p1, p2, 1.5, 1.5, 50);

                GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Yellow);
                collection.Add(box);

                builder = new MeshBuilder();

                Point3D next = new Point3D();
                if (vertex == area.Vertices.Last())
                {
                    next.X = area.Vertices[0].X;
                    next.Y = area.Vertices[0].Y;
                }
                else
                {
                    next.X = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1).X;
                    next.Y = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1).Y;
                }
                Point3D n1 = new Point3D(next.X, next.Y, area.MaxZ);
                Point3D n2 = new Point3D(next.X, next.Y, area.MinZ);

                //builder.AddPipe(p1, p2);
                builder.AddPipe(p1, n1, 0.5, 0.5, 50);
                builder.AddPipe(p2, n2, 0.5, 0.5, 50);
                collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));

            }

            _mapping[area] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Exemplo n.º 7
0
        private void AppearanceChanged()
        {
            var builder = new MeshBuilder(false, false);
            var p0      = new Point(0, 0);
            var p1      = new Point(this.Diameter / 2, 0);
            var p2      = new Point(this.Diameter / 2, this.Height);
            var p3      = new Point(this.DomeDiameter / 2, this.Height);

            var section = new List <Point> {
                p0, p1, p1, p2, p2, p3
            };
            var sectionIndices = new List <int> {
                0, 1, 2, 3, 4, 5
            };
            int n = 40;

            for (int i = n; i >= 0; i--)
            {
                double x = (double)i / n;
                double y = x * x;
                if (i < n)
                {
                    sectionIndices.Add(section.Count - 1);
                    sectionIndices.Add(section.Count);
                }

                section.Add(new Point(x * this.DomeDiameter / 2, this.Height + (this.DomeHeight * (1 - y))));
            }

            builder.AddSurfaceOfRevolution(new Point3D(0, 0, 0), new Vector3D(0, 0, 1), section, sectionIndices, 80);
            this.walls.Geometry = builder.ToMesh(true);

            var treadDepth   = 0.3;
            var riseHeight   = 0.15;
            var thickness    = 0.05;
            var width        = 1;
            var steps        = (int)(this.Height / riseHeight);
            var r            = (this.Diameter * 0.5) + (width * 0.5);
            var rp           = (this.Diameter * 0.5) + (width * 0.95);
            var stairBuilder = new MeshBuilder(false, false);
            var railBases    = new List <Point3D>();

            for (int i = 0; i < steps; i++)
            {
                var theta = treadDepth * i / r;
                var p     = new Point3D(Math.Cos(theta) * r, Math.Sin(theta) * r, (riseHeight * i) + (thickness / 2));
                var x     = new Vector3D(Math.Cos(theta), Math.Sin(theta), 0);
                var z     = new Vector3D(0, 0, 1);
                var y     = Vector3D.CrossProduct(z, x);
                stairBuilder.AddBox(p, x, y, width, treadDepth, thickness);
                railBases.Add(new Point3D(Math.Cos(theta) * rp, Math.Sin(theta) * rp, (riseHeight * i) + thickness));
            }

            var lastTheta = treadDepth * steps / r;

            // Railing along stairs
            var railingHeight   = 0.8;
            var railingDiameter = 0.05;
            var railings        = 3;
            var railingBuilder  = new MeshBuilder(false, false);

            // Top railing
            var railingPostDistance = 0.5;
            int topRailingPosts     = (int)(this.Diameter * Math.PI / railingPostDistance);
            var tr = (this.Diameter / 2) - railingDiameter;

            for (int i = 0; i < topRailingPosts; i++)
            {
                var theta = lastTheta + (2 * Math.PI * i / topRailingPosts);
                railBases.Add(new Point3D(Math.Cos(theta) * tr, Math.Sin(theta) * tr, this.Height));
            }

            BuildRailing(railingBuilder, railBases, railingHeight, railingDiameter, railings);

            this.stairs.Geometry  = stairBuilder.ToMesh();
            this.railing.Geometry = railingBuilder.ToMesh();
        }
Exemplo n.º 8
0
        public MainViewModel()
        {
            //    RenderTechniquesManager = new DefaultRenderTechniquesManager();
            EffectsManager = new DefaultEffectsManager();
            // ----------------------------------------------
            // titles
            this.Title    = "GroupElement Test";
            this.SubTitle = "WPF & SharpDX";

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

            var lineBuilder = new LineBuilder();

            lineBuilder.AddLine(new Vector3(0, 0, 0), new Vector3(10, 0, 0));
            lineBuilder.AddLine(new Vector3(0, 0, 0), new Vector3(0, 10, 0));
            lineBuilder.AddLine(new Vector3(0, 0, 0), new Vector3(0, 0, 10));
            AxisModel        = lineBuilder.ToLineGeometry3D();
            AxisModel.Colors = new Color4Collection(AxisModel.Positions.Count);
            AxisModel.Colors.Add(Colors.Red.ToColor4());
            AxisModel.Colors.Add(Colors.Red.ToColor4());
            AxisModel.Colors.Add(Colors.Green.ToColor4());
            AxisModel.Colors.Add(Colors.Green.ToColor4());
            AxisModel.Colors.Add(Colors.Blue.ToColor4());
            AxisModel.Colors.Add(Colors.Blue.ToColor4());

            AxisLabel = new BillboardText3D();
            AxisLabel.TextInfo.Add(new TextInfo()
            {
                Origin = new Vector3(11, 0, 0), Text = "X", Foreground = Colors.Red.ToColor4()
            });
            AxisLabel.TextInfo.Add(new TextInfo()
            {
                Origin = new Vector3(0, 11, 0), Text = "Y", Foreground = Colors.Green.ToColor4()
            });
            AxisLabel.TextInfo.Add(new TextInfo()
            {
                Origin = new Vector3(0, 0, 11), Text = "Z", Foreground = Colors.Blue.ToColor4()
            });

            var meshBuilder = new MeshBuilder(true);

            meshBuilder.AddSphere(new Vector3(0, 0, 0), 0.5);
            SphereModel = meshBuilder.ToMesh();
            meshBuilder = new MeshBuilder(true);
            meshBuilder.AddBox(Vector3.Zero, 0.5, 0.5, 0.5);
            BoxModel    = meshBuilder.ToMesh();
            meshBuilder = new MeshBuilder(true);
            meshBuilder.AddCone(Vector3.Zero, new Vector3(0, 2, 0), 1, true, 24);
            ConeModel = meshBuilder.ToMesh();

            AddGroupModelCommand               = new RelayCommand(AddGroupModel);
            RemoveGroupModelCommand            = new RelayCommand(RemoveGroupModel);
            AddTransparentGroupModelCommand    = new RelayCommand(AddTransparentMesh);
            RemoveTransparentGroupModelCommand = new RelayCommand(RemoveTransparentModel);
            ClearGroupModelCommand             = new RelayCommand((o) => { GroupModelSource.Clear(); });
            AnimateGroupModelCommand           = new RelayCommand(AnimateGroupModel);
            AddItemsModelCommand               = new RelayCommand(AddItemsModel);
            RemoveItemsModelCommand            = new RelayCommand(RemoveItemsModel);
            ClearItemsModelCommand             = new RelayCommand((o) => { ItemsSource.Clear(); });
            AnimateItemsModelCommand           = new RelayCommand(AnimateItemsModel);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Redraw the map
        /// </summary>
        /// <param name="FullRedraw">Clear all the static items or not</param>
        public void ReDrawMap(bool FullRedraw = false, bool DataRedraw = false, bool FastUpdate = false)
        {
            double Size   = 8000;
            double XScale = Size / universeWidth;
            double ZScale = Size / universeDepth;

            universeScale = Math.Min(XScale, ZScale);

            var mb       = new MeshBuilder();
            var mbRegion = new MeshBuilder();

            foreach (GateHelper gh in universeSysLinksCache)
            {
                double X1 = (gh.from.ActualX - universeXMin) * universeScale;
                double Y1 = (gh.from.ActualZ - universeZMin) * universeScale;
                double Z1 = (gh.from.ActualY - universeYMin) * universeScale;


                double X2 = (gh.to.ActualX - universeXMin) * universeScale;
                double Y2 = (gh.to.ActualZ - universeZMin) * universeScale;
                double Z2 = (gh.to.ActualY - universeYMin) * universeScale;


                if (gh.RegionalGate)
                {
                    mbRegion.AddCylinder(new Vector3((float)X1, (float)Y1, (float)Z1), new Vector3((float)X2, (float)Y2, (float)Z2), 1, 4);
                }
                else
                {
                    mb.AddCylinder(new Vector3((float)X1, (float)Y1, (float)Z1), new Vector3((float)X2, (float)Y2, (float)Z2), 1, 4);
                }
            }

            PhongMaterial em   = PhongMaterials.Gray;
            PhongMaterial emrg = PhongMaterials.Red;


            MeshGeometryModel3D geomModelGates = new MeshGeometryModel3D {
                Geometry = mb.ToMeshGeometry3D(), Material = em
            };

            UniverseMain3DViewPort.Items.Add(geomModelGates);

            MeshGeometryModel3D geomModelRegionalGates = new MeshGeometryModel3D {
                Geometry = mbRegion.ToMesh(), Material = emrg
            };

            UniverseMain3DViewPort.Items.Add(geomModelRegionalGates);


            var mbSystems = new MeshBuilder();

            foreach (EVEData.System sys in EM.Systems)
            {
                double X1 = (sys.ActualX - universeXMin) * universeScale;
                double Y1 = (sys.ActualZ - universeZMin) * universeScale;
                double Z1 = (sys.ActualY - universeYMin) * universeScale;

                Vector3 sysCentre = new Vector3((float)X1, (float)Y1, (float)Z1);

                mbSystems.AddBox(sysCentre, 10, 10, 10);



//                BillboardTextVisual3D sysTextBB = new BillboardTextVisual3D();
//
//                sysTextBB.Position = sysCentre;
//                sysTextBB.Text = "    " + sys.Name;
//                UniverseMain3DViewPort.Children.Add(sysTextBB);
            }



            PhongMaterial       emsys            = PhongMaterials.White;
            MeshGeometryModel3D geomModelSystems = new MeshGeometryModel3D {
                Geometry = mbSystems.ToMesh(), Material = emsys
            };

            UniverseMain3DViewPort.Items.Add(geomModelSystems);

//            UniverseMain3DViewPort.Camera.Position = new Point3D(4000, 4000, 1000);
//            UniverseMain3DViewPort.Camera.LookAt(new Point3D(0, 0, 0), 1);

            //            UniverseMain3DViewPort.Camera.ZoomExtents();
        }
Exemplo n.º 10
0
 private void MeshBuild()
 {
     //build the box for the nodes
     MeshBuilder builder = new MeshBuilder();
     builder.AddBox(new Point3D(0, 0, 0), 2, 2, 2);
     _nodeModel = new GeometryModel3D(builder.ToMesh(), Materials.Green);
 }
Exemplo n.º 11
0
        protected override MeshGeometry3D Tessellate()
        {
            double width = Columns*grid - margin*2;
            double length = Rows*grid - margin*2;
            double height = Height*plateThickness;
            var builder = new MeshBuilder(true, true);

            for (int i = 0; i < Columns; i++)
                for (int j = 0; j < Rows; j++)
                {
                    var o = new Point3D((i + 0.5)*grid, (j + 0.5)*grid, height);
                    builder.AddCone(o, new Vector3D(0, 0, 1), knobDiameter/2, knobDiameter/2, knobHeight, false, true,
                                    Divisions);
                    builder.AddPipe(new Point3D(o.X, o.Y, o.Z - wallThickness), new Point3D(o.X, o.Y, wallThickness),
                                    knobDiameter, outerDiameter, Divisions);
                }

            builder.AddBox(new Point3D(Columns * 0.5 * grid, Rows * 0.5 * grid, height - wallThickness / 2), width, length,
                          wallThickness,
                          MeshBuilder.BoxFaces.All);
            builder.AddBox(new Point3D(margin + wallThickness / 2, Rows * 0.5 * grid, height / 2 - wallThickness / 2),
                           wallThickness, length, height - wallThickness,
                           MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
            builder.AddBox(
                new Point3D(Columns * grid - margin - wallThickness / 2, Rows * 0.5 * grid, height / 2 - wallThickness / 2),
                wallThickness, length, height - wallThickness,
                MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
            builder.AddBox(new Point3D(Columns * 0.5 * grid, margin + wallThickness / 2, height / 2 - wallThickness / 2),
                           width, wallThickness, height - wallThickness,
                           MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
            builder.AddBox(
                new Point3D(Columns * 0.5 * grid, Rows * grid - margin - wallThickness / 2, height / 2 - wallThickness / 2),
                width, wallThickness, height - wallThickness,
                MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);

            return builder.ToMesh();
        }
        private void CreateArea(LineOfSightArea area)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();
            try
            {
                if (_mapping[area] != null)
                {
                    foreach (Model3D model in _mapping[area])
                    {
                        group.Children.Remove(model);
                    }
                }
            }
            catch (KeyNotFoundException)
            {
                //nothing needs to be done
            }

            foreach (var vertex in area.Vertices)
            {
                MeshBuilder builder = new MeshBuilder();
                Point3D p1 = new Point3D(vertex.X, vertex.Y, area.MaxZ);
                Point3D p2 = new Point3D(vertex.X, vertex.Y, area.MinZ);

                //if (Clipping != null && !Clipping.DrawPoint(p)) continue;

                builder.AddBox(p1, 4, 4, 4);
                builder.AddBox(p2, 4, 4, 4);
                builder.AddPipe(p1, p2, 1.5, 1.5, 50);

                GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Yellow);
                collection.Add(box);

                builder = new MeshBuilder();

                Point3D next;
                if (vertex == area.Vertices.Last())
                {
                    next = area.Vertices[0];
                }
                else
                {
                    next = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1);
                }
                Point3D n1 = new Point3D(next.X, next.Y, area.MaxZ);
                Point3D n2 = new Point3D(next.X, next.Y, area.MinZ);

                //builder.AddPipe(p1, p2);
                builder.AddPipe(p1, n1, 0.5, 0.5, 50);
                builder.AddPipe(p2, n2, 0.5, 0.5, 50);
                collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));

            }

            _mapping[area] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Exemplo n.º 13
0
        private void CreateGrid(Grid grid)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(grid))
            {
                foreach (Model3D model in _mapping[grid])
                {
                    group.Children.Remove(model);
                }
            }

            foreach (Waypoint wp in grid.Waypoints)
            {
                MeshBuilder builder = new MeshBuilder();
                Point3D p = new Point3D(wp.X,wp.Y,wp.Z);

                if (Clipping != null && !Clipping.DrawPoint(p)) continue;
                builder.AddBox(p, 2, 2, 2);

                Transform3D headingRotate = new RotateTransform3D()
                {
                    CenterX = wp.X,
                    CenterY = wp.Y,
                    CenterZ = wp.Z,
                    Rotation = new AxisAngleRotation3D(
                        new Vector3D(0, 0, -1), wp.HeadingDegrees)
                };

                GeometryModel3D box;
                Material mat;

                if (wp.PauseTime > 0)
                {
                    mat = Materials.Red;
                }
                else
                {
                    mat = Materials.DarkGray;
                }

                box = new GeometryModel3D(builder.ToMesh(),mat);
                box.Transform = headingRotate;
                collection.Add(box);

                builder = new MeshBuilder();
                float radius = 3.0f;
                double hx = wp.X + Math.Cos( (wp.HeadingDegrees-90) / 180 * Math.PI ) * radius;
                double hy = wp.Y + Math.Sin( (wp.HeadingDegrees + 90) / 180 * Math.PI ) * radius;

                builder.AddArrow(new Point3D(wp.X, wp.Y, wp.Z),new Point3D(hx, hy, wp.Z), 0.5,1);
                collection.Add(new GeometryModel3D(builder.ToMesh(), mat));

                //box = new GeometryModel3D(builder.ToMesh(), mat);
                //collection.Add(box);

                if(wp.Name != null && !String.IsNullOrWhiteSpace(wp.Name) )
                {
                    GeometryModel3D text = TextCreator.CreateTextLabelModel3D(wp.Name, BrushHelper.CreateGrayBrush(50), true, 2, new Point3D(p.X, p.Y, p.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
                    text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(p.X, p.Y, p.Z));
                    collection.Add(text);
                }

                //GeometryModel3D text = TextCreator.CreateTextLabelModel3D(wp.GridId.ToString() + "G:" + wp.Number.ToString() + "N:" + wp.PauseTime.ToString() + "P", BrushHelper.CreateGrayBrush(5), true, 2,
                  //                                                          new Point3D(p.X, p.Y, p.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
                //text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(p.X, p.Y, p.Z));
                //collection.Add(text);

                builder = new MeshBuilder();

                if (grid.WanderType == Grid.WanderTypes.Patrol || grid.WanderType == Grid.WanderTypes.Circular)
                {
                    IEnumerable<Waypoint> nextWaypointQuery = grid.Waypoints.Where(
                        x => x.Number > wp.Number).OrderBy(y => y.Number);
                    if (nextWaypointQuery.Count() > 0)
                    {
                        Waypoint nextWaypoint = nextWaypointQuery.ElementAt(0);
                        builder.AddArrow(p, new Point3D(nextWaypoint.X, nextWaypoint.Y, nextWaypoint.Z), 0.5);

                        collection.Add(
                            new GeometryModel3D(builder.ToMesh(), Materials.White));
                    }
                }

                //collection.Add( new GeometryModel3D(builder.ToMesh(), Materials.
            }

            //collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.White));

            _mapping[grid] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Exemplo n.º 14
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();

            // 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)
            };

            // setup lighting
            this.AmbientLightColor         = Colors.DimGray;
            this.DirectionalLightColor     = Colors.White;
            this.DirectionalLightDirection = new Vector3D(-2, -5, -2);

            // floor plane grid
            this.Grid          = LineBuilder.GenerateGrid(Vector3.UnitZ, -5, 5);
            this.GridColor     = Colors.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.º 15
0
        public MainViewModel()
        {
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];

            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         = Colors.DimGray;
            this.DirectionalLightColor     = Colors.White;
            this.DirectionalLightDirection = new Vector3D(-2, -5, -2);

            // floor plane grid
            this.Grid          = LineBuilder.GenerateGrid();
            this.GridColor     = Colors.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();
            var m1 = Load3ds("suzanne.3ds");

            this.Model2 = m1[0].Geometry as MeshGeometry3D;
            //Manully set an offset for test
            for (int i = 0; i < Model2.Positions.Count; ++i)
            {
                Model2.Positions[i] = Model2.Positions[i] + new Vector3(2, 3, 4);
            }
            Model2.UpdateBounds();

            // 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 = new TranslateTransform3D(0, 0, 0);
            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 = Colors.DarkRed;

            Console.WriteLine(dr);
            ResetTransformsCommand = new RelayCommand((o) =>
            {
                this.Model1Transform = new TranslateTransform3D(0, 0, 0);
                this.Model2Transform = new TranslateTransform3D(-3, 0, 0);
                this.Model3Transform = new TranslateTransform3D(+3, 0, 0);
            });
        }
Exemplo n.º 16
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            // 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
            };

            // setup lighting
            AmbientLightColor         = Colors.DimGray;
            DirectionalLightColor     = Colors.White;
            DirectionalLightDirection = new Vector3D(-2, -5, -2);

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

            // 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();

            var textBuilder = new MeshBuilder();

            textBuilder.ExtrudeText("HelixToolkit.SharpDX", "Arial", System.Windows.FontStyles.Normal, System.Windows.FontWeights.Bold,
                                    14, new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 1));
            TextModel = textBuilder.ToMesh();

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

            // model materials
            RedMaterial   = PhongMaterials.Red;
            GreenMaterial = PhongMaterials.Green;
            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();
            int numRows    = 11;
            int numColumns = 11;

            string[] texts = new string[]
            {
                "HelixToolkit",
                "abcde",
                "random",
                "SharpDX",
                "DirectX"
            };
            float angle = 0;

            for (var i = 0; i < numRows; i++)
            {
                for (var j = 0; j < numColumns; j++)
                {
                    angle += (float)Math.PI / 10;
                    Text.TextInfo.Add(new TextInfo(texts[(i + j) % texts.Length], new Vector3((i - numRows / 2), 0.0f, (j - numColumns / 2)))
                    {
                        Foreground = new Color4((float)i / numRows, 1 - (float)i / numRows, (float)(numColumns - j) / numColumns, 1f),
                        Background = new Color4(1 - (float)i / numRows, (float)(numColumns - j) / numColumns, (float)i / numRows, 0.8f),
                        Scale      = Math.Max(0.01f, (float)i / numRows * 0.02f),
                        Angle      = angle
                    });
                }
            }

            Billboard1Model = new BillboardSingleText3D()
            {
                TextInfo = new TextInfo("Model 1", new Vector3(0, 1, 0))
                {
                    Angle = 0
                },
                FontColor       = Colors.Blue.ToColor4(),
                FontSize        = 12,
                BackgroundColor = Colors.Plum.ToColor4(),
                FontStyle       = System.Windows.FontStyles.Italic,
                Padding         = new System.Windows.Thickness(2),
            };

            var background = Colors.Blue;

            background.A    = (byte)120;
            Billboard2Model = new BillboardSingleText3D()
            {
                TextInfo = new TextInfo("Model 2", new Vector3(2, 1, 0))
                {
                    Angle = -(float)Math.PI / 3
                },
                FontSize        = 12,
                FontColor       = Colors.Green.ToColor4(),
                BackgroundColor = background.ToColor4(),
                FontWeight      = System.Windows.FontWeights.Bold,
                Padding         = new System.Windows.Thickness(2),
            };
            background      = Colors.Purple;
            background.A    = (byte)50;
            Billboard3Model = new BillboardSingleText3D(2, 0.8f)
            {
                TextInfo = new TextInfo("Model 3", new Vector3(-2, 1, 0))
                {
                    Angle = -(float)Math.PI / 6
                },
                FontSize        = 12,
                FontColor       = Colors.Red.ToColor4(),
                BackgroundColor = background.ToColor4(),
                FontFamily      = "Times New Roman",
                FontStyle       = System.Windows.FontStyles.Italic,
                Padding         = new System.Windows.Thickness(2),
            };


            //BillboardImageModel = new BillboardSingleImage3D(CreateBitmapSample()) { MaskColor = Color.Black };
            BillboardImageModel = new BillboardSingleImage3D(CreatePNGSample(), 1, 1)
            {
                Angle = -(float)Math.PI / 5
            };
            BillboardImageModel.Center = new Vector3(2, 2, 0);

            UpXCommand        = new RelayCommand(x => { UpDirection = new Vector3D(1, 0, 0); });
            UpYCommand        = new RelayCommand(x => { UpDirection = new Vector3D(0, 1, 0); });
            UpZCommand        = new RelayCommand(x => { UpDirection = new Vector3D(0, 0, 1); });
            BackgroundTexture =
                BitmapExtensions.CreateLinearGradientBitmapStream(EffectsManager, 128, 128, Direct2DImageFormat.Bmp,
                                                                  new Vector2(0, 0), new Vector2(0, 128), new SharpDX.Direct2D1.GradientStop[]
            {
                new SharpDX.Direct2D1.GradientStop()
                {
                    Color = Colors.White.ToColor4(), Position = 0f
                },
                new SharpDX.Direct2D1.GradientStop()
                {
                    Color = Colors.DarkGray.ToColor4(), Position = 1f
                }
            });
        }
Exemplo n.º 17
0
 private static GeometryModel3D CreateVoxelModel3D(Voxel v)
 {
     const double size = 0.98;
     var m = new GeometryModel3D();
     var mb = new MeshBuilder();
     mb.AddBox(new Point3D(0, 0, 0), size, size, size);
     m.Geometry = mb.ToMesh();
     m.Material = MaterialHelper.CreateMaterial(v.Colour);
     m.Transform = new TranslateTransform3D(v.Position.X, v.Position.Y, v.Position.Z);
     return m;
 }
Exemplo n.º 18
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.º 19
0
        public void Play(object parameter)
        {
            CollisionTimes            = new List <List <DateTime> >();
            CollisionStates           = new List <JointCollisionStates[]>();
            CollisionHighlights_3D    = new Model3DGroup();
            CollisionHighlights_Front = new Model3DGroup();
            CollisionHighlights_Side  = new Model3DGroup();
            foreach (Gesture g in GestureCollection)
            {
                CollisionTimes.Add(new List <DateTime>());
                foreach (GestureFrame f in g.Frames)
                {
                    CollisionTimes.Last().Add(new DateTime());
                }
                CollisionStates.Add(new JointCollisionStates[2] {
                    JointCollisionStates.OutThere, JointCollisionStates.OutThere
                });
                CollisionHighlights_3D.Children.Add(new Model3DGroup());
                CollisionHighlights_Front.Children.Add(new Model3DGroup());
                CollisionHighlights_Side.Children.Add(new Model3DGroup());
            }
            HotspotCellsModelVisual3D_Hit_Visualizer.Content = CollisionHighlights_3D;
            // Mark gesture cells in 3D Grid
            Model3DGroup modelGroup = new Model3DGroup();

            foreach (Gesture g in GestureCollection)
            {
                foreach (GestureFrame f in g.Frames)
                {
                    // Create material
                    SolidColorBrush materialBrush = new SolidColorBrush()
                    {
                        Color   = Visualizer_GestureColors[GestureCollection.IndexOf(g) % Visualizer_GestureColors.Length].Color,
                        Opacity = 0.1 + ((double)(g.Frames.IndexOf(f) + 1) / (double)g.Frames.Count) * 0.6
                    };
                    DiffuseMaterial material = new DiffuseMaterial(materialBrush);
                    foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
                    {
                        int fcIndex = Array.IndexOf(f.FrontCells, fc);
                        foreach (GestureFrameCell sc in f.SideCells.Where(
                                     sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
                        {
                            // Init mesh
                            MeshBuilder meshBuilder = new MeshBuilder(false, false);
                            // Make cube and add to mesh
                            double  y          = (fc.LeftCM + fc.RightCM) / 2;
                            double  z          = (fc.TopCM + fc.BottomCM) / 2;
                            double  x          = (sc.LeftCM + sc.RightCM) / 2;
                            Point3D cubeCenter = new Point3D(x, y, z);
                            meshBuilder.AddBox(cubeCenter, 15, 15, 15);
                            // Create and freeze mesh
                            var mesh = meshBuilder.ToMesh(true);
                            // Create models
                            modelGroup.Children.Add(new GeometryModel3D(mesh, material));
                        }
                    }
                }
                HotspotCellsModelVisual3D_Visualizer.Content = modelGroup;
            }
            // Show visualizer
            TheEditor.Visibility     = Visibility.Hidden;
            TheVisualizer.Visibility = Visibility.Visible;
            EditorOverlay.Visibility = Visibility.Hidden;
            // Hide Manager
            ManagerOverlay.Visibility = Visibility.Visible;
            // Enable Kinect
            if (kinect != null)
            {
                kinect.SkeletonStream.Enable();
                kinect.SkeletonFrameReady += SkeletonFrameReady_Draw3D_Visualizer;
                kinect.SkeletonFrameReady += SkeletonFrameReady_Detect_Visualizer;
                kinect.Start();
            }
            // Kill keyboard control
            EventLogic.RemoveRoutedEventHandlers(ViewPort3D_Visualizer.CameraController, HelixToolkit.Wpf.CameraController.KeyDownEvent);
        }
Exemplo n.º 20
0
        private void CreatePoint(ZonePoint zp,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(zp))
            {
                foreach (Model3D model in _mapping[zp])
                {
                    group.Children.Remove(model);
                }
            }

            double px, py, pz;
            px = zp.X == 999999 ? 0 : zp.X;
            py = zp.Y == 999999 ? 0 : zp.Y;
            pz = zp.Z == 999999 ? 0 : zp.Z;

            Point3D p = new Point3D(px,py,pz);

            if (!Clipping.DrawPoint(p)) return;

            MeshBuilder builder = new MeshBuilder();
            builder.AddBox(p, 20, 20, 2);

            //connect box to destination
            px = zp.TargetX == 999999 ? px : zp.TargetX;
            py = zp.TargetY == 999999 ? py : zp.TargetY;
            pz = zp.TargetZ == 999999 ? pz : zp.TargetZ;

            GeometryModel3D box;
            box = new GeometryModel3D(builder.ToMesh(), Materials.Red);
            collection.Add(box);

            builder = new MeshBuilder();
            Point3D destP = new Point3D(px, py, pz);
            builder.AddArrow(p, destP, 0.5);
            builder.AddBox(destP, 20, 20, 2);

            if (zp.X == 999999 || zp.Y == 999999 || zp.Z == 999999 ||
                zp.TargetX == 999999 || zp.TargetY == 999999 || zp.TargetZ == 999999)
            {
                box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);
            }
            else
            {
                box = new GeometryModel3D(builder.ToMesh(), Materials.White);
            }

            collection.Add(box);

            if (flags != DisplayFlags.None)
            {
                builder = new MeshBuilder();

                if (flags.HasFlag(DisplayFlags.DarkGrayAura))
                {
                    builder.AddBox(p, 25,25, 1);
                    builder.AddBox(destP, 25, 25, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
                    collection.Add(box);
                }
                else if (flags.HasFlag(DisplayFlags.GreenAura))
                {
                    builder.AddBox(p, 25, 25, 1);
                    builder.AddBox(destP, 25, 25, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
                    collection.Add(box);
                }
            }

            _mapping[zp] = collection;

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Process point cloud as soon as it arrives
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImagingPipeline_ImageDataProcessed(object sender, Rubedos.PointcloudProcessing.ImagingPipelineProcessedEventArgs e)
        {
            var rgbd = pointCloudViewModel.ImagingPipeline.RgbdOut;

            if (points == null)
            {
                points = new float[rgbd.Cols * rgbd.Rows * rgbd.NumberOfChannels];
            }
            int w = rgbd.Cols, h = rgbd.Rows;

            // hint: working with data buffer is much faster than accessing individual points in Cv.Mat
            System.Runtime.InteropServices.Marshal.Copy(rgbd.DataPointer, points, 0, points.Length);

            float minZ = groundZ,
                  maxX = -groundW, minX = groundW, minY = groundD, maxY = -groundD;

            for (int y = 1; y < h; y += 1)
            {
                for (int x = 1; x < w; x += 1)
                {
                    var current = GetPoint(points, x, y, w, h);
                    if (current.Z > groundZ || current.Z < 1.0f ||
                        current.X > groundW / 2 || current.X < -groundW / 2 ||
                        current.Y > groundD / 2 || current.Y < -groundD / 2)
                    {
                        continue; // Out of space of interest
                    }
                    if (current.X > maxX)
                    {
                        maxX = current.X;
                    }
                    if (current.X < minX)
                    {
                        minX = current.X;
                    }
                    if (current.Y > maxY)
                    {
                        maxY = current.Y;
                    }
                    if (current.Y < minY)
                    {
                        minY = current.Y;
                    }
                    if (current.Z < minZ)
                    {
                        minZ = current.Z;
                    }
                }
            }
            Console.WriteLine("Boundaries: X ({0:0.00}; {1:0.00}) Y ({2:0.00}; {3:0.00}) Z ({4:0.00}; {5:0.00})",
                              maxX, minX, maxY, minY, groundZ, minZ);

            // Synchronizing with 3D rendering thread
            pointCloudViewModel.Context.Send((o) =>
            {
                boundingBoxGroup.Children.Clear();
                MeshBuilder mb = new MeshBuilder();
                var center     = new Vector3((maxY + minY) / 2, (maxX + minX) / 2, (groundZ - minZ) / 2);
                float xlen     = maxY - minY, ylen = maxX - minX, zlen = groundZ - minZ;
                mb.AddBox(center, xlen, ylen, zlen);

                MeshGeometryModel3D mmodel = new MeshGeometryModel3D();
                boundingBoxGroup.Children.Add(mmodel);
                mmodel.Geometry = mb.ToMeshGeometry3D();

                var boxColor    = System.Windows.Media.Color.FromArgb(30, 50, 0, 255).ToColor4();
                mmodel.Material = new PhongMaterial()
                {
                    AmbientColor = boxColor,      // System.Windows.Media.Colors.Gray.ToColor4(),
                    DiffuseColor = boxColor,      //System.Windows.Media.Colors.Yellow.ToColor4(),
                                                  //System.Windows.Media.Color.FromArgb(100, 255, 0 , 0).ToColor4(),
                    SpecularColor     = boxColor, // System.Windows.Media.Colors.Gray.ToColor4(),
                    SpecularShininess = 100f,
                };

                LineGeometryModel3D linem = new LineGeometryModel3D();
                var lb = new LineBuilder();
                lb.AddBox(center, xlen, ylen, zlen);
                linem.Thickness = 1;
                linem.Color     = System.Windows.Media.Colors.Yellow; //System.Windows.Media.Color.FromArgb(30, 50, 0, 255).ToColor4();
                linem.Geometry  = lb.ToLineGeometry3D();
                boundingBoxGroup.Children.Add(linem);
                float scale = 1.0f;
                labels.TextInfo.Clear();
                labels.TextInfo.Add(new TextInfo()
                {
                    Text   = String.Format("H = {0:0.0} m", zlen),
                    Origin = new Vector3(xlen / 2 + 0.1f, -(ylen / 2 + 0.1f), zlen / 2) + center, Foreground = Colors.Black.ToColor4(), Scale = scale
                });

                labels.TextInfo.Add(new TextInfo()
                {
                    Text       = String.Format("W = {0:0.0} m", xlen),
                    Origin     = new Vector3(0, ylen / 2 + 0.1f, zlen + 0.1f) + center,
                    Foreground = Colors.Black.ToColor4(),
                    Scale      = scale
                });

                labels.TextInfo.Add(new TextInfo()
                {
                    Text       = String.Format("D = {0:0.0} m", ylen),
                    Origin     = new Vector3(xlen / 2 + 0.1f, 0f, zlen + 0.1f) + center,
                    Foreground = Colors.Black.ToColor4(),
                    Scale      = scale
                });
            }, null);
        }
Exemplo n.º 22
0
        public MainViewModel()
        {
            //    RenderTechniquesManager = new DefaultRenderTechniquesManager();
            EffectsManager = new DefaultEffectsManager();
            // ----------------------------------------------
            // 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 = Colors.DarkGray;

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

            this.Light1Color = Colors.White;
            this.Light2Color = Colors.Red;
            this.Light3Color = Colors.LightYellow;
            this.Light4Color = Colors.LightBlue;

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

            this.Light1Direction          = new Vector3D(0, -10, 0);
            this.Light1Transform          = CreateAnimatedTransform1(-Light1Direction, new Vector3D(1, 0, 0), 24);
            this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction, 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 Vector3D(0, -5, -1);
            this.Light4Transform          = CreateAnimatedTransform2(-Light4Direction * 2, new Vector3D(0, 1, 0), 24);
            this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction, new Vector3D(1, 0, 0), 12);

            var transformGroup = new Media3D.Transform3DGroup();

            transformGroup.Children.Add(new Media3D.ScaleTransform3D(10, 10, 10));
            transformGroup.Children.Add(new Media3D.TranslateTransform3D(2, -4, 2));
            Model1Transform = transformGroup;
            // ----------------------------------------------
            // light model3d
            var sphere = new MeshBuilder();

            sphere.AddSphere(new Vector3(0, 0, 0), 0.2);
            Sphere = sphere.ToMeshGeometry3D();
            this.LightModelMaterial = new PhongMaterial
            {
                AmbientColor  = Colors.Gray.ToColor4(),
                DiffuseColor  = Colors.Gray.ToColor4(),
                EmissiveColor = Colors.Yellow.ToColor4(),
                SpecularColor = Colors.Black.ToColor4(),
            };

            // ----------------------------------------------
            // scene model3d
            var b1 = new MeshBuilder(true, true, true);

            b1.AddSphere(new Vector3(0.25f, 0.25f, 0.25f), 0.75, 24, 24);
            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, 24, 24);
            b1.AddCylinder(new Vector3(0f, -3f, -5f), new Vector3(0f, 3f, -5f), 1.2, 24);
            b1.AddSphere(new Vector3(-5.0f, -5.0f, 5.0f), 4, 24, 64);
            b1.AddCone(new Vector3(6f, -9f, -6f), new Vector3(6f, -1f, -6f), 4f, true, 64);
            this.Model          = b1.ToMeshGeometry3D();
            this.ModelTransform = new Media3D.TranslateTransform3D(0, 0, 0);
            this.ModelMaterial  = PhongMaterials.Chrome;

            this.ModelMaterial.NormalMap = LoadFileToMemory(new System.Uri(SelectedNormalTexture, System.UriKind.RelativeOrAbsolute).ToString());

            // ----------------------------------------------
            // floor model3d
            var b2 = new MeshBuilder(true, true, true);

            //b2.AddRectangularMesh(BoxFaces.Left, 10, 10, 10, 10);
            b2.AddBox(new Vector3(0.0f, -5.0f, 0.0f), 15, 1, 15, BoxFaces.All);
            //b2.AddSphere(new Vector3(-5.0f, -5.0f, 5.0f), 4, 24, 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      = Colors.Gray.ToColor4(),
                DiffuseColor      = new Color4(0.75f, 0.75f, 0.75f, 1.0f),
                SpecularColor     = Colors.White.ToColor4(),
                SpecularShininess = 100f,
                DiffuseMap        = LoadFileToMemory(new System.Uri(SelectedDiffuseTexture, System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap         = ModelMaterial.NormalMap,
                RenderShadowMap   = true
            };
            ModelMaterial.DiffuseMap = FloorMaterial.DiffuseMap;

            ReflectMaterial = PhongMaterials.PolishedSilver;
            ReflectMaterial.ReflectiveColor      = global::SharpDX.Color.Silver;
            ReflectMaterial.RenderEnvironmentMap = true;
            InitialObjectTransforms();
        }
Exemplo n.º 23
0
        private void gambarrumah()
        {
            objects.Children.Clear();
            var kerangkarumah = new MeshBuilder(false, false);
            var tembokrumah   = new MeshBuilder(false, false);
            var ataprumah     = new MeshBuilder(false, false);
            var jendelarumah  = new MeshBuilder(false, false);
            var pinturumah    = new MeshBuilder(false, false);

            kerangkarumah.AddPipe(titik[0], titik[1], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[1], titik[2], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[2], titik[3], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[3], titik[0], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[4], titik[5], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[5], titik[6], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[6], titik[7], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[7], titik[4], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[0], titik[4], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[1], titik[5], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[2], titik[6], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[3], titik[7], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[4], titik[8], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[5], titik[8], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[6], titik[9], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[7], titik[9], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[9], titik[8], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[10], titik[11], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[11], titik[12], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[12], titik[13], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[14], titik[15], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[15], titik[16], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[16], titik[17], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[17], titik[14], 0, 0.1, 90);
            kerangkarumah.AddPipe(titik[18], titik[19], 0, 0.1, 90);
            tembokrumah.AddBox(new Point3D((titik[0].X + titik[2].X) / 2, (titik[0].Y + titik[2].Y) / 2, (titik[0].Z + titik[2].Z) / 2), (titik[2].X - titik[0].X), (titik[2].Y - titik[0].Y), (titik[2].Z - titik[0].Z));
            tembokrumah.AddBox(new Point3D((titik[0].X + titik[5].X) / 2, (titik[0].Y + titik[5].Y) / 2, (titik[0].Z + titik[5].Z) / 2), (titik[5].X - titik[0].X), (titik[5].Y - titik[0].Y), (titik[5].Z - titik[0].Z));
            tembokrumah.AddBox(new Point3D((titik[1].X + titik[6].X) / 2, (titik[1].Y + titik[6].Y) / 2, (titik[1].Z + titik[6].Z) / 2), (titik[6].X - titik[1].X), (titik[6].Y - titik[1].Y), (titik[6].Z - titik[1].Z));
            tembokrumah.AddBox(new Point3D((titik[2].X + titik[7].X) / 2, (titik[2].Y + titik[7].Y) / 2, (titik[2].Z + titik[7].Z) / 2), (titik[2].X - titik[7].X), (titik[7].Y - titik[2].Y), (titik[7].Z - titik[2].Z));
            tembokrumah.AddBox(new Point3D((titik[3].X + titik[4].X) / 2, (titik[3].Y + titik[4].Y) / 2, (titik[3].Z + titik[4].Z) / 2), (titik[4].X - titik[3].X), (titik[4].Y - titik[3].Y), (titik[4].Z - titik[3].Z));
            jendelarumah.AddBox(new Point3D((titik[14].X + titik[16].X) / 2, (titik[14].Y + titik[16].Y) / 2, (titik[14].Z + titik[16].Z) / 2), (titik[16].X - titik[14].X), (titik[16].Y - titik[14].Y), (titik[16].Z - titik[14].Z));
            pinturumah.AddBox(new Point3D((titik[10].X + titik[12].X) / 2, (titik[10].Y + titik[12].Y) / 2, (titik[10].Z + titik[12].Z) / 2), (titik[12].X - titik[10].X), (titik[12].Y - titik[10].Y), (titik[12].Z - titik[10].Z));
            ataprumah.AddTriangle(titik[4], titik[5], titik[8]);
            ataprumah.AddTriangle(titik[6], titik[7], titik[9]);
            ataprumah.AddTriangle(titik[5], titik[6], titik[8]);
            ataprumah.AddTriangle(titik[7], titik[4], titik[8]);
            ataprumah.AddTriangle(titik[9], titik[8], titik[6]);
            ataprumah.AddTriangle(titik[8], titik[9], titik[7]);
            objects.Children.Add(new GeometryModel3D
            {
                Geometry = kerangkarumah.ToMesh(true),
                Material = MaterialHelper.CreateMaterial(Colors.DarkBlue)
            });
            objects.Children.Add(new GeometryModel3D
            {
                Geometry = tembokrumah.ToMesh(true),
                Material = MaterialHelper.CreateMaterial(Colors.MediumBlue)
            });
            objects.Children.Add(new GeometryModel3D
            {
                Geometry = ataprumah.ToMesh(true),
                Material = MaterialHelper.CreateMaterial(Colors.SaddleBrown)
            });
            objects.Children.Add(new GeometryModel3D
            {
                Geometry = jendelarumah.ToMesh(true),
                Material = MaterialHelper.CreateMaterial(Colors.LightBlue)
            });
            objects.Children.Add(new GeometryModel3D
            {
                Geometry = pinturumah.ToMesh(true),
                Material = MaterialHelper.CreateMaterial(Colors.SandyBrown)
            });
            var titiklenyap = new MeshBuilder(false, false);

            titiklenyap.AddEllipsoid(new Point3D(0, 0, Convert.ToDouble(TextBox_titiklenyapz.Text)), 0.2, 0.2, 0.2);
            objects.Children.Add(new GeometryModel3D
            {
                Geometry = titiklenyap.ToMesh(true),
                Material = MaterialHelper.CreateMaterial(Colors.Yellow)
            });
            placedobjects.Children.Clear();
            objects.Children.Add(sumbu);
            placedobjects.Content = objects;
        }
Exemplo n.º 24
0
        public MainViewModel()
        {
            //RenderTechniquesManager = new DefaultRenderTechniquesManager();
            //RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];
            // ----------------------------------------------
            // titles
            this.Title    = "Lighting Demo";
            this.SubTitle = "WPF & SharpDX";

            // ----------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = new Point3D(100, 100, 100), LookDirection = new Vector3D(-100, -100, -100), UpDirection = new Vector3D(0, 1, 0)
            };
            // ----------------------------------------------
            // setup scene
            this.AmbientLightColor = Colors.DimGray;
            this.Light1Color       = Colors.LightGray;


            this.Light1Direction = new Vector3D(-100, -100, -100);
            SetupCameraBindings(Camera);
            // ----------------------------------------------
            // ----------------------------------------------
            // scene model3d
            this.ModelMaterial = PhongMaterials.Silver;

            // ----------------------------------------------
            // floor model3d
            var b2 = new MeshBuilder(true, true, true);

            b2.AddBox(new Vector3(0.0f, 0, 0.0f), 150, 1, 150, BoxFaces.All);
            b2.AddBox(new Vector3(0, 25, 70), 150, 50, 20);
            b2.AddBox(new Vector3(0, 25, -70), 150, 50, 20);
            this.Floor                    = b2.ToMeshGeometry3D();
            this.FloorMaterial            = PhongMaterials.Bisque;
            this.FloorMaterial.DiffuseMap = LoadFileToMemory(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute).ToString());
            this.FloorMaterial.NormalMap  = LoadFileToMemory(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute).ToString());

            var caritems = Load3ds("leone.3DBuilder.obj").Select(x => x.Geometry as MeshGeometry3D).ToArray();
            var scale    = new Vector3(1f);

            foreach (var item in caritems)
            {
                for (int i = 0; i < item.Positions.Count; ++i)
                {
                    item.Positions[i] = item.Positions[i] * scale;
                }
            }
            Model = MeshGeometry3D.Merge(caritems);

            ModelTransform = new Media3D.RotateTransform3D()
            {
                Rotation = new Media3D.AxisAngleRotation3D(new Vector3D(1, 0, 0), -90)
            };

            Instances = new Matrix[6];
            for (int i = 0; i < Instances.Length; ++i)
            {
                Instances[i] = Matrix.Translation(new Vector3(15 * i - 30, 15 * (i % 2) - 30, 0));
            }

            OutlineInstances = new Matrix[6];
            for (int i = 0; i < Instances.Length; ++i)
            {
                OutlineInstances[i] = Matrix.Translation(new Vector3(15 * i - 30, 15 * (i % 2), 0));
            }

            var blendDesc = new BlendStateDescription();

            blendDesc.RenderTarget[0] = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                BlendOperation        = BlendOperation.Add,
                AlphaBlendOperation   = BlendOperation.Add,
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.One,
                SourceAlphaBlend      = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.One,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };
            BlendDescription        = blendDesc;
            DepthStencilDescription = new DepthStencilStateDescription()
            {
                IsDepthEnabled  = true,
                DepthComparison = Comparison.LessEqual,
                DepthWriteMask  = DepthWriteMask.Zero
            };
        }
Exemplo n.º 25
0
        public MainViewModel()
        {
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];

            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         = Colors.DimGray;
            this.DirectionalLightColor     = Colors.White;
            this.DirectionalLightDirection = new Vector3D(-2, -5, -2);

            // floor plane grid
            this.Grid          = LineBuilder.GenerateGrid();
            this.GridColor     = Media.Colors.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);
            //this.Lines = e1.ToLineGeometry3D().ToUnshared();
            this.Lines        = e1.ToLineGeometry3D(true);
            this.Lines.Colors = new Color4Collection();
            var linesCount = this.Lines.Indices.Count;
            var rnd        = new Random();

            while (linesCount-- > 0)
            {
                this.Lines.Colors.Add(rnd.NextColor());
            }

            // 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.º 26
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            Title          = "Material Demo";
            this.Camera    = new PerspectiveCamera {
                Position = new Point3D(-30, 30, -30), LookDirection = new Vector3D(30, -30, 30), UpDirection = new Vector3D(0, 1, 0)
            };

            var builder = new MeshBuilder();

            builder.AddBox(new Vector3(0, -6, 0), 200, 2, 100);

            Floor = builder.ToMesh();

            builder = new MeshBuilder();
            builder.AddSphere(Vector3.Zero, 2);

            LoadObj(@"shaderBall\shaderBall.obj");

            EnvironmentMap = LoadFileToMemory("Cubemap_Grandcanyon.dds");

            ColorStripeMaterial.ColorStripeX = GetGradients(new Color4(1, 0, 0, 1), new Color4(0, 1, 0, 1), new Color4(0, 0, 1, 1), 48).ToList();
            ColorStripeMaterial.ColorStripeY = GetGradients(new Color4(1, 1, 0, 1), new Color4(0, 1, 1, 1), new Color4(1, 0, 1, 1), 48).ToList();

            MeshTitles = new BillboardText3D();
            MeshTitles.TextInfo.Add(new TextInfo("Blinn", Transform1.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            MeshTitles.TextInfo.Add(new TextInfo("Normal", Transform2.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            MeshTitles.TextInfo.Add(new TextInfo("Diffuse", Transform3.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            MeshTitles.TextInfo.Add(new TextInfo("Position", Transform4.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            MeshTitles.TextInfo.Add(new TextInfo("VertexColor", Transform5.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            MeshTitles.TextInfo.Add(new TextInfo("ColorStripe", Transform6.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            MeshTitles.TextInfo.Add(new TextInfo("PBR", Transform7.ToVector3())
            {
                Scale = 0.08f, Background = new Color4(1, 1, 1, 1)
            });
            (FloorMaterial as PhongMaterial).RenderShadowMap = true;

            OpenPBRSampleCommand = new RelayCommand((o) =>
            {
                PBRWindow w = new PBRWindow()
                {
                    DataContext = new PBRViewModel(this.EffectsManager)
                    {
                        EnvironmentMap = this.EnvironmentMap
                    }
                };
                w.Show();
            });
        }
Exemplo n.º 27
0
        public MainPageViewModel()
        {
            EffectsManager = new DefaultEffectsManager(new Logger());

            Camera = new PerspectiveCamera()
            {
                Position = new Vector3(0, 0, -15), LookDirection = new Vector3(0, 0, 15), UpDirection = new Vector3(0, 1, 0)
            };

            var builder = new MeshBuilder(true, true, true);

            builder.AddBox(new SharpDX.Vector3(0, 0, 0), 2, 2, 2);
            builder.AddSphere(new Vector3(0, 2, 0), 1.5);
            Geometry = builder.ToMesh();
            Material = new PhongMaterial()
            {
                AmbientColor      = Color.Gray,
                DiffuseColor      = new Color4(0.75f, 0.75f, 0.75f, 1.0f),
                SpecularColor     = Color.White,
                SpecularShininess = 100f,
            };
            Material.DiffuseMap = LoadTexture("TextureCheckerboard2.jpg");
            Material.NormalMap  = LoadTexture("TextureCheckerboard2_dot3.jpg");
            var lineBuilder = new LineBuilder();

            lineBuilder.AddLine(Vector3.Zero, new Vector3(5, 0, 0));
            lineBuilder.AddLine(Vector3.Zero, new Vector3(0, 5, 0));
            lineBuilder.AddLine(Vector3.Zero, new Vector3(0, 0, 5));
            LineGeometry        = lineBuilder.ToLineGeometry3D();
            LineGeometry.Colors = new HelixToolkit.UWP.Core.Color4Collection()
            {
                Color.Red, Color.Red, Color.Green, Color.Green, Color.Blue, Color.Blue
            };

            builder = new MeshBuilder();
            builder.AddSphere(new Vector3(), 3);
            var mesh = builder.ToMesh();

            PointGeometry = new PointGeometry3D()
            {
                Positions = mesh.Positions
            };

            AxisLabelGeometry = new BillboardText3D();
            AxisLabelGeometry.TextInfo.Add(new TextInfo("X", new Vector3(5.5f, 0, 0))
            {
                Foreground = Color.Red
            });
            AxisLabelGeometry.TextInfo.Add(new TextInfo("Y", new Vector3(0, 5.5f, 0))
            {
                Foreground = Color.Green
            });
            AxisLabelGeometry.TextInfo.Add(new TextInfo("Z", new Vector3(0, 0, 5.5f))
            {
                Foreground = Color.Blue
            });

            builder = new MeshBuilder();
            builder.AddBox(new Vector3(0, -6, 0), 30, 0.5, 30);
            FloorModel = builder.ToMesh();

            FloorMaterial = PhongMaterials.LightGray;

            timer          = new DispatcherTimer();
            timer.Tick    += Timer_Tick;
            timer.Interval = new TimeSpan(0, 0, 0, 0, 16);
            timer.Start();
        }
Exemplo n.º 28
0
        private void InitializeScene()
        {
            camera = new PerspectiveCameraCore()
            {
                LookDirection     = new Vector3(0, 0, 50),
                Position          = new Vector3(0, 0, -50),
                FarPlaneDistance  = 1000,
                NearPlaneDistance = 0.1f,
                FieldOfView       = 45,
                UpDirection       = new Vector3(0, 1, 0)
            };
            viewport.CameraCore = camera;
            viewport.Items.Add(new DirectionalLightNode()
            {
                Direction = new Vector3(0, -1, 1), Color = Color.White
            });
            viewport.Items.Add(new PointLightNode()
            {
                Position = new Vector3(0, 0, -20), Color = Color.Yellow, Range = 20, Attenuation = Vector3.One
            });

            var builder = new MeshBuilder(true, true, true);

            builder.AddSphere(Vector3.Zero, 1, 12, 12);
            sphere  = builder.ToMesh();
            builder = new MeshBuilder(true, true, true);
            builder.AddBox(Vector3.Zero, 1, 1, 1);
            box    = builder.ToMesh();
            points = new PointGeometry3D()
            {
                Positions = sphere.Positions
            };
            var lineBuilder = new LineBuilder();

            lineBuilder.AddBox(Vector3.Zero, 2, 2, 2);
            lines       = lineBuilder.ToLineGeometry3D();
            groupSphere = new GroupNode();
            groupBox    = new GroupNode();
            groupLines  = new GroupNode();
            groupPoints = new GroupNode();
            InitializeMaterials();
            materialList = materials.Values.ToArray();
            var materialCount = materialList.Length;

            for (int i = 0; i < NumItems; ++i)
            {
                var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20)));
                groupSphere.AddChildNode(new MeshNode()
                {
                    Geometry = sphere, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back
                });
            }

            for (int i = 0; i < NumItems; ++i)
            {
                var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50)));
                groupBox.AddChildNode(new MeshNode()
                {
                    Geometry = box, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back
                });
            }

            //for(int i=0; i< NumItems; ++i)
            //{
            //    var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50)));
            //    groupPoints.AddChildNode(new PointNode() { Geometry = points, ModelMatrix = transform, Material = new PointMaterialCore() { PointColor = Color.Red } });
            //}

            //for (int i = 0; i < NumItems; ++i)
            //{
            //    var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50)));
            //    groupLines.AddChildNode(new LineNode() { Geometry = lines, ModelMatrix = transform, Material = new LineMaterialCore() { LineColor = Color.LightBlue } });
            //}

            viewport.Items.Add(groupSphere);
            groupSphere.AddChildNode(groupBox);
            groupSphere.AddChildNode(groupPoints);
            groupSphere.AddChildNode(groupLines);

            var viewbox = new ViewBoxNode();

            viewport.Items.Add(viewbox);
            var imGui = new ImGuiNode();

            viewport.Items.Add(imGui);
            imGui.UpdatingImGuiUI       += ImGui_UpdatingImGuiUI;
            io.KeyMap[GuiKey.Tab]        = (int)Keys.Tab;
            io.KeyMap[GuiKey.LeftArrow]  = (int)Keys.Left;
            io.KeyMap[GuiKey.RightArrow] = (int)Keys.Right;
            io.KeyMap[GuiKey.UpArrow]    = (int)Keys.Up;
            io.KeyMap[GuiKey.DownArrow]  = (int)Keys.Down;
            io.KeyMap[GuiKey.PageUp]     = (int)Keys.PageUp;
            io.KeyMap[GuiKey.PageDown]   = (int)Keys.PageDown;
            io.KeyMap[GuiKey.Home]       = (int)Keys.Home;
            io.KeyMap[GuiKey.End]        = (int)Keys.End;
            io.KeyMap[GuiKey.Delete]     = (int)Keys.Delete;
            io.KeyMap[GuiKey.Backspace]  = (int)Keys.Back;
            io.KeyMap[GuiKey.Enter]      = (int)Keys.Enter;
            io.KeyMap[GuiKey.Escape]     = (int)Keys.Escape;
        }
Exemplo n.º 29
0
        //public Camera Camera2 { private set; get; }

        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            Title          = "Shadow Map Demo";
            SubTitle       = "WPF & SharpDX";

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

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

            Camera1 = new PerspectiveCamera
            {
                Position          = new Point3D(0, 5, 0),
                LookDirection     = new Vector3D(0, -1, 0),
                UpDirection       = new Vector3D(1, 0, 0),
                FarPlaneDistance  = 5000,
                NearPlaneDistance = 1,
                FieldOfView       = 45
            };

            // 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.Indigo;

            // lines model3d
            Lines = LineBuilder.GenerateBoundingBox(Model);
            //this.PropertyChanged += MainViewModel_PropertyChanged;
            // 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;
            GrayMaterial.RenderShadowMap = RedMaterial.RenderShadowMap = GreenMaterial.RenderShadowMap = BlueMaterial.RenderShadowMap = true;
            //var b3 = new MeshBuilder();
            //b3.AddBox(new Vector3(), 0.3f, 0.3f, 0.3f, BoxFaces.All);
            //b3.AddCone(new Vector3(0, 0.3f, 0), new Vector3(0, 0f, 0), 0.2f, true, 24);
            //LightCameraModel = b3.ToMesh();
            //LightCameraTransform.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(1, 0, 0), -135)));
            //LightCameraTransform.Children.Add(new Media3D.TranslateTransform3D(0, 3, 3));
            //UpdateCamera();
        }
Exemplo n.º 30
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
            };

            // default render technique
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique         = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager          = new DefaultEffectsManager(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     = 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.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 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.Red;
            GreenMaterial = PhongMaterials.Green;
            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)));
                }
            }

            Billboard1Model = new BillboardSingleText3D()
            {
                TextInfo        = new TextInfo("Model 1", new Vector3(0, 1, 0)),
                FontColor       = Color.Blue,
                FontSize        = 12,
                BackgroundColor = Color.Plum,
                FontStyle       = System.Windows.FontStyles.Italic,
                Padding         = new System.Windows.Thickness(2)
            };

            var background = Color.Blue;

            background.A    = (byte)120;
            Billboard2Model = new BillboardSingleText3D()
            {
                TextInfo        = new TextInfo("Model 1", new Vector3(2, 1, 0)),
                FontSize        = 12,
                FontColor       = Color.Green,
                BackgroundColor = background,
                FontWeight      = System.Windows.FontWeights.Bold,
                Padding         = new System.Windows.Thickness(2)
            };
            background      = Color.Purple;
            background.A    = (byte)50;
            Billboard3Model = new BillboardSingleText3D(2, 0.8f)
            {
                TextInfo        = new TextInfo("Model 1", new Vector3(-2, 1, 0)),
                FontSize        = 12,
                FontColor       = Color.Red,
                BackgroundColor = background,
                FontFamily      = new System.Windows.Media.FontFamily("Times New Roman"),
                FontStyle       = System.Windows.FontStyles.Italic,
                Padding         = new System.Windows.Thickness(2)
            };


            //BillboardImageModel = new BillboardSingleImage3D(CreateBitmapSample()) { MaskColor = Color.Black };
            BillboardImageModel        = new BillboardSingleImage3D(CreatePNGSample(), 1, 1);
            BillboardImageModel.Center = new Vector3(2, 2, 0);
        }
Exemplo n.º 31
0
        public PBRViewModel(IEffectsManager manager)
        {
            EffectsManager = manager;
            this.Camera    = new PerspectiveCamera {
                Position = new Point3D(0, 60, 60), LookDirection = new Vector3D(0, -60, -60), UpDirection = new Vector3D(0, 1, 0)
            };
            var builder = new MeshBuilder();

            builder.AddSphere(Vector3.Zero, 2);
            SphereModel = builder.ToMesh();
            var normalMap = TextureModel.Create(new System.Uri("TextureNoise1_dot3.dds", System.UriKind.RelativeOrAbsolute).ToString());

            for (int i = -Row; i < Row; ++i)
            {
                for (int j = -Col; j < Col; ++j)
                {
                    var m = new PBRMaterial()
                    {
                        AlbedoColor          = albedoColor.ToColor4(),
                        RoughnessFactor      = 1.0 / (2 * Row) * Math.Abs(i + Row),
                        MetallicFactor       = 1.0 / (2 * Col) * Math.Abs(j + Col),
                        RenderEnvironmentMap = true,
                        EnableAutoTangent    = true,
                        NormalMap            = normalMap,
                        RenderShadowMap      = true
                    };
                    materials.Add(m);
                    Models.Add(new MeshGeometryModel3D()
                    {
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        Geometry         = SphereModel,
                        Material         = m,
                        IsThrowingShadow = true,
                        Transform        = new Media3D.TranslateTransform3D(new Vector3D(i * 6, 0, j * 6))
                    });
                }
            }
            builder = new MeshBuilder();
            builder.AddSphere(Vector3.Zero, 8, 12, 12);
            Model    = builder.ToMesh();
            Material = new PBRMaterial()
            {
                AlbedoColor              = albedoColor.ToColor4(),
                RenderEnvironmentMap     = true,
                AlbedoMap                = TextureModel.Create("Engraved_Metal_COLOR.jpg"),
                NormalMap                = TextureModel.Create("Engraved_Metal_NORM.jpg"),
                DisplacementMap          = TextureModel.Create("Engraved_Metal_DISP.png"),
                RoughnessMetallicMap     = TextureModel.Create("Engraved_Metal_RMC.png"),
                DisplacementMapScaleMask = new Vector4(0.1f, 0.1f, 0.1f, 0),
                EnableAutoTangent        = true, EnableTessellation = true, MaxDistanceTessellationFactor = 2, MinDistanceTessellationFactor = 4
            };
            ModelTransform = new Media3D.MatrixTransform3D(Matrix.Translation(0, 30, 0).ToMatrix3D());

            builder = new MeshBuilder();
            builder.AddBox(Vector3.Zero, 100, 0.5, 100);
            var floorGeo = builder.ToMesh();

            for (int i = 0; i < floorGeo.TextureCoordinates.Count; ++i)
            {
                floorGeo.TextureCoordinates[i] *= 5;
            }
            FloorModel    = floorGeo;
            FloorMaterial = new PBRMaterial()
            {
                AlbedoMap                = TextureModel.Create("Wood_Planks_COLOR.jpg"),
                NormalMap                = TextureModel.Create("Wood_Planks_NORM.jpg"),
                DisplacementMap          = TextureModel.Create("Wood_Planks_DISP.png"),
                RoughnessMetallicMap     = TextureModel.Create("Wood_Planks_RMA.png"),
                AmbientOcculsionMap      = TextureModel.Create("Wood_Planks_RMA.png"),
                DisplacementMapScaleMask = new Vector4(1f, 1f, 1f, 0),
                RoughnessFactor          = 0.8,
                MetallicFactor           = 0.2,
                RenderShadowMap          = true,
                EnableAutoTangent        = true,
            };
            FloorModelTransform = new Media3D.MatrixTransform3D(Matrix.Translation(0, -5, 0).ToMatrix3D());
        }
Exemplo n.º 32
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
            LoadModel("teapot_quads_tex.obj", MeshFaces.Default);
            this.ModelTransform = new Media3D.TranslateTransform3D();
            this.ModelMaterial  = PhongMaterials.PolishedSilver;
            this.ModelMaterial.ReflectiveColor      = Color.Silver;
            this.ModelMaterial.RenderEnvironmentMap = true;
            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.Model1 = b1.ToMeshGeometry3D();

            EffectsManager = new DefaultEffectsManager();

            SkyboxTexture = LoadFileToMemory("Cubemap_Grandcanyon.dds");
            int t = 5;

            for (int i = 0; i < 10; ++i)
            {
                Instances1.Add(Matrix.Translation(new Vector3(t, t, (i - 5) * t)));
            }
            for (int i = 0; i < 10; ++i)
            {
                Instances2.Add(Matrix.Translation(new Vector3(t, (i - 5) * t, t)));
            }
            for (int i = 0; i < 10; ++i)
            {
                Instances3.Add(Matrix.Translation(new Vector3(-(i - 5) * t, t, (i - 5) * t)));
            }
            //int t = 5;
            //Instances.Add(Matrix.Translation(new Vector3(t, t, t)));
            //Instances.Add(Matrix.Translation(new Vector3(-t, t, t)));
            //Instances.Add(Matrix.Translation(new Vector3(-t, -t, t)));
            //Instances.Add(Matrix.Translation(new Vector3(-t, -t, -t)));
            //Instances.Add(Matrix.Translation(new Vector3(t, -t, t)));
            //Instances.Add(Matrix.Translation(new Vector3(t, -t, -t)));
            //Instances.Add(Matrix.Translation(new Vector3(-t, t, -t)));
            //Instances.Add(Matrix.Translation(new Vector3(t, t, -t)));
            this.ModelMaterial1 = PhongMaterials.Red;
            this.ModelMaterial1.AmbientColor         = Color.Red;
            this.ModelMaterial1.RenderEnvironmentMap = true;
            this.ModelMaterial2 = PhongMaterials.Green;
            this.ModelMaterial2.AmbientColor         = Color.Green;
            this.ModelMaterial2.RenderEnvironmentMap = true;
            this.ModelMaterial3 = PhongMaterials.Blue;
            this.ModelMaterial3.AmbientColor         = Color.Blue;
            this.ModelMaterial3.RenderEnvironmentMap = true;
        }
        private void RenderBoard(LagoVista.EaglePCB.Models.PCB board, LagoVista.EaglePCB.Models.PCBProject project, bool resetZoomAndView = true)
        {
            var linePoints = new Point3DCollection();

            var modelGroup     = new Model3DGroup();
            var copperMaterial = MaterialHelper.CreateMaterial(Color.FromRgb(0xb8, 0x73, 0x33));
            var redMaterial    = MaterialHelper.CreateMaterial(Colors.Red);
            var greenMaterial  = MaterialHelper.CreateMaterial(Colors.Green);
            var blueMaterial   = MaterialHelper.CreateMaterial(Colors.Blue);
            var blackMaterial  = MaterialHelper.CreateMaterial(Colors.Black);
            var grayMaterial   = MaterialHelper.CreateMaterial(Colors.DarkGray);

            var scrapX         = project == null ? 0 : project.ScrapSides;
            var scrapY         = project == null ? 0 : project.ScrapTopBottom;
            var boardThickness = project == null ? 1.60 : project.StockThickness;


            if (_topWiresVisible)
            {
                foreach (var wireSection in board.TopWires.GroupBy(wre => wre.Width))
                {
                    var width = wireSection.First().Width;

                    foreach (var wire in wireSection)
                    {
                        var topWireMeshBuilder = new MeshBuilder(false, false);
                        var boxRect            = new Rect3D(wire.Rect.X1 - (width / 2), wire.Rect.Y1, -0.1, width, wire.Rect.Length, 0.2);
                        topWireMeshBuilder.AddBox(boxRect);

                        topWireMeshBuilder.AddCylinder(new Point3D(wire.Rect.X1, wire.Rect.Y1, -0.1), new Point3D(wire.Rect.X1, wire.Rect.Y1, .1), width / 2, 50, true, true);

                        var boxModel = new GeometryModel3D()
                        {
                            Geometry = topWireMeshBuilder.ToMesh(true), Material = copperMaterial
                        };
                        boxModel.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), wire.Rect.Angle), new Point3D(wire.Rect.X1, wire.Rect.Y1, 0));
                        modelGroup.Children.Add(boxModel);
                    }
                }
            }

            if (_bottomWiresVisible)
            {
                foreach (var wireSection in board.BottomWires.GroupBy(wre => wre.Width))
                {
                    var width = wireSection.First().Width;

                    foreach (var wire in wireSection)
                    {
                        var topWireMeshBuilder = new MeshBuilder(false, false);
                        var boxRect            = new Rect3D(wire.Rect.X1 - (width / 2), wire.Rect.Y1, -0.105, width, wire.Rect.Length, 0.2);
                        topWireMeshBuilder.AddBox(boxRect);

                        topWireMeshBuilder.AddCylinder(new Point3D(wire.Rect.X1, wire.Rect.Y1, -0.105), new Point3D(wire.Rect.X1, wire.Rect.Y1, .095), width / 2, 50, true, true);

                        var boxModel = new GeometryModel3D()
                        {
                            Geometry = topWireMeshBuilder.ToMesh(true), Material = grayMaterial
                        };
                        boxModel.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), wire.Rect.Angle), new Point3D(wire.Rect.X1, wire.Rect.Y1, 0));
                        modelGroup.Children.Add(boxModel);
                    }
                }
            }



            foreach (var element in board.Components)
            {
                foreach (var pad in element.SMDPads)
                {
                    var padMeshBuilder = new MeshBuilder(false, false);

                    padMeshBuilder.AddBox(new Rect3D(pad.OriginX - (pad.DX / 2), pad.OriginY - (pad.DY / 2), -0.1, (pad.DX), (pad.DY), 0.2));
                    var box = new GeometryModel3D()
                    {
                        Geometry = padMeshBuilder.ToMesh(true), Material = element.Layer == 1 ? copperMaterial : grayMaterial
                    };

                    var transformGroup = new Transform3DGroup();
                    transformGroup.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), element.RotateAngle)));
                    transformGroup.Children.Add(new TranslateTransform3D(new Vector3D(element.X.Value, element.Y.Value, element.Layer == 1 ? 0 : 0.05)));

                    box.Transform = transformGroup;

                    modelGroup.Children.Add(box);
                }

                foreach (var pad in element.Pads)
                {
                    var padCopperMeshBuilder = new MeshBuilder(false, false);
                    padCopperMeshBuilder.AddCylinder(new Point3D(pad.X, pad.Y, 0), new Point3D(pad.X, pad.Y, 0.1), pad.DrillDiameter * 0.75);
                    var padCopper = new GeometryModel3D()
                    {
                        Geometry = padCopperMeshBuilder.ToMesh(true), Material = copperMaterial
                    };
                    modelGroup.Children.Add(padCopper);

                    var padDrillMeshBuilder = new MeshBuilder(false, false);
                    padDrillMeshBuilder.AddCylinder(new Point3D(pad.X, pad.Y, 0), new Point3D(pad.X, pad.Y, 0.101), pad.DrillDiameter / 2);
                    var padDrill = new GeometryModel3D()
                    {
                        Geometry = padDrillMeshBuilder.ToMesh(true), Material = blackMaterial
                    };
                    modelGroup.Children.Add(padDrill);
                }

                if (_pcbVisible)
                {
                    var billBoard = new BillboardTextVisual3D()
                    {
                        Foreground = Brushes.White, Text = element.Name, Position = new Point3D(element.X.Value + scrapX, element.Y.Value + scrapY, 4), FontSize = 14
                    };
                    viewport.Children.Add(billBoard);
                }
            }

            foreach (var via in board.Vias)
            {
                var padCopperMeshBuilder = new MeshBuilder(false, false);
                padCopperMeshBuilder.AddCylinder(new Point3D(via.X, via.Y, 0), new Point3D(via.X, via.Y, 0.1), (via.DrillDiameter));
                var padCopper = new GeometryModel3D()
                {
                    Geometry = padCopperMeshBuilder.ToMesh(true), Material = copperMaterial
                };
                modelGroup.Children.Add(padCopper);

                var padDrillMeshBuilder = new MeshBuilder(false, false);
                padDrillMeshBuilder.AddCylinder(new Point3D(via.X, via.Y, 0), new Point3D(via.X, via.Y, 0.11), via.DrillDiameter / 2);
                var padDrill = new GeometryModel3D()
                {
                    Geometry = padDrillMeshBuilder.ToMesh(true), Material = blackMaterial
                };
                modelGroup.Children.Add(padDrill);
            }

            if (_pcbVisible)
            {
                foreach (var circle in board.Holes)
                {
                    var circleMeshBuilder = new MeshBuilder(false, false);
                    circleMeshBuilder.AddCylinder(new Point3D(circle.X, circle.Y, 0), new Point3D(circle.X, circle.Y, 0.01), circle.Drill / 2);
                    modelGroup.Children.Add(new GeometryModel3D()
                    {
                        Geometry = circleMeshBuilder.ToMesh(true), Material = blackMaterial
                    });
                }

                #region Hold your nose to discover why irregular boards don't render as expected...

                /* gonna cheat here in next chunk of code...need to make progress, assume all corners are
                 * either square or round.  If rounded, same radius...WILL revisit this at some point, KDW 2/24/2017
                 * FWIW - feel so dirty doing this, but need to move on :*(
                 * very happy to accept a PR to fix this!  Proper mechanism is to create a polygon and likely subdivide the curve into smaller polygon edges
                 * more work than it's worth right now....sorry again :(
                 */
                //TODO: Render proper edge of board.

                var boardEdgeMeshBuilder = new MeshBuilder(false, false);

                var cornerWires = board.Layers.Where(layer => layer.Number == 20).FirstOrDefault().Wires.Where(wire => wire.Curve.HasValue == true);
                var radius      = cornerWires.Any() ? Math.Abs(cornerWires.First().Rect.X1 - cornerWires.First().Rect.X2) : 0;
                if (radius == 0)
                {
                    boardEdgeMeshBuilder.AddBox(new Point3D(board.Width / 2, board.Height / 2, -boardThickness / 2), board.Width, board.Height, boardThickness);
                }
                else
                {
                    boardEdgeMeshBuilder.AddBox(new Point3D(board.Width / 2, board.Height / 2, -boardThickness / 2), board.Width - (radius * 2), board.Height - (radius * 2), boardThickness);
                    boardEdgeMeshBuilder.AddBox(new Point3D(board.Width / 2, radius / 2, -boardThickness / 2), board.Width - (radius * 2), radius, boardThickness);
                    boardEdgeMeshBuilder.AddBox(new Point3D(board.Width / 2, board.Height - radius / 2, -boardThickness / 2), board.Width - (radius * 2), radius, boardThickness);
                    boardEdgeMeshBuilder.AddBox(new Point3D(radius / 2, board.Height / 2, -boardThickness / 2), radius, board.Height - (radius * 2), boardThickness);
                    boardEdgeMeshBuilder.AddBox(new Point3D(board.Width - radius / 2, board.Height / 2, -boardThickness / 2), radius, board.Height - (radius * 2), boardThickness);
                    boardEdgeMeshBuilder.AddCylinder(new Point3D(radius, radius, -boardThickness), new Point3D(radius, radius, 0), radius, 50, true, true);
                    boardEdgeMeshBuilder.AddCylinder(new Point3D(radius, board.Height - radius, -boardThickness), new Point3D(radius, board.Height - radius, 0), radius, 50, true, true);
                    boardEdgeMeshBuilder.AddCylinder(new Point3D(board.Width - radius, radius, -boardThickness), new Point3D(board.Width - radius, radius, 0), radius, 50, true, true);
                    boardEdgeMeshBuilder.AddCylinder(new Point3D(board.Width - radius, board.Height - radius, -boardThickness), new Point3D(board.Width - radius, board.Height - radius, 0), radius, 50, true, true);
                }
                modelGroup.Children.Add(new GeometryModel3D()
                {
                    Geometry = boardEdgeMeshBuilder.ToMesh(true), Material = greenMaterial
                });

                #endregion
            }

            PCBLayer.Content   = modelGroup;
            PCBLayer.Transform = new TranslateTransform3D(scrapX, scrapY, 0);

            if (project != null)
            {
                var stockGroup = new Model3DGroup();

                var circleMeshBuilder = new MeshBuilder(false, false);
                var holdDownDrills    = project.GetHoldDownDrills(board);
                foreach (var drl in holdDownDrills)
                {
                    circleMeshBuilder.AddCylinder(new Point3D(drl.X, drl.Y, -boardThickness), new Point3D(drl.X, drl.Y, 0.01), project.HoldDownDiameter / 2);
                }

                stockGroup.Children.Add(new GeometryModel3D()
                {
                    Geometry = circleMeshBuilder.ToMesh(true), Material = blackMaterial
                });

                if (_stockVisible)
                {
                    var stockMeshBuilder = new MeshBuilder(false, false);
                    stockMeshBuilder.AddBox(new Point3D(project.StockWidth / 2, project.StockHeight / 2, -boardThickness / 2), project.StockWidth, project.StockHeight, boardThickness - 0.05);
                    stockGroup.Children.Add(new GeometryModel3D()
                    {
                        Geometry = stockMeshBuilder.ToMesh(true), Material = copperMaterial
                    });
                }

                StockLayer.Content = stockGroup;
            }
            else
            {
                StockLayer.Content = null;
            }

            if (resetZoomAndView)
            {
                RefreshExtents();
            }
        }
Exemplo n.º 34
0
        public MainPageViewModel()
        {
            EffectsManager = new DefaultEffectsManager(new Logger());

            Camera = new PerspectiveCamera()
            {
                Position = new Vector3(40, 10, 100), LookDirection = new Vector3(0, -10, -100), UpDirection = UpDirection, FarPlaneDistance = 500, NearPlaneDistance = 0.1
            };
            Camera1 = new OrthographicCamera()
            {
                Position = new Vector3(60, 10, 100), LookDirection = new Vector3(0, -10, -100), UpDirection = upDirection, Width = 30, FarPlaneDistance = 500, NearPlaneDistance = 20
            };
            var builder = new MeshBuilder(true, true, true);

            builder.AddBox(new SharpDX.Vector3(0, 0, 0), 2, 2, 2);
            builder.AddSphere(new Vector3(0, 2, 0), 1.5);
            Geometry = builder.ToMesh();
            Geometry.UpdateOctree();
            builder = new MeshBuilder();
            builder.AddSphere(new Vector3(0, 2, 0), 2);
            Sphere = builder.ToMesh();
            Sphere.UpdateOctree();

            Material = new PhongMaterial()
            {
                AmbientColor      = Color.Gray,
                DiffuseColor      = new Color4(0.75f, 0.75f, 0.75f, 1.0f),
                SpecularColor     = Color.White,
                SpecularShininess = 10f,
                ReflectiveColor   = new Color4(0.2f, 0.2f, 0.2f, 0.5f)
            };
            Material.DiffuseMap        = LoadTexture("TextureCheckerboard2.jpg");
            Material.NormalMap         = LoadTexture("TextureCheckerboard2_dot3.jpg");
            Material1                  = Material.Clone();
            Material1.ReflectiveColor  = Color.Silver;
            Material1.RenderDiffuseMap = false;
            Material1.RenderNormalMap  = false;
            var lineBuilder = new LineBuilder();

            lineBuilder.AddLine(Vector3.Zero, new Vector3(5, 0, 0));
            lineBuilder.AddLine(Vector3.Zero, new Vector3(0, 5, 0));
            lineBuilder.AddLine(Vector3.Zero, new Vector3(0, 0, 5));
            LineGeometry        = lineBuilder.ToLineGeometry3D();
            LineGeometry.Colors = new HelixToolkit.UWP.Core.Color4Collection()
            {
                Color.Red, Color.Red, Color.Green, Color.Green, Color.Blue, Color.Blue
            };

            builder = new MeshBuilder();
            builder.AddSphere(new Vector3(), 3);
            var mesh = builder.ToMesh();

            mesh.UpdateOctree();
            PointGeometry = new PointGeometry3D()
            {
                Positions = mesh.Positions
            };

            AxisLabelGeometry = new BillboardText3D();
            AxisLabelGeometry.TextInfo.Add(new TextInfo("X", new Vector3(5.5f, 0, 0))
            {
                Foreground = Color.Red
            });
            AxisLabelGeometry.TextInfo.Add(new TextInfo("Y", new Vector3(0, 5.5f, 0))
            {
                Foreground = Color.Green
            });
            AxisLabelGeometry.TextInfo.Add(new TextInfo("Z", new Vector3(0, 0, 5.5f))
            {
                Foreground = Color.Blue
            });

            builder = new MeshBuilder();
            builder.AddBox(new Vector3(0, -6, 0), 30, 0.5, 30);
            FloorModel = builder.ToMesh();

            FloorMaterial = PhongMaterials.Obsidian;
            FloorMaterial.ReflectiveColor = Color.Silver;

            EnvironmentMap = LoadTexture("Cubemap_Grandcanyon.dds");

            UpDirXCommand = new RelayCommand(() => { UpDirection = Vector3.UnitX; }, () => { return(UpDirection != Vector3.UnitX); });
            UpDirYCommand = new RelayCommand(() => { UpDirection = Vector3.UnitY; }, () => { return(UpDirection != Vector3.UnitY); });
            UpDirZCommand = new RelayCommand(() => { UpDirection = Vector3.UnitZ; }, () => { return(UpDirection != Vector3.UnitZ); });

            timer          = new DispatcherTimer();
            timer.Tick    += Timer_Tick;
            timer.Interval = new TimeSpan(0, 0, 0, 0, 16);
            timer.Start();
        }
        private void InitializeScene()
        {
            camera = new PerspectiveCameraCore()
            {
                LookDirection     = new Vector3(0, 0, 50),
                Position          = new Vector3(0, 0, -50),
                FarPlaneDistance  = 1000,
                NearPlaneDistance = 0.1f,
                FieldOfView       = 45,
                UpDirection       = new Vector3(0, 1, 0)
            };
            viewport.CameraCore = camera;
            viewport.Items.Add(new DirectionalLightNode()
            {
                Direction = new Vector3(0, -1, 1), Color = Color.White
            });
            viewport.Items.Add(new PointLightNode()
            {
                Position = new Vector3(0, 0, -20), Color = Color.Yellow, Range = 20, Attenuation = Vector3.One
            });

            var builder = new MeshBuilder(true, true, true);

            builder.AddSphere(Vector3.Zero, 1, 12, 12);
            sphere  = builder.ToMesh();
            builder = new MeshBuilder(true, true, true);
            builder.AddBox(Vector3.Zero, 1, 1, 1);
            box    = builder.ToMesh();
            points = new PointGeometry3D()
            {
                Positions = sphere.Positions
            };
            var lineBuilder = new LineBuilder();

            lineBuilder.AddBox(Vector3.Zero, 2, 2, 2);
            lines       = lineBuilder.ToLineGeometry3D();
            groupSphere = new GroupNode();
            groupBox    = new GroupNode();
            groupLines  = new GroupNode();
            groupPoints = new GroupNode();
            InitializeMaterials();
            materialList = materials.Values.ToArray();
            var materialCount = materialList.Length;

            for (int i = 0; i < NumItems; ++i)
            {
                var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20)));
                groupSphere.AddChildNode(new MeshNode()
                {
                    Geometry = sphere, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back
                });
            }

            for (int i = 0; i < NumItems; ++i)
            {
                var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50)));
                groupBox.AddChildNode(new MeshNode()
                {
                    Geometry = box, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back
                });
            }

            for (int i = 0; i < NumItems; ++i)
            {
                var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50)));
                groupPoints.AddChildNode(new PointNode()
                {
                    Geometry = points, ModelMatrix = transform, Color = Color.Red, Size = new Size2F(0.5f, 0.5f)
                });
            }

            for (int i = 0; i < NumItems; ++i)
            {
                var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50)));
                groupLines.AddChildNode(new LineNode()
                {
                    Geometry = lines, ModelMatrix = transform, Color = Color.LightBlue, Thickness = 0.5f
                });
            }

            viewport.Items.Add(groupSphere);
            groupSphere.AddChildNode(groupBox);
            groupSphere.AddChildNode(groupPoints);
            groupSphere.AddChildNode(groupLines);

            var viewbox = new ViewBoxNode();

            viewport.Items.Add(viewbox);
        }
Exemplo n.º 36
0
        private void CreateSpawn(EQEmu.Spawns.Spawn2 spawn,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(spawn))
            {
                foreach (Model3D model in _mapping[spawn])
                {
                    group.Children.Remove(model);
                }
            }

            MeshBuilder builder = new MeshBuilder();
            Point3D p = new Point3D(spawn.X,spawn.Y,spawn.Z);

            if( !Clipping.DrawPoint(p) ) return;

            builder.AddBox(p,2,2,2);

            Transform3D headingRotate = new RotateTransform3D()
            {
                CenterX = p.X,
                CenterY = p.Y,
                CenterZ = p.Z,
                Rotation = new AxisAngleRotation3D(
                    new Vector3D(0,0,-1),spawn.HeadingDegrees)
            };

            GeometryModel3D box;
            Material mat = Materials.White;

            if (flags == DisplayFlags.None)
            {
                if (spawn.RoamAreaId > 0)
                {
                    mat = Materials.Red;
                }
                else if (spawn.GridId > 0)
                {
                    mat = Materials.Yellow;
                }
            }
            else if (flags == DisplayFlags.Green)
            {
                mat = Materials.Green;
            }
            else if (flags == DisplayFlags.DarkGray)
            {
                mat = Materials.DarkGray;
            }
            else if (flags == DisplayFlags.Rainbow)
            {
                mat = Materials.Rainbow;
            }
            else if (flags == DisplayFlags.Blue)
            {
                mat = Materials.Blue;
            }

            box = new GeometryModel3D(builder.ToMesh(), mat);
            box.Transform = headingRotate;
            collection.Add(box);

            builder = new MeshBuilder();
            float radius = 3.0f;
            double hx = spawn.X + Math.Cos((spawn.HeadingDegrees - 90) / 180 * Math.PI) * radius;
            double hy = spawn.Y + Math.Sin((spawn.HeadingDegrees + 90) / 180 * Math.PI) * radius;

            builder.AddArrow(new Point3D(spawn.X, spawn.Y, spawn.Z), new Point3D(hx, hy, spawn.Z), 0.5, 1);
            collection.Add(new GeometryModel3D(builder.ToMesh(), mat));

            _mapping[spawn] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
        private void CreateSpawn(GroundSpawn spawn,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(spawn))
            {
                foreach (Model3D model in _mapping[spawn])
                {
                    group.Children.Remove(model);
                }
            }

            Point3D p = new Point3D(
                (spawn.MaxX + spawn.MinX) / 2,
                (spawn.MaxY + spawn.MinY) / 2,
                spawn.MaxZ);

            if (!Clipping.DrawPoint(p)) return;

            var xlen = spawn.MaxX - spawn.MinX;
            var ylen = spawn.MaxY - spawn.MinY;

            xlen = xlen <= 0 ? 4 : xlen;
            ylen = ylen <= 0 ? 4 : ylen;

            MeshBuilder builder = new MeshBuilder();
            builder.AddBox(p, ylen, xlen, 2);

            GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);

            collection.Add(box);

            if ( flags != DisplayFlags.None )
            {
                var scale = 1.25;
                builder = new MeshBuilder();

                if (flags.HasFlag(DisplayFlags.DarkGrayAura))
                {
                    builder.AddBox(p, ylen * scale, xlen * scale, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
                    collection.Add(box);
                }
                else if (flags.HasFlag(DisplayFlags.GreenAura))
                {
                    builder.AddBox(p, ylen * scale, xlen * scale, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
                    collection.Add(box);
                }
            }

            _mapping[spawn] = collection;

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Exemplo n.º 38
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)
            };

            // 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.º 39
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

            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DeferredRenderTechniqueNames.Deferred];
            //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 = LoadFileToMemory(new System.Uri(@"./Media/TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute).ToString());
            this.PlaneMaterial.NormalMap  = LoadFileToMemory(new System.Uri(@"./Media/TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute).ToString());

            // setup lighting
            this.AmbientLightColor         = Colors.DarkGray;
            this.DirectionalLightColor     = Colors.Gray;
            this.DirectionalLightDirection = new Vector3D(-2, -5, -2);

            this.PointLightColor       = Colors.White;
            this.PointLightAttenuation = new Vector3D(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       = Colors.AntiqueWhite;
            this.SpotLightAttenuation = new Vector3D(1.0, 0.1, 0.01);

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

            // spotlight collection
            this.SpotLightCollection = new ObservableElement3DCollection();
            this.SpotLightCount      = 7;
            this.SpotLightSpread     = 100;
        }
Exemplo n.º 40
0
        public MainViewModel()
        {
            this.Title      = "BoneSkin Demo";
            this.SubTitle   = "WPF & SharpDX";
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];

            this.Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
            {
                Position      = new Media3D.Point3D(20, 20, 20),
                LookDirection = new Media3D.Vector3D(-20, -20, -20),
                UpDirection   = new Media3D.Vector3D(0, 1, 0)
            };
            this.Light1Color       = Colors.White;
            this.Light1Direction   = new Media3D.Vector3D(-10, -10, -10);
            this.AmbientLightColor = Colors.DarkGray;
            SetupCameraBindings(this.Camera);

            var builder = new MeshBuilder(true, true, true);

            path = new List <Vector3>();
            for (int i = 0; i < NumSegments; ++i)
            {
                path.Add(new Vector3(0, (float)i / 10, 0));
            }

            builder.AddTube(path, 2, Theta, false, false, true);
            Model = builder.ToMesh();
            for (int i = 0; i < Model.Positions.Count; ++i)
            {
                Model.Positions[i] = new Vector3(Model.Positions[i].X, 0, Model.Positions[i].Z);
            }
            Material = new PhongMaterial()
            {
                DiffuseColor = Colors.SteelBlue.ToColor4()
            };
            for (int i = 0; i < numBonesInModel; ++i)
            {
                boneInternal[i] = Matrix.Identity;
            }
            Bones = new BoneMatricesStruct()
            {
                Bones = boneInternal.ToArray()
            };

            builder = new MeshBuilder(true, true, false);
            builder.AddBox(new Vector3(), 40, 0.5, 40, BoxFaces.All);
            FloorModel = builder.ToMesh();

            int boneId = 0;

            numSegmentPerBone = (int)Math.Max(1, (double)Model.Positions.Count / Theta / (numBonesInModel - 1));
            int count = 0;

            for (int i = 0; i < Model.Positions.Count / Theta; ++i)
            {
                boneParams.AddRange(Enumerable.Repeat(new BoneIds()
                {
                    Bone1   = Math.Min(numBonesInModel - 1, boneId),
                    Bone2   = Math.Min(numBonesInModel - 1, boneId - 1),
                    Bone3   = Math.Min(numBonesInModel - 1, boneId + 1),
                    Weights = new Vector4(0.6f, 0.2f, 0.2f, 0)
                }, Theta));
                ++count;
                if (count == numSegmentPerBone)
                {
                    count = 0;
                    ++boneId;
                }
            }

            VertexBoneParams = boneParams.ToArray();

            Instances = new List <Matrix>();
            for (int i = 0; i < 3; ++i)
            {
                Instances.Add(Matrix.Translation(new Vector3(-5 + i * 4, 0, -10)));
            }
            for (int i = 0; i < 3; ++i)
            {
                Instances.Add(Matrix.Translation(new Vector3(-5 + i * 4, 0, 0)));
            }
            for (int i = 0; i < 3; ++i)
            {
                Instances.Add(Matrix.Translation(new Vector3(-5 + i * 4, 0, 10)));
            }
            StartAnimation();
        }
Exemplo n.º 41
0
 private static Geometry3D GetDefaultGeometry()
 {
     // The default geometry is a box
     var mb = new MeshBuilder(false, false);
     mb.AddBox(new Point3D(0, 0, 0.5), 0.8, 0.8, 1);
     return mb.ToMesh();
 }
Exemplo n.º 42
0
        public MainViewModel()
        {
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager = new DefaultEffectsManager(RenderTechniquesManager);

            // ----------------------------------------------
            // titles
            this.Title = "SwapChain Top Surface Rendering Demo";
            this.SubTitle = "WPF & SharpDX";

            // ----------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera
            {
                Position = new Point3D(20, 20, 20),
                LookDirection = new Vector3D(-1, -1, -1),
                UpDirection = new Vector3D(0, 1, 0)
            };
            // (Camera as ProjectionCamera).FarPlaneDistance = 10000;
            this.Light1Direction = new Vector3(-100, -100, -100);
            SetupCameraBindings(this.Camera);
            // ----------------------------------------------
            // setup scene

            this.Light1Color = (Color4)Color.White;


            var builder = new MeshBuilder(true, false, false);
            builder.AddBox(new Vector3(), 40, 0.1, 40);
            Plane1Model = FloorModel = builder.ToMeshGeometry3D();

            builder = new MeshBuilder(true, false, false);
            builder.AddBox(new Vector3(), 0.1, 40, 40);
            Plane2Model = builder.ToMeshGeometry3D();

            FloorMaterial = new PhongMaterial();
            FloorMaterial.DiffuseColor = new Color4(1f, 1f, 1f, 0.2f);
            FloorMaterial.AmbientColor = new Color4(0, 0, 0, 0);
            FloorMaterial.ReflectiveColor = new Color4(0, 0, 0, 0);
            FloorMaterial.SpecularColor = new Color4(0, 0, 0, 0);

            PlaneMaterial = new PhongMaterial() { DiffuseColor = new Color4(0.1f, 0.1f, 0.8f, 0.2f) };

            var landerItems = Load3ds("Car.3ds").Select(x => x.Geometry as MeshGeometry3D).ToArray();
            Model = MeshGeometry3D.Merge(landerItems);
            ModelMaterial = PhongMaterials.Obsidian;
            var transGroup = new Media3D.Transform3DGroup();
            transGroup.Children.Add(new Media3D.ScaleTransform3D(0.01, 0.01, 0.01));
            transGroup.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Media3D.Vector3D(1, 0, 0), -90)));
            transGroup.Children.Add(new Media3D.TranslateTransform3D(new Media3D.Vector3D(0, 6, 0)));

            ModelTransform = transGroup;

            Plane1Transform = new TranslateTransform3D(new Vector3D(0, 15, 0));
            Plane2Transform = new TranslateTransform3D(new Vector3D(15, 0, 0));

            timer = new DispatcherTimer(DispatcherPriority.Render);           
            timer.Interval = TimeSpan.FromMilliseconds(30);
            timer.Tick += Timer_Tick;
            timer.Start();
        }
Exemplo n.º 43
0
        public void UpdateAll()
        {
            Model3DGroup group = Model as Model3DGroup;
            Material mat = Materials.Red;

            BuildDoors();

            group.Children.Clear();

            if (_doorObjects != null)
            {
                foreach (var dr in _doorObjects)
                {
                    var builder = new MeshBuilder();
                    var transforms = dr.GetTransforms();
                    if (dr.Polygons.ElementAt(0).BitmapInfo != null)
                    {
                        var img = dr.Polygons.ElementAt(0).BitmapInfo.Image;
                        var brush = new System.Windows.Media.ImageBrush(img);
                        brush.ViewportUnits = System.Windows.Media.BrushMappingMode.Absolute;
                        brush.TileMode = System.Windows.Media.TileMode.Tile;
                        mat = HelixToolkit.Wpf.MaterialHelper.CreateMaterial(brush);
                    }
                    else
                    {
                        mat = Materials.LightGray;
                    }

                    foreach (var poly in dr.Polygons)
                    {
                        Point3D p1 = new Point3D(poly.V1.X, poly.V1.Y, poly.V1.Z);
                        Point3D p2 = new Point3D(poly.V2.X, poly.V2.Y, poly.V2.Z);
                        Point3D p3 = new Point3D(poly.V3.X, poly.V3.Y, poly.V3.Z);

                        foreach (var transform in transforms)
                        {
                            p1 = transform.Transform(p1);
                            p2 = transform.Transform(p2);
                            p3 = transform.Transform(p3);
                        }

                        if (!Clipping.DrawPoint(p1) || !Clipping.DrawPoint(p2) || !Clipping.DrawPoint(p3))
                        {
                            continue;
                        }

                        var t1 = new System.Windows.Point(poly.V1.U, 1 - poly.V1.V);
                        var t2 = new System.Windows.Point(poly.V2.U, 1 - poly.V2.V);
                        var t3 = new System.Windows.Point(poly.V3.U, 1 - poly.V3.V);
                        //builder.AddTriangle(p3, p2, p1, t3, t2, t1);
                        builder.AddTriangle(p1, p2, p3, t1, t2, t3);
                    }
                    group.Children.Add(new GeometryModel3D(builder.ToMesh(), mat));
                }
            }

            var rotate = new RotateTransform3D();
            rotate.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);
            foreach (var door in _manager.Doors)
            {
                var bbuilder = new MeshBuilder();
                Material mater = Materials.Red;

                if (_selected != null && _selected.Contains(door))
                {
                    mater = Materials.Blue;
                }

                var pcenter = new Point3D(door.X, door.Y, door.Z);
                rotate.CenterX = pcenter.X;
                rotate.CenterY = pcenter.Y;

                float radius = 3.0f;
                double hx = pcenter.X + Math.Cos((door.HeadingDegrees - 90) / 180 * Math.PI) * radius;
                double hy = pcenter.Y + Math.Sin((door.HeadingDegrees + 90) / 180 * Math.PI) * radius;

                var p = rotate.Transform(new Point3D(hx, hy, door.Z));

                //bbuilder.AddArrow(pcenter, new Point3D(hx, hy, door.Z), 0.5, 1);
                bbuilder.AddArrow(pcenter,p, 0.5, 1);
                bbuilder.AddBox(pcenter, 0.5, 0.5, 20);

                group.Children.Add(new GeometryModel3D(bbuilder.ToMesh(), mater));
            }
        }