示例#1
0
        private void SetupScene()
        {
            RenderTechnique = new RenderTechnique("RenderCustom");

            WhiteMaterial = new PhongMaterial
            {
                Name              = "White",
                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                DiffuseColor      = defaultMaterialColor,
                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                SpecularShininess = 12.8f,
            };

            SelectedMaterial = new PhongMaterial
            {
                Name              = "White",
                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                DiffuseColor      = defaultSelectionColor,
                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                SpecularShininess = 12.8f,
            };

            Model1Transform = new TranslateTransform3D(0, -0, 0);

            // camera setup
            Camera = new PerspectiveCamera();

            SetCameraData(new CameraData());

            DrawGrid();
        }
示例#2
0
        public MainWindow(String[] filepath)
        {
            InitializeComponent();

            Rect3D initView = new Rect3D(new Point3D(0, 0, 0), new Size3D(100, 100, 100));

            ResetCameraPosition(initView);
            LoadModel(".\\SetupParts\\articulator2.stl");
            LoadModel(".\\SetupParts\\calibratePart.stl");

            for (int i = 0; i != filepath.Length; ++i)
            {
                int isload = LoadModel(filepath[i]);
                if (isload == 0)
                {
                    MeshGeometryModel3D bones          = ModelGroup.Children[2 + i] as MeshGeometryModel3D;
                    PhongMaterial       bones_material = bones.Material as PhongMaterial;
                    bones_material.DiffuseColor = SharpDX.Color.Gray;
                }
                MessageBox.Show(filepath[i]);
                MessageBox.Show(isload.ToString());
            }


            MeshGeometryModel3D model = ModelGroup.Children[1] as MeshGeometryModel3D;
            PhongMaterial       m     = model.Material as PhongMaterial;

            m.DiffuseColor = SharpDX.Color.Red;
        }
        public static void Run()
        {
            // ExStart:Non_PBRtoPBRMaterial
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();
            // initialize a new 3D scene
            var s   = new Scene();
            var box = new Box();

            s.RootNode.CreateChildNode("box1", box).Material = new PhongMaterial()
            {
                DiffuseColor = new Vector3(1, 0, 1)
            };
            GLTFSaveOptions opt = new GLTFSaveOptions(FileFormat.GLTF2);

            //Custom material converter to convert PhongMaterial to PbrMaterial
            opt.MaterialConverter = delegate(Material material)
            {
                PhongMaterial m = (PhongMaterial)material;
                return(new PbrMaterial()
                {
                    Albedo = new Vector3(m.DiffuseColor.x, m.DiffuseColor.y, m.DiffuseColor.z)
                });
            };
            // save in GLTF 2.0 format
            s.Save(MyDir + "Non_PBRtoPBRMaterial_Out.gltf", opt);
            // ExEnd:Non_PBRtoPBRMaterial
        }
示例#4
0
        // INHERITED METHODS
        public override bool HitTest(Ray rayWS, ref List <HitTestResult> hits)
        {
            if (initMaterial == PhongMaterials.White)
            {
                initMaterial = this.phongMaterial;
            }
            var result = base.HitTest(rayWS, ref hits);

            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
                this.phongMaterial = result ? this.SelectionMaterial : this.PassiveMaterial;

                if (result)
                {
                    // test property changed event of HitControl
                    if (NrConseqHits > 0)
                    {
                        this.HitPointPrev = this.HitPoint;
                    }
                    this.HitPoint = hits[0].PointHit;
                    AdjustForSnap();
                    NrConseqHits++;
                    this.HitPointString = point3ToString();
                }
                else
                {
                    NrConseqHits        = 0;
                    this.HitPoint       = new System.Windows.Media.Media3D.Point3D();
                    this.HitPointPrev   = new System.Windows.Media.Media3D.Point3D();
                    this.HitPointString = "-";
                }
            }
            // ActionManager.RecordModifyCallback(this, new List<DependencyProperty> { HitPointProperty, HitPointPrevProperty, NrConseqHitsProperty });
            return(result);
        }
 public static void AssignTo(this PhongMaterial material, PhongMaterial targetMaterial)
 {
     targetMaterial.AmbientColor                  = material.AmbientColor;
     targetMaterial.DiffuseAlphaMap               = material.DiffuseAlphaMap;
     targetMaterial.DiffuseColor                  = material.DiffuseColor;
     targetMaterial.DiffuseMap                    = material.DiffuseMap;
     targetMaterial.DiffuseMapSampler             = material.DiffuseMapSampler;
     targetMaterial.DisplacementMap               = material.DisplacementMap;
     targetMaterial.DisplacementMapSampler        = material.DisplacementMapSampler;
     targetMaterial.DisplacementMapScaleMask      = material.DisplacementMapScaleMask;
     targetMaterial.EmissiveColor                 = material.EmissiveColor;
     targetMaterial.EnableTessellation            = material.EnableTessellation;
     targetMaterial.MaxTessellationDistance       = material.MaxTessellationDistance;
     targetMaterial.MaxDistanceTessellationFactor = material.MaxDistanceTessellationFactor;
     targetMaterial.MinTessellationDistance       = material.MinTessellationDistance;
     targetMaterial.MinDistanceTessellationFactor = material.MinDistanceTessellationFactor;
     targetMaterial.NormalMap              = material.NormalMap;
     targetMaterial.EmissiveMap            = material.EmissiveMap;
     targetMaterial.SpecularColorMap       = material.SpecularColorMap;
     targetMaterial.ReflectiveColor        = material.ReflectiveColor;
     targetMaterial.SpecularColor          = material.SpecularColor;
     targetMaterial.SpecularShininess      = material.SpecularShininess;
     targetMaterial.RenderDiffuseAlphaMap  = material.RenderDiffuseAlphaMap;
     targetMaterial.RenderDiffuseMap       = material.RenderDiffuseMap;
     targetMaterial.RenderDisplacementMap  = material.RenderDisplacementMap;
     targetMaterial.RenderNormalMap        = material.RenderNormalMap;
     targetMaterial.RenderSpecularColorMap = material.RenderSpecularColorMap;
     targetMaterial.RenderEmissiveMap      = material.RenderEmissiveMap;
     targetMaterial.EnableAutoTangent      = material.EnableAutoTangent;
     targetMaterial.UVTransform            = material.UVTransform;
 }
