Ejemplo n.º 1
0
        private void AttachGameObject(MeshBlock meshBlock, GroupBranch groupBranch, AdjacencyCalculator adjacencyCalculator)
        {
            SplitBoundsBranch splitBoundsBranch = groupBranch.SplitBoundsBranchContaining(meshBlock.SplittedRegion);

            var meshBuilder = new MeshBuilder();
            adjacencyCalculator.SetupNext(groupBranch.SplittedMeshBlocks, groupBranch.Splits, meshBlock);

            for (var x = (int)meshBlock.OriginalBounds.MinX; x < meshBlock.OriginalBounds.MaxX; x++)
            {
                for (var y = (int)meshBlock.OriginalBounds.MinY; y < meshBlock.OriginalBounds.MaxY; y++)
                {
                    for (var z = (int)meshBlock.OriginalBounds.MinZ; z < meshBlock.OriginalBounds.MaxZ; z++)
                    {
                        AdjacencyMatrix adjacencyMatrix = adjacencyCalculator.CalculateAdjacency(x, y, z);
                        if (!adjacencyMatrix.IsVisible()) continue;

                        var clipBounds = new BlockBounds(x, y, z, x + 1, y + 1, z + 1);
                        clipBounds.ClipToBounds(groupBranch.Splits);
                        meshBlock.MeshSource.Build(new Vector3(x, y, z) - meshBlock.OriginalBounds.Position, adjacencyMatrix, meshBlock, meshBuilder, clipBounds);
                    }
                }
            }

            GameObject blockGameObject = Object.Instantiate(groupBranch.Level.Prefabs.BlockPrefab);
            blockGameObject.name = meshBlock.Id;
            blockGameObject.transform.localPosition = meshBlock.OriginalBounds.Position;
            splitBoundsBranch.BlocksLeaf.Attach(blockGameObject);

            Mesh mesh = meshBuilder.DoneCreateMesh();
            blockGameObject.GetComponent<MeshFilter>().mesh = mesh;
        }
Ejemplo n.º 2
0
        private void BuildSplitTrack(GroupBranch groupBranch, SubTrack track)
        {
            SplitBoundsBranch splitBranch = groupBranch.SplitBoundsBranchContaining(track.SplittedRegion);

            GameObject gameObj = new GameObject(track.Id);
            TrackExtruder trackExtruder = new TrackExtruder(TrackBuilderConfiguration.DefaultConfig);

            foreach (SubTrackGroup subTrackGroup in track.TrackGroups)
            {
                BezierSpline spline = subTrackGroup.Spline;
                Mesh trackMesh = trackExtruder.ExtrudeAlong(spline, track.SplitTrack.InitialDown);
                GameObject childTrack = GameObjectUtils.AsChildOf(gameObj.transform, new Vector3(), Object.Instantiate(groupBranch.Level.Prefabs.TrackPrefab));
                childTrack.name = subTrackGroup.Id;
                childTrack.GetComponent<MeshFilter>().mesh = trackMesh;
            }

            splitBranch.TracksLeaf.Attach(gameObj);
        }
Ejemplo n.º 3
0
 public BaseTree GetSplitBoundsBranch(GroupBranch groupBranch)
 {
     return groupBranch.SplitBoundsBranchContaining(BranchDefault.SubTrack.SplittedRegion);
 }