コード例 #1
0
ファイル: Material.cs プロジェクト: Zamir7/urho
 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;
 }
コード例 #2
0
ファイル: Material.cs プロジェクト: Zamir7/urho
 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;
 }
コード例 #3
0
ファイル: UrhoApp.cs プロジェクト: cianmulville/urho-samples
		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);
		}
コード例 #4
0
ファイル: Program.cs プロジェクト: xamarin/urho-samples
		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";
			}
		}