void RefreshImage() { // create texture if (texture == null && isTracking) { TexWidth = Convert.ToInt32(Math.Pow(2.0, Math.Ceiling(Math.Log(ImageWidth) / Math.Log(2.0)))); TexHeight = Convert.ToInt32(Math.Pow(2.0, Math.Ceiling(Math.Log(ImageHeight) / Math.Log(2.0)))); texture = new Texture2D(TexWidth, TexHeight, TextureFormat.RGBA32, false); var cols = texture.GetPixels32(); for (var i = 0; i < cols.Length; i++) { cols[i] = Color.black; } texture.SetPixels32(cols); texture.Apply(false); } if (texture != null && isTracking && TrackerStatus != 0) { CameraViewMaterial.SetTexture("_MainTex", texture); if (SystemInfo.graphicsDeviceVersion.StartsWith("Metal")) { VisageTrackerNative._bindTextureMetal(texture.GetNativeTexturePtr()); } else { VisageTrackerNative._bindTexture((int)texture.GetNativeTexturePtr()); } } }
void RefreshImage() { // create texture if (texture == null && isTracking) { TexWidth = Convert.ToInt32(Math.Pow(2.0, Math.Ceiling(Math.Log(ImageWidth) / Math.Log(2.0)))); TexHeight = Convert.ToInt32(Math.Pow(2.0, Math.Ceiling(Math.Log(ImageHeight) / Math.Log(2.0)))); #if UNITY_ANDROID texture = new Texture2D(TexWidth, TexHeight, TextureFormat.RGB24, false); #else texture = new Texture2D(TexWidth, TexHeight, TextureFormat.RGBA32, false); #endif var cols = texture.GetPixels32(); for (var i = 0; i < cols.Length; i++) { cols[i] = UnityEngine.Color.black; } texture.SetPixels32(cols); texture.Apply(false); #if UNITY_STANDALONE_WIN // "pin" the pixel array in memory, so we can pass direct pointer to it's data to the plugin, // without costly marshaling of array of structures. texturePixels = texture.GetPixels32(0); texturePixelsHandle = GCHandle.Alloc(texturePixels, GCHandleType.Pinned); #endif } if (texture != null && isTracking && TrackerStatus != 0) { #if UNITY_STANDALONE_WIN CameraViewMaterial.SetTexture("_MainTex", texture); // send memory address of textures' pixel data to VisageTrackerUnityPlugin VisageTrackerNative._setFrameData(texturePixelsHandle.AddrOfPinnedObject()); texture.SetPixels32(texturePixels, 0); texture.Apply(); #elif UNITY_IPHONE || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_ANDROID CameraViewMaterial.SetTexture("_MainTex", texture); if (SystemInfo.graphicsDeviceVersion.StartsWith("Metal")) { VisageTrackerNative._bindTextureMetal(texture.GetNativeTexturePtr()); } else { VisageTrackerNative._bindTexture((int)texture.GetNativeTexturePtr()); } #endif } }
void RefreshImage() { #if (UNITY_IPHONE || UNITY_ANDROID) && UNITY_EDITOR return; #endif // create texture if (Frame == null && isTracking) { TexWidth = Convert.ToInt32(Math.Pow(2.0, Math.Ceiling(Math.Log(ImageWidth) / Math.Log(2.0)))); TexHeight = Convert.ToInt32(Math.Pow(2.0, Math.Ceiling(Math.Log(ImageHeight) / Math.Log(2.0)))); #if UNITY_ANDROID Frame = new Texture2D(TexWidth, TexHeight, TextureFormat.RGB24, false); #else Frame = new Texture2D(TexWidth, TexHeight, TextureFormat.RGBA32, false); #endif #if UNITY_STANDALONE_WIN // "pin" the pixel array in memory, so we can pass direct pointer to it's data to the plugin, // without costly marshaling of array of structures. texturePixels = ((Texture2D)Frame).GetPixels32(0); texturePixelsHandle = GCHandle.Alloc(texturePixels, GCHandleType.Pinned); #endif } if (Frame != null && isTracking) { #if UNITY_STANDALONE_WIN // send memory address of textures' pixel data to VisageTrackerUnityPlugin VisageTrackerNative._setFrameData(texturePixelsHandle.AddrOfPinnedObject()); ((Texture2D)Frame).SetPixels32(texturePixels, 0); ((Texture2D)Frame).Apply(); #elif UNITY_IPHONE || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_ANDROID if (SystemInfo.graphicsDeviceVersion.StartsWith("Metal")) { VisageTrackerNative._bindTextureMetal(Frame.GetNativeTexturePtr()); } else { VisageTrackerNative._bindTexture((int)Frame.GetNativeTexturePtr()); } #endif } }