void WriteImageToTexture(Texture2D tex)
    {
        // NOTE: This method only works when unity is rendering with OpenGL ("unity.exe -force-opengl"). This is *much* faster
        // then Texture2D::SetPixels32 which we would have to use otherwise
        // NOTE: The native texture id needs a +1 if we are rendering to GUI
        if (openGl) {
            //Gl.glBindTexture(Gl.GL_TEXTURE_2D, (null == target) ? tex.GetNativeTextureID() + 1 : tex.GetNativeTextureID());
            //Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, (int)inputSize.x, (int)inputSize.y, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, Image.ImageMapPtr);
            GL.BindTexture(GL.TEXTURE_2D, (null == target) ? tex.GetNativeTextureID() + 1 : tex.GetNativeTextureID());
            GL.TexSubImage2D(GL.TEXTURE_2D, 0, 0, 0, (int)inputSize.x, (int)inputSize.y, GL.RGB, GL.UNSIGNED_BYTE, Image.ImageMapPtr);
            return;
        }

        // The slow method: copy image map data to a manager buffer, and then create a Color32
        // for each pixel
        Marshal.Copy(Image.ImageMapPtr, rawImageMap, 0, rawImageMap.Length);
        int src = 0;
        int dst = 0;
        for (int row = 0; row < (int)inputSize.y; row++) {
            for (int col = 0; col < (int)inputSize.x; col++) {
                imageMapPixels[dst] = new Color32(rawImageMap[src], rawImageMap[src + 1], rawImageMap[src + 2], 255);
                src += 3;
                dst++;
            }
            dst += (int)(outputSize.x - inputSize.x);
        }

        tex.SetPixels32(imageMapPixels);
        tex.Apply();
    }
 void WriteImageToTexture(Texture2D tex, IntPtr p)
 {
     // NOTE: This method only works when unity is rendering with OpenGL ("unity.exe -force-opengl"). This is *much* faster
     // then Texture2D::SetPixels which we would have to use otherwise
     Gl.glBindTexture(Gl.GL_TEXTURE_2D, tex.GetNativeTextureID()+1);
     Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, tex.width, tex.height, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, p);
 }
예제 #3
0
    /// <summary>
    /// Create camera texture and set it to the camera plane
    /// </summary>
    /// <returns>
    /// true when texture is created, else false
    /// </returns>
    private bool createTexture()
    {
        // get required texture size
        int textureSize = metaioSDK.getCameraTextureSize();

        if (textureSize <= 0)
            return false;

        // Create the texture that will hold camera frames
        Debug.Log("Creating texture with size: "+textureSize);
        Texture2D texture = new Texture2D (textureSize, textureSize, TextureFormat.RGBA32, false);

        cameraPlane.renderer.material.mainTexture = texture;
        textureID = texture.GetNativeTextureID();

        Debug.Log("Texture ID: "+textureID);

        // determine scale of the camera plane
        float scale = metaioSDK.getCameraPlaneScale();

        Debug.Log("Camera plane scale: "+scale);

        cameraPlane.transform.localScale = new Vector3(-scale, scale, scale);

        return true;
    }
예제 #4
0
    private void createTexture(int frameWidth, int frameHeight)
    {
        // Determine texture size required to render camera image
        int textureSize = Math.Max(frameWidth, frameHeight);
        textureSize--;
        textureSize |= textureSize >> 1;
        textureSize |= textureSize >> 2;
        textureSize |= textureSize >> 4;
        textureSize |= textureSize >> 8;
        textureSize |= textureSize >> 16;
        textureSize++;

        Debug.Log("Creating texture with size: "+textureSize);

        // Create texture that will hold camera frames
        m_Texture = new Texture2D (textureSize, textureSize, TextureFormat.RGBA32, false);

        // Check component type again
        if (GetComponent(typeof(GUITexture)))
        {
            GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
            gui.transform.position = Vector3.zero;
            gui.transform.rotation = Quaternion.identity;

            // Set texture and retrieve texture ID for texture uploading
            gui.texture = m_Texture;
            textureID = m_Texture.GetNativeTextureID();
        }
        else
        {
            Debug.Log("Game object has no renderer or gui texture to assign the generated texture to!");
        }

        Debug.Log("Texture ID: "+textureID);
    }
