/// <summary> /// Generates a square grid with a step of 1.0 /// </summary> /// <returns></returns> public static LineGeometry3D GenerateGrid(Vector3 plane, int min = 0, int max = 10) { var grid = new LineBuilder(); //int width = max - min; if (plane == Vector3.UnitX) { for (int i = min; i <= max; i++) { grid.AddLine(new Vector3(0, i, min), new Vector3(0, i, max)); grid.AddLine(new Vector3(0, min, i), new Vector3(0, max, i)); } } else if (plane == Vector3.UnitY) { for (int i = min; i <= max; i++) { grid.AddLine(new Vector3(i, 0, min), new Vector3(i, 0, max)); grid.AddLine(new Vector3(min, 0, i), new Vector3(max, 0, i)); } } else { for (int i = min; i <= max; i++) { grid.AddLine(new Vector3(i, min, 0), new Vector3(i, max, 0)); grid.AddLine(new Vector3(min, i, 0), new Vector3(max, i, 0)); } } return(grid.ToLineGeometry3D()); }
public MainViewModel() { // titles this.Title = "Deferred Shading Demo"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // clear color this.BackgroundColor = (Color4)Color.White; // default render technique this.RenderTechnique = Techniques.RenderDeferred; // setup lighting this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.DirectionalLightColor2 = Color.Red; this.DirectionalLightColor1 = Color.Green; this.DirectionalLightColor3 = Color.Blue; this.DirectionalLightDirection1 = new Vector3(-0, -50, -0); this.DirectionalLightDirection2 = new Vector3(-0, -50, -50); this.DirectionalLightDirection3 = new Vector3(-50, -50, -0); // 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(true,true,true); 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 = meshGeometry.TextureCoordinates.Select(x => x.ToColor4()).ToArray(); 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.White; this.RedMaterial.DiffuseMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); this.RedMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)); this.GreenMaterial = PhongMaterials.DefaultVRML; //this.GreenMaterial.TextureMap = this.RedMaterial.TextureMap; this.BlueMaterial = PhongMaterials.Silver; //this.BlueMaterial.TextureMap = this.RedMaterial.TextureMap; }
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 = meshGeometry.TextureCoordinates.Select(x => x.ToColor4()).ToArray(); 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; }
public MainViewModel() { this.Title = "Manipulator Demo"; this.SubTitle = null; // camera setup this.Camera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = CreateAnimatedTransform(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1), 20); this.Model2Transform = new TranslateTransform3D(-3, 0, 0); this.Model3Transform = new TranslateTransform3D(+3, 0, 0); // model materials this.Material1 = PhongMaterials.Orange; this.Material2 = PhongMaterials.Orange; this.Material3 = PhongMaterials.Red; var dr = Color.DarkRed; Console.WriteLine(dr); }
/// <summary> /// Returns a line geometry of the axis-aligned bounding-box of the given mesh. /// </summary> /// <param name="mesh">Input mesh for the computation of the b-box</param> /// <returns></returns> public static LineGeometry3D GenerateBoundingBox(global::SharpDX.BoundingBox bb) { var cc = bb.GetCorners(); var ll = new LineBuilder(); ll.AddLine(cc[0], cc[1]); ll.AddLine(cc[1], cc[2]); ll.AddLine(cc[2], cc[3]); ll.AddLine(cc[3], cc[0]); ll.AddLine(cc[4], cc[5]); ll.AddLine(cc[5], cc[6]); ll.AddLine(cc[6], cc[7]); ll.AddLine(cc[7], cc[4]); ll.AddLine(cc[0], cc[4]); ll.AddLine(cc[1], cc[5]); ll.AddLine(cc[2], cc[6]); ll.AddLine(cc[3], cc[7]); return(ll.ToLineGeometry3D()); }
public MainViewModel() { Title = "Instancing Demo"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = (Color4)Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // scene model3d var b1 = new MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5, BoxFaces.All); Model = b1.ToMeshGeometry3D(); var l1 = new LineBuilder(); l1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5); Lines = l1.ToLineGeometry3D(); int num = 10; var instances = new List<Matrix>(); for (int i = -num; i < num; i++) { for (int j = -num; j < num; j++) { instances.Add(Matrix.Translation(new Vector3(i / 1.0f, j / 1.0f, 0f))); } } ModelInstances = instances; SubTitle = "Number of Instances: " + instances.Count.ToString(); // model trafo ModelTransform = Media3D.Transform3D.Identity;// new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)); // model material ModelMaterial = PhongMaterials.Glass; }
/// <summary> /// Returns a line geometry of the axis-aligned bounding-box of the given mesh. /// </summary> /// <param name="mesh">Input mesh for the computation of the b-box</param> /// <returns></returns> public static LineGeometry3D GenerateBoundingBox(global::SharpDX.BoundingBox bb) { var cc = bb.GetCorners(); var ll = new LineBuilder(); ll.AddLine(cc[0], cc[1]); ll.AddLine(cc[1], cc[2]); ll.AddLine(cc[2], cc[3]); ll.AddLine(cc[3], cc[0]); ll.AddLine(cc[4], cc[5]); ll.AddLine(cc[5], cc[6]); ll.AddLine(cc[6], cc[7]); ll.AddLine(cc[7], cc[4]); ll.AddLine(cc[0], cc[4]); ll.AddLine(cc[1], cc[5]); ll.AddLine(cc[2], cc[6]); ll.AddLine(cc[3], cc[7]); return ll.ToLineGeometry3D(); }
/// <summary> /// Generates a square grid with a step of 1.0 /// </summary> /// <returns></returns> public static LineGeometry3D GenerateGrid(Vector3 plane, int min = 0, int max = 10) { var grid = new LineBuilder(); //int width = max - min; if (plane == Vector3.UnitX) { for (int i = min; i <= max; i++) { grid.AddLine(new Vector3(0, i, min), new Vector3(0, i, max)); grid.AddLine(new Vector3(0, min, i), new Vector3(0, max, i)); } } else if (plane == Vector3.UnitY) { for (int i = min; i <= max; i++) { grid.AddLine(new Vector3(i, 0, min), new Vector3(i, 0, max)); grid.AddLine(new Vector3(min, 0, i), new Vector3(max, 0, i)); } } else { for (int i = min; i <= max; i++) { grid.AddLine(new Vector3(i, min, 0), new Vector3(i, max, 0)); grid.AddLine(new Vector3(min, i, 0), new Vector3(max, i, 0)); } } return grid.ToLineGeometry3D(); }