示例#6
0
 /// <summary>
 /// Makes the model visual3 d.
 /// </summary>
 /// <param name="ts">The ts.</param>
 /// <returns>Visual3D.</returns>
 private static MeshGeometryModel3D MakeModelVisual3D(TessellatedSolid ts)
 {
     var defaultMaterial = new PhongMaterial()
     {
         DiffuseColor = new SharpDX.Color4(
             ts.SolidColor.Rf, ts.SolidColor.Gf, ts.SolidColor.Bf, ts.SolidColor.Af)
     };
     //if (ts.HasUniformColor)
     {
         var positions =
             ts.Faces.SelectMany(
                 f => f.Vertices.Select(v =>
                                        new Vector3((float)v.Coordinates[0], (float)v.Coordinates[1], (float)v.Coordinates[2])));
         var normals =
             ts.Faces.SelectMany(f =>
                                 f.Vertices.Select(v =>
                                                   new Vector3((float)f.Normal[0], (float)f.Normal[1], (float)f.Normal[2])));
         return(new MeshGeometryModel3D
         {
             Geometry = new MeshGeometry3D
             {
                 Positions = new Vector3Collection(positions),
                 // TriangleIndices = new Int32Collection(triIndices),
                 Normals = new Vector3Collection(normals)
             },
             Material = defaultMaterial
         });
     }
 }
        static OcTreeManager()
        {
            LineBuilder b = new LineBuilder();

            b.AddBox(Vector3.Zero, 1, 1, 1);
            CellFrame = b.ToLineGeometry3D();

            EndPoint = LinesCutom.GetEndPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT * 0.8f);
            MidPoint = LinesCutom.GetMidPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT);
            IntPoint = LinesCutom.GetIntersectionMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT);

            ChamferedBoxMesh = MeshesCustom.GetChamferedBox(Vector3.Zero, 1f, 1f, 1f, 0.2f, 0.05f);
            MeshesCustom.CompressMesh(ref ChamferedBoxMesh);

            ChamferedBoxMesh_Normals = MeshesCustom.GetVertexNormalsAsLines(ChamferedBoxMesh, 0.15f);

            RedTransparent = new PhongMaterial();
            RedTransparent.DiffuseColor      = new Color4(0.8f, 0f, 0f, 0.25f);
            RedTransparent.AmbientColor      = new Color4(0.6f, 0f, 0f, 1f);
            RedTransparent.SpecularColor     = new Color4(1f, 0.75f, 0f, 1f);
            RedTransparent.SpecularShininess = 1;

            YellowTransparent = new PhongMaterial();
            YellowTransparent.DiffuseColor      = new Color4(1f, 0.93f, 0f, 0.5f);
            YellowTransparent.AmbientColor      = new Color4(0.92f, 0.69f, 0f, 1f);
            YellowTransparent.SpecularColor     = new Color4(1f, 1f, 1f, 1f);
            YellowTransparent.SpecularShininess = 3;
        }