예제 #5
0
    public void SetTexture(Material material)
    {
        videoTex = new Texture2D(1024, 1024, TextureFormat.BGRA32, false);
        material.mainTexture = videoTex;

        if (platformSupported) {
            int nativeID = videoTex.GetNativeTextureID();
            _setTexture(nativeID);
        }
    }
예제 #6
0
    /// <summary>
    /// Initializes the texture, and Initializes the plugin, which sets up the FBO
    /// </summary>
    static void Initialize()
    {
        _texture = new Texture2D(1,1,TextureFormat.ARGB32, false);
        _texture.SetPixel(0,0, Color.black);

        #if UNITY_IOS && !UNITY_EDITOR
        InitializeTexture(_texture.GetNativeTextureID());
        //Always call this after changing OpenGL values. Otherwise odd things happen
        GL.InvalidateState();
        #endif
    }
 public bool Load(Texture2D texture,string movieFileName)
 {
     uint textureId = (uint)texture.GetNativeTextureID();
     if( textureId == 0 ){ return false; }
     string dataPath = Application.dataPath;
     #if !UNITY_EDITOR && UNITY_STANDALONE_OSX
     dataPath += "/Data";
     #endif
     instanceId = _Load(movieFileName,textureId,dataPath);
     return ( instanceId != 0 );
 }
예제 #8
0
파일: VideoTexture.cs 프로젝트: pocdev/ar
	// Constructor. used to create a video texture
	public VideoTexture( string filename, int width, int height, bool shouldLoop = false, float startTime = 0, bool playAudio = false )
	{
		_instanceId = Prime31.Utils.randomString();
		
        // Create texture that will be updated in the plugin code
		texture = new Texture2D( width, height, TextureFormat.ARGB32, false );
    
        if( Application.platform == RuntimePlatform.IPhonePlayer )
			_arStartVideoTexturePlayback( _instanceId, filename, texture.GetNativeTextureID(), shouldLoop, startTime, playAudio );
		
		VideoTextureManager.registerInstance( _instanceId, this );
	}
예제 #9
0
    void Awake()
    {
        targetTexture = new Texture2D(textureSideWidth, textureSideWidth, textureFormat, false);
        targetTexture.wrapMode = textureWrapMode;

        if(targetMaterial && targetTexture) {
            defaultTexture = targetMaterial.mainTexture;

            Everyplay.FaceCamSetTargetTextureId(targetTexture.GetNativeTextureID());
            Everyplay.FaceCamSetTargetTextureWidth(textureSideWidth);
            Everyplay.FaceCamSetTargetTextureHeight(textureSideWidth);

            Everyplay.FaceCamSessionStarted += OnSessionStart;
            Everyplay.FaceCamSessionStopped += OnSessionStop;
        }
    }
예제 #10
0
    // Use this for initialization
    void Start()
    {
        tex = new Texture2D(640, 480, TextureFormat.RGB24, false);
        tex.wrapMode = TextureWrapMode.Clamp;
        renderer.sharedMaterial.mainTexture = tex;

        SetTexture(
            tex.GetNativeTextureID(),
            tex.width,
            tex.height,
            0
        );

        tStop = false;
        wfeof = new WaitForEndOfFrame();
        StartCoroutine(CodecJobAsync());
    }
