/// <summary> /// Builds the structure. /// </summary> public override VertexStructure BuildStructure(StructureBuildOptions buildOptions) { VertexStructure result = new VertexStructure(); // Hold dictionary containg materials and corresponding structures Dictionary <NamedOrGenericKey, VertexStructureSurface> materialRelated = new Dictionary <NamedOrGenericKey, VertexStructureSurface>(); // Build bottom structure VertexStructureSurface bottomSurface = result.CreateSurface(); bottomSurface.Material = m_bottomMaterial; materialRelated[m_bottomMaterial] = bottomSurface; // Calculate half vector of total ground size. Vector2 totalHalfSize = new Vector2(m_totalSizeWithoutBorder.X / 2f, m_totalSizeWithoutBorder.Y / 2f); Vector2 tileHalfSize = new Vector2(m_tileSize.X / 2f, m_tileSize.Y / 2f); // Build all tiles foreach (FloorTile actTile in m_groundTiles) { // Get the material of the tile NamedOrGenericKey actMaterial = actTile.Material; if (actMaterial.IsEmpty) { actMaterial = m_groundMaterial; } // Get surface object VertexStructureSurface actSurface = null; if (materialRelated.ContainsKey(actMaterial)) { actSurface = materialRelated[actMaterial]; } else { actSurface = result.CreateSurface(); actSurface.Material = actMaterial; materialRelated[actMaterial] = actSurface; } // Get position of the tile Vector3 tilePosition = new Vector3( (actTile.XPos * m_tileSize.X) - totalHalfSize.X, 0f, (actTile.YPos * m_tileSize.Y) - totalHalfSize.Y); // Add tile information to current VertexStructures actSurface.BuildCubeTop4V( new Vector3(tilePosition.X, -m_height, tilePosition.Z), new Vector3(m_tileSize.X, m_height, m_tileSize.Y), Color4.White); bottomSurface.BuildCubeBottom4V( new Vector3(tilePosition.X, -m_height, tilePosition.Z), new Vector3(m_tileSize.X, m_height, m_tileSize.Y), Color4.White); } // Build all borders VertexStructureSurface borderSurface = null; if (materialRelated.ContainsKey(m_borderMaterial)) { borderSurface = materialRelated[m_borderMaterial]; } else { borderSurface = result.CreateSurface(); borderSurface.Material = m_borderMaterial; materialRelated[m_borderMaterial] = borderSurface; } foreach (BorderInformation actBorder in m_borders) { if (m_borderSize <= 0f) { Vector3 tilePosition = new Vector3( (actBorder.TileXPos * m_tileSize.X) - totalHalfSize.X, 0f, (actBorder.TileYPos * m_tileSize.Y) - totalHalfSize.Y); //Build simple borders switch (actBorder.Location) { case BorderLocation.Left: borderSurface.BuildRect4V( new Vector3(tilePosition.X, -m_height, tilePosition.Z), new Vector3(tilePosition.X, 0f, tilePosition.Z), new Vector3(tilePosition.X, 0f, tilePosition.Z + m_tileSize.Y), new Vector3(tilePosition.X, -m_height, tilePosition.Z + m_tileSize.Y)); break; case BorderLocation.Top: borderSurface.BuildRect4V( new Vector3(tilePosition.X, -m_height, tilePosition.Z + m_tileSize.Y), new Vector3(tilePosition.X, 0f, tilePosition.Z + m_tileSize.Y), new Vector3(tilePosition.X + m_tileSize.X, 0f, tilePosition.Z + m_tileSize.Y), new Vector3(tilePosition.X + m_tileSize.X, -m_height, tilePosition.Z + m_tileSize.Y)); break; case BorderLocation.Right: borderSurface.BuildRect4V( new Vector3(tilePosition.X + m_tileSize.X, -m_height, tilePosition.Z + m_tileSize.Y), new Vector3(tilePosition.X + m_tileSize.X, 0f, tilePosition.Z + m_tileSize.Y), new Vector3(tilePosition.X + m_tileSize.X, 0f, tilePosition.Z), new Vector3(tilePosition.X + m_tileSize.X, -m_height, tilePosition.Z)); break; case BorderLocation.Bottom: borderSurface.BuildRect4V( new Vector3(tilePosition.X + m_tileSize.X, -m_height, tilePosition.Z), new Vector3(tilePosition.X + m_tileSize.X, 0f, tilePosition.Z), new Vector3(tilePosition.X, 0f, tilePosition.Z), new Vector3(tilePosition.X, -m_height, tilePosition.Z)); break; } } else { //Build complex borders } } //Return all generated VertexStructures return(result); }
/// <summary> /// Builds the structure needed for the pallet /// </summary> /// <param name="buildOptions">Some generic options for structure building</param> public override VertexStructure BuildStructure(StructureBuildOptions buildOptions) { bool createContent = m_contentHeight > 0f; // Prepare result array VertexStructure result = new VertexStructure(); VertexStructureSurface surfacePallet = result.CreateSurface(); VertexStructureSurface surfaceContent = null; if (createContent) { surfaceContent = result.CreateSurface(); } // Build pallet #region ----------------------------------------------------------- if (buildOptions.IsHighDetail) { float middleFront = m_width / 2f; float middleSide = m_depth / 2f; float middleFrontBegin = middleFront - m_bigFooterWidth / 2f; float middleSideBegin = middleSide - m_bigFooterWidth / 2f; float lastBeginSmall = m_width - m_smallFooterWidth; float lastBeginBig = m_depth - m_bigFooterWidth; float footerHeight = m_palletHeight - m_boardHeight * 3f; float quarterFrontBegin = ((m_bigFooterWidth / 2f) + ((middleFront - (m_bigFooterWidth / 2f)) / 2f)) - (m_smallFooterWidth / 2f); // +(middleFront / 2f - m_smallFooterWidth / 2f); float threeQuarterFrontBegin = middleFront + (middleFront - quarterFrontBegin - m_smallFooterWidth); //(middleFront / 2f) * 3f - m_smallFooterWidth / 2f; surfacePallet.Material = m_palletMaterial; // Build 3 board on bottom surfacePallet.BuildCube24V(new Vector3(0f, 0f, 0f), new Vector3(m_smallFooterWidth, m_boardHeight, m_depth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(middleFrontBegin, 0f, 0f), new Vector3(m_bigFooterWidth, m_boardHeight, m_depth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(lastBeginSmall, 0f, 0f), new Vector3(m_smallFooterWidth, m_boardHeight, m_depth), m_palletColor); // Build 9 footers surfacePallet.BuildCubeSides16V(new Vector3(0f, m_boardHeight, 0f), new Vector3(m_smallFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(0f, m_boardHeight, middleSideBegin), new Vector3(m_smallFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(0f, m_boardHeight, lastBeginBig), new Vector3(m_smallFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(middleFrontBegin, m_boardHeight, 0f), new Vector3(m_bigFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(middleFrontBegin, m_boardHeight, middleSideBegin), new Vector3(m_bigFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(middleFrontBegin, m_boardHeight, lastBeginBig), new Vector3(m_bigFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(lastBeginSmall, m_boardHeight, 0f), new Vector3(m_smallFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(lastBeginSmall, m_boardHeight, middleSideBegin), new Vector3(m_smallFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCubeSides16V(new Vector3(lastBeginSmall, m_boardHeight, lastBeginBig), new Vector3(m_smallFooterWidth, footerHeight, m_bigFooterWidth), m_palletColor); // Build boards above footers surfacePallet.BuildCube24V(new Vector3(0f, m_boardHeight + footerHeight, 0f), new Vector3(m_width, m_boardHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(0f, m_boardHeight + footerHeight, middleSideBegin), new Vector3(m_width, m_boardHeight, m_bigFooterWidth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(0f, m_boardHeight + footerHeight, lastBeginBig), new Vector3(m_width, m_boardHeight, m_bigFooterWidth), m_palletColor); // Build top boards float localYPos = m_palletHeight - m_boardHeight; surfacePallet.BuildCube24V(new Vector3(0f, localYPos, 0f), new Vector3(m_bigFooterWidth, m_boardHeight, m_depth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(middleFrontBegin, localYPos, 0f), new Vector3(m_bigFooterWidth, m_boardHeight, m_depth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(m_width - m_bigFooterWidth, localYPos, 0f), new Vector3(m_bigFooterWidth, m_boardHeight, m_depth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(quarterFrontBegin, localYPos, 0f), new Vector3(m_smallFooterWidth, m_boardHeight, m_depth), m_palletColor); surfacePallet.BuildCube24V(new Vector3(threeQuarterFrontBegin, localYPos, 0f), new Vector3(m_smallFooterWidth, m_boardHeight, m_depth), m_palletColor); } else { surfacePallet.BuildCube24V( new Vector3(0f, 0f, 0f), new Vector3(m_width, m_palletHeight, m_depth), m_palletColor); } #endregion ----------------------------------------------------------- // Build content #region ----------------------------------------------------------- if (createContent) { surfaceContent.Material = m_contentMaterial; surfaceContent.BuildCubeSides16V(new Vector3(0f, m_palletHeight, 0f), new Vector3(m_width, m_contentHeight, m_depth), m_contentColor); surfaceContent.BuildCubeTop4V(new Vector3(0f, m_palletHeight, 0f), new Vector3(m_width, m_contentHeight, m_depth), m_contentColor); surfaceContent.BuildCubeBottom4V(new Vector3(0f, m_palletHeight, 0f), new Vector3(m_width, m_contentHeight, m_depth), m_contentColor); } #endregion ----------------------------------------------------------- Matrix4x4 rotMatrix = Matrix4x4.CreateRotationY(EngineMath.RAD_90DEG); result.UpdateVerticesUsingRelocationBy(new Vector3(-m_width / 2f, 0f, -m_depth / 2f)); result.CalculateTangentsAndBinormals(); result.TransformVertices(rotMatrix); return(result); }