Example #1
0
		protected override async void Start()
		{
			base.Start();

			EnableGestureManipulation = true;
			EnableGestureTapped = true;

			Log.LogLevel = LogLevel.Warning;
			Log.LogMessage += l => { Debug.WriteLine(l.Level + ":  " + l.Message); };

			// Create a node for the Earth
			earthNode = Scene.CreateChild();
			earthNode.Position = new Vector3(0, 0, 1.5f);
			earthNode.SetScale(0.3f);

			DirectionalLight.Brightness = 1f;
			DirectionalLight.Node.SetDirection(new Vector3(-1, 0, 0.5f));

			var earth = earthNode.CreateComponent<Sphere>();
			earthMaterial = ResourceCache.GetMaterial("Materials/Earth.xml");
			earth.SetMaterial(earthMaterial);

			var moonNode = earthNode.CreateChild();
			moonNode.SetScale(0.27f);
			moonNode.Position = new Vector3(1.2f, 0, 0);
			var moon = moonNode.CreateComponent<Sphere>();
			moon.SetMaterial(ResourceCache.GetMaterial("Materials/Moon.xml"));

			// Run a few actions to spin the Earth, the Moon and the clouds.
			earthNode.RunActions(new RepeatForever(new RotateBy(duration: 1f, deltaAngleX: 0, deltaAngleY: -4, deltaAngleZ: 0)));
		}
Example #2
0
		protected override async void Start()
		{
			base.Start();
			clientConnection = new ClientConnection();
			clientConnection.Disconnected += ClientConnection_Disconnected;
			clientConnection.RegisterForRealtimeUpdate(GetCurrentPositionDto);
			clientConnection.RegisterFor<PointerPositionChangedDto>(OnClientPointerChanged);

			Zone.AmbientColor = new Color(0.3f, 0.3f, 0.3f);
			DirectionalLight.Brightness = 0.5f;

			environmentNode = Scene.CreateChild();
			EnableGestureTapped = true;

			cubeNode = environmentNode.CreateChild();
			cubeNode.SetScale(0.2f);
			cubeNode.Position = new Vector3(1000, 1000, 1000);
			var box = cubeNode.CreateComponent<Box>();
			box.Color = Color.White;

			var moveAction = new MoveBy(0.5f, new Vector3(0, 0.005f, 0));
			cubeNode.RunActions(new RepeatForever(new RotateBy(1f, 0, 120, 0)));
			cubeNode.RunActions(new RepeatForever(moveAction, moveAction.Reverse()));

			//material = Material.FromColor(Color.Gray); //-- debug mode
			material = Material.FromColor(Color.Transparent, true);

			await RegisterCortanaCommands(new Dictionary<string, Action> {
				{ "stop spatial mapping", StopSpatialMapping}
			});

			while (!await ConnectAsync()) { }
		}
Example #3
0
 public static Material FromImage(string image)
 {
     var cache = Application.Current.ResourceCache;
     var material = new Material();
     material.SetTexture(TextureUnit.Diffuse, cache.GetTexture2D(image));
     material.SetTechnique(0, CoreAssets.Techniques.Diff, 0, 0);
     return material;
 }
Example #4
0
 public static Material FromColor(Color color)
 {
     var material = new Material();
     var cache = Application.Current.ResourceCache;
     material.SetTechnique(0, color.A == 1 ? CoreAssets.Techniques.NoTexture : CoreAssets.Techniques.NoTextureAlpha, 1, 1);
     material.SetShaderParameter("MatDiffColor", color);
     return material;
 }
