private void CreateScene() { var readerObj = new ReaderObj(); _readModel3D = readerObj.ReadModel3D(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Models\teapot-hires.obj")) as GeometryModel3D; if (_readModel3D != null) { var meshGeometry3D = (MeshGeometry3D)_readModel3D.Geometry; _readModel3D.Material = new DiffuseMaterial(new SolidColorBrush(System.Windows.Media.Color.FromArgb(200, 200, 200, 200))); _readModel3D.BackMaterial = _readModel3D.Material; Ab3d.Utilities.ModelUtils.CenterAndScaleModel3D(_readModel3D, new Point3D(0, 0, 0), new Size3D(100, 100, 100), preserveAspectRatio: true); meshGeometry3D = Ab3d.Utilities.MeshUtils.TransformMeshGeometry3D(meshGeometry3D, _readModel3D.Transform); var modelVisual3D = _readModel3D.CreateModelVisual3D(); MainViewport3D.Children.Add(modelVisual3D); MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args) { _dxMesh = new DXMeshGeometry3D(meshGeometry3D); _dxMesh.InitializeResources(MainDXViewportView.DXScene.DXDevice); RecreateOctTree(); }; } _hitLinesModelVisual3D = new ModelVisual3D(); MainViewport3D.Children.Add(_hitLinesModelVisual3D); Camera1.Distance = 200; }
private void AddTestModels() { // Load teapot model from obj file var readerObj = new ReaderObj(); var geometryModel3D = readerObj.ReadModel3D(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Models\teapot.obj")) as GeometryModel3D; if (geometryModel3D == null) { return; } _objectGeometry3D = (MeshGeometry3D)geometryModel3D.Geometry; int positionsCount = _objectGeometry3D.Positions.Count; // Create and fill the _positionColorsArray with the last color (light blue) _positionColorsArray = new Color4[positionsCount]; var lastColor = _gradientColor4Array[_gradientColor4Array.Length - 1]; FillPositionColorsArray(lastColor); // Now create the VertexColorMaterial that will be used instead of standard material // and will make the model render with special effect where each vertex can have its own color. _vertexColorMaterial = new VertexColorMaterial() { PositionColors = _positionColorsArray, // The PositionColors property is used to specify colors for each vertex CreateDynamicBuffer = true, // Because we will update the _positionColorsArray on each frame, it is better to create a dynamic DirectX buffer // To show specular effect set the specular data here: //SpecularPower = 16, //SpecularColor = Color3.White, //HasSpecularColor = true }; // Create standard WPF material and set the _vertexColorMaterial to be used when the model is rendered in DXEngine. var vertexColorDiffuseMaterial = new DiffuseMaterial(); vertexColorDiffuseMaterial.SetUsedDXMaterial(_vertexColorMaterial); // Create a GeometryModel3D that will be rendered with _vertexColorMaterial _vertexColorGeometryModel3D = new GeometryModel3D(_objectGeometry3D, vertexColorDiffuseMaterial); var vertexColorModelVisual3D = new ModelVisual3D() { Content = _vertexColorGeometryModel3D }; MainViewport.Children.Add(vertexColorModelVisual3D); // Show the same MeshGeometry3D but this time with wireframe material var wireframeWpfMaterial = new DiffuseMaterial(); _lineMaterial = new LineMaterial() { LineThickness = 1, LineColor = Color4.Black, DepthBias = 0.1f, }; wireframeWpfMaterial.SetUsedDXMaterial(_lineMaterial); var wireframeGeometryModel3D = new GeometryModel3D(_objectGeometry3D, wireframeWpfMaterial); var wireframeModelVisual3D = new ModelVisual3D() { Content = wireframeGeometryModel3D }; MainViewport.Children.Add(wireframeModelVisual3D); }
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); }