public void SetUp() { VLog.log(VLog.LEVEL_INFO, "VideoFormater Awake"); if (leftSide != null) { leftSideMeshFilter = leftSide.GetComponent <MeshFilter>(); leftSideMeshRenderer = leftSide.GetComponent <MeshRenderer>(); } if (rightSide != null) { rightSideMeshFilter = rightSide.GetComponent <MeshFilter>(); rightSideMeshRenderer = rightSide.GetComponent <MeshRenderer>(); } if (leftSide != null) { leftSide.GetComponent <MeshRenderer>().material.shader = Shader.Find("VRVIU/Unlit_SphereInside"); } if (rightSide != null) { rightSide.GetComponent <MeshRenderer>().material.shader = Shader.Find("VRVIU/Unlit_SphereInside"); } BindPlayer(); UnityEngine.XR.InputTracking.Recenter(); // Get left eye camera component GameObject cameraObject = GameObject.Find(LEFT_EYE_CAMERA_NAME); if (cameraObject != null) { leftEyeCameraObject = cameraObject; leftEyeCamera = cameraObject.GetComponent <Camera>(); } // Get right eye camera component cameraObject = GameObject.Find(RIGHT_EYE_CAMERA_NAME); if (cameraObject != null) { rightEyeCameraObject = cameraObject; rightEyeCamera = cameraObject.GetComponent <Camera>(); } if (leftEyeCamera == null || rightEyeCamera == null) { VLog.log(VLog.LEVEL_WARN, "Missing left or right eye camera in your scene, which will cause stereo unavailable."); } }
//------------------------------------------------------------------------- // Load new mesh and bind to target materials private Mesh loadMesh(string meshURL) { // Try to load the mesh as a resource, we will have a copy in the Resource/Meshes folder. // To do this, we only need the 'filename' component of the mesh name. Mesh newMesh = null; string[] parts = meshURL.Split('/'); if (parts.Length > 0) { string meshName; string[] meshFullName = parts[parts.Length - 1].Split('.'); meshName = "Meshes/" + meshFullName[0]; newMesh = Resources.Load(meshName, typeof(Mesh)) as Mesh; if (newMesh != null) { VLog.log(VLog.LEVEL_DEBUG, "Loaded mesh from internal resource " + meshName); } } // If we can't load a built-in resource, then we load the mesh URL from the web. if (newMesh == null) { WWW meshFile = new WWW(meshURL); while (!meshFile.isDone && (meshFile.error == null)) { ; } if (string.IsNullOrEmpty(meshFile.error)) { // Load mesh here newMesh = ObjImporter.ImportMesh(meshFile.text); VLog.log(VLog.LEVEL_DEBUG, "New mesh imported from " + meshURL); if (newMesh == null) { VLog.log(VLog.LEVEL_ERROR, "Unable to parse mesh at URL " + meshURL + " error " + meshFile.error); return(newMesh); } } else { VLog.log(VLog.LEVEL_ERROR, "Unable to retrieve mesh URL " + meshURL + " error " + meshFile.error); return(newMesh); } } if (newMesh != null) { VLog.log(VLog.LEVEL_ERROR, "Download a new mesh URL " + meshURL); } return(newMesh); }
public void OnEnable() { VLog.log(VLog.LEVEL_INFO, "SilverFormat OnEnable"); VideoFormater formatter = FindObjectOfType <VideoFormater>(); if (formatter) { leftEyeCamera = formatter.getLeftCameraObject(); rightEyeCamera = formatter.getRightCameraObject(); } else { // get the left eye camera object leftEyeCamera = GameObject.Find(LEFT_EYE_CAMERA_NAME); // get the right eye camera object rightEyeCamera = GameObject.Find(RIGHT_EYE_CAMERA_NAME); } // get left eye camera components leftEyeCameraComponent = leftEyeCamera.GetComponent <Camera>(); // get right camera component rightEyeCameraComponent = rightEyeCamera.GetComponent <Camera>(); }
public void SetUpViewerFormat() { int LEFT_EYE_LAYER_MASK = (1 << LayerMask.NameToLayer(LEFT_EYE_LAYER_NAME)); int RIGHT_EYE_LAYER_MASK = (1 << LayerMask.NameToLayer(RIGHT_EYE_LAYER_NAME)); int UI_LAYER_MASK = (1 << LayerMask.NameToLayer(UI_LAYER_NAME)); int DEFAULT_LAYER_MASK = (1 << LayerMask.NameToLayer(DEFAULT_LAYER_NAME)); int IGONRE_RAYCAST_LAYER_MASK = (1 << LayerMask.NameToLayer(IGONRE_RAYCAST_LAYER_NAME)); int EVERY_THING_LAYER_MASK = (1 << LayerMask.NameToLayer(EVERYTHING_LAYER_NAME)); int TRANSPRENTFX_LAYER_MASK = (1 << LayerMask.NameToLayer(TRANSPARENTFX_LAYER_NAME)); // set up camera and image materials for specified playback format // monoscopic image if (!m_formatType.ToLower().Contains(FORMAT_STEREO_STRING)) { // if mono image, then just use left camera and disable the right camera // disable right camera object if (rightEyeCamera != null) { rightEyeCamera.SetActive(true); } // enable left eye camera object if (leftEyeCamera != null) { leftEyeCamera.SetActive(true); } // set left camera component to display both eyes leftEyeCameraComponent.stereoTargetEye = StereoTargetEyeMask.Both; // only need to show left eye layer display (since we will display same image on both eyes) leftEyeCameraComponent.cullingMask = LEFT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; rightEyeCameraComponent.stereoTargetEye = StereoTargetEyeMask.Both; rightEyeCameraComponent.cullingMask = RIGHT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; } else { // stereoscopic image - use both left and right cameras // enable left camera object if (leftEyeCamera != null) { // set left eye camera active leftEyeCamera.SetActive(true); // set left camera component to display to left eye only leftEyeCameraComponent.stereoTargetEye = StereoTargetEyeMask.Left; // set left camera to only show left eye layer display leftEyeCameraComponent.cullingMask = LEFT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; leftEyeCameraComponent.stereoSeparation = 0; } // enable right camera object if (rightEyeCamera != null) { // set right eye camera active rightEyeCamera.SetActive(true); // set right camera component to display to right eye only rightEyeCameraComponent.stereoTargetEye = StereoTargetEyeMask.Right; // set right camera to only show right eye layer display rightEyeCameraComponent.cullingMask = RIGHT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; rightEyeCameraComponent.stereoSeparation = 0; } } // texture tiling and offset float textureScaleX, textureScaleY; float textureLeftEyeOffsetX, textureLeftEyeOffsetY; float textureRightEyeOffsetX, textureRightEyeOffsetY; VLog.log(VLog.LEVEL_DEBUG, "SetUpViewerFormat m_formatType" + m_formatType); VLog.log(VLog.LEVEL_DEBUG, "SetUpViewerFormat m_videoFormatType" + m_videoFormatType); // set display image material based on encoded image format if (m_formatType.ToLower().Contains(FORMAT_TOP_BOTTOM_STRING)) { textureScaleX = TOP_BOTTOM_TEXTURE_SCALE_X; textureScaleY = TOP_BOTTOM_TEXTURE_SCALE_Y; textureLeftEyeOffsetX = TOP_BOTTOM_OFFSET_X; textureLeftEyeOffsetY = UPPER_TEXTURE_OFFSET; textureRightEyeOffsetX = TOP_BOTTOM_OFFSET_X; textureRightEyeOffsetY = LOWER_TEXTURE_OFFSET; } else if (m_formatType.ToLower().Contains(FORMAT_BOTTOM_TOP_STRING)) { textureScaleX = TOP_BOTTOM_TEXTURE_SCALE_X; textureScaleY = TOP_BOTTOM_TEXTURE_SCALE_Y; textureLeftEyeOffsetX = TOP_BOTTOM_OFFSET_X; textureLeftEyeOffsetY = LOWER_TEXTURE_OFFSET; textureRightEyeOffsetX = TOP_BOTTOM_OFFSET_X; textureRightEyeOffsetY = UPPER_TEXTURE_OFFSET; } else if (m_formatType.ToLower().Contains(FORMAT_LEFT_RIGHT_STRING)) { textureScaleX = LEFT_RIGHT_TEXTURE_SCALE_X; textureScaleY = LEFT_RIGHT_TEXTURE_SCALE_Y; textureLeftEyeOffsetX = LEFT_TEXTURE_OFFSET; textureLeftEyeOffsetY = LEFT_RIGHT_OFFSET_Y; textureRightEyeOffsetX = RIGHT_TEXTURE_OFFSET; textureRightEyeOffsetY = LEFT_RIGHT_OFFSET_Y; } else if (m_formatType.ToLower().Contains(FORMAT_RIGHT_LEFT_STRING)) { textureScaleX = LEFT_RIGHT_TEXTURE_SCALE_X; textureScaleY = LEFT_RIGHT_TEXTURE_SCALE_Y; textureLeftEyeOffsetX = RIGHT_TEXTURE_OFFSET; textureLeftEyeOffsetY = LEFT_RIGHT_OFFSET_Y; textureRightEyeOffsetX = LEFT_TEXTURE_OFFSET; textureRightEyeOffsetY = LEFT_RIGHT_OFFSET_Y; } else { VLog.log(VLog.LEVEL_DEBUG, "SetUpViewerFormat m_videoFormatType" + m_videoFormatType); textureScaleX = MONO_TEXTURE_SCALE; textureScaleY = MONO_TEXTURE_SCALE; textureLeftEyeOffsetX = 0.0f; textureLeftEyeOffsetY = 0.0f; textureRightEyeOffsetX = 0.0f; textureRightEyeOffsetY = 0.0f; if (m_videoFormatType.ToLower().Contains(FORMAT_LEFT_RIGHT_STRING) || m_videoFormatType.ToLower().Contains(FORMAT_RIGHT_LEFT_STRING)) { textureScaleX = TOMONO_TEXTURE_SCALE; VLog.log(VLog.LEVEL_DEBUG, "SetUpViewerFormat textureScaleX = TOMONO_TEXTURE_SCALE" + TOMONO_TEXTURE_SCALE); } if (m_videoFormatType.ToLower().Contains(FORMAT_BOTTOM_TOP_STRING) || m_videoFormatType.ToLower().Contains(FORMAT_TOP_BOTTOM_STRING)) { textureScaleY = TOMONO_TEXTURE_SCALE; VLog.log(VLog.LEVEL_DEBUG, "SetUpViewerFormat textureScaleY = TOMONO_TEXTURE_SCALE" + TOMONO_TEXTURE_SCALE); } } // get left eye image sphere GameObject leftEyeImageSphere = GameObject.Find(LEFT_EYE_IMAGE_SPHERE_NAME); // get left eye mesh renderer leftEyeImageRenderer = leftEyeImageSphere.GetComponent <MeshRenderer>(); leftEyeImageFilter = leftEyeImageSphere.GetComponent <MeshFilter>(); // load default material for left eye Material leftMat = (Material)Instantiate(leftEyeImageRenderer.material); // duplicate material for right eye Material rightMat = (Material)Instantiate(leftMat); // set up tiling and offset for left material leftMat.mainTextureScale = new Vector2(textureScaleX, textureScaleY); leftMat.mainTextureOffset = new Vector2(textureLeftEyeOffsetX, textureLeftEyeOffsetY); // set up tiling and offset for right material rightMat.mainTextureScale = new Vector2(textureScaleX, textureScaleY); rightMat.mainTextureOffset = new Vector2(textureRightEyeOffsetX, textureRightEyeOffsetY); // set material for left eye image rendering leftEyeImageRenderer.material = leftMat; // get right eye image sphere GameObject rightEyeImageSphere = GameObject.Find(RIGHT_EYE_IMAGE_SPHERE_NAME); // get right eye mesh renderer rightEyeImageRenderer = rightEyeImageSphere.GetComponent <MeshRenderer>(); rightEyeImageFilter = rightEyeImageSphere.GetComponent <MeshFilter>(); // set material for right eye image rendering rightEyeImageRenderer.material = rightMat; }
// Use this for initialization void Start() { VLog.log(VLog.LEVEL_INFO, "SilverFormat Start"); SetUpViewerFormat(); }
/// <summary> /// Switch video format according to current viedoFormat. /// </summary> private void Switch() { #region Ajust camera settings. int LEFT_EYE_LAYER_MASK = (1 << LayerMask.NameToLayer(LEFT_EYE_LAYER_NAME)) | (1 << 0); int RIGHT_EYE_LAYER_MASK = (1 << LayerMask.NameToLayer(RIGHT_EYE_LAYER_NAME)) | (1 << 0); int UI_LAYER_MASK = (1 << LayerMask.NameToLayer(UI_LAYER_NAME)) | (1 << 0); int DEFAULT_LAYER_MASK = (1 << LayerMask.NameToLayer(DEFAULT_LAYER_NAME)) | (1 << 0); int IGONRE_RAYCAST_LAYER_MASK = (1 << LayerMask.NameToLayer(IGONRE_RAYCAST_LAYER_NAME)); int EVERY_THING_LAYER_MASK = (1 << LayerMask.NameToLayer(EVERYTHING_LAYER_NAME)); int TRANSPRENTFX_LAYER_MASK = (1 << LayerMask.NameToLayer(TRANSPARENTFX_LAYER_NAME)); VLog.log(VLog.LEVEL_DEBUG, "video format switch " + format); // Monoscopic if (format == VideoFormat.OPT_FLAT_MONO || format == VideoFormat.OPT_ERP_180_MONO || format == VideoFormat.OPT_ERP_360_MONO || format == VideoFormat.OPT_FISHEYE_MONO || format == VideoFormat.OPT_TROPIZED_MONO) { if (leftEyeCamera != null) { // Enable left eye camera component leftEyeCamera.gameObject.SetActive(true); // Set left camera component to display both eyes leftEyeCamera.stereoTargetEye = StereoTargetEyeMask.Both; // Only need to show left eye layer display content (since we will display same image on both eyes) leftEyeCamera.cullingMask = LEFT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; leftSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", Vector2.one); leftSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", Vector2.zero); if (videoFormat != VideoFormat.OPT_FLAT_MONO && videoFormat != VideoFormat.OPT_ERP_180_MONO && videoFormat != VideoFormat.OPT_ERP_360_MONO && videoFormat != VideoFormat.OPT_FISHEYE_MONO && videoFormat != VideoFormat.OPT_TROPIZED_MONO) { if (videoFormat == VideoFormat.OPT_ERP_180_LR || videoFormat == VideoFormat.OPT_ERP_360_LR || videoFormat == VideoFormat.OPT_FLAT_LR || videoFormat == VideoFormat.OPT_FISHEYE_LR || videoFormat == VideoFormat.OPT_TROPIZED_LR) { leftSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(0.5f, 1.0f)); leftSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", new Vector2(0.5f, 0.0f)); } else { leftSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(1.0f, 0.5f)); leftSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", Vector2.zero); } } } if (rightEyeCamera != null) { // Disable right eye camera component rightEyeCamera.gameObject.SetActive(true); // Set left camera component to display both eyes rightEyeCamera.stereoTargetEye = StereoTargetEyeMask.Both; rightEyeCamera.cullingMask = RIGHT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; rightSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", Vector2.one); rightSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", Vector2.zero); if (videoFormat != VideoFormat.OPT_FLAT_MONO && videoFormat != VideoFormat.OPT_ERP_180_MONO && videoFormat != VideoFormat.OPT_ERP_360_MONO && videoFormat != VideoFormat.OPT_FISHEYE_MONO && videoFormat != VideoFormat.OPT_TROPIZED_MONO) { if (videoFormat == VideoFormat.OPT_ERP_180_LR || videoFormat == VideoFormat.OPT_ERP_360_LR || videoFormat == VideoFormat.OPT_FLAT_LR || videoFormat == VideoFormat.OPT_FISHEYE_LR || videoFormat == VideoFormat.OPT_TROPIZED_LR) { rightSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(0.5f, 1.0f)); rightSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", new Vector2(0.5f, 0.0f)); } else { rightSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(1.0f, 0.5f)); rightSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", Vector2.zero); } } } } // Stereoscopic else { if (leftEyeCamera != null) { // Enable left camera component leftEyeCamera.gameObject.SetActive(true); // Set left camera component to display to left eye only leftEyeCamera.stereoTargetEye = StereoTargetEyeMask.Left; // Set left camera to only show left eye layer display leftEyeCamera.cullingMask = RIGHT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; if (format == VideoFormat.OPT_ERP_180_LR || format == VideoFormat.OPT_ERP_360_LR || format == VideoFormat.OPT_FLAT_LR || format == VideoFormat.OPT_FISHEYE_LR || format == VideoFormat.OPT_TROPIZED_LR) { leftSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(0.5f, 1.0f)); leftSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", new Vector2(0.5f, 0.0f)); } else { leftSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(1.0f, 0.5f)); leftSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", Vector2.zero); } } if (rightEyeCamera != null) { // Enable right camera component rightEyeCamera.gameObject.SetActive(true); // Set right camera component to display to right eye only rightEyeCamera.stereoTargetEye = StereoTargetEyeMask.Right; // Set right camera to only show right eye layer display rightEyeCamera.cullingMask = LEFT_EYE_LAYER_MASK + UI_LAYER_MASK + DEFAULT_LAYER_MASK + IGONRE_RAYCAST_LAYER_MASK + EVERY_THING_LAYER_MASK + TRANSPRENTFX_LAYER_MASK; if (format == VideoFormat.OPT_ERP_180_LR || format == VideoFormat.OPT_ERP_360_LR || format == VideoFormat.OPT_FLAT_LR || format == VideoFormat.OPT_FISHEYE_LR || format == VideoFormat.OPT_TROPIZED_LR) { rightSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(0.5f, 1.0f)); rightSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", Vector2.zero); } else { rightSide.GetComponent <MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(1.0f, 0.5f)); rightSide.GetComponent <MeshRenderer>().material.SetTextureOffset("_MainTex", new Vector2(0.0f, 0.5f)); } } } #endregion #region Adjust mesh component for rendering. //UnloadMesh(); SilverPlayer.MeshType meshType = SilverPlayer.MeshType.eMeshTypeErp360; SilverPlayer.MeshQuality meshQuality = SilverPlayer.MeshQuality.eQ1; float density = 0.5f; if (format == VideoFormat.OPT_FISHEYE_MONO || format == VideoFormat.OPT_FISHEYE_TB || format == VideoFormat.OPT_FISHEYE_LR) { meshType = SilverPlayer.MeshType.eMeshTypeFisheye180; } else if (format == VideoFormat.OPT_ERP_180_MONO || format == VideoFormat.OPT_ERP_180_LR || format == VideoFormat.OPT_ERP_180_TB) { meshType = SilverPlayer.MeshType.eMeshTypeErp180; } else if (format == VideoFormat.OPT_ERP_360_MONO || format == VideoFormat.OPT_ERP_360_LR || format == VideoFormat.OPT_ERP_360_TB) { meshType = SilverPlayer.MeshType.eMeshTypeErp360; } else if (format == VideoFormat.OPT_TROPIZED_TB || format == VideoFormat.OPT_TROPIZED_LR) { //meshType = SilverPlayer.MeshType.eMeshTypeTropized; } else if (format == VideoFormat.OPT_FLAT_MONO || format == VideoFormat.OPT_FLAT_LR || format == VideoFormat.OPT_FLAT_TB) { meshType = SilverPlayer.MeshType.eMeshTypePlane; } else { VLog.log(VLog.LEVEL_ERROR, "ERROR: unknown video format input."); return; } defaultMesh = SilverPlayer.GenerateMesh(meshType, meshQuality, density, 1, 1); if (!string.IsNullOrEmpty(m_mesh_url) && format != VideoFormat.OPT_FLAT_MONO && format != VideoFormat.OPT_FLAT_LR && format != VideoFormat.OPT_FLAT_TB) { defaultMesh = loadMesh(m_mesh_url); } if (leftSideMeshFilter != null && defaultMesh != null) { //Debug.LogError("Generate meshtype "+ meshType); leftSideMeshFilter.mesh = defaultMesh; } if (rightSideMeshFilter != null && defaultMesh != null) { rightSideMeshFilter.mesh = defaultMesh; } //} // else { //} #endregion }
// Use this for initialization void Start() { VLog.log(VLog.LEVEL_INFO, "VideoFormater start"); }
/// <summary> /// Triggered when some errors happened in video player. /// </summary> void OnError(int errorCode, int errorCodeExtra) { VLog.log(VLog.LEVEL_INFO, "OnError"); }
/// <summary> /// Triggered when video resized in video player. /// </summary> void OnResize() { VLog.log(VLog.LEVEL_INFO, "OnResize"); }
void OnEnd() { VLog.log(VLog.LEVEL_INFO, "OnEnd"); }
/// <summary> /// Triggered when first frame feed out from video player. /// </summary> void OnFirstFrameReady() { VLog.log(VLog.LEVEL_INFO, "OnFirstFrameReady"); }
/// <summary> /// Triggered when video player state transition to ready. /// </summary> void OnReady() { VLog.log(VLog.LEVEL_INFO, "OnReady"); }