示例#8
0
        public void Shade_WithRayCastOnInnerSphere_ExpectCorrectColor()
        {
            //arrange
            var outerMaterial = new PhongMaterial(new Color(0.8, 1.0, 0.6), ambience: 1.0, diffusion: 0.7, specularity: 0.2);
            var innerMaterial = new PhongMaterial(ambience: 1.0);
            var surfaces      = new[]
            {
                Scene.Default
                .Surfaces
                .First()
                .WithMaterial(outerMaterial),
                Scene.Default
                .Surfaces
                .Skip(1)
                .First()
                .WithMaterial(innerMaterial)
            };
            var scene = new Scene(surfaces, Scene.Default.LightSources);
            var ray   = new Ray(new Point3D(0, 0, 0.75), new Vector3D(0, 0, -1));

            //act
            var color = scene.Shade(ray);

            //assert
            Assert.AreEqual(innerMaterial.Color, color);
        }
        public MainViewModel()
        {
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];
            // ----------------------------------------------
            // titles
            this.Title    = "SwapChain Top Surface Rendering Demo";
            this.SubTitle = "WPF & SharpDX";

            // ----------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera
            {
                Position      = new Point3D(20, 20, 20),
                LookDirection = new Vector3D(-20, -20, -20),
                UpDirection   = new Vector3D(0, 1, 0)
            };
            // ----------------------------------------------
            // setup scene

            this.Light1Color = Colors.White;


            var builder = new MeshBuilder(true, false, false);

            builder.AddBox(new Vector3(), 40, 0.1, 40);
            Plane1Model = FloorModel = builder.ToMeshGeometry3D();

            builder = new MeshBuilder(true, false, false);
            builder.AddBox(new Vector3(), 0.1, 40, 40);
            Plane2Model = builder.ToMeshGeometry3D();

            FloorMaterial = new PhongMaterial();
            FloorMaterial.DiffuseColor    = new Color4(1f, 1f, 1f, 0.2f);
            FloorMaterial.AmbientColor    = new Color4(0, 0, 0, 0);
            FloorMaterial.ReflectiveColor = new Color4(0, 0, 0, 0);
            FloorMaterial.SpecularColor   = new Color4(0, 0, 0, 0);

            PlaneMaterial = new PhongMaterial()
            {
                DiffuseColor = new Color4(0.1f, 0.1f, 0.8f, 0.2f)
            };

            var landerItems = Load3ds("Car.3ds").Select(x => x.Geometry as MeshGeometry3D).ToArray();

            Model = MeshGeometry3D.Merge(landerItems);
            Model.UpdateOctree();
            ModelMaterial = PhongMaterials.Bronze;
            var transGroup = new Media3D.Transform3DGroup();

            transGroup.Children.Add(new Media3D.ScaleTransform3D(0.01, 0.01, 0.01));
            transGroup.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Media3D.Vector3D(1, 0, 0), -90)));
            transGroup.Children.Add(new Media3D.TranslateTransform3D(new Media3D.Vector3D(0, 6, 0)));

            ModelTransform = transGroup;

            Plane1Transform = new TranslateTransform3D(new Vector3D(0, 15, 0));
            Plane2Transform = new TranslateTransform3D(new Vector3D(15, 0, 0));
        }
示例#10
0
        public static void AddSphere(Vector3 position, double radius, PhongMaterial color, Viewport3DX viewport)
        {
            var m = GetSphere(position, radius, color);

            m.Attach(viewport.RenderHost);

            viewport.Items.Add(m);
        }
示例#11
0
        public static IMaterial IceMaterial()
        {
            var pm = new PhongMaterial(new double[] { 0.5, 0.9, 1.0 }, 0.05, 0.2, 0.2, 4, 0.0);

            pm.n  = 1.01;
            pm.Kt = 1.18;
            return(pm);
        }
