Esempio n. 1
0
    // Common entry point for both OpenAsync and Open to have transform data only accessible on main thread
    public bool Open(string urlPath, Vector3 defaultBoundsScale)
    {
        if (!isInitialized)
        {
            if (!Initialize())
            {
                return(false);
            }
        }

        // On Android a bare filename means a file in StreamingAssets which can be loaded via Android asset manager API,
        // and an absolute path will be opened directly, so just pass unmodified 'urlPath' directly through to plugin.
        if (Application.platform == RuntimePlatform.Android)
        {
        }
        else if (!Path.IsPathRooted(urlPath))
        {
            urlPath = Application.streamingAssetsPath + "/" + urlPath;
        }

        bool res = pluginInterop.OpenHCapObject(urlPath, ref Settings);

        if (res)
        {
            Url = urlPath;

            if (pluginInterop.GetHCapObjectFileInfo(ref fileInfo))
            {
                Vector3 min = Vector3.zero;
                Vector3 max = Vector3.zero;
                if ((fileInfo.maxX - fileInfo.minX) > 0.0f ||
                    (fileInfo.maxY - fileInfo.minY) > 0.0f ||
                    (fileInfo.maxZ - fileInfo.minZ) > 0.0f)
                {
                    min = new Vector3((float)fileInfo.minX, (float)fileInfo.minY, (float)fileInfo.minZ);
                    max = new Vector3((float)fileInfo.maxX, (float)fileInfo.maxY, (float)fileInfo.maxZ);
                }
                else // We need some sane bounds even if the hcap file doesn't tell us.
                {
                    min = new Vector3(0.5f / defaultBoundsScale.x, 0.5f / defaultBoundsScale.y, 0.5f / defaultBoundsScale.z);
                    max = new Vector3(1.1f / defaultBoundsScale.x, 1.1f / defaultBoundsScale.y, 1.1f / defaultBoundsScale.z);
                }
                localSpaceBounds.SetMinMax(min, max);
            }
            // Initialize with reasonable numbers if available.  Important for index and vertex buffers to avoid reallocation in the middle of playback
            lastFrameInfo.indexCount    = fileInfo.maxIndexCount > DefaultMaxIndexCount ? fileInfo.maxIndexCount : DefaultMaxIndexCount;
            lastFrameInfo.vertexCount   = fileInfo.maxVertexCount > DefaultMaxVertexCount ? fileInfo.maxVertexCount : DefaultMaxVertexCount;
            lastFrameInfo.textureWidth  = (int)fileInfo.fileWidth;
            lastFrameInfo.textureHeight = (int)fileInfo.fileHeight;

            HandleOnOpen(urlPath);
        }
        else
        {
            logger.LogError(TAG, "HoloVideoObject::Open Error: unable to OpenHCapObject()");
        }
        return(res);
    }
Esempio n. 2
0
    // Common entry point for both OpenAsync and Open to have transform data only accessible on main thread
    public bool Open(string urlPath, Vector3 defaultBoundsScale)
    {
        if (!isInitialized)
        {
            if (!Initialize())
            {
                return(false);
            }
        }

        urlPath = ConstructFullUrl(urlPath);

        bool res = pluginInterop.OpenHCapObject(urlPath, ref Settings);

        isPlaying = false;
        if (res)
        {
            ClockScale  = _clockScale;
            AudioVolume = _audioVolume;
            Url         = urlPath;

            if (pluginInterop.GetHCapObjectFileInfo(ref fileInfo))
            {
                Vector3 min = Vector3.zero;
                Vector3 max = Vector3.zero;
                if ((fileInfo.maxX - fileInfo.minX) > 0.0f ||
                    (fileInfo.maxY - fileInfo.minY) > 0.0f ||
                    (fileInfo.maxZ - fileInfo.minZ) > 0.0f)
                {
                    min = new Vector3((float)fileInfo.minX, (float)fileInfo.minY, (float)fileInfo.minZ);
                    max = new Vector3((float)fileInfo.maxX, (float)fileInfo.maxY, (float)fileInfo.maxZ);
                }
                else // We need some sane bounds even if the hcap file doesn't tell us.
                {
                    min = new Vector3(0.5f / defaultBoundsScale.x, 0.5f / defaultBoundsScale.y, 0.5f / defaultBoundsScale.z);
                    max = new Vector3(1.1f / defaultBoundsScale.x, 1.1f / defaultBoundsScale.y, 1.1f / defaultBoundsScale.z);
                }
                localSpaceBounds.SetMinMax(min, max);
            }
            // Initialize with reasonable numbers if available.  Important for index and vertex buffers to avoid reallocation in the middle of playback
            lastFrameInfo.indexCount    = fileInfo.maxIndexCount > DefaultMaxIndexCount ? fileInfo.maxIndexCount : DefaultMaxIndexCount;
            lastFrameInfo.vertexCount   = fileInfo.maxVertexCount > DefaultMaxVertexCount ? fileInfo.maxVertexCount : DefaultMaxVertexCount;
            lastFrameInfo.textureWidth  = (int)fileInfo.fileWidth;
            lastFrameInfo.textureHeight = (int)fileInfo.fileHeight;
        }
        else
        {
            logger.LogError(TAG, "HoloVideoObject::Open Error: unable to OpenHCapObject()");
        }
        return(res);
    }