static void OnServoWindowCreated(int uid, int windowIndex, int widthPixels, int heightPixels, int formatNative)
    {
        TextureFormat format = ServoUnityTextureUtils.GetTextureFormatFromNativeTextureFormat(formatNative);

        if (widthPixels == 0 || heightPixels == 0 || format == (TextureFormat)0)
        {
            Debug.LogError("OnServoWindowCreated got invalid format.");
            return;
        }

        // If we initiated the creation of the new window, this find operation will succeed. But
        // if Servo initiated the creation, then there isn't yet a Unity object backing it, so
        // we'll need to create one.
        ServoUnityWindow window = ServoUnityWindow.FindWindowWithUID(uid);

        if (window == null)
        {
            ServoUnityController suc = FindObjectOfType <ServoUnityController>(); // Create it on the same gameobject holding the ServoUnityController.
            if (!suc)
            {
                Debug.LogError("ServoUnityController.OnServoWindowCreated: Couldn't find a ServoUnityController.");
                return;
            }
            window = ServoUnityWindow.CreateNewInParent(suc.transform.parent.gameObject);
        }

        window.WasCreated(windowIndex, widthPixels, heightPixels, format);
    }
Example #2
0
    public static void Configure2DVideoSurface(GameObject vmgo, Texture2D vt, float textureScaleU, float textureScaleV,
                                               float width, float height, bool flipX, bool flipY)
    {
        // Check parameters.
        if (!vt)
        {
            Debug.LogError("Error: CreateWindowMesh null Texture2D");
            return;
        }
        // Create the mesh
        var m = ServoUnityTextureUtils.CreateVideoMesh(textureScaleU, textureScaleV, width, height, flipX, flipY);

        // Assign the texture to the window's material
        Material vm = vmgo.GetComponent <Renderer>().material;

        vm.mainTexture = vt;

        // Assign the mesh to the mesh filter
        MeshFilter filter = vmgo.GetComponent <MeshFilter>();

        filter.mesh = m;

        // Update the mesh collider mesh
        MeshCollider vmc = vmgo.GetComponent <MeshCollider>();;

        vmc.sharedMesh = filter.sharedMesh;
    }
Example #3
0
    public bool ServoUnityGetWindowTextureFormat(int windowIndex, out int width, out int height, out TextureFormat format,
                                                 out bool mipChain, out bool linear, out IntPtr nativeTexureID)
    {
        int formatNative;

        IntPtr[] nativeTextureIDHandle = new IntPtr[1];
        ServoUnityPlugin_pinvoke.servoUnityGetWindowTextureFormat(windowIndex, out width, out height, out formatNative, out mipChain,
                                                                  out linear, nativeTextureIDHandle);
        nativeTexureID = nativeTextureIDHandle[0];

        format = ServoUnityTextureUtils.GetTextureFormatFromNativeTextureFormat(formatNative);
        if (format == (TextureFormat)0)
        {
            return(false);
        }

        return(true);
    }
    /// <summary>
    /// Given a GameObject holding a Renderer, MeshFilter, and MeshCollider, create (or replace) the
    /// mesh filter & collider's mesh with a new mesh of appropriate dimensions and texture coordinates
    /// to display the texture (as determined by width, height, textureScaleU, textureScaleV, flipX, and flipY).
    /// </summary>
    /// <param name="vmgo"></param>
    /// <param name="vt"></param>
    /// <param name="textureScaleU"></param>
    /// <param name="textureScaleV"></param>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="flipX"></param>
    /// <param name="flipY"></param>
    public static void Configure2DVideoSurface(GameObject vmgo, Texture2D vt, float textureScaleU, float textureScaleV,
                                               float width, float height, bool flipX, bool flipY)
    {
        // Check parameters.
        if (!vt)
        {
            Debug.LogError("Error: CreateWindowMesh null Texture2D");
            return;
        }
        // Create the mesh
        Mesh m = ServoUnityTextureUtils.CreateVideoMesh(textureScaleU, textureScaleV, width, height, flipX, flipY);

        // Assign the texture to the window's material
        Material vm = vmgo.GetComponent <Renderer>().material;

        vm.mainTexture = vt;

        // Assign the mesh to the mesh filter
        MeshFilter filter = vmgo.GetComponent <MeshFilter>();

        filter.mesh = m;

        // Update collider, if present.
        Collider c = vmgo.GetComponent <Collider>();

        if (c != null)
        {
            if (c is MeshCollider)
            {
                (c as MeshCollider).sharedMesh = filter.sharedMesh;
            }
            else if (c is BoxCollider)
            {
                float depth = (new Vector2(width, height)).magnitude * 0.05f;
                (c as BoxCollider).size   = new Vector3(width, height, depth);
                (c as BoxCollider).center = new Vector3(0.0f, height / 2.0f, depth / 2.0f); // Place box's front face at z = 0.0f, and lower edge at y = 0.0f.
            }
        }
    }