예제 #11
0
    //Inicializa WebBroser
    public void Init(int width, int height)
    {
        this.width = width;
        this.height = height;
        m_texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
        m_TextureID = m_texture.GetNativeTextureID();

        if(m_bForceOpenGL && !Application.isEditor)
        {
            UnityWebCore.CreateView(m_TextureID, new System.IntPtr(0), width, height, false, 10);
        }
        else
        {
             //Get Color[] (pixels) from texture
            m_pixels = m_texture.GetPixels(0);
            // Create GCHandle - Allocation of m_pixels in memory.
            m_pixelsHandler = GCHandle.Alloc(m_pixels, GCHandleType.Pinned);

            UnityWebCore.CreateView(m_TextureID, m_pixelsHandler.AddrOfPinnedObject(), width, height, true, 10);
        }

        // assign m_texture to this GUITexture texture
        textureGui.renderer.material.mainTexture = m_texture;

        beginNavigationDelFunc = new UnityWebCore.BeginNavigationDelFunc(this.onBeginNavigationDelFunc);
        beginLoadingDelFunc = new UnityWebCore.BeginLoadingDelFunc(this.onBeginLoadingDelFunc);
        finishLoadingDelFunc = new UnityWebCore.FinishLoadingDelFunc(this.onFinishLoadingDelFunc);
        receiveTitleDelFunc = new UnityWebCore.ReceiveTitleDelFunc(this.onReceiveTitleDelFunc);
        changeTooltipDelFunc = new UnityWebCore.ChangeTooltipDelFunc(this.onChangeTooltipDelFunc);
        changeTargetURLDelFunc = new UnityWebCore.ChangeTargetURLDelFunc(this.onChangeTargetURLDelFunc);
        changeCursorDelFunc = new UnityWebCore.ChangeCursorDelFunc(this.onChangeCursorDelFunc);

        UnityWebCore.SetBeginNavigationFunc(m_TextureID, beginNavigationDelFunc);
        UnityWebCore.SetBeginLoadingFunc(m_TextureID, beginLoadingDelFunc);
        UnityWebCore.SetFinishLoadingFunc(m_TextureID, finishLoadingDelFunc);
        UnityWebCore.SetReceiveTitleFunc(m_TextureID, receiveTitleDelFunc);
        UnityWebCore.SetChangeTooltipFunc(m_TextureID, changeTooltipDelFunc);
        UnityWebCore.SetChangeTargetURLFunc(m_TextureID, changeTargetURLDelFunc);
        UnityWebCore.SetChangeCursorFunc(m_TextureID, changeCursorDelFunc);

        browserEventHandler.setDimensions(width, height);

        m_bInitialized = true;

        browserEventHandler.interactive = true;
    }
예제 #12
0
    // Returns list of looked up service hosts
    public static Texture2D GetPanoramaData(string localID)
    {
        // Call plugin only when running on real device
        if (Application.platform != RuntimePlatform.OSXEditor) {

            int width = _iOS_Gallery__GetPanoramaWidth (localID);
            int height = _iOS_Gallery__GetPanoramaHeight (localID);
            Texture2D tex = new Texture2D (width, height);

            _iOS_Gallery__PanoramaToTexture (localID, tex.GetNativeTextureID(), width, height );

            tex.Apply();

            return tex;
        }
        else {
            return Texture2D.blackTexture;
        }
    }
예제 #13
0
	// Starts the camera capture and returns a Texture2D that will have the camera output as it's content
    public static Texture2D startCameraCapture( bool useFrontCameraIfAvailable, LTCapturePreset capturePreset )
    {
		// force lower presets for devices that cant handle higher as a safety net
		if( useFrontCameraIfAvailable && capturePreset == LTCapturePreset.Size1280x720 )
			capturePreset = LTCapturePreset.Size640x480;
		
		if( iPhone.generation == iPhoneGeneration.iPhone3G )
			capturePreset = LTCapturePreset.Size192x144;

		var isMediumResDevice = ( iPhone.generation == iPhoneGeneration.iPad1Gen || iPhone.generation == iPhoneGeneration.iPhone3GS );
		if( capturePreset == LTCapturePreset.Size1280x720 && isMediumResDevice )
			capturePreset = LTCapturePreset.Size640x480;
		
    	int width = 0, height = 0;
		switch( capturePreset )
		{
			case LTCapturePreset.Size192x144:
				width = 192;
				height = 144;
				break;
			case LTCapturePreset.Size640x480:
				width = 640;
				height = 480;
				break;
			case LTCapturePreset.Size1280x720:
				width = 1280;
				height = 720;
				break;
		}

        // Create texture that will be updated in the plugin code
		Texture2D texture = new Texture2D( width, height, TextureFormat.ARGB32, false );
		
        if( Application.platform == RuntimePlatform.IPhonePlayer )
			_arStartCameraCapture( useFrontCameraIfAvailable, (int)capturePreset, texture.GetNativeTextureID() );
		
		return texture;
    }
