Пример #1
0
        void RenderInputProjection(InputFeedProjection feedProjection)
        {
            if (!feedProjection.readyToRender)
            {
                return;
            }

            int oldCullingMask             = cleanProxyCamera.cullingMask;
            CameraClearFlags oldClearFlags = cleanProxyCamera.clearFlags;

            cleanProxyCamera.cullingMask   = 0;
            cleanProxyCamera.clearFlags    = CameraClearFlags.Depth;
            cleanProxyCamera.targetTexture = Output as RenderTexture;

            renderProjectionCommand.DrawRenderer(feedProjection.MeshRenderer, feedProjection.MeshRenderer.sharedMaterial);
            cleanProxyCamera.AddCommandBuffer(CameraEvent.AfterEverything, renderProjectionCommand);

            cleanProxyCamera.Render();

            cleanProxyCamera.RemoveCommandBuffer(CameraEvent.AfterEverything, renderProjectionCommand);
            renderProjectionCommand.Clear();

            cleanProxyCamera.cullingMask   = oldCullingMask;
            cleanProxyCamera.clearFlags    = oldClearFlags;
            cleanProxyCamera.targetTexture = null;
        }
Пример #2
0
        public void Run()
        {
            if (context.Data == null)
            {
                return;
            }
            InputFeedProjection projection = InputFeedProjection.FindProjection(context);

            if (projection == null)
            {
                return;
            }

            GameObject prefab = projectionObjectOverride;

            if (prefab == null)
            {
                prefab = projection.gameObject;
            }

            GameObject copyObj = Instantiate(prefab);

            copyObj.transform.SetParent(copyGroup);
            copyObj.transform.position = projection.transform.position;
            copyObj.transform.rotation = projection.transform.rotation;

            if (projectionObjectOverride == null)
            {
                InputFeedProjection            copyProjection = copyObj.GetComponent <InputFeedProjection>();
                SetTransformFromCameraSettings copyMovement   = copyObj.GetComponent <SetTransformFromCameraSettings>();
                Destroy(copyProjection);
                Destroy(copyMovement);
            }

            MeshFilter   origFilter   = projection.GetComponent <MeshFilter>();
            MeshRenderer copyRenderer = copyObj.GetComponent <MeshRenderer>();
            MeshFilter   copyFilter   = copyObj.GetComponent <MeshFilter>();

            //Copy Texture
            RenderTexture originalTex = projection.FindFeed().ProcessedTexture;
            RenderTexture copyTex     = new RenderTexture(originalTex.width, originalTex.height, 0, originalTex.format);

            Graphics.Blit(originalTex, copyTex);

            //Copy Material
            Material originalMat = copyRenderer.sharedMaterial; //allow override to replace material
            Material copyMat     = new Material(originalMat);

            copyMat.name         += " Copy";
            copyMat.mainTexture   = copyTex;
            copyRenderer.material = copyMat;

            //Copy Mesh
            Mesh originalMesh = origFilter.sharedMesh;
            Mesh copyMesh     = new Mesh();

            copyMesh.SetVertices(new List <Vector3>(originalMesh.vertices));
            copyMesh.SetTriangles(originalMesh.triangles, 0, true);
            copyMesh.SetUVs(0, new List <Vector2>(originalMesh.uv));
            copyMesh.RecalculateNormals();
            copyMesh.UploadMeshData(false);
            copyFilter.mesh = copyMesh;

            copyRenderer.enabled = true;
            copyObj.SetActive(true);
        }