static BoxPlane GetBoxPlane(Vector3 position, Vector3 size) { BoxPlane boxplane = new BoxPlane(); size = new Vector3(Mathf.Abs(size.x), Mathf.Abs(size.y), Mathf.Abs(size.z)); boxplane.forwardPlane = new Vector3(position.x, position.y, position.z + size.z / 2); boxplane.backPlane = new Vector3(position.x, position.y, position.z - size.z / 2); boxplane.rightPlane = new Vector3(position.x + size.x / 2, position.y, position.z); boxplane.leftPlane = new Vector3(position.x - size.x / 2, position.y, position.z); boxplane.upPlane = new Vector3(position.x, position.y + size.y / 2, position.z); boxplane.downPlane = new Vector3(position.x, position.y - size.y / 2, position.z); return(boxplane); }
/// <summary> /// /// </summary> /// <param name="plane"></param> /// <param name="curvature"></param> /// <param name="tiling"></param> /// <param name="distance"></param> /// <param name="orientation"></param> /// <param name="groupName"></param> /// <returns></returns> protected Mesh CreateSkyDomePlane( BoxPlane plane, float curvature, float tiling, float distance, Quaternion orientation, string groupName ) { Plane p = new Plane(); Vector3 up = Vector3.Zero; string meshName = "SkyDomePlane_"; // set up plane equation p.D = distance; switch ( plane ) { case BoxPlane.Front: p.Normal = Vector3.UnitZ; up = Vector3.UnitY; meshName += "Front"; break; case BoxPlane.Back: p.Normal = -Vector3.UnitZ; up = Vector3.UnitY; meshName += "Back"; break; case BoxPlane.Left: p.Normal = Vector3.UnitX; up = Vector3.UnitY; meshName += "Left"; break; case BoxPlane.Right: p.Normal = -Vector3.UnitX; up = Vector3.UnitY; meshName += "Right"; break; case BoxPlane.Up: p.Normal = -Vector3.UnitY; up = Vector3.UnitZ; meshName += "Up"; break; case BoxPlane.Down: return null; } // modify orientation p.Normal = orientation * p.Normal; up = orientation * up; // check to see if mesh exists MeshManager meshManager = MeshManager.Instance; Mesh planeMesh = (Mesh)meshManager[ meshName ]; // destroy existing if ( planeMesh != null ) { meshManager.Unload( planeMesh ); planeMesh.Dispose(); } // create new float planeSize = distance * 2; int segments = 16; planeMesh = meshManager.CreateCurvedIllusionPlane( meshName, groupName, p, planeSize, planeSize, curvature, segments, segments, false, 1, tiling, tiling, up, orientation, BufferUsage.DynamicWriteOnly, BufferUsage.StaticWriteOnly, true, true ); return planeMesh; }
/// <summary> /// Utility method for creating the planes of a skybox. /// </summary> /// <param name="plane"></param> /// <param name="distance"></param> /// <param name="orientation"></param> /// <param name="groupName"></param> /// <returns></returns> protected Mesh CreateSkyboxPlane( BoxPlane plane, float distance, Quaternion orientation, string groupName ) { Plane p = new Plane(); string meshName = "SkyboxPlane_"; Vector3 up = Vector3.Zero; // set the distance of the plane p.D = distance; switch ( plane ) { case BoxPlane.Front: p.Normal = Vector3.UnitZ; up = Vector3.UnitY; meshName += "Front"; break; case BoxPlane.Back: p.Normal = -Vector3.UnitZ; up = Vector3.UnitY; meshName += "Back"; break; case BoxPlane.Left: p.Normal = Vector3.UnitX; up = Vector3.UnitY; meshName += "Left"; break; case BoxPlane.Right: p.Normal = -Vector3.UnitX; up = Vector3.UnitY; meshName += "Right"; break; case BoxPlane.Up: p.Normal = -Vector3.UnitY; up = Vector3.UnitZ; meshName += "Up"; break; case BoxPlane.Down: p.Normal = Vector3.UnitY; up = -Vector3.UnitZ; meshName += "Down"; break; } // modify by orientation p.Normal = orientation * p.Normal; up = orientation * up; MeshManager modelMgr = MeshManager.Instance; // see if this mesh exists Mesh planeModel = (Mesh)modelMgr[ meshName ]; // trash it if it already exists if ( planeModel != null ) { modelMgr.Unload( planeModel ); } float planeSize = distance * 2; // create and return the plane mesh return modelMgr.CreatePlane( meshName, groupName, p, planeSize, planeSize, 1, 1, false, 1, 1, 1, up ); }