返回介绍

TerrainData.SetAlphamaps 设置透明贴图

发布于 2019-12-18 15:38:37 字数 3022 浏览 1294 评论 0 收藏 0

JavaScript => public function SetAlphamaps(x: int, y: int, map: float[,,]): void;
C# => public void SetAlphamaps(int x, int y, float[,,] map);

Description 描述

Assign all splat values in the given map area.
在指定的区域内分配溅斑值。

The array supplied to this function determines the width and height of the portion to be replaced. The third dimension of the array corresponds to the number of splatmap textures.
数组提供给这个函数要替换的部分的宽度和高度。该三维数组与splatmap贴图数量相匹配。

JavaScript:

	// Blend the two terrain textures according to the steepness of
	// the slope at each point.
	function Start () {
		var map: float[,,] = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 2];
 
		// For each point on the alphamap...
		for (var y = 0; y < t.terrainData.alphamapHeight; y++) {
			for (var x = 0; x < t.terrainData.alphamapWidth; x++) {
				// Get the normalized terrain coordinate that
				// corresponds to the the point.
				var normX = x * 1.0 / (t.terrainData.alphamapWidth - 1);
				var normY = y * 1.0 / (t.terrainData.alphamapHeight - 1);
 
				// Get the steepness value at the normalized coordinate.
				var angle = t.terrainData.GetSteepness(normX, normY);
 
				// Steepness is given as an angle, 0..90 degrees. Divide
				// by 90 to get an alpha blending value in the range 0..1.
				var frac = angle / 90.0;
				map[x, y, 0] = frac;
				map[x, y, 1] = 1 - frac;
			}
		}
 
		t.terrainData.SetAlphamaps(0, 0, map);
	}

C#:

// Blend the two terrain textures according to the steepness of
	// the slope at each point.
	function Start () {
		var map: float[,,] = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 2];
 
		// For each point on the alphamap...
		for (var y = 0; y < t.terrainData.alphamapHeight; y++) {
			for (var x = 0; x < t.terrainData.alphamapWidth; x++) {
				// Get the normalized terrain coordinate that
				// corresponds to the the point.
				var normX = x * 1.0 / (t.terrainData.alphamapWidth - 1);
				var normY = y * 1.0 / (t.terrainData.alphamapHeight - 1);
 
				// Get the steepness value at the normalized coordinate.
				var angle = t.terrainData.GetSteepness(normX, normY);
 
				// Steepness is given as an angle, 0..90 degrees. Divide
				// by 90 to get an alpha blending value in the range 0..1.
				var frac = angle / 90.0;
				map[x, y, 0] = frac;
				map[x, y, 1] = 1 - frac;
			}
		}
 
		t.terrainData.SetAlphamaps(0, 0, map);
	}

terraindata

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文