示例#12
0
        public Selector()
        {
            PhongMaterial mtl = new PhongMaterial();

            Hilite          = new Appearance();
            mtl.Diffuse     = new Col4(0.6f, 0.8f, 0.1f);
            Hilite.Material = mtl;
            Hilite.Name     = "selector.hilite";
        }
        public static void Run()
        {
            // ExStart:AddMaterialToCube                      
            // Initialize scene object
            Scene scene = new Scene();
            
            // Initialize cube node object
            Node cubeNode = new Node("cube");

            // Call Common class create mesh using polygon builder method to set mesh instance 
            Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); 
         
            // Point node to the mesh
            cubeNode.Entity = mesh;
            
            // Add cube to the scene
            scene.RootNode.ChildNodes.Add(cubeNode);
            
            // Initiallize PhongMaterial object
            PhongMaterial mat = new PhongMaterial();
            
            // Initiallize Texture object
            Texture diffuse = new Texture();
            
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();
            
            // Set local file path
            diffuse.FileName = MyDir + "surface.dds";

            // Set Texture of the material
            mat.SetTexture("DiffuseColor", diffuse);

            // Embed raw content data to FBX (only for FBX and optional)
            // Set file name
            diffuse.FileName = "embedded-texture.png";
            // Set binary content
            diffuse.Content = File.ReadAllBytes(MyDir + "aspose-logo.jpg");

            // Set color
            mat.SpecularColor = new Vector3(Color.Red);

            // Set brightness
            mat.Shininess = 100;

            // Set material property of the cube object
            cubeNode.Material = mat;
            
            MyDir = MyDir + RunExamples.GetOutputFilePath("MaterialToCube.fbx");

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);
            // ExEnd:AddMaterialToCube

            Console.WriteLine("\nMaterial added successfully to cube.\nFile saved at " + MyDir);

        }
