Esempio 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;
        }
Esempio n. 2
0
 public XmlMeshBlock(string id, MeshBlock.Type blockType, Quaternion rotation, Vector3 position, Vector3 size)
 {
     Id = id;
     BlockType = blockType;
     Rotation = rotation;
     Position = position;
     Size = size;
 }
Esempio n. 3
0
        public void SetupNext(IList<MeshBlock> groupBlocks, IList<Split> splits, MeshBlock meshBlock)
        {
            this.intersectors = groupBlocks;
            this.meshBlock = meshBlock;
            this.splits = splits;

            List<MeshBlock> intersectors = new List<MeshBlock>();
            foreach (MeshBlock test in groupBlocks)
            {
                if (test == meshBlock)
                    continue;

                if (test.Intersects(meshBlock))
                    intersectors.Add(test);
            }
            this.intersectors = intersectors.ToArray();
        }
Esempio n. 4
0
        public void Build(Vector3 pos, AdjacencyMatrix adjacencyMatrix, MeshBlock block, MeshBuilder meshBuilder, BlockBounds clipBounds)
        {

        }
Esempio n. 5
0
 private AdjacencyMatrix CalculateInternalAdjacency(MeshBlock meshBlock, int x, int y, int z)
 {
     this.meshBlock = meshBlock;
     this.x = x;
     this.y = y;
     this.z = z;
     this.adjacencyMatrix.Reset(meshBlock.RotationQuat);
     this.CalculateInternalAdjacency();
     return adjacencyMatrix;
 }
Esempio n. 6
0
 public bool Intersects(MeshBlock test)
 {
     return Intersects1D(OriginalBounds.MinX, OriginalBounds.MinX, OriginalBounds.MaxX, OriginalBounds.MaxX) &&
         Intersects1D(OriginalBounds.MinY, OriginalBounds.MinY, OriginalBounds.MaxY, OriginalBounds.MaxY) &&
         Intersects1D(OriginalBounds.MinZ, OriginalBounds.MinZ, OriginalBounds.MaxZ, OriginalBounds.MaxZ);
 }
Esempio n. 7
0
        public void Build(Vector3 pos, AdjacencyMatrix adjacencyMatrix, MeshBlock block, MeshBuilder meshBuilder, BlockBounds clipBounds)
        {
            Quaternion rot = block.RotationQuat;
            Matrix4x4 transform = Matrix4x4.TRS(pos + new Vector3(0.5f, 0.5f, 0.5f), rot, new Vector3(1, 1, 1));
            BlockBounds localClipBounds = new BlockBounds (clipBounds.Position - block.OriginalBounds.Position - pos, clipBounds.Size);
            localClipBounds.SetToRotationFrom (Quaternion.Inverse(block.RotationQuat), new Vector3(0.5f, 0.5f, 0.5f));
            meshBuilder.BeforeNext (transform, new Vector3(-0.5f, -0.5f, -0.5f), localClipBounds);

            foreach (Part part in _blockParts)
            {
                if ((part.Direction == null) || (!adjacencyMatrix.RPt(part.Direction[0], part.Direction[1], part.Direction[2]).Occluded))
                {
                    IProcMeshGenerator meshGenerator;
                    if(!_meshGenerators.TryGetValue(part.MeshGenerator, out meshGenerator)){
                        _meshGenerators[part.MeshGenerator] = (meshGenerator = (IProcMeshGenerator)Activator.CreateInstance(part.MeshGenerator));
                    }

                    meshGenerator.BuildMesh(part.PartType, adjacencyMatrix, meshBuilder, localClipBounds);
                }
            }
        }