- Home /
Question by
Guirao · Sep 04, 2013 at 02:32 PM ·
texturemeshproceduralruntime-generation
Procedural quad, problem with texture
Hello I have a problem, I have created a quad in runtime (it's not a single triangle, acually there are two vertices in the left) and I have attached a material with the following image.
This is the result:
If I make a perfect square the result is good tho.
Some code:
void Start()
{
go = new GameObject();
go.transform.parent = null;
go.transform.position = Vector3.zero;
go.transform.rotation = Quaternion.identity;
go.AddComponent<MeshFilter>();
go.AddComponent<MeshRenderer>();
mesh = go.GetComponent<MeshFilter>().mesh;
renderer = go.GetComponent<MeshRenderer>();
renderer.material = material;
renderer.castShadows = false;
renderer.receiveShadows = false;
uv = new Vector2[]
{
new Vector2(0, 0),
new Vector2(0, 1),
new Vector2(1, 0),
new Vector2(1, 1),
};
triangles = new int[]
{
0, 2, 1,
1, 2, 3,
};
vertices = new Vector3[4];
}
Mesh CreatePlaneMesh(RaycastHit hit)
{
vertices[0] = -transform.forward * startHeight;
vertices[1] = hit.point-transform.position - transform.forward * endHeight;
vertices[2] = transform.forward * startHeight;
vertices[3] = hit.point-transform.position + transform.forward * endHeight;
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
mesh.RecalculateNormals();
return mesh;
}
I'm drawing the vertices like this:
0---------------1
| |
| |
2---------------3
problem3.jpg
(48.8 kB)
untitled-1.jpg
(12.6 kB)
Comment
Best Answer
Answer by fherbst · Sep 04, 2013 at 02:38 PM
What do you expect to happen? The output is exactly what's to be expected from your input vertices, uv and texture.
If you want the texture to be applied "from the front", just calculate the appropriate uv coordinates for your distortion, e.g. both the left vertices would have UV coords near (0, 0.5) in your example image.