Hi,
I have create a basic square mseh via C# code like:
public Mesh CreatePlaneMesh()
{
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[]
{
new Vector3( 1, 1, 0),
new Vector3( 1, -1, 0),
new Vector3(-1, 1, 0),
new Vector3(-1, -1, 0),
};
Vector2[] uv = new Vector2[]
{
new Vector2(1, 1),
new Vector2(1, 0),
new Vector2(0, 1),
new Vector2(0, 0),
};
int[] triangles = new int[]
{
0, 1, 2,
2, 1, 3,
};
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
mesh.RecalculateNormals();
return mesh;
}
And a second mesh from an obj file.
When I display a texture2D on each of them everything work fine.
But when I assign a render texture. the render texture is display correctly on the square not on my own mesh. I can see only the last lign of my render texture on my mesh.
// create render texture
RenderTexture _RenderTexture = new RenderTexture(512, 512, 24);
_RenderTexture.Create();
_RenderTexture.name = "Camera render texture";
// render texture to Main camera
var original = GameObject.FindWithTag("MainCamera");
original.camera.targetTexture = _RenderTexture;
original.camera.Render();
// Render texture to plane texture
Material mat = new Material(Shader.Find("Diffuse"));
mat.name = "Camera Texture";
mat.SetTexture("_MainTex", _RenderTexture);
var plane = GameObject.Find("mesh");
plane.renderer.material = mat;
I do not understand why is wrong in my code because, the mmesh is working fine