예제 #1
0
        /// <summary>
        /// For the ground plane
        /// </summary>
        public HorizontalMeshContributor(GroundPoint groundPoint)
        {
            List <IMeshBuilderPoint>   points    = new List <IMeshBuilderPoint>();
            List <MeshBuilderTriangle> triangles = new List <MeshBuilderTriangle>();
            VoxelCell         baseCell           = groundPoint.Voxels[0];
            Vector3           lookTarget         = Vector3.up;
            IMeshBuilderPoint corePoint          = new MeshBuilderCellPoint(baseCell);

            points.Add(corePoint);
            foreach (GroundQuad quad in groundPoint.PolyConnections)
            {
                GroundPoint       diagonal      = quad.GetDiagonalPoint(groundPoint);
                Vector3           quadPos       = new Vector3(quad.Center.x, 0, quad.Center.y);
                IMeshBuilderPoint diagonalPoint = new MeshBuilderConnectionPoint(baseCell, diagonal.Voxels[0], quadPos);
                GroundPoint[]     otherPoints   = quad.Points.Where(item => item != baseCell.GroundPoint && item != diagonal).ToArray();
                IMeshBuilderPoint otherPointA   = new MeshBuilderConnectionPoint(baseCell, otherPoints[0].Voxels[0]);
                IMeshBuilderPoint otherPointB   = new MeshBuilderConnectionPoint(baseCell, otherPoints[1].Voxels[0]);

                MeshBuilderTriangle triangleA = new MeshBuilderTriangle(baseCell, null, corePoint, diagonalPoint, otherPointA, lookTarget);
                MeshBuilderTriangle triangleB = new MeshBuilderTriangle(baseCell, null, diagonalPoint, corePoint, otherPointB, lookTarget);

                points.Add(diagonalPoint);
                points.Add(otherPointA);
                points.Add(otherPointB);
                triangles.Add(triangleA);
                triangles.Add(triangleB);
            }

            Points    = points.ToArray();
            Triangles = triangles.ToArray();
        }
        public VerticalMeshContributor(VoxelCell sourceCell, GroundEdge edge, VoxelCell connectedCell)
        {
            VoxelCell baseAbove                       = sourceCell.CellAbove;
            VoxelCell connectedAbove                  = connectedCell.CellAbove;
            MeshBuilderConnectionPoint edgePoint      = new MeshBuilderConnectionPoint(sourceCell, connectedCell);
            MeshBuilderConnectionPoint edgeAbovePoint = new MeshBuilderConnectionPoint(baseAbove, connectedAbove);

            if (!connectedCell.Filled || edge.IsBorder)
            {
                points.Add(edgePoint);
                points.Add(edgeAbovePoint);
            }

            if (!connectedCell.Filled)
            {
                foreach (GroundQuad quad in edge.Quads)
                {
                    Vector3   quadPos      = new Vector3(quad.Center.x, sourceCell.Height, quad.Center.y);
                    VoxelCell diagonalCell = quad.GetDiagonalPoint(sourceCell.GroundPoint).Voxels[sourceCell.Height];
                    MeshBuilderConnectionPoint diagonalPoint = new MeshBuilderConnectionPoint(diagonalCell, sourceCell, quadPos);
                    VoxelCell diagonalAbove = diagonalCell.CellAbove;
                    Vector3   quadAbove     = new Vector3(quad.Center.x, sourceCell.Height + 1, quad.Center.y);
                    MeshBuilderConnectionPoint diagonalAbovePoint = new MeshBuilderConnectionPoint(diagonalAbove, baseAbove, quadAbove);

                    points.Add(diagonalPoint);
                    points.Add(diagonalAbovePoint);

                    MeshBuilderTriangle triA = new MeshBuilderTriangle(connectedCell, sourceCell, edgePoint, diagonalPoint, diagonalAbovePoint);
                    MeshBuilderTriangle triB = new MeshBuilderTriangle(connectedCell, sourceCell, edgePoint, diagonalAbovePoint, edgeAbovePoint);
                    triangles.Add(triA);
                    triangles.Add(triB);
                }
            }

            if (edge.IsBorder)
            {
                MeshBuilderCellPoint basePoint  = new MeshBuilderCellPoint(sourceCell);
                MeshBuilderCellPoint abovePoint = new MeshBuilderCellPoint(baseAbove);
                points.Add(basePoint);
                points.Add(abovePoint);

                Vector2             quadCenter = edge.Quads.First().Center;
                Vector3             quadPos    = new Vector3(quadCenter.x, sourceCell.Height, quadCenter.y);
                Vector3             lookTarget = edgePoint.Position - quadPos;
                MeshBuilderTriangle borderA    = new MeshBuilderTriangle(null, sourceCell, basePoint, abovePoint, edgePoint, lookTarget);
                MeshBuilderTriangle borderB    = new MeshBuilderTriangle(null, sourceCell, abovePoint, edgeAbovePoint, edgePoint, lookTarget);
                triangles.Add(borderA);
                triangles.Add(borderB);
            }
        }
