/// <inheritdoc/> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName, new XAttribute("dimX", DimX.ToString(CultureInfo.InvariantCulture)), new XAttribute("dimY", DimY.ToString(CultureInfo.InvariantCulture)), new XAttribute("dimZ", DimZ.ToString(CultureInfo.InvariantCulture))); Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <inheritdoc/> protected override void Check() { if (DimX < 1) { throw new ArgumentException($"Invalid DimX {DimX.ToString(CultureInfo.InvariantCulture)}. DimX must be GE to 1.", "DimX"); } if (DimY < 1) { throw new ArgumentException($"Invalid DimY {DimY.ToString(CultureInfo.InvariantCulture)}. DimY must be GE to 1.", "DimY"); } if (DimZ < 1) { throw new ArgumentException($"Invalid DimZ {DimZ.ToString(CultureInfo.InvariantCulture)}. DimZ must be GE to 1.", "DimZ"); } return; }
private void CreareBoundingBox() { // Initialize minimum and maximum corners of the bounding box to max and min values Vector3 Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 Max = new Vector3(float.MinValue, float.MinValue, float.MinValue); // Loop all parts of the mesh to get bounding box size. foreach (ModelMeshPart meshPart in Mesh.MeshParts) { // Vertex buffer parameters int VertexStride = meshPart.VertexBuffer.VertexDeclaration.VertexStride; int VertexBufferSize = meshPart.NumVertices * VertexStride; // Get vertex data as float float[] VertexData = new float[VertexBufferSize / sizeof(float)]; meshPart.VertexBuffer.GetData(VertexData); // Iterate through vertices (possibly) growing bounding box, all calculations are done in world space for (int i = 0; i < VertexBufferSize / sizeof(float); i += VertexStride / sizeof(float)) { Vector3 Position = new Vector3(VertexData[i], VertexData[i + 1], VertexData[i + 2]); Min = Vector3.Min(Min, Position); Max = Vector3.Max(Max, Position); } } BBox = new BoundingBox(Min, Max); // Compute dimensions and areas. ComputeDimensions(); // Create bounding box vertices. Vector3[] Corners = BBox.GetCorners(); BBoxVertices = new List <VertexPositionColor[]>() { GetFaceVertices(Corners, new int[] { 5, 1, 2, 5, 2, 6 }), // right -> XPlus GetFaceVertices(Corners, new int[] { 4, 0, 3, 4, 3, 7 }), // left -> XMinus GetFaceVertices(Corners, new int[] { 4, 5, 1, 4, 1, 0 }), // bottom -> YPlus GetFaceVertices(Corners, new int[] { 3, 2, 6, 3, 6, 7 }), // top -> YMinus GetFaceVertices(Corners, new int[] { 0, 1, 2, 0, 2, 3 }), // front -> ZPlus GetFaceVertices(Corners, new int[] { 4, 5, 6, 4, 6, 7 }), // back -> ZMinus }; Console.WriteLine("\tCreated Bounding Box of size " + DimX.ToString("F3") + " x " + DimY.ToString("F3") + " x " + DimZ.ToString("F3") + "."); Console.WriteLine("\t\tSurface area = " + GetBBoxTotalArea()); Console.WriteLine("\t\tFace areas = " + GetBBoxFaceArea(AAFace.XMinus) + ", " + GetBBoxFaceArea(AAFace.YMinus) + ", " + GetBBoxFaceArea(AAFace.ZMinus) + "."); }