예제 #14
0
 // Tells QCAR where the texture id to use for updating video
 // background data
 public override bool SetVideoBackgroundTexture(Texture2D texture)
 {
     if (QCARRuntimeUtilities.IsPlayMode())
     {
         VideoBackgroundForEmulator = texture;
         return true;
     }
     else
     {
         if (texture != null)
         {
             return QCARWrapper.Instance.RendererSetVideoBackgroundTextureID(texture.GetNativeTextureID()) != 0;
         }
         return true;
     }
 }
예제 #15
0
    public static void SetThumbnailTargetTexture(Texture2D texture)
    {
        if (EveryplayInstance != null)
        {
            currentThumbnailTargetTexture = texture;
#if !UNITY_3_5
            #if EVERYPLAY_IPHONE_ENABLED
            if (texture != null)
            {
                EveryplaySetThumbnailTargetTexture(currentThumbnailTargetTexture.GetNativeTexturePtr());
                EveryplaySetThumbnailTargetTextureWidth(currentThumbnailTargetTexture.width);
                EveryplaySetThumbnailTargetTextureHeight(currentThumbnailTargetTexture.height);
            }
            else
            {
                EveryplaySetThumbnailTargetTexture(System.IntPtr.Zero);
            }
            #elif EVERYPLAY_ANDROID_ENABLED
            if (texture != null)
            {
                EveryplaySetThumbnailTargetTextureId(currentThumbnailTargetTexture.GetNativeTextureID());
                EveryplaySetThumbnailTargetTextureWidth(currentThumbnailTargetTexture.width);
                EveryplaySetThumbnailTargetTextureHeight(currentThumbnailTargetTexture.height);
            }
            else
            {
                EveryplaySetThumbnailTargetTextureId(0);
            }
            #endif
#endif
        }
    }
예제 #16
0
    // Starts the camera capture and returns a Texture2D that will have the camera output as it's content
    public static Texture2D startCameraCapture( bool useFrontCameraIfAvailable, ARQuality quality )
    {
        // we need to figure out the actual size of the texture based on the device and camera
        // Preset	3G			3GS			4 back		4 front		iPad 2
        // High		400x304		640x480		1280x720	640x480		640x480
        // Medium	400x304		480x360		480x360		480x360		480x360
        // Low		400x306		192x144		192x144		192x144		192x144
        // 640x480	NA			640x480		640x480		640x480		640x480

        int width = 0, height = 0;
        bool useLowQuality = quality == ARQuality.Low;

        if( iPhoneSettings.generation == iPhoneGeneration.iPhone3G )
        {
            width = 400;
            height = useLowQuality ? 306 : 304;
        }
        else if( iPhoneSettings.generation == iPhoneGeneration.iPhone3GS )
        {
            width = useLowQuality ? 192 : 480;
            height = useLowQuality ? 144 : 360;
        }
        else if( iPhoneSettings.generation == iPhoneGeneration.iPhone4 || iPhoneSettings.generation == iPhoneGeneration.iPodTouch4Gen )
        {
            if( useFrontCameraIfAvailable )
            {
                width = useLowQuality ? 192 : 480;
                height = useLowQuality ? 144 : 360;
            }
            else
            {
                width = useLowQuality ? 192 : 480;
                height = useLowQuality ? 144 : 360;
            }
        }
        else if( iPhoneSettings.generation == iPhoneGeneration.Unknown && ( Screen.width == 1024 || Screen.height == 1024 ) ) // ghetto iPad 2 detection
        {
            if( useFrontCameraIfAvailable )
            {
                width = useLowQuality ? 192 : 480;
                height = useLowQuality ? 144 : 360;
            }
            else
            {
                width = useLowQuality ? 192 : 480;
                height = useLowQuality ? 144 : 360;
            }
        }
        else // fallback to catch unknown devices
        {
            if( useFrontCameraIfAvailable )
            {
                width = useLowQuality ? 192 : 480;
                height = useLowQuality ? 144 : 360;
            }
            else
            {
                width = useLowQuality ? 192 : 480;
                height = useLowQuality ? 144 : 360;
            }
        }

        // Create texture that will be updated in the plugin code
        Texture2D texture = new Texture2D( width, height, TextureFormat.ARGB32, false );

        if( Application.platform == RuntimePlatform.IPhonePlayer )
            _arStartCameraCapture( useFrontCameraIfAvailable, useLowQuality, texture.GetNativeTextureID() );

        return texture;
    }
