コード例 #1
0
        public void InitWebcam(bool front_facing)
        {
            if (rawImage == null)
            {
                rawImage = GetComponent <RawImage>();
                if (rawImage != null)
                {
                    rawImage.texture = Texture2D.blackTexture;
                }
            }
            if (textureToShow == null)
            {
                textureToShow = new Texture2D(Constants.CAMERA_REQUESTED_WIDTH,
                                              Constants.CAMERA_REQUESTED_HEIGHT,
                                              TextureFormat.RGBA32,
                                              false);
                textureToShow.Apply();
            }
#if !UNITY_EDITOR
            PikkartARCore.CameraUpdateUnityTextureId_GL(textureToShow.GetNativeTexturePtr());
#endif

#if UNITY_EDITOR
            PikkartARCore.UpdateViewport((int)Constants.CAMERA_REQUESTED_WIDTH, (int)Constants.CAMERA_REQUESTED_HEIGHT, 0);
#endif

            DeviceOrientationChange.OnScreenDataChange += OnScreenDataChange;
            portraitScale = new Vector3(
                (float)Constants.CAMERA_REQUESTED_HEIGHT / (float)Constants.CAMERA_REQUESTED_WIDTH,
                (float)Constants.CAMERA_REQUESTED_HEIGHT / (float)Constants.CAMERA_REQUESTED_WIDTH,
                1.0f);

            data = null;

            imagePtr_send    = IntPtr.Zero;
            imagePtr_receive = Marshal.AllocHGlobal(Constants.CAMERA_REQUESTED_WIDTH * Constants.CAMERA_REQUESTED_HEIGHT * 4);

            webcamTexture = GetManagedWebCamTexture(front_facing);

            if (rawImage != null)
            {
                rawImage.texture = textureToShow;
            }
            initialized_manager = true;

            OnScreenDataChange(DeviceOrientationChange.GetUpdatedDeviceOrientation());
        }