Ejemplo n.º 1
0
    private void createTexture()
    {
        uint movieWidth  = MetaioSDKUnity.getMovieTextureWidth(movieGeometry);
        uint movieHeight = MetaioSDKUnity.getMovieTextureHeight(movieGeometry);

        // Shouldn't happen, dimensions are initialized by now
        if (movieWidth == 0 || movieHeight == 0)
        {
            throw new Exception("Movie not loaded yet, width/height is zero");
        }

        int textureSizeX = nextPowerOf2(movieWidth);
        int textureSizeY = nextPowerOf2(movieHeight);

        Texture2D texture = new Texture2D(textureSizeX, textureSizeY, TextureFormat.RGBA32, false);

        // User has to set transparency-supporting shader himself since he might as well overwrite the shader with
        // a custom one, so we do not force anyone to use the Unity built-in shader
        Material mat = gameObject.renderer.material;

        texture.wrapMode = TextureWrapMode.Clamp;
        mat.mainTexture  = texture;

        // Most videos are not a power of 2 in dimensions, so scale the UV coordinates appropriately.
        // Unity seems to interpret the (0,0) coordinate of OpenGL textures as bottom left, so we
        // need to vertically flip the V coordinate here.
        mat.mainTextureScale  = new Vector2((float)movieWidth / textureSizeX, -(float)movieHeight / textureSizeY);
        mat.mainTextureOffset = new Vector2(0, (float)movieHeight / textureSizeY);

        textureID = texture.GetNativeTextureID();

        Debug.Log(string.Format("Texture ID for movie {0} ({1}x{2}): {3}", movieFile, movieWidth, movieHeight, textureID));
    }