# how can I fix this generated coordinated texture wrap?

I just want to use a simple brick texture as generated and wrapped a mesh object seamlessly, however it looks like below, I don't want to use UV map as I will be working with all different types of meshes, how can I fix this please? thanks blend file is http://www.pasteall.org/blend/42548

• ok, i've added the blend file @ShadyPuck – ideorium Jun 29 '16 at 12:20
• The base problem here is that the bricks texture is 2d by nature. You can fix this with some clever node work. Basically you need to mask your faces by normal, so you can map them using different UVs depending on the direction they are facing. – Duarte Farrajota Ramos Jun 29 '16 at 12:33

ok... this is not simple or there is something I really ignore about brick texture.

So here is some nodes which aim to determine which direction (X, Y, Z) has the most influence on a face.

After that, the idea is to fake the brick texture giving it a false Z direction depending on the axis which has the most influence on the face. Here are the full nodes: The top part is a comparison based on the dot product of the face normals respectively with (1, 0, 0), (0, 1, 0) and (0, 0, 1) vectors. Then it tests which is the bigger value (X, Y or Z).

The bottom part, recombine X, Y, and Z into "fake Z direction" and this fake Z direction is driven by the mix RGB (applied as vectors) with a factor determined by the calculation above.

(probably, I will be ridiculous when someone will answer "hey ! there is this simple option here ! ...)

edit : for the smooth shading meshes, replace the "normal" from texture coordinate, with "true normal" from geometry, like this : The result is better : If you are willing to automatically generate UV maps, you might be interested in the python script at http://web.purplefrog.com/~thoth/blender/python-cookbook/uv-from-geometry-cubic.html . It assigns a UV map automatically by guessing which axis a polygon is facing.

import bpy
import bmesh
from math import *
from mathutils import *

def set_uvs_for_face(bm, fi, uv_layer):
face = bm.faces[fi]
normal = face.normal
dx=abs(normal)
dy=abs(normal)
dz=abs(normal)

if (dz > dx):
u = Vector([1,0,0])
if (dz>dy):
v = Vector([0,1,0])
else:
v = Vector([0,0,1])
else:
v = Vector([0,0,1])
if dx>dy:
u = Vector([0,1,0])
else:
u = Vector([1,0,0])
for i in range(len(face.loops)):
l = face.loops[i]
l[uv_layer].uv = [ u.dot(l.vert.co),
v.dot(l.vert.co)]

def set_uvs(mesh, name=None):

if name is None:
if 0<len(mesh.uv_textures):
uv = mesh.uv_textures
else:
uv = mesh.uv_textures.new("cubic")
else:
uv = mesh.uv_textures.get(name)
if uv is None:
uv = mesh.uv_textures.new(name)

bm = bmesh.new()
bm.from_mesh(mesh)
bm.faces.ensure_lookup_table()

uv_layer = bm.loops.layers.uv[uv.name]

for fi in range(len(bm.faces)):
set_uvs_for_face(bm, fi, uv_layer)

bm.to_mesh(mesh)

#
#
#

mode = bpy.context.mode
if 'OBJECT' != mode:
bpy.ops.object.mode_set(mode='OBJECT')

obj = bpy.context.active_object
set_uvs(obj.data)

if 'OBJECT' != mode:
bpy.ops.object.mode_set(mode = mode)