Показать сообщение отдельно
Старый 04.01.2011, 12:59   #17
Slayer
Нуждающийся
 
Регистрация: 23.09.2010
Сообщений: 54
Написано 8 полезных сообщений
(для 26 пользователей)
Ответ: Не получается натянуть текстуру на террайн

Да, конечно, вот код где назначаются текстуры:
SplatPrototype[] test = new SplatPrototype[3];
    
float[,,] splatmapData;
    
int Tw terrain.terrainData.heightmapWidth 1;
    
splatmapData terrain.terrainData.GetAlphamaps(00TwTw);
    
terrain.terrainData.alphamapResolution Tw;
    
//float[,,] splatmapData = new float[terrain.terrainData.alphamapWidth, terrain.terrainData.alphamapHeight, terrain.terrainData.alphamapLayers];
    
test[0] = new SplatPrototype();
    
test[0].texture = (Texture2D)Resources.Load("grass"typeof(Texture2D));
    
test[0].tileOffset = new Vector2(00);
    
test[0].tileSize = new Vector2(1515);
    
test[1] = new SplatPrototype();
    
test[1].texture = (Texture2D)Resources.Load("Balmoral"typeof(Texture2D));
    
test[1].tileOffset = new Vector2(00);
    
test[1].tileSize = new Vector2(1515);
    
test[1].texture.Apply(true);
    
test[2] = new SplatPrototype();
    
test[2].texture = (Texture2D)Resources.Load("grydirt2"typeof(Texture2D));
    
test[2].tileOffset = new Vector2(00);
    
test[2].tileSize = new Vector2(1515);
    
test[2].texture.Apply(true);
    
    
terrain.terrainData.splatPrototypes test
а вот кусок, где пытаюсь назначить эти текстуры:
for(int y=0terrain.terrainData.alphamapHeighty++)
    {
        for(
int x=0terrain.terrainData.alphamapWidthx++)
        {
        
float height terrain.terrainData.GetHeight(x,y);
        
Vector3 splat = new Vector3(0,1,0);
        if (
height 10.0) {
            
splat Vector3.Lerp(splat, new Vector3(0,0,1), (height-0.5f)*);
        } else {
            
splat Vector3.Lerp(splat, new Vector3(1,0,0), height*);
        }
        
        
splat.Normalize();
        
splatmapData[xy0] = splat.x;
        
splatmapData[xy1] = splat.y;
        
splatmapData[xy2] = splat.z;
        
        }
    }
    
    
terrain.terrainData.Flush(); 
Если нужно. могу выслать на мыло все куском.
(Offline)
 
Ответить с цитированием