public static void Run()
        {
            try
            {
                // ExStart:Render3DModelImageFromCamera

                // Load scene from file
                Scene scene = new Scene(RunExamples.GetDataFilePath("camera.3ds"));
                // Create a camera at (10,10,10) and look at the origin point for rendering,
                // It must be attached to the scene before render
                Camera camera = new Camera();
                scene.RootNode.CreateChildNode("camera", camera);
                camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
                camera.LookAt = Vector3.Origin;

                // Specify the image render option
                ImageRenderOptions opt = new ImageRenderOptions();
                // Set the background color
                opt.BackgroundColor = Color.AliceBlue;
                // Tells renderer where the it can find textures
                opt.AssetDirectories.Add(RunExamples.GetDataDir() + "textures");
                // Turn on shadow
                opt.EnableShadows = true;
                // Render the scene in given camera's perspective into specified png file with size 1024x1024
                scene.Render(camera, RunExamples.GetOutputFilePath("Render3DModelImageFromCamera.png"), new Size(1024, 1024), ImageFormat.Png, opt);
                // ExEnd:Render3DModelImageFromCamera
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:Render3DModelImageFromCamera

                // Load scene from file
                Scene scene = new Scene();
                var   path  = RunExamples.GetDataFilePath("Aspose3D.obj");
                scene.Open(path);
                // Create a camera at (10,10,10) and look at the origin point for rendering,
                // It must be attached to the scene before render
                Camera cam = new Camera(ProjectionType.Perspective);
                cam.NearPlane = 1;
                cam.FarPlane  = 500;
                scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(170, 16, 130);
                cam.LookAt = new Vector3(28, 0, -30);


                //create three lights to illuminate the scene
                scene.RootNode.CreateChildNode(new Light()
                {
                    LightType           = LightType.Point,
                    ConstantAttenuation = 0.3,
                    Color = new Vector3(Color.White)
                }).Transform.Translation = new Vector3(30, 10, 10);
                scene.RootNode.CreateChildNode(new Light()
                {
                    LightType           = LightType.Directional,
                    ConstantAttenuation = 0.3,
                    Direction           = new Vector3(-0.3, -0.4, 0.3),
                    Color = new Vector3(Color.White)
                });
                scene.RootNode.CreateChildNode(new Light()
                {
                    LightType   = LightType.Spot,
                    CastShadows = true,
                    LookAt      = new Vector3(28, 10, -30),
                    Color       = new Vector3(Color.White)
                }).Transform.Translation = new Vector3(40, 10, 50);

                // Specify the image render option
                ImageRenderOptions opt = new ImageRenderOptions();
                // Set the background color
                opt.BackgroundColor = Color.AliceBlue;
                // Tells renderer where the it can find textures
                opt.AssetDirectories.Add(RunExamples.GetDataDir() + "textures");
                // Turn on shadow
                opt.EnableShadows = true;
                // Render the scene in given camera's perspective into specified png file with size 1024x1024
                scene.Render(cam, RunExamples.GetOutputFilePath("Render3DModelImageFromCamera.png"), new Size(1024, 1024), ImageFormat.Png, opt);
                // ExEnd:Render3DModelImageFromCamera
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:Render3DModelImageFromCamera
                // The path to the documents directory.
                string MyDir = RunExamples.GetDataDir();

                // Load scene from file
                Scene scene = new Scene(MyDir + "camera.3ds");
                // Create a camera at (10,10,10) and look at the origin point for rendering,
                // It must be attached to the scene before render
                Camera camera = new Camera();
                scene.RootNode.CreateChildNode("camera", camera);
                camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
                camera.LookAt = Vector3.Origin;

                // Specify the image render option
                ImageRenderOptions opt = new ImageRenderOptions();
                // Set the background color
                opt.BackgroundColor = Color.AliceBlue;
                // Tells renderer where the it can find textures
                opt.AssetDirectories.Add(MyDir + "textures");
                // Turn on shadow
                opt.EnableShadows = true;
                // Render the scene in given camera's perspective into specified png file with size 1024x1024
                scene.Render(camera, MyDir + "Render3DModelImageFromCamera_out.png", new Size(1024, 1024), ImageFormat.Png, opt);
                // ExEnd:Render3DModelImageFromCamera  
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            
        }
        public static void Run()
        {
            try
            {
                // ExStart:CastAndReceiveShadow
                // The path to the documents directory.
                string MyDir = RunExamples.GetDataDir();

                Scene scene = new Scene();
                Camera camera = new Camera();
                camera.NearPlane = 0.1;
                scene.RootNode.CreateChildNode("camera", camera);
                Light light;
                scene.RootNode.CreateChildNode("light", light = new Light()
                {
                    NearPlane = 0.1,
                    CastShadows = true,
                    Color = new Vector3(Color.White)
                }).Transform.Translation = new Vector3(9.4785, 5, 3.18);
                light.LookAt = Vector3.Origin;
                light.Falloff = 90;

                // Create a plane
                Node plane = scene.RootNode.CreateChildNode("plane", new Plane(20, 20));
                plane.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.DarkOrange) };
                plane.Transform.Translation = new Vector3(0, 0, 0);

                // Create a torus for casting shadows
                Mesh m = (new Torus("", 1, 0.4, 20, 20, Math.PI * 2)).ToMesh();
                Node torus = scene.RootNode.CreateChildNode("torus", m);
                torus.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.Cornsilk) };
                torus.Transform.Translation = new Vector3(2, 1, 1);

                { 
                    // Create a blue box don't cast shadows
                    m = (new Box()).ToMesh();
                    m.CastShadows = false;
                    Node box = scene.RootNode.CreateChildNode("box", m);
                    box.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.Blue) };
                    box.Transform.Translation = new Vector3(2, 1, -1);
                }
                {
                    // Create a red box that don't receive shadow but cast shadows
                    m = (new Box()).ToMesh();
                    m.ReceiveShadows = false;
                    Node box = scene.RootNode.CreateChildNode("box", m);
                    box.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.Red) };
                    box.Transform.Translation = new Vector3(-2, 1, 1);
                }
                camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
                camera.LookAt = Vector3.Origin;
                ImageRenderOptions opt = new ImageRenderOptions() { EnableShadows = true };
                scene.Render(camera, MyDir + "CastAndReceiveShadow_out.png", new Size(1024, 1024), ImageFormat.Png, opt);
                // ExEnd:CastAndReceiveShadow  
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


        }
