public void ProcPostLodInit() { _dataLoader = VFVoxelTerrain.RandomMap ? VFVoxelTerrain.self.DataLoader : new VFDataReader(string.IsNullOrEmpty(VFVoxelTerrain.MapDataPath_Zip) ? string.Empty : (VFVoxelTerrain.MapDataPath_Zip + "/water"), OnWaterDataLoad); _voxels = new VFLODDataSource(LodMan.LodTreeNodes, IdxInLODNodeData); _fluidProcessor = new EulerianFluidProcessor(); _fluidProcessor.DirtyChunkPosList.AddRange(_dirtyChunkPosList); StartCoroutine(CoFuildProcess()); }
public void MakeAScan(Vector3 pos, List <byte> matList, int rad = 80) { _dataSource = VFVoxelTerrain.self.Voxels; centerPos = pos; mMatList = matList; radius = rad; StopAllCoroutines(); StartCoroutine(Scan()); }
void Update() { if (bRefresh) { bRefresh = false; _dataSource = VFVoxelTerrain.self.Voxels; // centerPos = GetComponent<MSMainCamera>()._posCenter.transform.position; if (null != GameUI.Instance.mMainPlayer) { centerPos = GameUI.Instance.mMainPlayer.position; } StartCoroutine(Scan()); } }
public void ProcPostLodInit() { if (RandomMap) { _dataLoader = new VFDataRTGen(RandomMapConfig.RandSeed); _voxels = new VFLODDataSource(LodMan.LodTreeNodes, IdxInLODNodeData); //_lodDataUpdate = null; } else { _dataLoader = new VFDataReader(string.IsNullOrEmpty(VFVoxelTerrain.MapDataPath_Zip) ? string.Empty : (VFVoxelTerrain.MapDataPath_Zip + "/map")); _voxels = new VFLODDataSource(LodMan.LodTreeNodes, IdxInLODNodeData); _lodDataUpdate = new LODDataUpdate(); } }
//读取以指定序号voxel为中心,半径 + 过滤区域 大小的范围内的所有voxel VFVoxel[, ,] ReadVoxels(IntVector3 _centerIdx, int _alterRadius, int _filterSize) { int _radius = _alterRadius + _filterSize; int _size = 2 * _radius + 1; VFVoxel[, ,] _voxels = new VFVoxel[_size, _size, _size]; IVxDataSource _vds = m_voxelTerrain.Voxels; IntVector3 _chunkIdx = new IntVector3(); for (int _ix = -_radius; _ix <= _radius; ++_ix) { for (int _iy = -_radius; _iy <= _radius; ++_iy) { for (int _iz = -_radius; _iz <= _radius; ++_iz) { int _vx = _centerIdx.x + _ix; int _vy = _centerIdx.y + _iy; int _vz = _centerIdx.z + _iz; if (_vx < 0 || _vy < 0 || _vz < 0) { continue; } _chunkIdx.x = _vx >> m_shift; _chunkIdx.y = _vy >> m_shift; _chunkIdx.z = _vz >> m_shift; VFVoxelChunkData _vc = _vds.readChunk(_chunkIdx.x, _chunkIdx.y, _chunkIdx.z); _vx = (_vx & m_voxelNumPerChunkMask); _vy = (_vy & m_voxelNumPerChunkMask); _vz = (_vz & m_voxelNumPerChunkMask); _voxels[_ix + _radius, _iy + _radius, _iz + _radius] = _vc.ReadVoxelAtIdx(_vx, _vy, _vz); } } } return(_voxels); }
// public static bool RayCastDrawTarget(Ray ray, out DrawTarget target, int minvol, bool voxelbest = false) // { // target = new DrawTarget(); // // RaycastHit rch_voxel = new RaycastHit(); // } public static bool RayCastVoxel(Ray ray, out RaycastHit rch, int minvol = 1) { rch = new RaycastHit(); if (VFVoxelTerrain.self == null) { return(false); } IVxDataSource ds = VFVoxelTerrain.self.Voxels; // Define a small number. float epsilon = 0.0001F; // Define a large number. //float upsilon = 10000F; // ray origin inside a voxel if (ds.SafeRead(Mathf.FloorToInt(ray.origin.x), Mathf.FloorToInt(ray.origin.y), Mathf.FloorToInt(ray.origin.z)).Volume >= minvol) { return(false); } // Start and adder. float xStart, yStart, zStart; float xAdder, yAdder, zAdder; float xMin, yMin, zMin; float xMax, yMax, zMax; xAdder = ray.direction.x > epsilon ? 1 : (ray.direction.x < -epsilon ? -1 : 0); yAdder = ray.direction.x > epsilon ? 1 : (ray.direction.x < -epsilon ? -1 : 0); zAdder = ray.direction.x > epsilon ? 1 : (ray.direction.x < -epsilon ? -1 : 0); Bounds bound = VFVoxelTerrain.self.LodMan._Lod0ViewBounds; xMin = bound.min.x; yMin = bound.min.y; zMin = bound.min.z; xMax = bound.max.x; yMax = bound.max.y; zMax = bound.max.z; xStart = (int)(((int)ray.origin.x) + 1 + xAdder * 0.5f); yStart = (int)(((int)ray.origin.y) + 1 + yAdder * 0.5f); zStart = (int)(((int)ray.origin.z) + 1 + zAdder * 0.5f); // Clamp the start xStart = Mathf.Clamp(xStart, xMin, xMax); yStart = Mathf.Clamp(yStart, yMin, yMax); zStart = Mathf.Clamp(zStart, zMin, zMax); // Normalize the ray ray.direction = ray.direction.normalized; // Define the Enter // float EnterX = upsilon + 1; // float EnterY = upsilon + 1; // float EnterZ = upsilon + 1; // Find the X-cast Enter if (xAdder != 0) { for (float x = xStart; x > xMin - 0.1f && x <= xMax + 0.1f; x += xAdder) { float enter = (x - ray.origin.x) / ray.direction.x; Vector3 Hit = ray.origin + ray.direction * enter; if (ds.Read(Mathf.FloorToInt(Hit.x + xAdder * 0.5f), Mathf.FloorToInt(Hit.y), Mathf.FloorToInt(Hit.z)).Volume >= minvol) { //EnterX = enter; break; } } } return(false); }