Exemplo n.º 1
0
        public void Init(VoxelLayer aLayer, ParamForOptimizerThread aTextureParam, Vector3 aVectorX, Vector3 aVectorY, Vector3 aOffset, int aOptmalisationMinMergableVoxels, VoxelContainer aContainer)
        {
            vertices  = new List <Vector3>();
            uvs       = new List <Vector2>();
            triangles = new List <int>();

            this.layer   = aLayer;
            this.texture = aTextureParam.voxelTexture;
            this.vectorX = aVectorX;
            this.vectorY = aVectorY;
            this.offset  = aOffset;
            this.optmalisationMinMergableVoxels = aOptmalisationMinMergableVoxels;
            this.ownerContainer = aContainer;
            this.textureWidth   = aTextureParam.textureWidth;
            this.textureHeight  = aTextureParam.textureHeight;
            //      this.ownerContainer.PrepareTextureAndUVDictionary(true);
        }
Exemplo n.º 2
0
        private List <Voxel> GetMergableVoxels(VoxelLayer aVoxelLayer, Voxel aStartVoxel, Vector3 aDirectionX, Vector3 aDirectionY, out Vector2 aScaleFactor)
        {
            List <Voxel>   result     = new List <Voxel>();
            List <Vector2> factorList = new List <Vector2>();
            Vector2        maxSteps   = ownerContainer.GetMaxStepsInLayer(aStartVoxel, aVoxelLayer, aDirectionX, aDirectionY);

            for (int factorX = (int)maxSteps.x; factorX >= 0; factorX--)
            {
                for (int factorY = (int)maxSteps.y; factorY >= 0; factorY--)
                {
                    bool allMergableInArea = true;
                    for (int x = 0; x <= factorX; x++)
                    {
                        for (int y = 0; y <= factorY; y++)
                        {
                            Vector3 curPos = aStartVoxel.position + (aDirectionX * x) + (aDirectionY * y);
                            if (ownerContainer.FindVoxelInLayerByPos(aVoxelLayer, curPos) == null)
                            {
                                allMergableInArea = false;
                                break;
                            }
                        }
                        if (!allMergableInArea)
                        {
                            break;
                        }
                    }
                    if (allMergableInArea)
                    {
                        factorList.Add(new Vector2(factorX, factorY));
                        break;
                    }
                }
                if (factorList.Count > 0)
                {
                    break;
                }
            }


            int     maxMergableVoxels = 0;
            Vector2 resultFactor      = Vector2.zero;

            foreach (Vector2 curFactor in factorList)
            {
                if (maxMergableVoxels < this.GetMergableVoxelsFromFactor(curFactor))
                {
                    resultFactor      = curFactor;
                    maxMergableVoxels = this.GetMergableVoxelsFromFactor(curFactor);
                }
            }

            result.Add(aStartVoxel);

            for (int x = 0; x <= resultFactor.x; x++)
            {
                for (int y = 0; y <= resultFactor.y; y++)
                {
                    Vector3 curPos   = aStartVoxel.position + (aDirectionX * x) + (aDirectionY * y);
                    Voxel   newVoxel = ownerContainer.FindVoxelInLayerByPos(aVoxelLayer, curPos);
                    if ((newVoxel != null) && (result.IndexOf(newVoxel) < 0))
                    {
                        result.Add(newVoxel);
                    }
                }
            }

            resultFactor += Vector2.one;
            aScaleFactor  = resultFactor;
            return(result);
        }