示例#14
0
        public static void Run()
        {
            //ExStart:AddMaterialToCube
            // Initialize scene object
            Scene scene = new Scene();

            // Initialize cube node object
            Node cubeNode = new Node("cube");

            // Call Common class create mesh using polygon builder method to set mesh instance
            Mesh mesh = Common.CreateMeshUsingPolygonBuilder();

            // Point node to the mesh
            cubeNode.Entity = mesh;

            // Add cube to the scene
            scene.RootNode.ChildNodes.Add(cubeNode);

            // Initiallize PhongMaterial object
            PhongMaterial mat = new PhongMaterial();

            // Initiallize Texture object
            Texture diffuse = new Texture();

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();

            // Set local file path
            diffuse.FileName = MyDir + "surface.dds";

            // Set Texture of the material
            mat.SetTexture("DiffuseColor", diffuse);

            // embed raw content data to FBX (only for FBX and optional)
            // set file name
            diffuse.FileName = "embedded-texture.png";
            // set binary content
            diffuse.Content = File.ReadAllBytes(MyDir + "aspose-logo.jpg");

            // Set color
            mat.SpecularColor = new Vector3(Color.Red);

            // Set brightness
            mat.Shininess = 100;

            // Set material property of the cube object
            cubeNode.Material = mat;

            MyDir = MyDir + RunExamples.GetOutputFilePath("MaterialToCube.fbx");

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);
            //ExEnd:AddMaterialToCube

            Console.WriteLine("\nMaterial added successfully to cube.\nFile saved at " + MyDir);
        }
 public void Chapter_XIV_b()
 {
     var floor = new PhongMaterial(Util.FromHex("#222831"))
     {
         Reflectivity = .9f, Specular = .5f, Shininess = 300
     };
     var p = new Plane(Translation(0, -.25f, 0))
     {
         Material = floor
     };
 private void GenerateBorder()
 {
     borderMesh = new MeshBuilder();
     GenerateBorderPositions();
     GenerateBorderTriangleIndices();
     GenerateBorderUVCoordinates();
     TerrainMeshBorderGeometry3D = borderMesh.ToMeshGeometry3D();
     TerrainMeshBorderMaterial   = new PhongMaterial();
     TerrainMeshBorderMaterial.RenderDiffuseMap = true;
 }
示例#17
0
        private void SetupScene()
        {
            var ptColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["PointColor"];

            defaultPointColor = new Color4(ptColor.R / 255.0f, ptColor.G / 255.0f, ptColor.B / 255.0f, ptColor.A / 255.0f);

            var lineColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["EdgeColor"];

            defaultLineColor = new Color4(lineColor.R / 255.0f, lineColor.G / 255.0f, lineColor.B / 255.0f, lineColor.A / 255.0f);

            directionalLightColor     = new Color4(0.9f, 0.9f, 0.9f, 1.0f);
            directionalLightDirection = new Vector3(-0.5f, -1.0f, 0.0f);

            var matColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["MaterialColor"];

            materialColor = new Color4(matColor.R / 255.0f, matColor.G / 255.0f, matColor.B / 255.0f, matColor.A / 255.0f);

            RenderTechnique = Techniques.RenderDynamo;

            WhiteMaterial = new PhongMaterial
            {
                Name              = "White",
                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                DiffuseColor      = materialColor,
                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                SpecularShininess = 12.8f,
            };

            var selColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["SelectionColor"];

            selectionColor   = new Color4(selColor.R / 255.0f, selColor.G / 255.0f, selColor.B / 255.0f, selColor.A / 255.0f);
            SelectedMaterial = new PhongMaterial
            {
                Name              = "White",
                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                DiffuseColor      = selectionColor,
                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                SpecularShininess = 12.8f,
            };

            Model1Transform = new TranslateTransform3D(0, -0, 0);

            // camera setup
            Camera = new PerspectiveCamera
            {
                UpDirection      = new Vector3D(0, 1, 0),
                FarPlaneDistance = 10000000,
            };

            ResetCamera();

            DrawGrid();
        }
示例#18
0
        public static Material ToMaterial(this Color color)
        {
            var material = new PhongMaterial();

            material.AmbientColor      = new SharpDX.Color4(1.0f);
            material.DiffuseColor      = new SharpDX.Color4(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
            material.SpecularColor     = new SharpDX.Color4(1.0f);
            material.SpecularShininess = 100.0f;

            return(material);
        }
        public void Chapter_XI_b()
        {
            var floorMaterial = new PhongMaterial(Color.White)
            {
                IOR          = Constants.GlassIOR,
                Reflectivity = 1f
            };
            var skyMaterial = new PhongMaterial(Color.White)
            {
                Pattern = new RingPattern(Util.FromHex("#0092ca"), Util.FromHex("#00adb5"))
            };
            var sky = new Plane(Translation(0, 5, 0))
            {
                Material = skyMaterial
            };
            var floor = new Plane {
                Material = floorMaterial
            };

            var w = new World
            {
                Objects = new List <Entity> {
                    floor, sky
                }
            };

            for (var i = 0; i < 20; i++)
            {
                var rnd = new Random();
                var x   = (float)rnd.NextDouble();
                var y   = (float)rnd.NextDouble();
                var z   = (float)rnd.NextDouble();
                var col = new Color(x, y, z);
                var mat = new PhongMaterial(col)
                {
                    IOR = Constants.GlassIOR, Transparency = y, Reflectivity = x, Specular = z
                };
                var s = new Sphere(Translation((x * 10f) - 5f, y, z * 10f) * Scale(y))
                {
                    Material = mat
                };
                w.Objects.Add(s);
            }
            var l = PointLight.Default;

            l.Intensity *= 2f;
            w.Lights.Add(l);
            var cam = new Camera(20, 10, MathF.PI / 1.5f)
            {
                Transform = Camera.ViewTransform(Point(0f, 1f, -2f), Point(0f, 1f, 0f), Direction(0f, 1f, 0f))
            };

            cam.Render(w);
        }
        private void GenerateMain()
        {
            terrainMesh = new MeshBuilder();
            GenerateTerrainPositions();
            GenerateTerrainTriangleIndices();
            GenerateTerrainUVCoordinates();
            TerrainMeshMainGeometry3D = terrainMesh.ToMeshGeometry3D();
            TerrainMeshMainMaterial   = new PhongMaterial();

            TerrainMeshMainMaterial.RenderDiffuseMap = true;
            TerrainMeshTransform = new Media3D.TranslateTransform3D(0, 0, 0);
        }
示例#21
0
        /// <summary>
        /// 設定模型材質
        /// </summary>
        public void SetBoneMaterial()
        {
            PhongMaterial material = new PhongMaterial
            {
                ReflectiveColor   = SharpDX.Color.Black,
                AmbientColor      = new SharpDX.Color(0.0f, 0.0f, 0.0f, 1.0f),
                EmissiveColor     = SharpDX.Color.Black,
                SpecularColor     = new SharpDX.Color(90, 90, 90, 255),
                SpecularShininess = 60,
                DiffuseColor      = BoneDiffuseColor.ToColor4()
            };

            this.Material = material;
        }
示例#22
0
        public void SetModelMaterial(MeshGeometryModel3D model)
        {
            PhongMaterial material = new PhongMaterial
            {
                ReflectiveColor   = SharpDX.Color.Black,
                AmbientColor      = new SharpDX.Color(0.0f, 0.0f, 0.0f, 1.0f),
                EmissiveColor     = SharpDX.Color.Black,
                SpecularColor     = new SharpDX.Color(90, 90, 90, 255),
                SpecularShininess = 60,
                DiffuseColor      = SharpDX.Color.Blue
            };

            model.Material = material;
        }
示例#23
0
        private void BuildPlanes()
        {
            PlaneGeometry = new ObservableElement3DCollection();
            var builder = new MeshBuilder(true);

            builder.AddBox(new SharpDX.Vector3(0, 0, 0), 15, 15, 0.5);
            var mesh = builder.ToMesh();

            var material = new PhongMaterial();

            material.DiffuseColor = new SharpDX.Color4(1, 0, 0, 0.5f);

            var model = new MeshGeometryModel3D()
            {
                Geometry      = mesh,
                Material      = material,
                Transform     = new Media3D.TranslateTransform3D(-15, 0, 0),
                IsTransparent = true,
                CullMode      = SharpDX.Direct3D11.CullMode.Back
            };

            PlaneGeometry.Add(model);

            material = new PhongMaterial();
            material.DiffuseColor = new SharpDX.Color4(0, 1, 0, 0.5f);

            model = new MeshGeometryModel3D()
            {
                Geometry      = mesh,
                Material      = material,
                Transform     = new Media3D.TranslateTransform3D(-20, 5, -10),
                IsTransparent = true,
                CullMode      = SharpDX.Direct3D11.CullMode.Back
            };
            PlaneGeometry.Add(model);

            material = new PhongMaterial();
            material.DiffuseColor = new SharpDX.Color4(0, 0, 1, 0.5f);

            model = new MeshGeometryModel3D()
            {
                Geometry      = mesh,
                Material      = material,
                Transform     = new Media3D.TranslateTransform3D(-25, 10, -20),
                IsTransparent = true,
                CullMode      = SharpDX.Direct3D11.CullMode.Back
            };
            PlaneGeometry.Add(model);
        }
示例#24
0
        public MainViewModel()
        {
            // titles
            Title    = "Simple Demo";
            SubTitle = "WPF & SharpDX";

            // camera setup
            Camera = new PerspectiveCamera
            {
                Position         = new Point3D(3, 3, 5),
                LookDirection    = new Vector3D(-3, -3, -5),
                UpDirection      = new Vector3D(0, 1, 0),
                FarPlaneDistance = 5000000
            };

            // default render technique
            RenderTechniquesManager = new DefaultRenderTechniquesManager();
            RenderTechnique         = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn];
            EffectsManager          = new DefaultEffectsManager(RenderTechniquesManager);

            // setup lighting
            AmbientLightColor         = new Color4(1f, 1f, 1f, 1f);
            DirectionalLightColor     = Color.White;
            DirectionalLightDirection = new Vector3(-2, -5, -2);

            // scene model3d
            var b1 = new MeshBuilder();

            b1.AddSphere(new Vector3(0, 0, 0), 100000, 180, 90);

            var meshGeometry = b1.ToMeshGeometry3D();

            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            Model = meshGeometry;

            // model materials
            var uri   = new System.Uri(@"Earth4k.jpg", System.UriKind.RelativeOrAbsolute);
            var image = new FileStream(uri.ToString(), FileMode.Open);

            RedMaterial = new PhongMaterial
            {
                DiffuseColor    = Color.White,
                AmbientColor    = Color.Black,
                ReflectiveColor = Color.Black,
                EmissiveColor   = Color.Black,
                SpecularColor   = Color.Black,
                DiffuseAlphaMap = image,
            };
        }
示例#25
0
        private static void Main()
        {
            var origin       = new Point3D(0, 0, -5);
            var canvasSize   = 1000;
            var canvasDepth  = 10;
            var scale        = 7.0d / (double)canvasSize;
            var ambientColor = new Color(0.1, 0.1, 0.1);

            var rays = from x in Enumerable.Range(-canvasSize / 2, canvasSize)
                       from y in Enumerable.Range(-canvasSize / 2, canvasSize)
                       select(Index: (x, y), Ray: new Ray(origin, new Vector3D(x * scale, y * scale, canvasDepth, true)));

            var sphereColor    = Color.Magenta;
            var sphereMaterial = new PhongMaterial(sphereColor, 0.1, 0.9, 0.9, 200.0);
            var sphere         = new Sphere(Matrix.Shear(Dimension.X, Dimension.Y, 0.5), sphereMaterial);

            var lightPosition = new Point3D(-10, 10, -10);
            var lightColor    = Color.White;
            var lightSource   = new PointLightSource(lightPosition, lightColor);

            var hits = rays.AsParallel()
                       .Select(r => (r.Index, r.Ray, Hit: sphere.Intersect(r.Ray).GetNearestHit()));

            var canvas = new Canvas(canvasSize, canvasSize);

            foreach (var hit in hits)
            {
                var xPixel = hit.Index.x + (canvasSize / 2);
                var yPixel = -hit.Index.y + (canvasSize / 2);

                if (!hit.Hit.HasValue)
                {
                    canvas[xPixel, yPixel] = ambientColor;
                }
                else
                {
                    var surface      = hit.Hit.Value.Surface;
                    var point        = hit.Ray.GetPosition(hit.Hit.Value.Distance);
                    var normalVector = surface.GetNormal(point);
                    var eyeVector    = -hit.Ray.Direction;

                    canvas[xPixel, yPixel] = surface.Material.Illuminate(point, eyeVector, normalVector, lightSource);
                }
            }

            var filePath = $"C:\\temp\\RayVE\\SphereDrawing\\{DateTime.Now:yyyyMMdd_HHmmss}.ppm";

            File.WriteAllText(filePath, canvas.ToPPM(255));
        }
        public static void Run()
        {
            // Initialize scene object
            Scene scene = new Scene();

            // Initialize cube node object
            Node cubeNode = new Node("cube");

            // Call Common class create mesh method to set mesh instance
            Mesh mesh = Common.CreateMesh();

            // Point node to the mesh
            cubeNode.Entity = mesh;

            // Add cube to the scene
            scene.RootNode.ChildNodes.Add(cubeNode);

            // Initiallize PhongMaterial object
            PhongMaterial mat = new PhongMaterial();

            // Initiallize Texture object
            Texture diffuse = new Texture();

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_GeometryAndHierarchy();

            // Set local file path
            diffuse.FileName = MyDir + "surface.dds";

            // Set Texture of the material
            mat.SetTexture("DiffuseColor", diffuse);

            // Set color
            mat.SpecularColor = new Vector3(Color.Red);

            // Set brightness
            mat.Shininess = 100;

            // Set material property of the cube object
            cubeNode.Material = mat;

            MyDir = MyDir + "MaterialToCube.fbx";

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);

            Console.WriteLine("\nMaterial added successfully to cube.\nFile saved at " + MyDir);
        }
