public MainViewModel() { this.Title = "ImageViewDemo"; this.SubTitle = "WPF & SharpDX"; this.RenderTechniquesManager = new DefaultRenderTechniquesManager(); this.RenderTechnique = this.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; this.EffectsManager = new DefaultEffectsManager(this.RenderTechniquesManager); this.OpenCommand = new RelayCommand((x) => this.OnOpenClick()); // camera setup this.defaultPerspectiveCamera = new PerspectiveCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0), NearPlaneDistance = 0.5, FarPlaneDistance = 150 }; this.defaultOrthographicCamera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0), NearPlaneDistance = 0, FarPlaneDistance = 100 }; this.Camera = this.defaultPerspectiveCamera; // setup lighting this.AmbientLightColor = new Color4(0f, 0f, 0f, 0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-0, -0, -10); // floor plane grid this.Grid = LineBuilder.GenerateGrid(Vector3.UnitZ, -5, 5, -5, 5); this.GridColor = Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(0, 0, 0); // plane var b2 = new MeshBuilder(); b2.AddBox(new Vector3(0, 0, 0), 10, 10, 0, BoxFaces.PositiveZ); this.Plane = b2.ToMeshGeometry3D(); this.PlaneMaterial = PhongMaterials.Blue; this.PlaneTransform = new Media3D.TranslateTransform3D(-0, -0, -0); //this.PlaneMaterial.ReflectiveColor = Color.Black; this.PlaneTransform = new Media3D.TranslateTransform3D(0, 0, 0); }
public MainViewModel() { // titles this.Title = "Simple Demo (Workitem 10043)"; this.SubTitle = "Please switch to Viewport 2 and then back to Viewport 1"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; if (this.RenderTechniquesManager != null) { // default render technique this.RenderTechnique = RenderTechniquesManager.RenderTechniques.Get(DefaultRenderTechniqueNames.Blinn); } // 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; }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); 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 = 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 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); //e1.AddLine(new Vector3(-1, 0, 0), new Vector3(1, 0, 0)); this.Lines = e1.ToLineGeometry3D(); // 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; }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); 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); }
public void ComputeNormals() { var builder = new MeshBuilder(false); builder.AddPolygon(new List<Vector3> { new Vector3(0f, 0f, 0f), new Vector3(7f, 0f, 0f), new Vector3(7f, 0f, 7f), }); Assert.IsNull(builder.Normals); Assert.IsFalse(builder.HasNormals); builder.ComputeNormalsAndTangents(MeshFaces.Default); Assert.IsTrue(builder.HasNormals); Assert.AreEqual(3, builder.Normals.Count); }
static Sphere() { var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); geometry = b1.ToMeshGeometry3D(); }
/// <summary> /// Adds a mesh. /// </summary> public void AddMesh() { var meshBuilder = new MeshBuilder(true, true); this.meshBuilders.Add(meshBuilder); this.materials.Add(PhongMaterials.Green); }
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.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); this.ModelMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)); //odelMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureNoise1_dot3.jpg", System.UriKind.RelativeOrAbsolute)); // ---------------------------------------------- // 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 = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)), NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)), }; }
static Cube() { var b1 = new MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1); geometry = b1.ToMeshGeometry3D(); }
/// <summary> /// Called when geometry has been changed. /// </summary> protected override void OnModelChanged() { var mb = new MeshBuilder(); var p0 = this.Offset; //new Vector3(0, 0, 0); if (this.InnerDiameter >= this.OuterDiameter) this.OuterDiameter = this.InnerDiameter + 0.3; var d = this.Axis; d.Normalize(); var p1 = p0 - (d * (float)this.Length * 0.5f); var p2 = p0 + (d * (float)this.Length * 0.5f); mb.AddPipe(p1, p2, this.InnerDiameter, this.OuterDiameter, 64); this.Geometry = mb.ToMeshGeometry3D(); }
/// <summary> /// Gets a unit sphere from the cache. /// </summary> /// <param name="subdivisions"> /// The number of subdivisions. /// </param> /// <returns> /// A unit sphere mesh. /// </returns> private static MeshGeometry3D GetUnitSphere(int subdivisions) { if (UnitSphereCache.ContainsKey(subdivisions)) { return UnitSphereCache[subdivisions]; } var mb = new MeshBuilder(false, false); mb.AddRegularIcosahedron(new Vector3(), 1, false); for (int i = 0; i < subdivisions; i++) { mb.SubdivideLinear(); } for (int i = 0; i < mb.positions.Count; i++) { var v = mb.positions[i]; v.Normalize(); mb.positions[i] = v; } var mesh = mb.ToMeshGeometry3D(); UnitSphereCache[subdivisions] = mesh; return mesh; }
/// <summary> /// Appends the specified mesh. /// </summary> /// <param name="mesh"> /// The mesh. /// </param> public void Append(MeshBuilder mesh) { if (mesh == null) { throw new ArgumentNullException("mesh"); } this.Append(mesh.positions, mesh.triangleIndices, mesh.normals, mesh.textureCoordinates); }
/// <summary> /// Called when geometry has been changed. /// </summary> protected override void OnModelChanged() { var mb = new MeshBuilder(); var p0 = this.Offset;// new Vector3(0, 0, 0); var d = this.Direction; d.Normalize(); var p1 = p0 + (d * (float)this.Length); mb.AddArrow(p0, p1, this.Diameter, 2, 64); this.Geometry = mb.ToMeshGeometry3D(); }
/// <summary> /// Creates a MeshGeometry3D object from the loaded file. Polygons are triangulated using triangle fans. /// </summary> /// <returns> /// A MeshGeometry3D. /// </returns> public MeshGeometry3D CreateMeshGeometry3D(ModelInfo info = default(ModelInfo)) { var mb = new MeshBuilder(info.Normals, info.Tangents); foreach (var p in this.Vertices) { mb.Positions.Add(p); } foreach (var face in this.Faces) { mb.AddTriangleFan(face); } mb.ComputeNormalsAndTangents(info.Faces); return mb.ToMeshGeometry3D(); }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); // 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) }; // default render technique this.RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; // 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(Vector3.UnitZ, -5, 5); this.GridColor = SharpDX.Color.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()); }
public override void Attach(IRenderHost host) { /// --- attach this.renderTechnique = host.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.CubeMap]; base.Attach(host); /// --- get variables this.vertexLayout = renderHost.EffectsManager.GetLayout(this.renderTechnique); this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name); this.effectTransforms = new EffectTransformVariables(this.effect); /// -- attach cube map if (this.Filename != null) { /// -- attach texture using (var texture = Texture2D.FromFile<Texture2D>(this.Device, this.Filename)) { this.texCubeMapView = new ShaderResourceView(this.Device, texture); } this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource(); this.texCubeMap.SetResource(this.texCubeMapView); this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar(); this.bHasCubeMap.Set(true); /// --- set up geometry var sphere = new MeshBuilder(false,true,false); sphere.AddSphere(new Vector3(0, 0, 0)); this.geometry = sphere.ToMeshGeometry3D(); /// --- set up vertex buffer this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex() { Position = new Vector4(x, 1f) }).ToArray()); /// --- set up index buffer this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.Array); /// --- set up rasterizer states var rasterStateDesc = new RasterizerStateDescription() { FillMode = FillMode.Solid, CullMode = CullMode.Back, IsMultisampleEnabled = true, IsAntialiasedLineEnabled = true, IsFrontCounterClockwise = false, }; this.rasterState = new RasterizerState(this.Device, rasterStateDesc); /// --- set up depth stencil state var depthStencilDesc = new DepthStencilStateDescription() { DepthComparison = Comparison.LessEqual, DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All, IsDepthEnabled = true, }; this.depthStencilState = new DepthStencilState(this.Device, depthStencilDesc); } /// --- flush this.Device.ImmediateContext.Flush(); }