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 void Merge(TerrainWeldUvs weldUv) { if (weldUv.LeftUv.x > -0.5f) { LeftUv = weldUv.LeftUv; } if (weldUv.TopUv.x > -0.5f) { TopUv = weldUv.TopUv; } if (weldUv.RightUv.x > -0.5f) { RightUv = weldUv.RightUv; } if (weldUv.BottomUv.x > -0.5f) { BottomUv = weldUv.BottomUv; } }
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 void CreateDebugObject(DebugObjectSpecification specification, Texture weldTexture, TerrainWeldUvs uvs) { var go = GameObject.CreatePrimitive(PrimitiveType.Plane); go.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(specification.MeshResolution.X, specification.MeshResolution.Y); Material material = new Material(Shader.Find("Custom/Test/TerrainWelding")); material.SetTexture("_HeightmapTex", specification.HeightTexture.Texture); material.SetVector("_HeightmapUv", specification.HeightmapUv); material.SetFloat("_HeightmapLodOffset", specification.HeightmapLodOffset); material.SetTexture("_WeldTexture", weldTexture); material.SetVector("_LeftWeldTextureUvRange", uvs.LeftUv); material.SetVector("_RightWeldTextureUvRange", uvs.RightUv); material.SetVector("_TopWeldTextureUvRange", uvs.TopUv); material.SetVector("_BottomWeldTextureUvRange", uvs.BottomUv); go.GetComponent <MeshRenderer>().material = material; go.transform.localPosition = new Vector3(specification.StartPos.x, 0, specification.StartPos.y); go.transform.localScale = specification.LocalScale; }