示例#27
0
        public static void Run()
        {
            // Initialize scene object
            Scene scene = new Scene();

            // Initialize cube node object
            Node cubeNode = new Node("cube");

            // Call Common class create mesh method to set mesh instance
            Mesh mesh = Common.CreateMesh();

            // Point node to the mesh
            cubeNode.Entity = mesh;

            // Add cube to the scene
            scene.RootNode.ChildNodes.Add(cubeNode);

            // Initiallize PhongMaterial object
            PhongMaterial mat = new PhongMaterial();

            // Initiallize Texture object
            Texture diffuse = new Texture();

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_GeometryAndHierarchy();

            // Set local file path
            diffuse.FileName = MyDir + "surface.dds";

            // Set Texture of the material
            mat.SetTexture("DiffuseColor", diffuse);

            // Set color
            mat.SpecularColor = new Vector3(Color.Red);

            // Set brightness
            mat.Shininess = 100;

            // Set material property of the cube object
            cubeNode.Material = mat;

            MyDir = MyDir + "MaterialToCube.fbx";

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);

            Console.WriteLine("\nMaterial added successfully to cube.\nFile saved at " + MyDir);
        }
示例#28
0
文件: Textures.cs 项目: Dersei/Aethra
        public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing)
        {
            var renderTarget = new Framebuffer(width, height);

            renderTarget.Clear(color);
            var camera           = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -10), Vector3.Forward, Vector3.Up);
            var objects          = new List <IHittable>();
            var circuitryTexture = Texture.LoadFrom(@"_Resources/Textures/circuitry-albedo.png").ToInfo(3);
            var sunTexture       = Texture.LoadFrom(@"_Resources/Textures/sun.png").ToInfo();
            var modelTexture     = Texture.LoadFrom(@"_Resources/Textures/texel_density.png").ToInfo();
            var crystalTexture   = Texture.LoadFrom(@"_Resources/Textures/crystal.png").ToInfo();

            var circuitryMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 0.5f,
                                                      circuitryTexture);
            var sunMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f,
                                                sunTexture);
            var modelMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f,
                                                  modelTexture);
            var crystalMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f,
                                                    crystalTexture);

            var circuitry = new Sphere(new Vector3(2.5f, -1, 0), 0.5f, circuitryMaterial);
            var sun       = new Sphere(new Vector3(2.5f, -2.5f, 0), 0.75f, sunMaterial);
            var model     = Model.LoadFromFile("_Resources/Models/lowpolytree_unwrap.obj", modelMaterial, 1, Vector3.Down);
            var crystal   = Model.LoadFromFile("_Resources/Models/crystal.obj", crystalMaterial, 3, Vector3.Left * 2);

            objects.Add(circuitry);
            objects.Add(sun);
            objects.Add(model);
            objects.Add(crystal);

            Scene = new Scene(objects, camera,
                              new List <Light>
            {
                new PointLight {
                    Position = new Vector3(1, 2f, 0), Color = FloatColor.White
                },
                new PointLight {
                    Position = new Vector3(-2, 2f, 0), Color = FloatColor.Red
                },
                new PointLight {
                    Position = new Vector3(-4, 2f, -3), Color = FloatColor.White
                },
                new PointLight {
                    Position = new Vector3(-2, -1f, 0), Color = FloatColor.Green
                },
            }, FloatColor.Black);
        }