예제 #17
0
        public TTFTextTexturePortion ComputeGlyphBitmap(object parameters, object font, char c)
        {
            SysFontTexture tex=new SysFontTexture();
            FontSelector fs=(FontSelector)GetFontSelectorFromFontName((string) font);
            tex.AndroidFontName=fs.AndroidFontName;
            tex.AppleFontName=fs.AppleFontName;
            tex.Update();

              Texture2D _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false);
              //Texture2D _texture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
              _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave;
              _texture.filterMode = FilterMode.Point;
              _texture.wrapMode = TextureWrapMode.Clamp;
               	 int textureID = _texture.GetNativeTextureID();

            SysFont.QueueTexture(""+c,
            #if UNITY_ANDROID
            fs.AndroidFontName
            #else
            #if UNITY_IPHONE
            fs.AppleFontName
            #else
            ((string)font)
            #endif
            #endif
            ,
            12,
            false,//_isBold,
            false,//_isItalic,
            SysFont.Alignment.Left,//_alignment,
            false,
            2048,
              		2048,
            textureID
            );

            int _textWidthPixels  = SysFont.GetTextWidth(textureID);
            int _textHeightPixels = SysFont.GetTextHeight(textureID);

            SysFont.UpdateQueuedTexture(textureID);
            Debug.Log(".");

            Parameters cp =parameters as Parameters;
            Material m=null;
            if (cp!=null) {
              Shader shader=Shader.Find(cp.shaderName);
              if (shader==null) {shader=Shader.Find("Mobile/Diffuse");}
             	  if (shader==null) {shader=Shader.Find("Diffuse");}
              m=new Material(shader);
              m.color=new Color(cp.red,cp.green,cp.blue,cp.alpha);
              m.mainTexture=_texture;
            }
            else {
              Shader shader=Shader.Find("SysFont/Unlit Transparent");
              if (shader==null) {shader=Shader.Find("Mobile/Diffuse");}
             	  if (shader==null) {shader=Shader.Find("Diffuse");}
              m=new Material(shader);
              m.color=Color.black;
              m.mainTexture=_texture;
            }

            TTFTextTexturePortion p=new TTFTextTexturePortion(
            m,
            0,0,1,1,
            _textWidthPixels * cp.scale,_textHeightPixels *cp.scale,
            0,0,
            true
            );

            return p;
        }
예제 #18
0
        public Vector3 GetAdvance(object parameters,object font, char c)
        {
            //return Vector3.zero;
            FontSelector fs =font as FontSelector;
            Parameters cp = parameters  as Parameters;
            if (cp.fixedWidth) {
            return new Vector3(1,0,0);
            }
            else {

              Texture2D _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false);
              _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave;
             	  _texture.filterMode = FilterMode.Point;
             	  _texture.wrapMode = TextureWrapMode.Clamp;
               		  int textureID = _texture.GetNativeTextureID();

               SysFont.QueueTexture(""+c,
            #if UNITY_ANDROID
            fs.AndroidFontName
            #else
            #if UNITY_IPHONE
            fs.AppleFontName
            #else
            ((string)font)
            #endif
            #endif
            ,
            12,
            false,//_isBold,
            false,//_isItalic,
            SysFont.Alignment.Left,//_alignment,
            false,
            2048,
              		2048,
            textureID
               );

            int _textWidthPixels  = SysFont.GetTextWidth(textureID);
            //    		int _textHeightPixels = SysFont.GetTextHeight(textureID);
            GameObject.Destroy(_texture);
            return new Vector3( _textWidthPixels * cp.scale,0,0);
            }
        }