예제 #3
0
        public HorizontalMeshContributor(VoxelCell sourceCell, bool upwardFacing)
        {
            VoxelCell targetCell    = upwardFacing ? sourceCell.CellAbove : sourceCell.CellBelow;
            VoxelCell alignmentCell = upwardFacing ? sourceCell.CellAbove : sourceCell;

            Vector3 lookTarget = upwardFacing ? Vector3.up : Vector3.down;

            List <IMeshBuilderPoint>   points    = new List <IMeshBuilderPoint>();
            List <MeshBuilderTriangle> triangles = new List <MeshBuilderTriangle>();

            IMeshBuilderPoint corePoint = new MeshBuilderCellPoint(alignmentCell);

            points.Add(corePoint);
            foreach (GroundQuad quad in targetCell.GroundPoint.PolyConnections)
            {
                GroundPoint diagonal = quad.GetDiagonalPoint(targetCell.GroundPoint);
                Vector3     quadPos  = new Vector3(quad.Center.x, alignmentCell.Height, quad.Center.y);

                IMeshBuilderPoint diagonalPoint = new MeshBuilderConnectionPoint(alignmentCell, diagonal.Voxels[alignmentCell.Height], quadPos);
                GroundPoint[]     otherPoints   = quad.Points.Where(item => item != targetCell.GroundPoint && item != diagonal).ToArray();
                IMeshBuilderPoint otherPointA   = new MeshBuilderConnectionPoint(alignmentCell, otherPoints[0].Voxels[alignmentCell.Height]);
                IMeshBuilderPoint otherPointB   = new MeshBuilderConnectionPoint(alignmentCell, otherPoints[1].Voxels[alignmentCell.Height]);

                MeshBuilderTriangle triangleA = new MeshBuilderTriangle(targetCell, sourceCell, corePoint, diagonalPoint, otherPointA, lookTarget);
                MeshBuilderTriangle triangleB = new MeshBuilderTriangle(targetCell, sourceCell, diagonalPoint, corePoint, otherPointB, lookTarget);

                points.Add(diagonalPoint);
                points.Add(otherPointA);
                points.Add(otherPointB);
                triangles.Add(triangleA);
                triangles.Add(triangleB);
            }

            Points    = points.ToArray();
            Triangles = triangles.ToArray();
        }
예제 #4
0
        private IReadOnlyList <MeshHitTarget> CreateHittable(List <MeshBuilderTriangle> meshBuidlerTriangles)
        {
            MeshHitTarget[] ret = new MeshHitTarget[meshBuidlerTriangles.Count];
            Dictionary <MeshBuilderTriangle, int> indexTable = new Dictionary <MeshBuilderTriangle, int>();

            for (int i = 0; i < meshBuidlerTriangles.Count; i++)
            {
                indexTable.Add(meshBuidlerTriangles[i], i);
            }
            foreach (IGrouping <VoxelCell, MeshBuilderTriangle> item in meshBuidlerTriangles.GroupBy(item => item.SourceCell))
            {
                foreach (var subItem in item.GroupBy(subItem => subItem.TargetCell))
                {
                    MeshBuilderTriangle firstValue = subItem.First();
                    MeshHitTarget       hitTarget  = new MeshHitTarget(firstValue.TargetCell, firstValue.SourceCell, subItem);
                    foreach (MeshBuilderTriangle bedrock in subItem)
                    {
                        int index = indexTable[bedrock];
                        ret[index] = hitTarget;
                    }
                }
            }
            return(ret.ToList().AsReadOnly());
        }