/// <summary> /// Translates a point into a solid drawable object /// </summary> /// <param name="point">The point to draw</param> /// <param name="color">The color of the object</param> /// <param name="offSetX">An optional offset by which the object gets shifted along the x-axis</param> /// <param name="offSetY">An optional offset by which the object gets shifted along the y-axis</param> /// <param name="offSetZ">An optional offset by which the object gets shifted along the z-axis</param> /// <returns>The newly composed drawable object</returns> public static ModelVisual3D Translate( MeshPoint point, Color color, double offSetX = 0, double offSetY = 0, double offSetZ = 0, double radius = 0.1) { SphereVisual3D sphere = new SphereVisual3D(); sphere.Center = new Point3D( point.X + offSetX, point.Y + offSetY, point.Z + offSetZ); sphere.Radius = radius; sphere.Material = new DiffuseMaterial(GeneratePlainBrush(color)); sphere.SetName(point.VolatileID.ToString()); // TODO remove debug? return(sphere); }
private void CreateTestModels() { _rootModelVisual3D = new ModelVisual3D(); MainViewport3D.Children.Add(_rootModelVisual3D); // SphereVisual3D _sphereVisual3D = new Ab3d.Visuals.SphereVisual3D() { CenterPosition = new Point3D(-50, 0, -50), Radius = 30, Material = new DiffuseMaterial(Brushes.Silver) }; _sphereVisual3D.SetName("SphereVisual3D"); _rootModelVisual3D.Children.Add(_sphereVisual3D); var readerObj = new ReaderObj(); var teapotModel = readerObj.ReadModel3D(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Models\teapot-hires.obj")); Ab3d.Utilities.ModelUtils.CenterAndScaleModel3D(teapotModel, centerPosition: new Point3D(50, 0, -50), finalSize: new Size3D(80, 80, 80), preserveAspectRatio: true); _teapotModelVisual3D = new ModelVisual3D() { Content = teapotModel }; teapotModel.SetName("teapot Model3D"); _teapotModelVisual3D.SetName("teapot ModelVisual3D"); _rootModelVisual3D.Children.Add(_teapotModelVisual3D); // InstancedMeshGeometryVisual3D var boxMesh3D = new Ab3d.Meshes.BoxMesh3D(new Point3D(0, 0, 0), new Size3D(6, 6, 6), 1, 1, 1); InstanceData[] instancedData = DXEnginePerformance.InstancedMeshGeometry3DTest.CreateInstancesData(center: new Point3D(-50, 0, 50), size: new Size3D(80, 50, 80), modelScaleFactor: 1, xCount: 5, yCount: 1, zCount: 5, useTransparency: false); _instancedMeshGeometryVisual3D = new InstancedMeshGeometryVisual3D(boxMesh3D.Geometry); _instancedMeshGeometryVisual3D.InstancesData = instancedData; _instancedMeshGeometryVisual3D.SetName("InstancedMeshGeometryVisual3D"); _rootModelVisual3D.Children.Add(_instancedMeshGeometryVisual3D); // MeshObjectNode and SceneNodeVisual3D var meshGeometry3D = new Ab3d.Meshes.PyramidMesh3D(new Point3D(50, -20, 50), new Size3D(80, 40, 80)).Geometry; var dxMeshGeometry3D = new Ab3d.DirectX.Models.DXMeshGeometry3D(meshGeometry3D); var standardMaterial = new StandardMaterial() { DiffuseColor = Colors.Gold.ToColor3() }; _pyramidMeshObjectNode = new Ab3d.DirectX.MeshObjectNode(dxMeshGeometry3D, standardMaterial); _disposables.Add(dxMeshGeometry3D); _disposables.Add(_pyramidMeshObjectNode); var sceneNodeVisual3D = new SceneNodeVisual3D(_pyramidMeshObjectNode); sceneNodeVisual3D.SetName("SceneNodeVisual3D"); _rootModelVisual3D.Children.Add(sceneNodeVisual3D); }
private void CreateSceneObjects() { MainViewport.Children.Clear(); _selectedObjectNames = new List <string>(); var rnd = new Random(); for (int i = 0; i < 4; i++) { var boxVisual3D = new BoxVisual3D() { CenterPosition = new Point3D(i * 50 - 100, 0, -25), Size = new Size3D(20, 20, 20), Material = new DiffuseMaterial(Brushes.Silver) }; string name = "Box_" + (i + 1).ToString(); boxVisual3D.SetName(name); MainViewport.Children.Add(boxVisual3D); var checkBox = new CheckBox() { Content = name, Tag = boxVisual3D, IsChecked = rnd.Next(2) > 0 }; checkBox.Checked += OnModelCheckBoxCheckedChanged; checkBox.Unchecked += OnModelCheckBoxCheckedChanged; OptionsPanel.Children.Add(checkBox); if (checkBox.IsChecked ?? false) { _selectedObjectNames.Add(name); } var sphereVisual3D = new SphereVisual3D() { CenterPosition = new Point3D(i * 50 - 100, 0, 25), Radius = 10, Material = new DiffuseMaterial(Brushes.Silver) }; name = "Sphere_" + (i + 1).ToString(); sphereVisual3D.SetName(name); MainViewport.Children.Add(sphereVisual3D); checkBox = new CheckBox() { Content = name, Tag = sphereVisual3D, IsChecked = rnd.Next(2) > 0 }; checkBox.Checked += OnModelCheckBoxCheckedChanged; checkBox.Unchecked += OnModelCheckBoxCheckedChanged; OptionsPanel.Children.Add(checkBox); if (checkBox.IsChecked ?? false) { _selectedObjectNames.Add(name); } } }