# Immediate Geometry Texturing

Attention Topic was automatically imported from the old Question2Answer platform.

Hello All,

I am currently experimenting with using intimidate geometry in one of my projects. I have used this as I have some dynamic models that vary frame on frame.

Although at my current point I am struggling to get a texture applied to the mesh I am creating. I was wondering if any of you had some pointers of how to get this done or an example that I could work backwards so I can learn?

My main goal would be to get a texture applied to the whole model, the nice to have down the line will be to apply sharers ect to make it nicer but for now just a simple static texture applied to the model will be nice.

If it is not possible to apply a texture then i would appropriate some guidance of how to properly color the model.

Textures need texture coordinates, a.k.a UVs. These are regular `Vector2` attributes you can add when building your geometry, for each vertex.
For example, a quad made of 4 vertices might have the following UVs: `(0,0), (1, 0), (1, 1), (0, 1)`.
More complex models require to think about “unwrapping”, like a paper origami, to properly layout the UVs. It can be based on typical primitives like cylinders, quads or spheres, which have several known working UV layouts.

A quick alternative for really complex models is to use triplanar mapping. This technique generates UVs based on vertex coordinates, at the cost of a few more computations in the shader, so that your mesh doesn’t need to have UVs. You can toggle this option in `SpatialMaterial`.

Note: the same applies to colors. You can color a model by changing `albedo` in the material, but you can also specify colors per vertex (if the material has `use_vertex_color_as_albedo` checked).

So at what point do I create this UV, will I have to dynamically create it each frame after I have used my calls to create the immediate geometry?

Also how is it possible to unwrap intimidate geometry as its mesh is not known at build time?

NewDevTrying | 2019-07-17 19:02

You have to do it for every vertex that you add to `ImmediateGeometry`. This is per vertex, so that the renderer knows which coordinate of the texture to use on every specific point of the mesh:

``````immediate_geometry.set_uv(uv1) # Used for the next vertex

immediate_geometry.set_uv(uv2) # Used for the next vertex

immediate_geometry.set_uv(uv3) # Used for the next vertex

# etc
``````

You might not know the mesh beforehands, but maybe you know at least what kind of mesh it is. Is it a ribbon? A tube? A heightmap? A completely arbitrary shape? If it’s the latter, triplanar shading might be easier.

Zylann | 2019-07-17 19:44

Ok, so I guess if you use set_uv, add_vertex pairs Then after I just apply a texture as normal once to the overall mesh?

NewDevTrying | 2019-07-17 19:49

Yes once you have UVs you can apply textures from a `SpatialMaterial`.

Zylann | 2019-07-17 19:50

thanks very much

NewDevTrying | 2019-07-17 20:43

How would i set the color of a Vertex in an Immediate Mesh?