예제 #19
0
    /// <summary>
    /// Create camera texture and set it to the camera plane
    /// </summary>
    /// <returns>
    /// true when texture is created, else false
    /// </returns>
    public bool createTexture(uint enforceSize)
    {
        uint requiredSize;
        if(enforceSize > 0)
            requiredSize = enforceSize;
        else
            requiredSize = MetaioSDKUnity.getRequiredTextureSize();

        if (requiredSize <= 0)
            return false;

        // Reuse old texture if required size didn't change
        if (textureCreated && currentTextureSize == requiredSize)
            return true;

        // Create the texture that will hold camera frames

        // Android and OSX
        TextureFormat textureFormat = TextureFormat.RGBA32;

        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            // iOS
            textureFormat = TextureFormat.BGRA32;
        }
        else if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
        {
            // Windows
            textureFormat = TextureFormat.RGB24;
        }

        Debug.Log("Creating texture with size " + requiredSize + " and format " + textureFormat);

        texture = new Texture2D((int)requiredSize, (int)requiredSize, textureFormat, false);

        if (texture == null)
            return false;

        currentTextureSize = requiredSize;

        cameraPlane.GetComponent<Renderer>().material.mainTexture = texture;
        textureID = texture.GetNativeTextureID();

        Debug.Log("Texture ID: "+textureID);

        return true;
    }
예제 #20
0
    // Starts
    public static Texture2D startVideoTexturePlayback( string filename, int width, int height, bool shouldLoop )
    {
        // Create texture that will be updated in the plugin code
        Texture2D texture = new Texture2D( width, height, TextureFormat.ARGB32, false );

        if( Application.platform == RuntimePlatform.IPhonePlayer )
            _arStartVideoTexturePlayback( filename, texture.GetNativeTextureID(), shouldLoop );

        return texture;
    }
예제 #21
0
    // Use this for initialization
    void Start()
    {
        // Use the main camera if one wasn't set in the Inspector
        if (m_Camera == null)
        {
            m_Camera = Camera.main;
        }

        // Ask the renderer to stop drawing the videobackground.
        QCARRenderer.Instance.DrawVideoBackground = false;

        // Create texture of size 0 that will be updated in the plugin (we allocate buffers in native code)
        mTexture = new Texture2D(0, 0, TextureFormat.RGB565, false);
        mTexture.filterMode = FilterMode.Bilinear;
        mTexture.wrapMode = TextureWrapMode.Clamp;

        // Assign texture to the renderer
        renderer.material.mainTexture = mTexture;

        // Set the native texture ID:
        int nativeTextureID = mTexture.GetNativeTextureID();
        if (!QCARRenderer.Instance.SetVideoBackgroundTextureID(nativeTextureID))
        {
            Debug.Log("Failed to setVideoBackgroundTextureID " + nativeTextureID);
        }
        else
        {
            Debug.Log("Successfully setVideoBackgroundTextureID " + nativeTextureID);
        }
    }
        /// <summary>
        /// Sets the callback for image updates.
        /// </summary>
        /// <param name="cameraId">Camera identifier.</param>
        public virtual void SetCallback(Tango.TangoEnums.TangoCameraId cameraId, bool useExperimentalOverlay, Texture2D videoOverlayTexture)
        {
            m_usingExperimentalOverlay = useExperimentalOverlay;
            if(!useExperimentalOverlay)
            {
                m_previousImageBuffer = new TangoUnityImageData();
                m_onImageAvailable = new Tango.VideoOverlayProvider.TangoService_onImageAvailable(_OnImageAvailable);
                Tango.VideoOverlayProvider.SetCallback(cameraId, m_onImageAvailable);
            }
            else
            {
                if(videoOverlayTexture != null)
                {
                    m_onUnityFrameAvailable = new Tango.VideoOverlayProvider.TangoService_onUnityFrameAvailable(_OnExperimentalUnityFrameAvailable);
                    VideoOverlayProvider.ExperimentalConnectTexture(cameraId,
                                                                    videoOverlayTexture.GetNativeTextureID(),
                                                                    m_onUnityFrameAvailable);

                    Debug.Log("VideoOverlayListener.SetCallback() : Experimental Overlay listener hooked up");
                }
                else
                {
                    Debug.Log("VideoOverlayListener.SetCallback() : No Texture2D found!");
                }
            }
        }
