Exemple #1
0
        protected override void Start()
        {
            // 3D scene with Octree
            Scene             = new Scene(Context);
            Octree            = Scene.CreateComponent <Octree>();
            RootNode          = Scene.CreateChild("RootNode");
            RootNode.Position = new Vector3(x: 0, y: 0, z: 8);

            LightNode = Scene.CreateChild("DirectionalLight");
            LightNode.SetDirection(new Vector3(0.5f, 0.0f, 0.8f));
            Light                   = LightNode.CreateComponent <Light>();
            Light.LightType         = LightType.Directional;
            Light.CastShadows       = true;
            Light.ShadowBias        = new BiasParameters(0.00025f, 0.5f);
            Light.ShadowCascade     = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);
            Light.SpecularIntensity = 0.5f;
            Light.Color             = new Color(1.2f, 1.2f, 1.2f);

            // Camera
            CameraNode = Scene.CreateChild(name: "Camera");
            Camera     = CameraNode.CreateComponent <Camera>();

            // Viewport
            Viewport = new Viewport(Context, Scene, Camera, null);
            Renderer.SetViewport(0, Viewport);
            Viewport.SetClearColor(Color.White);

            // Subscribe to Esc key:
            Input.SubscribeToKeyDown(args => { if (args.Key == Key.Esc)
                                               {
                                                   Exit();
                                               }
                                     });
        }
        protected override void Start()
        {
            // 3D scene with Octree
            Scene             = new Scene(Context);
            Octree            = Scene.CreateComponent <Octree>();
            Zone              = Scene.CreateComponent <Zone>();
            Zone.AmbientColor = new Color(0.6f, 0.6f, 0.6f);
            RootNode          = Scene.CreateChild("RootNode");
            RootNode.Position = new Vector3(x: 0, y: -2, z: 8);

            // Camera
            CameraNode          = Scene.CreateChild(name: "Camera");
            CameraNode.Rotation = new Quaternion(Pitch = 0, 0, 0);
            Camera = CameraNode.CreateComponent <Camera>();

            // Light
            LightNode          = CameraNode.CreateChild();
            LightNode.Position = new Vector3(-5, 10, 0);
            Light            = LightNode.CreateComponent <Light>();
            Light.Range      = 100;
            Light.Brightness = 0.5f;
            Light.LightType  = LightType.Point;

            // Viewport
            Viewport = new Viewport(Context, Scene, Camera, null);
            Renderer.SetViewport(0, Viewport);
            Viewport.SetClearColor(new Color(0.88f, 0.88f, 0.88f));

            if (Platform.IsMobile())
            {
                Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2);
            }
            else if (Platform != Platforms.UWP && Platform != Platforms.SharpReality)
            {
                ResourceCache.AutoReloadResources = true;
                Renderer.HDRRendering             = true;
                Viewport.RenderPath.Append(CoreAssets.PostProcess.BloomHDR);
                Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA3);
            }

#if DESKTOP
            Input.SubscribeToMouseWheel(args => CameraNode.Translate(-Vector3.UnitZ * 1f * args.Wheel * -1));
            Input.SetMouseVisible(true, true);
            Input.SubscribeToKeyDown(args => {
                if (args.Key == Key.Esc)
                {
                    Exit();
                }
            });
#endif
        }
Exemple #3
0
		protected override void Start()
		{
			// UI text 
			var helloText = new Text(Context);
			helloText.Value = "UrhoSharp face detection";
			helloText.HorizontalAlignment = Urho.Gui.HorizontalAlignment.Center;
			helloText.VerticalAlignment = Urho.Gui.VerticalAlignment.Top;
			helloText.SetColor(new Color(r: 0f, g: 0f, b: 1f));
			helloText.SetFont(font: CoreAssets.Fonts.AnonymousPro, size: 30);
			UI.Root.AddChild(helloText);

			// 3D scene with Octree
			scene = new Scene(Context);
			scene.CreateComponent<Octree>();

			// Mask
			maskNode = scene.CreateChild();
			maskNode.Position = new Vector3(x: 1, y: 0, z: 5);
			maskNode.Scale = new Vector3(1, 1, 1) / 3f;
			var leftEye = maskNode.CreateChild();
			var leftEyeModel = leftEye.CreateComponent<Urho.Shapes.Sphere>();
			var rightEye = maskNode.CreateChild();
			var rightEyeModel = rightEye.CreateComponent<Urho.Shapes.Sphere>();

			leftEye.Position = new Vector3(-0.6f, 0, 0);
			rightEye.Position = new Vector3(0.6f, 0, 0);

			leftEye.RunActions(new TintTo(1f, Randoms.Next(), Randoms.Next(), Randoms.Next()));
			rightEye.RunActions(new TintTo(1f, Randoms.Next(), Randoms.Next(), Randoms.Next()));

			// Light
			Node lightNode = scene.CreateChild();
			lightNode.Position = new Vector3(-2, 0, 0);
			var light = lightNode.CreateComponent<Light>();
			light.Range = 20;
			light.Brightness = 1f;

			// Camera
			Node cameraNode = scene.CreateChild();
			camera = cameraNode.CreateComponent<Camera>();

			// Viewport
			var vp = new Viewport(Context, scene, camera, null);
			Renderer.SetViewport(0, vp);
			vp.SetClearColor(Color.White);
		}