/// <summary> /// Creates a reflection of a <see cref="View"/> and adds it to <see cref="View.ChildViews"/> /// </summary> /// <param name="baseView">The <see cref="View"/> the reflection is based on</param> /// <param name="reflectPlane">A plane alongside which the view shall be reflected</param> /// <param name="clipTolerance">How much to shift the clip plane away from the reflect plane</param> /// <returns>The new view</returns> public static WaterView CreateReflection(View baseView, DoublePlane reflectPlane, float clipTolerance) { #region Sanity checks if (baseView == null) { throw new ArgumentNullException(nameof(baseView)); } if (reflectPlane == default(DoublePlane)) { throw new ArgumentNullException(nameof(reflectPlane)); } #endregion // Clone and modify the camera var newCamera = new ReflectCamera(baseView.Camera, reflectPlane) { Name = baseView.Camera.Name + " Reflection", ClipPlane = new DoublePlane(reflectPlane.Point - reflectPlane.Normal * clipTolerance, reflectPlane.Normal) }; // Create the new view, make sure the camera stays in sync, copy default properties var newView = new WaterView(baseView, newCamera, reflection: true) { Name = baseView.Name + " Reflection", InvertCull = true, BackgroundColor = baseView.BackgroundColor }; baseView.ChildViews.Add(newView); return(newView); }
void Start() { m_SampleSpacing = 1.0f / heightMapSize; m_IsSupported = CheckSupport(); if (!m_IsSupported) { return; } m_SampleCamera = new GameObject("[LiquidSampleCamera]").AddComponent <LiquidSampleCamera>(); m_SampleCamera.transform.SetParent(transform); m_SampleCamera.transform.localPosition = Vector3.zero; m_SampleCamera.transform.localEulerAngles = new Vector3(90, 0, 0); m_SampleCamera.Init(liquidWidth, liquidLength, liquidDepth, m_ForceFactor, new Vector4(transform.up.x, transform.up.y, transform.up.z, -Vector3.Dot(transform.up, transform.position)), m_LiquidParams, heightMapSize); m_LiquidMeshRenderer = gameObject.GetComponent <MeshRenderer>(); if (m_LiquidMeshRenderer == null) { m_LiquidMeshRenderer = gameObject.AddComponent <MeshRenderer>(); } m_LiquidMeshFilter = gameObject.GetComponent <MeshFilter>(); if (m_LiquidMeshFilter == null) { m_LiquidMeshFilter = gameObject.AddComponent <MeshFilter>(); } m_LiquidMesh = Utils.GenerateLiquidMesh(liquidWidth, liquidLength, geometryCellSize); m_LiquidMeshFilter.sharedMesh = m_LiquidMesh; m_LiquidMeshRenderer.sharedMaterial = m_LiquidMaterial; m_LiquidArea = new Vector4(transform.position.x - liquidWidth * 0.5f, transform.position.z - liquidLength * 0.5f, transform.position.x + liquidWidth * 0.5f, transform.position.z + liquidLength * 0.5f); m_ReflectCamera = gameObject.AddComponent <ReflectCamera>(); }