コード例 #1
0
    public void ApplyCluster(VoxelCluster voxelCluster)
    {
        isStatic = isOriginal ? true : voxelCluster.ShouldBeStatic(isStatic);

        Vector3 GetLocalPosWithWorldRotation(Vector3 localPos, Transform t)
        {
            return(t.TransformPoint(localPos) - t.position);
        }

        Vector3 pivot = GetPivot(voxelCluster.Bins, voxelCluster.Dimensions, isStatic);

        //meshTransform.position += GetLocalPosWithWorldRotation(voxelCluster.VoxelOffset, meshTransform);
        //meshTransform.parent = null;
        //transform.position = meshTransform.position + GetLocalPosWithWorldRotation(pivot, meshTransform);
        //meshTransform.parent = transform;

        meshTransform.position += GetLocalPosWithWorldRotation(voxelCluster.VoxelOffset, meshTransform);

        Vector3 cachedMeshTransformPos = meshTransform.position;

        transform.position     = meshTransform.position + GetLocalPosWithWorldRotation(pivot, meshTransform);
        meshTransform.position = cachedMeshTransformPos;

        binGridDimensions = voxelCluster.Dimensions;
        bins = voxelCluster.Bins;

        voxelBuilder.Refresh();
    }
コード例 #2
0
    public static void FindVoxelClustersAndSplit(VoxelGrid voxelGrid, Queue <int> newlyCleanedBins)
    {
        bool[] visitedBins = new bool[voxelGrid.GetBinCount()];

        clusters.Clear();
        while (newlyCleanedBins.Count > 0)
        {
            int binIndex = newlyCleanedBins.Dequeue();

            VoxelCluster cluster = TryFindCluster(binIndex, voxelGrid.GetBins(), voxelGrid.GetBinGridDimensions(), visitedBins);
            if (cluster != null)
            {
                clusters.Add(cluster);
            }
        }

        VoxelGrid[] splitVoxelGrids = TrySplit(voxelGrid, clusters);
        ApplyClusters(splitVoxelGrids, clusters);
    }