Ejemplo n.º 1
0
    /// <summary>
    /// Constructor that sets up the garbage matte for the desired camera in the desired place.
    /// </summary>
    /// <param name="cam">Camera in which to apply the matte effect</param>
    /// <param name="greenScreenMaterial">Material reference, usually Mat_ZED_Greenscreen</param>
    /// <param name="target">Center location of the matte effect</param>
    /// <param name="matte">Optional reference to another garbage matte, used to copy its current edit mode. </param>
    public GarbageMatte(ZEDManager camManager, Material greenScreenMaterial, Transform target, GarbageMatte matte)
    {
        this.target       = target;
        currentPlaneIndex = 0;


        zed      = camManager.zedCamera;
        this.cam = camManager.GetComponentInChildren <Camera>();
        points.Clear();

        outlineMaterial = Resources.Load("Materials/Mat_ZED_Outlined") as Material;

        go          = new List <GameObject>();
        meshFilters = new List <MeshFilter>();

        shader_greenScreen = greenScreenMaterial;
        ResetPoints(false);
        if (matte != null)
        {
            editMode = matte.editMode;
        }
        if (commandBuffer == null)
        {
            //Create a command buffer to clear the depth and stencil
            commandBuffer      = new CommandBuffer();
            commandBuffer.name = "GarbageMatte";
            commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CurrentActive, BuiltinRenderTextureType.Depth);

            //Remove the previous command buffer to set the garbage matte first
            CommandBuffer[] cmd = cam.GetCommandBuffers(CameraEvent.BeforeDepthTexture);
            cam.RemoveCommandBuffers(CameraEvent.BeforeDepthTexture);
            if (cmd.Length > 0)
            {
                cam.AddCommandBuffer(CameraEvent.BeforeDepthTexture, commandBuffer);
                for (int i = 0; i < cmd.Length; ++i)
                {
                    cam.AddCommandBuffer(CameraEvent.BeforeDepthTexture, cmd[i]);
                }
            }
        }
        if (loadAtStart && Load())
        {
            Debug.Log("Config garbage matte found, and loaded ( " + garbageMattePath + " )");
            ApplyGarbageMatte();
            editMode = false;
        }

        isInit = true;
    }