public MeshFromHeightmap3(MeshFromHeightmap3 copy) { Heightmap = (Content.DataLink <Texel.R32F[, ]>)copy.Heightmap.Clone(); HeightmapLayout = copy.HeightmapLayout; Grid = (Grid)copy.Grid.Clone(); Height = copy.Height; PointSample = copy.PointSample; HeightmapReadPosition = copy.HeightmapReadPosition; }
public static Mesh Construct(MeshFromHeightmap3 metaResource) { var indexedPlane = Construct(metaResource.Grid); int heightMapHeight = metaResource.Heightmap.Data.GetLength(0); int heightMapWidth = metaResource.Heightmap.Data.GetLength(1); Vector2 gridStep = new Vector2(metaResource.HeightmapLayout.Width / heightMapWidth, metaResource.HeightmapLayout.Height / heightMapHeight); for (int i = 0; i < indexedPlane.VertexBuffer.Count; i++) { var v = indexedPlane.VertexBuffer[i]; // 0 -> Heightmap size Vector2 relativePosition = Common.Math.ToVector2(v.Position + metaResource.HeightmapReadPosition) - new Vector2(metaResource.HeightmapLayout.X, metaResource.HeightmapLayout.Y); // 0 -> 1 relativePosition.X /= metaResource.HeightmapLayout.Width; relativePosition.Y /= metaResource.HeightmapLayout.Height; Texel.R32F height; if (metaResource.PointSample) { height = TextureUtil.HeightmapPointSample(metaResource.Heightmap.Data, relativePosition); } else { height = TextureUtil.HeightmapSample(metaResource.Heightmap.Data, relativePosition, true); } float h = metaResource.Grid.Position.Z + height.R * metaResource.Height; v.Position = new Vector3( v.Position.X, v.Position.Y, h); v.Normal = TextureUtil.NormalFromHeightmap(metaResource.Heightmap.Data, relativePosition, gridStep, new Size(heightMapWidth, heightMapHeight)); indexedPlane.VertexBuffer[i] = v; } return(indexedPlane); }
public static Mesh Construct(MeshFromHeightmap3 metaResource) { var indexedPlane = Construct(metaResource.Grid); int heightMapHeight = metaResource.Heightmap.Data.GetLength(0); int heightMapWidth = metaResource.Heightmap.Data.GetLength(1); Vector2 gridStep = new Vector2(metaResource.HeightmapLayout.Width / heightMapWidth, metaResource.HeightmapLayout.Height / heightMapHeight); for (int i = 0; i < indexedPlane.VertexBuffer.Count; i++) { var v = indexedPlane.VertexBuffer[i]; // 0 -> Heightmap size Vector2 relativePosition = Common.Math.ToVector2(v.Position + metaResource.HeightmapReadPosition) - new Vector2(metaResource.HeightmapLayout.X, metaResource.HeightmapLayout.Y); // 0 -> 1 relativePosition.X /= metaResource.HeightmapLayout.Width; relativePosition.Y /= metaResource.HeightmapLayout.Height; Texel.R32F height; if (metaResource.PointSample) height = TextureUtil.HeightmapPointSample(metaResource.Heightmap.Data, relativePosition); else height = TextureUtil.HeightmapSample(metaResource.Heightmap.Data, relativePosition, true); float h = metaResource.Grid.Position.Z + height.R * metaResource.Height; v.Position = new Vector3( v.Position.X, v.Position.Y, h); v.Normal = TextureUtil.NormalFromHeightmap(metaResource.Heightmap.Data, relativePosition, gridStep, new Size(heightMapWidth, heightMapHeight)); indexedPlane.VertexBuffer[i] = v; } return indexedPlane; }
public MeshFromHeightmap3(MeshFromHeightmap3 copy) { Heightmap = (Content.DataLink<Texel.R32F[,]>)copy.Heightmap.Clone(); HeightmapLayout = copy.HeightmapLayout; Grid = (Grid)copy.Grid.Clone(); Height = copy.Height; PointSample = copy.PointSample; HeightmapReadPosition = copy.HeightmapReadPosition; }