第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 SetAlphamaps 設(shè)置為某一特定紋理?

如何將 SetAlphamaps 設(shè)置為某一特定紋理?

PHP
不負(fù)相思意 2024-01-21 10:15:39
我想用特定的紋理改變我的地形的紋理。我對設(shè)置 splatmapdata 感到困惑,任何人都可以幫助我嗎?private void ChangeTexture(Vector3 WorldPos){    print ("changeTexture");    int mapX = (int)(((WorldPos.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth);    int mapZ = (int)(((WorldPos.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight);    float[,,] splatmapData = terrainData.GetAlphamaps(3, 3, 15, 15);    terrainData.SetAlphamaps (mapX, mapZ, splatmapData);    terrain.Flush ();}
查看完整描述

1 回答

?
慕田峪9158850

TA貢獻1794條經(jīng)驗 獲得超7個贊

返回的數(shù)據(jù)由GetAlphamaps

返回的數(shù)組是三維的 - 前兩個維度表示地圖上的 x 和 y 坐標(biāo),而第三個維度表示應(yīng)用 alphamap 的 splatmap 紋理。

或者簡單來說就是“float[x, y, l]哪里”

  • x= 寬度(以像素為單位)

  • y= 高度(以像素為單位)

  • l= 紋理層

假設(shè)您想將其設(shè)置為該像素坐標(biāo)處的某個紋理,您要做的就是

  • 將紋理層的權(quán)重設(shè)置為1

  • 將所有其他層權(quán)重設(shè)置為0

假設(shè)您有 3 層,并且您希望第二層(=索引1)是完全加權(quán)的紋理:

float[,,] splatmapData = terrainData.GetAlphamaps(mapX, mapZ, 15, 15);


// Iterate over x-y coordinates within the array

for(var y = 0; i < 15; y++)

{

? ? for(var x = 0; x < 15; x++)

? ? {

? ? ? ? // Set first layers weight to 0

? ? ? ? splatmapData[x, y, 0] = 0;


? ? ? ? // Set second layer's weight to 1

? ? ? ? splatmapData[x, y, 1] = 1;


? ? ? ? // Set third layer's weight to 0

? ? ? ? splatmapData[x, y, 2] = 0;

? ? }

}


terrainData.SetAlphamaps(mapX, mapZ, splatmapData);

然后我會enum為各層實現(xiàn)一個,比如


public enum TerrainLayer

{

? ? Default = 0,

?

? ? Green,

? ? Red

}

因此您可以簡單地將相應(yīng)的圖層索引作為參數(shù)傳遞 - 比傳遞值本身更安全int:


private void ChangeTexture(Vector3 worldPos, TerrainLayer toLayer)

{

? ? print ("changeTexture");


? ? int mapX = (int)(((worldPos.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth);

? ? int mapZ = (int)(((worldPos.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight);


? ? float[,,] splatmapData = terrainData.GetAlphamaps(mapX, mapZ, 15, 15);


? ? for(var z = 0; z < 15; z++)

? ? {

? ? ? ? for(var x = 0; x < 15; x++)

? ? ? ? {

? ? ? ? ? ? // This ofcourse would be more efficient if you do this only once

? ? ? ? ? ? // e.g. in Awake since the enum won't change on runtime

? ? ? ? ? ? var values = (TerrainLAyer[])Enum.GetValues(typeof(TerrainLayer));


? ? ? ? ? ? // Iterate through the enum and?

? ? ? ? ? ? for(var l = 0; l < values.Length; l++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? // set all layers to 0 except the toLayer

? ? ? ? ? ? ? ? splatmapData[x, z, l] = values[l] == toLayer ? 1 : 0;

? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? terrainData.SetAlphamaps (mapX, mapZ, splatmapData);

? ? terrain.Flush ();

}

現(xiàn)在你可以簡單地稱它為例如


ChangeTexture(somePosition, TerrainLayer.Green);


查看完整回答
反對 回復(fù) 2024-01-21
  • 1 回答
  • 0 關(guān)注
  • 234 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號