Example #5
0
		protected override void Start()
		{
			debugHud = new MonoDebugHud(this) { FpsOnly = true };
			debugHud.Show();

			scene = new Scene();
			scene.CreateComponent<Octree>();
			var zone = scene.CreateComponent<Zone>();
			zone.AmbientColor = new Color(0.5f, 0.5f, 0.5f);

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

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

			lightNode = scene.CreateChild();
			lightNode.Position = new Vector3(0, 3, 0);
			var light = lightNode.CreateComponent<Light>();
			light.LightType = LightType.Directional;
			light.Brightness = 0.6f;
			light.Range = 200;

			environmentNode = scene.CreateChild();
			environmentNode.SetScale(0.1f);

			humanNode = environmentNode.CreateChild();
			humanNode.Position = new Vector3(0, -1f, 0);
			humanNode.SetScale(1f);
			var model = humanNode.CreateComponent<StaticModel>();
			model.Model = ResourceCache.GetModel("Jack.mdl");

			material = Material.FromColor(new Color(72/255f, 99/255f, 142/255f));

			yaw = -65;
			pitch = 55;
			cameraNode.Position = new Vector3(0.6f, 1.3f, -0.4f);
			cameraNode.Rotation = new Quaternion(pitch, yaw, 0);

			lightNode.SetDirection(new Vector3(-1, -1f, 0));
			InitTouchInput();
			var pointer = scene.CreateComponent<CubePointer>();
			pointer.PositionChanged += Pointer_PositionChanged;
		}
Example #6
0
		protected override async void Start()
		{
			base.Start();
			environmentNode = Scene.CreateChild();

			// Allow tap gesture
			EnableGestureTapped = true;

			// Create a bucket
			bucketNode = Scene.CreateChild();
			bucketNode.SetScale(0.1f);

			// Create instructions
			textNode = bucketNode.CreateChild();
			var text3D = textNode.CreateComponent<Text3D>();
			text3D.HorizontalAlignment = HorizontalAlignment.Center;
			text3D.VerticalAlignment = VerticalAlignment.Top;
			text3D.ViewMask = 0x80000000; //hide from raycasts
			text3D.Text = "Place on a horizontal\n  surface and click";
			text3D.SetFont(CoreAssets.Fonts.AnonymousPro, 26);
			text3D.SetColor(Color.White);
			textNode.Translate(new Vector3(0, 3f, -0.5f));

			// Model and Physics for the bucket
			var bucketModel = bucketNode.CreateComponent<StaticModel>();
			bucketMaterial = Material.FromColor(validPositionColor);
			bucketModel.Model = ResourceCache.GetModel("Models/bucket.mdl");
			bucketModel.SetMaterial(bucketMaterial);
			bucketModel.ViewMask = 0x80000000; //hide from raycasts
			bucketNode.CreateComponent<RigidBody>();
			var shape = bucketNode.CreateComponent<CollisionShape>();
			shape.SetTriangleMesh(bucketModel.Model, 0, Vector3.One, Vector3.Zero, Quaternion.Identity);

			// Material for spatial surfaces
			spatialMaterial = new Material();
			spatialMaterial.SetTechnique(0, CoreAssets.Techniques.NoTextureUnlitVCol, 1, 1);

			// make sure 'spatialMapping' capabilaty is enabled in the app manifest.
			var spatialMappingAllowed = await StartSpatialMapping(new Vector3(50, 50, 10), 1200);
		}
Example #7
0
 public static Material SkyboxFromImages(
     string imagePositiveX,
     string imageNegativeX,
     string imagePositiveY,
     string imageNegativeY,
     string imagePositiveZ,
     string imageNegativeZ)
 {
     var cache = Application.Current.ResourceCache;
     var material = new Material();
     TextureCube cube = new TextureCube();
     cube.SetData(CubeMapFace.PositiveX, cache.GetFile(imagePositiveX, false));
     cube.SetData(CubeMapFace.NegativeX, cache.GetFile(imageNegativeX, false));
     cube.SetData(CubeMapFace.PositiveY, cache.GetFile(imagePositiveY, false));
     cube.SetData(CubeMapFace.NegativeY, cache.GetFile(imageNegativeY, false));
     cube.SetData(CubeMapFace.PositiveZ, cache.GetFile(imagePositiveZ, false));
     cube.SetData(CubeMapFace.NegativeZ, cache.GetFile(imageNegativeZ, false));
     material.SetTexture(TextureUnit.Diffuse, cube);
     material.SetTechnique(0, CoreAssets.Techniques.DiffSkybox, 0, 0);
     material.CullMode = CullMode.None;
     return material;
 }
