public MainViewModel(Viewport3DX viewport, TreeView treeview) { // ---------------------------------------------- // titles this.Title = "Ifc Viewer"; this.SubTitle = "By LinJiarui"; // ---------------------------------------------- // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(8, 9, 7), LookDirection = new Vector3D(-5, -12, -5), UpDirection = new Vector3D(0, 0, 1) }; // ---------------------------------------------- // setup scene this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.RenderLight1 = true; this.RenderLight2 = false; this.RenderLight3 = false; 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, }; viewController = new ViewController(); Model = new Element3DCollection(); viewController.InitGraphics(viewport, Model, treeview); }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); // ---------------------------------------------- // titles this.Title = "SwapChain Top Surface Rendering Demo"; this.SubTitle = "WPF & SharpDX"; // ---------------------------------------------- // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(100, 100, 100), LookDirection = new Vector3D(-100, -100, -100), UpDirection = new Vector3D(0, 1, 0) }; // ---------------------------------------------- // setup scene this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.Light1Color = (Color4)Color.White; this.Light2Color = (Color4)Color.Red; this.Light3Color = (Color4)Color.LightYellow; this.Light4Color = (Color4)Color.LightBlue; this.Light2Attenuation = new Vector3(0.1f, 0.05f, 0.010f); this.Light3Attenuation = new Vector3(0.1f, 0.01f, 0.005f); this.Light4Attenuation = new Vector3(0.1f, 0.02f, 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), 36); this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-100, 50, 0), new Vector3D(0, 0, 1), 3); this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 50, 100), new Vector3D(0, 1, 0), 5); this.Light4Direction = new Vector3(0, -100, 0); this.Light4Transform = new TranslateTransform3D(-Light4Direction.ToVector3D()); this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction.ToVector3D(), new Vector3D(1, 0, 0), 48); // ---------------------------------------------- // light model3d var sphere = new MeshBuilder(); sphere.AddSphere(new Vector3(0, 0, 0), 4); Sphere = sphere.ToMeshGeometry3D(); this.LightModelMaterial = new PhongMaterial { AmbientColor = Color.Gray, DiffuseColor = Color.Gray, EmissiveColor = Color.Yellow, SpecularColor = Color.Black, }; var models = Load3ds("wall12.obj").Select(x => x.Geometry as MeshGeometry3D).ToArray(); Floor = models[0]; Floor.UpdateOctree(); 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 }; var landerItems = Load3ds("Car.3ds").Select(x => x.Geometry as MeshGeometry3D).ToArray(); Model = MeshGeometry3D.Merge(landerItems); Model.UpdateOctree(); ModelMaterial = PhongMaterials.BlackRubber; var transGroup = new Media3D.Transform3DGroup(); transGroup.Children.Add(new Media3D.ScaleTransform3D(0.04, 0.04, 0.04)); var rotateAnimation = new Rotation3DAnimation { RepeatBehavior = RepeatBehavior.Forever, By = new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 90), Duration = TimeSpan.FromSeconds(4), IsCumulative = true, }; var rotateTransform = new Media3D.RotateTransform3D(); transGroup.Children.Add(rotateTransform); rotateTransform.BeginAnimation(Media3D.RotateTransform3D.RotationProperty, rotateAnimation); transGroup.Children.Add(new Media3D.TranslateTransform3D(0, 60, 0)); ModelTransform = transGroup; NumberOfTriangles = Floor.Indices.Count / 3 + Model.Indices.Count / 3; NumberOfVertices = Floor.Positions.Count + Model.Positions.Count; }
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.NormalMap = LoadFileToMemory(new System.Uri(SelectedNormalTexture, System.UriKind.RelativeOrAbsolute).ToString()); // ---------------------------------------------- // 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 = LoadFileToMemory(new System.Uri(SelectedDiffuseTexture, System.UriKind.RelativeOrAbsolute).ToString()), NormalMap = ModelMaterial.NormalMap }; ModelMaterial.DiffuseMap = FloorMaterial.DiffuseMap; }