示例#29
0
        /*
         * Make the shape for the Kinect depth camera output
         */
        protected Shape MakeCameraOutputShape(Camera cam, bool iscolor)
        {
            Shape         shape     = new Shape();
            Appearance    app       = new Appearance();
            PhongMaterial mtl       = new PhongMaterial(new Col4(1.0f, 1.0f, 1.0f, 0.7f));
            Sampler       sampler   = new Sampler();
            TriMesh       mesh      = new TriMesh("position float 3, normal float 3, texcoord float 2");
            Vec2          videosize = new Vec2(640, 480);
            Vec2          texsize   = new Vec2(1024, 512);
            Box3          vvol      = cam.ViewVol;
            Vec3          campos    = cam.Translation;
            float         camdist   = campos.Length;            // distance of camera from body
            float         backdist  = camdist + vvol.max.z / 6.0f;
            float         h         = backdist * vvol.Height / vvol.min.z;
            float         w         = h;

            backdist -= camdist;
            if (Kinect != null)
            {
                Texture tex = new Texture();
                sampler.Texture = tex;
                if (iscolor)
                {
                    tex.Name            = "magicmirror.kinect.colorimage";
                    Kinect.ColorTexture = tex;
                }
                else
                {
                    tex.Name            = "magicmirror.kinect.depthimage";
                    Kinect.DepthTexture = tex;
                }
            }
            sampler.Name = "diffuse";
            sampler.Set(Sampler.TEXTUREOP, Sampler.DIFFUSE);
            sampler.Set(Sampler.TEXCOORD, 0);
            app.Set(Appearance.CULLING, 1);
            app.Set(Appearance.LIGHTING, 1);
            app.Set(Appearance.TRANSPARENCY, 1);
            app.SetSampler(0, sampler);
            app.Material     = mtl;
            app.Name         = "cameraoutput";
            shape.Appearance = app;
            GeoUtil.Rect(mesh, h * videosize.x / videosize.y, h, videosize.x / texsize.x, videosize.y / texsize.y);
            shape.Geometry = mesh;
            shape.Name     = "magicmirror.kinect.camerashape";
            shape.Translate(0, h / 2, -backdist);
            return(shape);
        }
        static PolygonDisplay()
        {
            VolumeMat = new PhongMaterial();
            VolumeMat.DiffuseColor      = new Color4(1f, 1f, 1f, 0.8f);
            VolumeMat.AmbientColor      = new Color4(0.8f, 0.8f, 0.8f, 1f);
            VolumeMat.EmissiveColor     = new Color4(0.25f, 0.25f, 0.25f, 0f);
            VolumeMat.SpecularColor     = new Color4(1f, 1f, 1f, 1f);
            VolumeMat.SpecularShininess = 3;

            SubpolyColors = new List <Color>();
            SubpolyColors.Add(Color.Red);
            SubpolyColors.Add(Color.Blue);
            SubpolyColors.Add(Color.Orange);
            SubpolyColors.Add(Color.Violet);
            SubpolyColors.Add(Color.Yellow);
            SubpolyColors.Add(Color.Green);
        }
示例#31
0
        public SphereModel(Vector3 center, double radius, bool enableTransform = true)
            : base()
        {
            Center = center;
            Radius = radius;
            CreateModel();
            if (enableTransform)
            {
                CreateAnimatedTransform1(DynamicTransform, center.ToVector3D(), new Media3D.Vector3D(rnd.Next(-1, 1), rnd.Next(-1, 1), rnd.Next(-1, 1)), rnd.Next(10, 100));
            }
            var color = rnd.NextColor();

            Material = new PhongMaterial()
            {
                DiffuseColor = color.ToColor4()
            };
        }
示例#32
0
        public PhongMaterial SetMaterial(Color4 color)
        {
            HelixToolkit.Wpf.SharpDX.PhongMaterial material = new PhongMaterial();

            material.ReflectiveColor = SharpDX.Color.Black;
            float ambient = 0.0f;

            material.AmbientColor  = new SharpDX.Color(ambient, ambient, ambient, 1.0f);
            material.EmissiveColor = SharpDX.Color.Black; //這是自己發光的顏色
            int specular = 90;

            material.SpecularColor     = new SharpDX.Color(specular, specular, specular, 255);
            material.SpecularShininess = 60;
            material.DiffuseColor      = color;

            return(material);
        }