Beispiel #5
0
        public static void Run()
        {
            try
            {
                // ExStart:CastAndReceiveShadow

                Scene  scene  = new Scene();
                Camera camera = new Camera();
                camera.NearPlane = 0.1;
                scene.RootNode.CreateChildNode("camera", camera);
                Light light;
                scene.RootNode.CreateChildNode("light", light = new Light()
                {
                    NearPlane   = 0.1,
                    CastShadows = true,
                    Color       = new Vector3(Color.White)
                }).Transform.Translation = new Vector3(9.4785, 5, 3.18);
                light.LookAt             = Vector3.Origin;
                light.Falloff            = 90;

                // Create a plane
                Node plane = scene.RootNode.CreateChildNode("plane", new Plane(20, 20));
                plane.Material = new PhongMaterial()
                {
                    DiffuseColor = new Vector3(Color.DarkOrange)
                };
                plane.Transform.Translation = new Vector3(0, 0, 0);

                // Create a torus for casting shadows
                Mesh m     = (new Torus("", 1, 0.4, 20, 20, Math.PI * 2)).ToMesh();
                Node torus = scene.RootNode.CreateChildNode("torus", m);
                torus.Material = new PhongMaterial()
                {
                    DiffuseColor = new Vector3(Color.Cornsilk)
                };
                torus.Transform.Translation = new Vector3(2, 1, 1);

                {
                    // Create a blue box don't cast shadows
                    m             = (new Box()).ToMesh();
                    m.CastShadows = false;
                    Node box = scene.RootNode.CreateChildNode("box", m);
                    box.Material = new PhongMaterial()
                    {
                        DiffuseColor = new Vector3(Color.Blue)
                    };
                    box.Transform.Translation = new Vector3(2, 1, -1);
                }
                {
                    // Create a red box that don't receive shadow but cast shadows
                    m = (new Box()).ToMesh();
                    m.ReceiveShadows = false;
                    Node box = scene.RootNode.CreateChildNode("box", m);
                    box.Material = new PhongMaterial()
                    {
                        DiffuseColor = new Vector3(Color.Red)
                    };
                    box.Transform.Translation = new Vector3(-2, 1, 1);
                }
                camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
                camera.LookAt = Vector3.Origin;
                ImageRenderOptions opt = new ImageRenderOptions()
                {
                    EnableShadows = true
                };
                scene.Render(camera, RunExamples.GetOutputFilePath("CastAndReceiveShadow_out.png"), new Size(1024, 1024), ImageFormat.Png, opt);
                // ExEnd:CastAndReceiveShadow
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }