38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace AmazingAssets.TerrainToMesh.Example
|
|
{
|
|
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
|
public class ExportMeshAndSplatmap : MonoBehaviour
|
|
{
|
|
public TerrainData terrainData;
|
|
|
|
public int vertexCountHorizontal = 100;
|
|
|
|
public int vertexCountVertical = 100;
|
|
|
|
[Space(10f)]
|
|
public bool exportHoles;
|
|
|
|
public bool createFallbackTextures;
|
|
|
|
private void Start()
|
|
{
|
|
if (!(terrainData == null))
|
|
{
|
|
Mesh sharedMesh = terrainData.TerrainToMesh().ExportMesh(vertexCountHorizontal, vertexCountVertical, Normal.CalculateFromMesh);
|
|
GetComponent<MeshFilter>().sharedMesh = sharedMesh;
|
|
Material material = terrainData.TerrainToMesh().ExportSplatmapMaterial(exportHoles);
|
|
GetComponent<Renderer>().sharedMaterial = material;
|
|
if (createFallbackTextures)
|
|
{
|
|
Texture2D value = terrainData.TerrainToMesh().ExportBasemapDiffuseTexture(1024, exportHoles, unpack: false);
|
|
Texture2D value2 = terrainData.TerrainToMesh().ExportBasemapNormalTexture(1024, unpack: false);
|
|
material.SetTexture(Utilities.GetMaterailPropMainTex(), value);
|
|
material.SetTexture(Utilities.GetMaterailPropBumpMap(), value2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|