Example #8
0
		void CreateVideoTexturePlaceholder(int width, int height)
		{
			cameraTexture = new Texture2D(this.Context);
			cameraTexture.SetNumLevels(1);
			cameraTexture.SetSize(width, height, Urho.Graphics.RGBFormat, TextureUsage.Dynamic);
			var material = new Material();
			material.SetTexture(TextureUnit.Diffuse, cameraTexture);
			material.SetTechnique(0, CoreAssets.Techniques.Diff, 0, 0);
			planeNode = scene.CreateChild();
			planeNode.Position = new Vector3(0, 0, 7);
			const float xScale = 5;
			planeNode.Scale = new Vector3(xScale, xScale * height / width, xScale);
			var planeModel = planeNode.CreateComponent<StaticModel>();
			planeModel.Model = CoreAssets.Models.Box;
			planeModel.SetMaterial(material);
		}
Example #9
0
		async Task<string> CaptureAndAnalyze(bool readText = false)
		{
			var imgFormat = ImageEncodingProperties.CreateJpeg();

			//NOTE: this is how you can save a frame to the CameraRoll folder:
			//var file = await KnownFolders.CameraRoll.CreateFileAsync($"MCS_Photo{DateTime.Now:HH-mm-ss}.jpg", CreationCollisionOption.GenerateUniqueName);
			//await mediaCapture.CapturePhotoToStorageFileAsync(imgFormat, file);
			//var stream = await file.OpenStreamForReadAsync();

			// Capture a frame and put it to MemoryStream
			var memoryStream = new MemoryStream();
			using (var ras = new InMemoryRandomAccessStream())
			{
				await mediaCapture.CapturePhotoToStreamAsync(imgFormat, ras);
				ras.Seek(0);
				using (var stream = ras.AsStreamForRead())
					stream.CopyTo(memoryStream);
			}

			var imageBytes = memoryStream.ToArray();
			memoryStream.Position = 0;

			if (withPreview)
			{
				InvokeOnMain(() =>
					{
						var image = new Image();
						image.Load(new Urho.MemoryBuffer(imageBytes));

						Node child = Scene.CreateChild();
						child.Position = LeftCamera.Node.WorldPosition + LeftCamera.Node.WorldDirection * 2f;
						child.LookAt(LeftCamera.Node.WorldPosition, Vector3.Up, TransformSpace.World);

						child.Scale = new Vector3(1f, image.Height / (float)image.Width, 0.1f) / 10;
						var texture = new Texture2D();
						texture.SetData(image, true);

						var material = new Material();
						material.SetTechnique(0, CoreAssets.Techniques.Diff, 0, 0);
						material.SetTexture(TextureUnit.Diffuse, texture);

						var box = child.CreateComponent<Box>();
						box.SetMaterial(material);

						child.RunActions(new EaseBounceOut(new ScaleBy(1f, 5)));
					});
			}
			
			try
			{
				var client = new VisionServiceClient(VisionApiKey);
				if (readText)
				{
					var ocrResult = await client.RecognizeTextAsync(memoryStream, detectOrientation: false);
					var words = ocrResult.Regions.SelectMany(region => region.Lines).SelectMany(line => line.Words).Select(word => word.Text);
					return "it says: " + string.Join(" ", words);
				}
				else
				{
					// just describe the picture, you can also use cleint.AnalyzeImageAsync method to get more info
					var result = await client.DescribeAsync(memoryStream);
					return result?.Description?.Captions?.FirstOrDefault()?.Text;
				}
			}
			catch (ClientException exc)
			{
				return exc?.Error?.Message ?? "Failed";
			}
			catch (Exception exc)
			{
				return "Failed";
			}
		}