예제 #23
0
    public static void FaceCamSetTargetTexture(Texture2D texture)
    {
        if (EveryplayInstance != null && hasMethods == true)
        {
#if !UNITY_3_5
            #if EVERYPLAY_FACECAM_BINDINGS_ENABLED
            #if EVERYPLAY_IPHONE_ENABLED || EVERYPLAY_OSX_ENABLED
            if (texture != null)
            {
                EveryplayFaceCamSetTargetTexture(texture.GetNativeTexturePtr());
                EveryplayFaceCamSetTargetTextureWidth(texture.width);
                EveryplayFaceCamSetTargetTextureHeight(texture.height);
            }
            else
            {
                EveryplayFaceCamSetTargetTexture(System.IntPtr.Zero);
            }
            #elif EVERYPLAY_ANDROID_ENABLED
            if (texture != null)
            {
                EveryplayFaceCamSetTargetTextureId(texture.GetNativeTextureID());
                EveryplayFaceCamSetTargetTextureWidth(texture.width);
                EveryplayFaceCamSetTargetTextureHeight(texture.height);
            }
            else
            {
                EveryplayFaceCamSetTargetTextureId(0);
            }
            #endif
            #endif
#endif
        }
    }
    void InitializeTexture()
    {
        int videoWidth = PointCloudAdapter.pointcloud_get_video_width ();
        int videoHeight = PointCloudAdapter.pointcloud_get_video_height ();
        float videoCropX = PointCloudAdapter.pointcloud_get_video_crop_x ();
        float videoCropY = PointCloudAdapter.pointcloud_get_video_crop_y ();

        int bigDim = Mathf.Max (videoWidth, videoHeight);

        textureSize = GetPowerOfTwo (bigDim);
        textureSizeInv = 1.0f / textureSize;

        float cx = videoCropX / textureSize;
        float cy = videoCropY / textureSize;

        videoTexture = new Texture2D (textureSize, textureSize, TextureFormat.BGRA32, false);
        videoTextureID = videoTexture.GetNativeTextureID ();

        videoTextureCoordinates = new Rect (videoWidth * textureSizeInv - cx,
                                           cy,
                                           -videoWidth * textureSizeInv + 2 * cx,
                                           videoHeight * textureSizeInv - 2 * cy);
    }
    /// <summary>
    /// This creates an emtpy texture and passes its texture id to native so that the video background can be rendered into it.
    /// </summary>
    private void CreateAndSetVideoTexture()
    {
        // Create texture of size 0 that will be updated in the plugin (we allocate buffers in native code)
        mTexture = new Texture2D(0, 0, TextureFormat.RGB565, false);

        mTexture.filterMode = FilterMode.Bilinear;
        mTexture.wrapMode = TextureWrapMode.Clamp;

        // Assign texture to the renderer
        renderer.material.mainTexture = mTexture;

        // Set the texture to render into:
        if (!QCARRenderer.Instance.SetVideoBackgroundTexture(mTexture))
        {
            Debug.Log("Failed to setVideoBackgroundTexture " + mTexture.GetNativeTextureID());
        }
        else
        {
            Debug.Log("Successfully setVideoBackgroundTexture " + +mTexture.GetNativeTextureID());
        }
    }
예제 #26
0
 public static void FaceCamSetTargetTexture(Texture2D texture)
 {
     if(EveryplayInstance != null) {
     #if !UNITY_3_5
         #if !UNITY_EDITOR
         #if UNITY_IPHONE && EVERYPLAY_IPHONE
         if(texture != null) {
             EveryplayFaceCamSetTargetTexture(texture.GetNativeTexturePtr());
             EveryplayFaceCamSetTargetTextureWidth(texture.width);
             EveryplayFaceCamSetTargetTextureHeight(texture.height);
         }
         else {
             EveryplayFaceCamSetTargetTexture(System.IntPtr.Zero);
         }
         #elif UNITY_ANDROID && EVERYPLAY_ANDROID
         if(texture != null) {
             EveryplayFaceCamSetTargetTextureId(texture.GetNativeTextureID());
             EveryplayFaceCamSetTargetTextureWidth(texture.width);
             EveryplayFaceCamSetTargetTextureHeight(texture.height);
         }
         else {
             EveryplayFaceCamSetTargetTextureId(0);
         }
         #endif
         #endif
     #endif
     }
 }