1
$\begingroup$

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

enter image description here

blend file is http://www.pasteall.org/blend/42548

$\endgroup$
3
  • $\begingroup$ Can you upload your .blend file? $\endgroup$
    – Shady Puck
    Jun 29, 2016 at 12:00
  • $\begingroup$ ok, i've added the blend file @ShadyPuck $\endgroup$
    – ideorium
    Jun 29, 2016 at 12:20
  • $\begingroup$ 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. $\endgroup$ Jun 29, 2016 at 12:33

2 Answers 2

5
$\begingroup$

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.

enter image description here

Here are the full nodes:

enter image description here

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.

Here is the blend file :

(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 : enter image description here

The result is better : enter image description here

$\endgroup$
3
  • $\begingroup$ I actually develop a node setup with more flexibility but full copying your setup to discover normals. Is there any channel (chat/website) i can message you to show you my node setup and to get your consent to release it for free? $\endgroup$ Oct 29, 2022 at 15:04
  • $\begingroup$ @JoãoSantos you have my consent! no problem for that. $\endgroup$
    – lemon
    Oct 30, 2022 at 16:59
  • $\begingroup$ thanks friend. Im still working out some kinks 'cus i wanted to be fool proof and super easy to apply on any geometry. Using the generated of course. :) $\endgroup$ Nov 4, 2022 at 18:01
0
$\begingroup$

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[0])
    dy=abs(normal[1])
    dz=abs(normal[2])

    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[0]
        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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .