Added code that actually adds an image texture.
This commit is contained in:
BIN
DirtBlock.png
Normal file
BIN
DirtBlock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
22
ImageTextureTrial2.py
Normal file
22
ImageTextureTrial2.py
Normal file
@@ -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)
|
||||||
|
|
7
Trial.py
7
Trial.py
@@ -8,9 +8,9 @@ size = 1;
|
|||||||
# Setting the x, y, and z positions.
|
# Setting the x, y, and z positions.
|
||||||
x = y = z = size / 2;
|
x = y = z = size / 2;
|
||||||
# Setting the number of cubes in each coordinate.
|
# Setting the number of cubes in each coordinate.
|
||||||
xNum = 20;
|
xNum = 3;
|
||||||
yNum = 20;
|
yNum = 3;
|
||||||
zNum = 1;
|
zNum = 3;
|
||||||
# Setting the initial value for the number of cubes in each recursive call.
|
# Setting the initial value for the number of cubes in each recursive call.
|
||||||
cubeCount = 0;
|
cubeCount = 0;
|
||||||
# Setting the maximum amount of cubes that is needed to be created.
|
# Setting the maximum amount of cubes that is needed to be created.
|
||||||
@@ -72,3 +72,4 @@ spawnGround();
|
|||||||
# - I need to add the materials to the cubes and somehow save it in the Blender program.
|
# - 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 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.
|
# - 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.
|
Reference in New Issue
Block a user