import bpy from math import atan2, pi import mathutils # Delete default cube if present # Our delete all function would have worked fine too if "Cube" in bpy.data.objects: bpy.data.objects["Cube"].select_set(True) bpy.ops.object.delete() bpy.ops.mesh.primitive_grid_add(size=1, x_subdivisions=100, y_subdivisions=100, calc_uvs=True) cube = bpy.context.active_object # Only need one material material = bpy.data.materials.new(name=f"FaceMaterial") material.use_nodes = True texture = bpy.data.images.load("amb.jpg") cube.data.materials.append(material) bsdf_node = material.node_tree.nodes.get("Principled BSDF") texture_node = material.node_tree.nodes.new(type="ShaderNodeTexImage") texture_node.image = texture material.node_tree.links.new(texture_node.outputs["Color"], bsdf_node.inputs["Base Color"]) c3 = mathutils.Vector((.387, .291 )) c2 = mathutils.Vector((.391, .732 )) c1 = mathutils.Vector((.657, .649 )) c0 = mathutils.Vector((.658, .378 )) for i, poly in enumerate(cube.data.polygons): uv_layer = cube.data.uv_layers.active.data for j, loop_index in enumerate(poly.loop_indices): vco = cube.data.vertices[poly.vertices[j]].co x,y = (0.5 + vco.x, 0.5 + vco.y) y = (y ** 1.4 ) tc = (1-x)*(1-y)*c1 + (1-x)*y*c2 + x*(1-y)*c0 + x*y*c3 uv_layer[loop_index].uv = tc # For each point in our grid of points: # Calculate the texture coordinate using bilinear interpolation cube.scale = (5, 10, 1) # Copy over uv values