private void MoveCurrentSegmentLevel(int delta) { var newLevelIndex = (_levels.Count + _levels.IndexOf(_selectedLevel) + delta) % _levels.Count; _selectedLevel = _levels[newLevelIndex]; Debug.Log("HeightPyramidExplorer: selected level " + _selectedLevel); }
public void DisableLevelShapes(HeightPyramidLevel level) { foreach (var heightPyramidSegmentShapeGroup in _perLevelEntites.Where(c => c.Key == level).Select(c => c.Value.ShapeGroup)) { heightPyramidSegmentShapeGroup.DisableShapes(); } }
public static MyRectangle TerrainShapeSegmentAlignedPositionToWorldSpaceArea(HeightPyramidLevel level, HeightPyramidPerLevelConfiguration perLevelConfiguration, IntVector2 segmentAlignedPosition) { var segmentLength = perLevelConfiguration.BiggestShapeObjectInGroupLength; if (level == HeightPyramidLevel.Mid) { segmentAlignedPosition = segmentAlignedPosition + new IntVector2(-1, 0); } else if (level == HeightPyramidLevel.Top) { segmentAlignedPosition = segmentAlignedPosition + new IntVector2(-8, -4); } var surfaceWorldSpaceRectangle = new MyRectangle(segmentAlignedPosition.X * segmentLength, segmentAlignedPosition.Y * segmentLength , segmentLength, segmentLength); //if (level == HeightPyramidLevel.Mid) //{ // surfaceWorldSpaceRectangle = RectangleUtils.MoveBy(surfaceWorldSpaceRectangle, new Vector2(90 * 8 * 1, 0)); //} //else if (level == HeightPyramidLevel.Top) //{ // surfaceWorldSpaceRectangle = RectangleUtils.MoveBy(surfaceWorldSpaceRectangle, new Vector2(90 * -8, 90*-4)); //} return(surfaceWorldSpaceRectangle); }
public void Initialize(List <HeightPyramidLevel> levels, Texture floorTexturesArray, IntVector2 slotMapSize, Dictionary <int, Vector2> ringsUvRange, Dictionary <HeightPyramidLevel, float> perLevelBiggestShapeLengths) { _levels = levels; _selectedLevel = _levels.First(); _floorTexturesArray = floorTexturesArray; _slotMapSize = slotMapSize; ExplorerMaterial.SetTexture("_FloorTexturesArray", floorTexturesArray); ExplorerMaterial.SetVector("_SlotMapSize", new Vector4(slotMapSize.X, slotMapSize.Y, 0, 0)); var packedRingRanges = new Vector4(); for (int i = 0; i < ringsUvRange.Count; i++) { packedRingRanges[i] = ringsUvRange[i].y; } ExplorerMaterial.SetVector($"_RingsUvRange", packedRingRanges); var perLevelFloorTextureWorldSpaceSize = perLevelBiggestShapeLengths.ToDictionary(c => c.Key, c => c.Value * slotMapSize.X); //TODO what whith Y var packedSizes = new Vector4(); foreach (var pair in perLevelFloorTextureWorldSpaceSize) { packedSizes[pair.Key.GetIndex()] = pair.Value; } ExplorerMaterial.SetVector("_PerLevelFloorTextureWorldSpaceSizes", packedSizes); _fillingStateBuffer = new ComputeBuffer(slotMapSize.X * slotMapSize.Y * _levels.Count, System.Runtime.InteropServices.Marshal.SizeOf(typeof(GpuSingleSegmentState))); ExplorerMaterial.SetBuffer("_FillingStateBuffer", _fillingStateBuffer); }
private Vector2 WorldSpaceToLevelUvSpace(Vector2 worldSpace, HeightPyramidLevel levelIndex, Dictionary <HeightPyramidLevel, Vector2> levelCentersWorldSpace) { Vector2 levelWorldSize = _floorTextureWorldSizes[levelIndex]; Vector2 pyramidCenterWorldSize = levelCentersWorldSpace[levelIndex]; return(((worldSpace - pyramidCenterWorldSize) / (levelWorldSize)).Add(0.5f)); }
public void UpdateUniforms(HeightPyramidSegmentShapeGroup group, HeightPyramidLevel groupLevel, Vector2 travelerPosition , Dictionary <HeightPyramidLevel, LocationParametersUniforms> uniformsForAllLevels) { var thisLevelUniforms = uniformsForAllLevels[groupLevel]; group.ETerrainMaterials.ForEach(c => { c.SetVector("_TravellerPositionWorldSpace", travelerPosition); c.SetVector("_MainPyramidCenterWorldSpace", thisLevelUniforms.PyramidCenterWorldSpace); }); }
public void InitializePyramidUniforms(HeightPyramidSegmentShapeGroup @group, HeightPyramidLevel groupLevel, List <EGroundTexture> floorTextureArrays, int levelsCount, int ringsPerLevelCount) { group.ETerrainMaterials.ForEach(c => { c.SetInt("_LevelsCount", levelsCount); c.SetInt("_RingsPerLevelCount", ringsPerLevelCount); c.SetInt("_ThisLevelIndex", groupLevel.GetIndex()); foreach (var aFloorTextureArray in floorTextureArrays) { c.SetTexture("_" + aFloorTextureArray.TextureType.GetName(), aFloorTextureArray.Texture); } }); }
public static HeightPyramidLevel?GetHigherLevel(this HeightPyramidLevel level) { switch (level) { case HeightPyramidLevel.Bottom: return(HeightPyramidLevel.Mid); case HeightPyramidLevel.Mid: return(HeightPyramidLevel.Top); case HeightPyramidLevel.Top: return(null); } return(null); }
public static FlatLod HeightPyramidLevelToSurfaceTextureFlatLod(HeightPyramidLevel level) { switch (level) { case HeightPyramidLevel.Top: return(new FlatLod(0, 0)); case HeightPyramidLevel.Mid: return(new FlatLod(1, 0)); case HeightPyramidLevel.Bottom: return(new FlatLod(2, 0)); } Preconditions.Fail($"Unsupported HeightPyramidLevel {level}"); return(new FlatLod(-1, -1)); }
public void AddListener(HeightPyramidLevel level, UnityThreadCompoundSegmentFillingListener listener) { Preconditions.Assert(!_listenersDict.ContainsKey(level), $"There aelaady is listener from level {level}"); _listenersDict[level] = listener; }
public static int GetIndex(this HeightPyramidLevel level) { return((int)level); }
public HeightPyramidSegmentShapeGroup CreateGroup(HeightPyramidLevelTemplate pyramidLevelTemplate, HeightPyramidLevel level, GameObject pyramidRootGo) { var parentGO = new GameObject("ETerrainParent " + level); var center = pyramidLevelTemplate.Center; parentGO.transform.localPosition = new Vector3(center.x, 0, center.y); var objectsPerRing = pyramidLevelTemplate.PerRingTemplates.Keys.ToDictionary(c => c, c => new List <GameObject>()); GameObject centerObject = null; var ring1ElementMesh = _meshGenerator.AddOrder(() => PlaneGenerator.CreateETerrainSegmentMesh( _perLevelConfiguration.RingObjectMeshVertexLength.X, _perLevelConfiguration.RingObjectMeshVertexLength.Y)).Result; //todo ring1ElementMesh.RecalculateBounds(); MeshGenerationUtils.SetYBounds(ring1ElementMesh, 0f, 1f); foreach (var shapeTemplate in pyramidLevelTemplate.ShapeTemplates) { if (shapeTemplate.RingIndex == 0) //center { var centerMesh = _meshGenerator.AddOrder(() => PlaneGenerator.CreateETerrainSegmentMesh(_perLevelConfiguration.CenterObjectMeshVertexLength.X, _perLevelConfiguration.CenterObjectMeshVertexLength.Y)) .Result; //todo MeshGenerationUtils.SetYBounds(centerMesh, 0f, 1f); centerObject = CreateShapeObject(centerMesh, shapeTemplate, "Center"); centerObject.transform.SetParent(parentGO.transform); } else { var shape = CreateShapeObject(ring1ElementMesh, shapeTemplate, "Ring " + shapeTemplate.RingIndex); shape.transform.SetParent(parentGO.transform); objectsPerRing[shapeTemplate.RingIndex].Add(shape); } } parentGO.transform.localScale = new Vector3(1, _commonConfiguration.YScale, 1); parentGO.transform.SetParent(pyramidRootGo.transform); return(new HeightPyramidSegmentShapeGroup() { CentralShape = centerObject, ParentGameObject = parentGO, ShapesPerRing = objectsPerRing }); }
public HeightPyramidSegmentShapeGroup CreateGroup(HeightPyramidLevelTemplate pyramidLevelTemplate, HeightPyramidLevel level, GameObject pyramidRootGo) { var parentGO = new GameObject("ETerrainParent " + level); var center = pyramidLevelTemplate.Center; parentGO.transform.localPosition = new Vector3(center.x, 0, center.y); var ringTemplateElementMesh = _meshGenerator.AddOrder(() => PlaneGenerator.CreateETerrainSegmentMesh(_perLevelConfiguration.RingObjectMeshVertexLength.X, _perLevelConfiguration.RingObjectMeshVertexLength.Y)) .Result; //todo var centerMesh = _meshGenerator.AddOrder(() => PlaneGenerator.CreateETerrainSegmentMesh(_perLevelConfiguration.CenterObjectMeshVertexLength.X, _perLevelConfiguration.CenterObjectMeshVertexLength.Y)) .Result; //todo var shapeMeshesToCombine = new List <CombineInstance>(); foreach (var shapeTemplate in pyramidLevelTemplate.ShapeTemplates) { Mesh thisSegmentMesh = null; if (shapeTemplate.RingIndex == 0) //center { thisSegmentMesh = centerMesh; } else { thisSegmentMesh = ringTemplateElementMesh; } var trs = CreateTrsMatrixForShape(shapeTemplate); shapeMeshesToCombine.Add(new CombineInstance() { transform = trs, mesh = thisSegmentMesh }); } var finalMesh = _meshGenerator.AddOrder(() => { var m = MeshGenerationUtils.CreateMeshAsSum(shapeMeshesToCombine); MeshGenerationUtils.RecalculateUvAsInPlane(m); return(m); }).Result; //TODO MeshGenerationUtils.SetYBoundsToInfinity(finalMesh); var mainObject = CreateShapeObject(finalMesh, "MainObject", center, pyramidLevelTemplate.FlatSize); mainObject.transform.SetParent(parentGO.transform); parentGO.transform.localScale = new Vector3(1, _commonConfiguration.YScale, 1); parentGO.transform.SetParent(pyramidRootGo.transform); return(new HeightPyramidSegmentShapeGroup() { CentralShape = mainObject, ParentGameObject = parentGO, }); }
public void AddSegment(Texture segmentTexture, HeightPyramidLevel levelOf, IntVector2 segmentAlignedPosition) { var placementDetails = _levelManagers[levelOf].Place(segmentAlignedPosition); _placer.PlaceSegmentAsync(segmentTexture, placementDetails); }
public static MyRectangle SurfaceTextureSegmentAlignedPositionToWorldSpaceArea(HeightPyramidLevel level, HeightPyramidPerLevelConfiguration perLevelConfiguration, IntVector2 segmentAlignedPosition) { var segmentLength = perLevelConfiguration.BiggestShapeObjectInGroupLength; var floatSegmentAlignedPosition = segmentAlignedPosition.ToFloatVec(); if (level == HeightPyramidLevel.Mid) { floatSegmentAlignedPosition = floatSegmentAlignedPosition + new Vector2(-1, -0.5f); } else if (level == HeightPyramidLevel.Top) { floatSegmentAlignedPosition = floatSegmentAlignedPosition + new Vector2(-8, -4); } else { floatSegmentAlignedPosition = floatSegmentAlignedPosition + new Vector2(-1 / 8f, -1 / 16f); } var surfaceWorldSpaceRectangle = new MyRectangle(floatSegmentAlignedPosition.x * segmentLength, floatSegmentAlignedPosition.y * segmentLength , segmentLength, segmentLength); return(surfaceWorldSpaceRectangle); }
public static TerrainCardinalResolution HeightPyramidLevelToTerrainShapeDatabaseResolution(HeightPyramidLevel level) { switch (level) { case HeightPyramidLevel.Top: return(TerrainCardinalResolution.MAX_RESOLUTION); case HeightPyramidLevel.Mid: return(TerrainCardinalResolution.MID_RESOLUTION); case HeightPyramidLevel.Bottom: return(TerrainCardinalResolution.MIN_RESOLUTION); } Preconditions.Fail($"Unsupported HeightPyramidLevel {level}"); return(null); }