2017-08-16 16 views
1

私は現在、自分のゲーム用のカスタムマップを生成するマッピングツールを開発中です。私はメッシュジェネレーションを完璧に動作させていますが、テクスチャを一貫性のあるものにするためにUVマップを正しくUVマップする方法を理解することはできません。私は、それぞれの座標ペアを使って完全に床に作業しているUVマップを持っていますが、壁は同じように動作していないようです。壁をUVマップする適切な方法は何ですか?

UVマップを垂直の壁にマップする適切な方法を知っている人はいますか?

ここでは私の現在の壁のいくつかの例は以下のとおりです。 enter image description here enter image description here

私は現在、私は、このような状況のために

 currentMesh.uvs.Add(new Vector2(0, 0)); 
     currentMesh.uvs.Add(new Vector2(1, 0)); 
     currentMesh.uvs.Add(new Vector2(0, 1)); 
     currentMesh.uvs.Add(new Vector2(1, 1)); 

答えて

1

私は数字に管理していますそれを出す。私は

 Vector3 heading = new Vector3(floor2.x - floor1.x, 0, floor2.z - floor1.z); 
     Vector3 direction = heading/heading.magnitude; 

     currentMesh.uvs.Add(new Vector2(((floor1.x * direction.x) + (floor1.z * direction.z))/scale, floor1.y/scale)); 
     currentMesh.uvs.Add(new Vector2(((floor2.x * direction.x) + (floor2.z * direction.z))/scale, floor2.y/scale)); 
     currentMesh.uvs.Add(new Vector2(((ceil1.x * direction.x) + (ceil1.z * direction.z))/scale, ceil1.y/scale)); 
     currentMesh.uvs.Add(new Vector2(((ceil2.x * direction.x) + (ceil2.z * direction.z))/scale, ceil2.y/scale)); 

enter image description here

を望んでいた私は、頂点の XZを取り、壁の方向に応じて、2つの重量を取っていたやってしまった、それが結果になってしまった何か
1

壁のUVマッピングのためにこれを使用しています次の手順を実行します。
1.テクスチャを正方形にします(下のコードで計算を減らすため)。また、シームレスで折り返しモードを繰り返します。
2.このような長方形の長さと幅を見つける:このコードを使用して

Length = (float)Vector3.Distance(mesh.vertices [0],mesh.vertices [1]) 
Width = (float)Vector3.Distance(mesh.vertices [0],mesh.vertices [3]) 

3.Then I UVマップ:私は .Z を取った、ここで

Vector2[] uv = new Vector2[mesh.vertices.Length]; 
    float min = Length>Width?Length:Width; 
    for (int i = 0, y = 0; i < uv.Length; i++){ 
     uv [i] = new Vector2 ((float)mesh.vertices [i].z/min, (float)mesh.vertices [i].y/min);  
    } 

をし、 .y、私の平面がyz平面にあるので。このコードがしていることは、矩形の小さな腕を見つけ、それに従ってテクスチャにフィットします。私はここからこれを学んだ
enter image description here

:ここenter image description here

は、私が使用するテクスチャです:
はここでの結果のスクリーンショットです
http://catlikecoding.com/unity/tutorials/procedural-grid/

関連する問題