diff --git a/DirtBlock.png b/DirtBlock.png new file mode 100644 index 0000000..222d5c5 Binary files /dev/null and b/DirtBlock.png differ diff --git a/ImageTextureTrial2.py b/ImageTextureTrial2.py new file mode 100644 index 0000000..a8f198b --- /dev/null +++ b/ImageTextureTrial2.py @@ -0,0 +1,22 @@ +# Link to the code from StackExchange: https://blender.stackexchange.com/questions/157531/blender-2-8-python-add-texture-image + +#Import python +import bpy +from bpy import context, data, ops + + +mat = bpy.data.materials.new(name="New_Mat") +mat.use_nodes = True +bsdf = mat.node_tree.nodes["Principled BSDF"] +texImage = mat.node_tree.nodes.new('ShaderNodeTexImage') +texImage.image = bpy.data.images.load("C:\\Users\\satna\\OneDrive\\Desktop\\Programming\\Python\\Blender\\Blender-World-Generator\\DirtBlock.png") +mat.node_tree.links.new(bsdf.inputs['Base Color'], texImage.outputs['Color']) + +ob = context.view_layer.objects.active + +# Assign it to object +if ob.data.materials: + ob.data.materials[0] = mat +else: + ob.data.materials.append(mat) + diff --git a/Trial.py b/Trial.py index 8291247..f017f93 100644 --- a/Trial.py +++ b/Trial.py @@ -8,9 +8,9 @@ size = 1; # Setting the x, y, and z positions. x = y = z = size / 2; # Setting the number of cubes in each coordinate. -xNum = 20; -yNum = 20; -zNum = 1; +xNum = 3; +yNum = 3; +zNum = 3; # Setting the initial value for the number of cubes in each recursive call. cubeCount = 0; # Setting the maximum amount of cubes that is needed to be created. @@ -71,4 +71,5 @@ spawnGround(); # - z is for creating cubes in the z axis. # - I need to add the materials to the cubes and somehow save it in the Blender program. # - I need to replace the nested for loop with a recursive function to spawn the ground. -# - I need to add a function to create a tree in a random position. This function will create cubes and put them in a way to look like a tree. It will also assign the correct materials to their proper cubes. \ No newline at end of file +# - I need to add a function to create a tree in a random position. This function will create cubes and put them in a way to look like a tree. It will also assign the correct materials to their proper cubes. +# - I need to find a way to create creat and assign a single material to all the respective cubes. \ No newline at end of file