//Call this whenever you change the icMaterial on this gameobject.
        //E.g. when changing from an icImageMaterial to a icBinkMaterial
        //Will pick the first enabled icMaterial. If all are disabled, will pick the first one.
        public void RefreshIcMaterial()
        {
            if (icMat != null) {
            icMat.RemoveRenderPass(this);
            }
            this.icMat = null;
            icMaterial[] icMats = this.GetComponents<icMaterial>();

            if (icMats.Length > 0) {
            for (int i = 0; i < icMats.Length; i++) {
                icMaterial mat = icMats[i];
                if (mat.enabled) {
                    this.icMat = mat;
                    break;
                }

            }
            if (this.icMat == null) {
                this.icMat = icMats[0];
            }

            this.icMat.AddRenderPass(this);
            } else {
            Debug.LogWarning ("icRenderPass was added to a GameObject with no icMaterial");
            }
        }
 protected StereoMediaReady LinkSingleMediaReady(icMaterial stereoChildMat)
 {
     if (stereoChildMat) {
     StereoMediaReady mrScript = this.gameObject.AddComponent<StereoMediaReady>();
     mrScript.enabled = false;
     stereoChildMat.mediaReadyCallbacks.Add(mrScript);
     return mrScript;
     } else {
     return null;
     }
 }
        void Start()
        {
            SetStereoMode(leftObject, StereoMode.LEFT);
            SetStereoMode(rightObject, StereoMode.RIGHT);
            leftObject.transform.parent = this.transform;
            rightObject.transform.parent = this.transform;
            this.leftIcMat = this.leftObject.GetComponent<icMaterial>();
            this.rightIcMat = this.rightObject.GetComponent<icMaterial>();
            UpdateStereoChild(this.leftIcMat);
            UpdateStereoChild(this.rightIcMat);

            LinkMediaReadies();
        }
 public void SetIcMaterial(icMaterial icm)
 {
     this.icMat = icm;
 }
        /**
         * Ctor.
         * @param id The projector id.
         * @param width width of the projector grid.
         * @param height height of the projector grid.
         * @param start start seam for the projector.
         * @param end end seam for the projector.
         */
        public ProjectorDescription(ProjectorMesh projectorMesh,
                                    int renderTextureWidth,
                                    int renderTextureHeight,
                                    GameObject warpMeshPrefab,
                                    Transform clusterManager)
        {
            this.projectorMesh = projectorMesh;
            nodeNumber         = projectorMesh.Id / 2;

            if (projectorMesh.Id % 2 == 0)
            {
                stereoType = ProjectorStereoType.Left;
            }
            else if (projectorMesh.Id % 2 == 1)
            {
                stereoType = ProjectorStereoType.Right;
            }
            meshVertices = new Vector3[projectorMesh.NumVertices];
            meshUVs      = new Vector2[projectorMesh.NumVertices];
            triangles    = new int[3 * 2 * projectorMesh.GridWidth * projectorMesh.GridHeight];

            _projectorObject = new GameObject("Ortho Camera Rig: " + projectorMesh.Id);

            //
            // Position this rig under the Cluster Manager
            // to make the scene browser clearer
            _projectorObject.transform.parent = clusterManager;

            /////////////////
            // Create Mesh //
            /////////////////
            Mesh mesh = this.CreateMesh();

            if (mesh == null)
            {
                // Create mesh failed, exit
                throw new Exception("Mesh Creation Failed.");
            }
//            Debug.Log("Mesh Created.");

            // Projector is the left of the two assigned to this IG
            string     warpMeshPrefix = "IG(" + (projectorMesh.Id / 2) + ").Projector(" + projectorMesh.Id + ")";
            GameObject warpMeshObject = GameObject.Instantiate(warpMeshPrefab) as GameObject;

            warpMeshObject.name = warpMeshPrefix + ".object";
            //GameObject warpMeshObject = new GameObject(warpMeshPrefix + ".object");
            warpMeshObject.transform.parent = this.ProjectorObject.transform;
            //warpMeshObject.AddComponent("MeshFilter");
            //warpMeshObject.AddComponent("MeshRenderer");
            (warpMeshObject.GetComponent("MeshFilter") as MeshFilter).mesh = mesh;
            MeshRenderer meshRenderer = warpMeshObject.GetComponent <MeshRenderer>();

            meshRenderer.castShadows    = false;
            meshRenderer.receiveShadows = false;

            this.warpMeshObject = warpMeshObject;


            ///////////////////////////////////////////////////
            // Create a new render texture for the projector //
            ///////////////////////////////////////////////////
            int           renderTextureDepth = 24;
            RenderTexture renderTexture      = new RenderTexture(renderTextureWidth, renderTextureHeight, renderTextureDepth);

            this._targetRenderTexture = renderTexture;

            ///////////////////////////////////////////////////
            // Create a new blend texture for this projector //
            ///////////////////////////////////////////////////
            string path = "file:///" + CONFIG_PATH + "Avie/BlendTextures/blend" + projectorMesh.Id.ToString("00") + ".png";
            WWW    www  = new WWW(path);

            this._targetBlendTexture = www.texture;

            if (www.error != null)
            {
                Debug.Log(www.error);
            }

            ///////////////////////////////////////////////////
            // Add HSV/ Gamma adjust						 //
            ///////////////////////////////////////////////////
            icMaterial icm = this.warpMeshObject.AddComponent <icMaterial>();

            icm.multiplyByParentColour = false;


            RefreshTextureScript rts = this.warpMeshObject.AddComponent <RefreshTextureScript>();

            rts.toReplace = this._targetRenderTexture;
            ImageShaderScript iss = this.warpMeshObject.AddComponent <ImageShaderScript>();

            iss.separatePass = true;
            iss.enabled      = false;
            //imageShaderScript needs to be enabled one frame later, or a white flash occurs...
        }
示例#6
0
 void Awake()
 {
     attachedIcMat = this.GetComponent<icMaterial>() as icMaterial;
 }
 void UpdateStereoChild(icMaterial icMat)
 {
     if (icMat) {
     icMat.baseScale = this.baseScale;
     icMat.autoAspectRatio = this.autoAspectRatio;
     icMat.keepStartingAspectRatio = this.keepStartingAspectRatio;
     }
 }