public StripRegistrationResult RegisterStrip(StripSide leader) { Preconditions.Assert( Math.Abs(leader.NormalizedMarginUvOfTerrain.x) < 0.00001f && Math.Abs(leader.NormalizedMarginUvOfTerrain.y - 1) < 0.00001f, "Leader's marginUv must be 0-1, but is " + leader.NormalizedMarginUvOfTerrain); for (int i = 0; i < _stripColumns.Length; i++) { var column = _stripColumns[i]; if (column.HasEmptyStrip) { var stripInColumnIndex = column.AllocateStrip(leader); return(new StripRegistrationResult() { StripPosition = new WeldStripPosition() { ColumnIndex = i, StripInColumnIndex = stripInColumnIndex }, WeldUvs = TerrainWeldUvs.CreateFrom(leader.WeldSideType, CreateNormalizedWeldRange( CalculateWeldRange(stripInColumnIndex, leader.NormalizedMarginUvOfTerrain), i)) }); } } Preconditions.Fail("E22. There are no empty strips"); return(null); }
public int AllocateStrip(StripSide leader) { Preconditions.Assert(HasEmptyStrip, "There is no empty strip in this column"); for (int i = 0; i < _strips.Length; i++) { if (_strips[i] == null) { _strips[i] = new WeldStrip() { Leader = leader, Followers = new List <StripSide>() }; return(i); } } Preconditions.Fail("E46 Not expected"); return(-1); }
public TerrainWeldUvs AddStipSegment(WeldStripPosition stripPosition, StripSide follower) { var strip = _stripColumns[stripPosition.ColumnIndex].GetSegment(stripPosition.StripInColumnIndex); strip.Followers.Add(follower); var leader = strip.Leader; var leaderSideInfo = CreateDrawingSideInfo(leader, follower.NormalizedMarginUvOfTerrain); var followerSideInfo = CreateDrawingSideInfo(follower, new Vector2(0, 1)); var donorSide = leaderSideInfo; var acceptorSide = followerSideInfo; if (follower.WeldSideType.IsDonorSide()) { donorSide = followerSideInfo; acceptorSide = leaderSideInfo; } var weldRange = CalculateWeldRange(stripPosition.StripInColumnIndex, follower.NormalizedMarginUvOfTerrain); WeldOnTextureInfo weldInfo = new WeldOnTextureInfo() { ColumnIndex = stripPosition.ColumnIndex, WeldRange = weldRange }; acceptorSide.SamplingDistance = weldInfo.WeldRange.Length / (acceptorSide.FullLodSidePixelsRange.Length - 1); donorSide.SamplingDistance = weldInfo.WeldRange.Length / (donorSide.FullLodSidePixelsRange.Length - 1); _weldingExecutor.RenderWeld(new WeldTextureDrawingOrder() { FirstSideInfo = acceptorSide, SecondSideInfo = donorSide, WeldOnTextureInfo = weldInfo }); return(TerrainWeldUvs.CreateFrom(follower.WeldSideType, CreateNormalizedWeldRange(weldRange, stripPosition.ColumnIndex))); }
private static WeldTextureDrawingSideInfo CreateDrawingSideInfo(StripSide leader, Vector2 normalizedMarginUvOfTerrain) { var texSize = new Vector2(leader.HeightTexture.Size.X - 1, leader.HeightTexture.Size.Y - 1); texSize = new Vector2(texSize.x / Mathf.Pow(2, leader.Lod), texSize.y / Mathf.Pow(2, leader.Lod)); var texAreaUvd = RectangleUtils.CalculateSubPosition(new MyRectangle(0, 0, texSize.x, texSize.y), leader.HeightTextureUvs); var constantCoord = 0; if (leader.WeldSideType == WeldSideType.Right) { constantCoord = Mathf.RoundToInt(texAreaUvd.MaxX); } else if (leader.WeldSideType == WeldSideType.Left) { constantCoord = Mathf.RoundToInt(texAreaUvd.X); } else if (leader.WeldSideType == WeldSideType.Top) { constantCoord = Mathf.RoundToInt(texAreaUvd.MaxY); } else if (leader.WeldSideType == WeldSideType.Bottom) { constantCoord = Mathf.RoundToInt(texAreaUvd.Y); } Vector2 baseFullSideRange; if (leader.WeldSideType.GetOrientation() == WeldOrientation.Horizontal) { baseFullSideRange = new Vector2(texAreaUvd.X, texAreaUvd.MaxX); } else { baseFullSideRange = new Vector2(texAreaUvd.Y, texAreaUvd.MaxY); } baseFullSideRange = VectorUtils.CalculateSubPosition(baseFullSideRange, normalizedMarginUvOfTerrain); var leaderSideLength = Mathf.RoundToInt(texAreaUvd.Width); if (leaderSideLength % 5 == 1) { leaderSideLength--; //change 241 to 240 etc } //leaderSideLength /= Mathf.RoundToInt(Mathf.Pow(2, leader.Lod)); int samplingDistance = 240 / leaderSideLength; WeldTextureDrawingSideInfo firstSideInfo = new WeldTextureDrawingSideInfo() { ConstantCoord = constantCoord, FullLodSidePixelsRange = new IntVector2(Mathf.RoundToInt(baseFullSideRange.x), Mathf.RoundToInt(baseFullSideRange.y + 1)), HeightTexture = leader.HeightTexture, LodLevel = leader.Lod, SamplingDistance = samplingDistance, SideType = leader.WeldSideType }; return(firstSideInfo); }