public override List <CornerCoords> getObstacleCorners(GPUFluid.GridDimensions dimensions, Vector3 _scale) { gridPosition = new Vector3(-(1.0f / dimensions.x), -(1.0f / dimensions.y), -(1.0f / dimensions.z)); cellSize = new Vector3(_scale.x / (dimensions.x * 16.0f), _scale.y / (dimensions.y * 16.0f), _scale.z / (dimensions.z * 16.0f)); foreach (Transform child in obstacles) { if (child.gameObject.activeSelf) { Vector3 scale = child.localScale; Vector3 position = child.position; position -= gridPosition; CornerCoords coords = getCornerCoords(position, scale, dimensions); cornerCoordList.Add(coords); //snaps Obstacle position and scale to grid child.position = Vector3.Scale(new Vector3((coords.xStart + coords.xEnd) / 2f, (coords.yStart + coords.yEnd) / 2f, (coords.zStart + coords.zEnd) / 2f), cellSize) + gridPosition; child.localScale = Vector3.Scale(new Vector3(coords.xEnd - coords.xStart, coords.yEnd - coords.yStart, coords.zEnd - coords.zStart), cellSize); } } return(cornerCoordList); }
private CornerCoords getCornerCoords(Vector3 position, Vector3 scale, GPUFluid.GridDimensions dimensions) { CornerCoords coords = new CornerCoords(); float corner = position.x - scale.x / 2f; coords.xStart = Mathf.RoundToInt(Mathf.Clamp(corner / cellSize.x, 0, dimensions.x * 16)); corner = position.x + scale.x / 2f; coords.xEnd = Mathf.RoundToInt(Mathf.Clamp(corner / cellSize.x, 0, dimensions.x * 16)); corner = position.y - scale.y / 2f; coords.yStart = Mathf.RoundToInt(Mathf.Clamp(corner / cellSize.y, 0, dimensions.y * 16)); corner = position.y + scale.y / 2f; coords.yEnd = Mathf.RoundToInt(Mathf.Clamp(corner / cellSize.y, 0, dimensions.y * 16)); corner = position.z - scale.z / 2f; coords.zStart = Mathf.RoundToInt(Mathf.Clamp(corner / cellSize.z, 0, dimensions.z * 16)); corner = position.z + scale.z / 2f; coords.zEnd = Mathf.RoundToInt(Mathf.Clamp(corner / cellSize.z, 0, dimensions.z * 16)); return(coords); }
public void Initialize(GridDimensions dimensions) { this.dimensions = dimensions; InitializeComputeBuffer(); InitializeComputeShader(); InitializeTexture3D(); InitializeMaterial(); material.SetVector("offset", new Vector4(offset.x, offset.y, offset.z, 1)); material.SetVector("scale", new Vector4(scale.x, scale.y, scale.z, 1)); material.SetVector("dimensions", new Vector4(1.0f / (dimensions.x * 32), 1.0f / (dimensions.y * 32), 1.0f / (dimensions.z * 32), 1)); material.SetTexture("_MainTex", texture3D); material.SetBuffer("mesh", mesh); }
public virtual List <CornerCoords> getObstacleCorners(GPUFluid.GridDimensions dimensions, Vector3 _scale) { return(cornerCoordList); }