Ejemplo n.º 1
0
        public ProjectBox(float projectWidth, float projectLength, float projectHeight)
        {
            // Set ProjectBox Properties
            this.projectWidth  = projectWidth;
            this.projectLength = projectLength;
            this.projectHeight = projectHeight;

            // Create a model group
            modelGroup = new Model3DGroup();
            modelGroup.SetName("ModelGroup");

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);

            meshBuilder.AddBox(new Point3D(0, 0, 0.5 * this.projectHeight), this.projectWidth, this.projectLength, this.projectHeight);

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

            // Create some materials
            var greenMaterial  = MaterialHelper.CreateMaterial(Colors.YellowGreen);
            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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <returns>A Model3D object.</returns>
        private Model3DGroup BuildModel()
        {
            Model3DGroup modelGroup = null;

            this.Dispatch(() =>
            {
                modelGroup = new Model3DGroup();
                modelGroup.SetName("groupModel");
                int n = 0;
                foreach (var g in this.Groups)
                {
                    int m = 0;
                    foreach (var gm in g.CreateModels())
                    {
                        if (this.Freeze)
                        {
                            gm.Freeze();
                        }
                        gm.SetName("model_" + n.ToString() + "_" + m.ToString());
                        modelGroup.Children.Add(gm);
                        m++;
                    }
                    n++;
                }

                if (this.Freeze)
                {
                    modelGroup.Freeze();
                }
            });
            return(modelGroup);
        }
Ejemplo n.º 3
0
        public Model3DGroup GetAirplaneModel()
        {
            ObjReader    CurrentHelixObjReader = new ObjReader();
            Model3DGroup MyModel = CurrentHelixObjReader.Read(GetExeDirectory() + "\\Resources\\Models\\plane.obj");

            Transform3DGroup group = new Transform3DGroup();

            group.Children.Add(new TranslateTransform3D(new Vector3D(0, 0, 0)));
            group.Children.Add(new ScaleTransform3D(new Vector3D(0.05, 0.05, 0.05)));
            group.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90)));
            MyModel.Transform = group;
            this.Name         = "RA" + this.GetHashCode().ToString();
            Label             = CreateBillboard(this.Name);
            MyModel.SetName(this.Name);
            return(MyModel);
        }
        public DXEventManager3DSample()
        {
            InitializeComponent();


            Box1Visual3D.SetName("Box1Visual3D");
            BoxesGroupVisual3D.SetName("BoxesGroupVisual3D");
            Box2Visual3D.SetName("Box2Visual3D");
            Box3Visual3D.SetName("Box3Visual3D");
            Box4Visual3D.SetName("Box4Visual3D");
            Line1.SetName("Line1");
            Line2.SetName("Line2");
            Rectangle1.SetName("Rectangle1");


            var meshGeometry3D = new Ab3d.Meshes.SphereMesh3D(centerPosition: new Point3D(0, 0, 0), radius: 5, segments: 20, generateTextureCoordinates: false).Geometry;

            // The following method prepare InstanceData array with data for each instance (WorldMatrix and Color)
            InstanceData[] instancedData = DXEnginePerformance.InstancedMeshGeometry3DTest.CreateInstancesData(center: new Point3D(0, 0, 0),
                                                                                                               size: new Size3D(200, 50, 50),
                                                                                                               modelScaleFactor: 1,
                                                                                                               xCount: 10,
                                                                                                               yCount: 3,
                                                                                                               zCount: 3,
                                                                                                               useTransparency: false);


            // Create InstancedGeometryVisual3D with selected meshGeometry and InstancesData
            _instancedMeshGeometryVisual3D = new InstancedMeshGeometryVisual3D(meshGeometry3D);
            _instancedMeshGeometryVisual3D.InstancesData = instancedData;
            _instancedMeshGeometryVisual3D.SetName("InstancedMeshGeometryVisual3D");
            _instancedMeshGeometryVisual3D.Transform = new TranslateTransform3D(0, 50, 0);

            MainViewport3D.Children.Add(_instancedMeshGeometryVisual3D);

            _selectedInstanceIndex = -1;


            var model3DGroup = new Model3DGroup();

            model3DGroup.SetName("Model3DGroup");

            var frozenModel3DGroup = new Model3DGroup();

            frozenModel3DGroup.SetName("FrozenModel3DGroup");

            var box1Material = new DiffuseMaterial(Brushes.LightPink);
            var box2Material = new DiffuseMaterial(Brushes.LightCyan);

            var boxModel3D = Ab3d.Models.Model3DFactory.CreateBox(new Point3D(-100, 2, 25), new Size3D(60, 4, 50), box2Material);

            frozenModel3DGroup.Children.Add(boxModel3D);

            var pyramidModel3D = Ab3d.Models.Model3DFactory.CreatePyramid(new Point3D(-100, 2, 20), new Size3D(20, 20, 20), box2Material);

            frozenModel3DGroup.Children.Add(pyramidModel3D);

            for (int i = 0; i < 5; i++)
            {
                var geometryModel3D = new GeometryModel3D(meshGeometry3D, box1Material);
                geometryModel3D.Transform = new TranslateTransform3D(-130 + i * 15, 5, 80);
                geometryModel3D.SetName("GroupedSphere_" + i.ToString());

                model3DGroup.Children.Add(geometryModel3D);

                geometryModel3D           = new GeometryModel3D(meshGeometry3D, box2Material);
                geometryModel3D.Transform = new TranslateTransform3D(-130 + i * 15, 10, 50);
                geometryModel3D.SetName("FrozenGroupedSphere_" + i.ToString());

                frozenModel3DGroup.Children.Add(geometryModel3D);
            }


            frozenModel3DGroup.Freeze();

            MainViewport3D.Children.Add(model3DGroup.CreateModelVisual3D());
            MainViewport3D.Children.Add(frozenModel3DGroup.CreateModelVisual3D());

            _dxEventManager3D = new DXEventManager3D(MainDXViewportView);

            RegisterEventSource(Box1Visual3D);
            RegisterEventSource(BoxesGroupVisual3D);
            RegisterEventSource(Line1);
            RegisterEventSource(Line2);
            RegisterEventSource(Rectangle1);
            RegisterEventSource(_instancedMeshGeometryVisual3D);

            RegisterEventSource(model3DGroup);
            RegisterEventSource(frozenModel3DGroup);


            // Prevent TransparentPlaneVisual3D to be used by hit-testing
            _dxEventManager3D.RegisterExcludedVisual3D(TransparentPlaneVisual3D);


            this.PreviewMouseMove += delegate(object sender, MouseEventArgs args)
            {
                var position = args.GetPosition(this);
                MousePositionTextBlock.Text = $"Mouse pos: {position.X:0} {position.Y:0}";
            };

            this.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e)
            {
                var position = e.GetPosition(this);
                if (position == _lastMouseDownPosition)
                {
                    return;
                }

                System.Diagnostics.Debug.WriteLine("Mouse position: " + position.ToString());

                _lastMouseDownPosition = position;
            };


            // IMPORTANT:
            // It is very important to call Dispose method on DXSceneView after the control is not used any more (see help file for more info)
            this.Unloaded += (sender, args) => MainDXViewportView.Dispose();
        }