diff --git a/Trial.py b/GenerateTerrain.py similarity index 97% rename from Trial.py rename to GenerateTerrain.py index f017f93..d007e79 100644 --- a/Trial.py +++ b/GenerateTerrain.py @@ -1,75 +1,75 @@ -#Imports. -import bpy; -import random; - -# Variables: -# Size of each cube. -size = 1; -# Setting the x, y, and z positions. -x = y = z = size / 2; -# Setting the number of cubes in each coordinate. -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. -numOfCubes = xNum * yNum * zNum; -print(numOfCubes); - -#Function to clean the scene. This removes all of the objects, collections, materials, particles, textures, images, curves, meshes, actions, nodes, and worlds from the scene. -def cleanScene(): - # Changes the mode to object mode if it is in Edit mode. - if (bpy.context.active_object and bpy.context.active_object.mode == "EDIT"): - bpy.ops.object.editmode_toggle(); - - # Checks for hidden stuff and unhides them. - for obj in bpy.data.objects: - obj.hide_set(False); - obj.hide_select = False; - obj.hide_viewport = False; - - # Selects all the objects and then deletes. - bpy.ops.object.select_all(action = "SELECT"); - bpy.ops.object.delete(); - -# Function to spawn the "ground" by creating several cubes using a nested for loop. -def spawnGround(): - # Iterate over each grid "cell" we want a cube at. - for x in range(xNum): - for y in range(yNum): - for z in range(zNum): - # Set the location. - location = (x, y, z); - - # Add the cubes. - bpy.ops.mesh.primitive_cube_add(size = size, location = location, scale = (size, size, size)); - # Set the newly created cube as the active object. - activeObject = bpy.context.active_object; - # Add a new material slot. - # bpy.ops.object.material_slot_add(); - # Creating a new material and assigning it to the active cube. - material = bpy.data.materials.new("Material"); - material.use_nodes = True; - materialNodes = material.node_tree.nodes; - materialLinks = material.node_tree.links; - - activeObject.data.materials.append(material); - - # Change the base colour. - materialNodes['Principled BSDF'].inputs['Base Color'].default_value = (1.0, 0.47, 1.0, 1.0); - -# Calling the functions: -cleanScene(); -spawnGround(); - - -# Notes: -# - For loop for the grid: -# - x is for creating cubes in the x axis. -# - y is for creating cubes in the y axis. -# - 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. +#Imports. +import bpy; +import random; + +# Variables: +# Size of each cube. +size = 1; +# Setting the x, y, and z positions. +x = y = z = size / 2; +# Setting the number of cubes in each coordinate. +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. +numOfCubes = xNum * yNum * zNum; +print(numOfCubes); + +#Function to clean the scene. This removes all of the objects, collections, materials, particles, textures, images, curves, meshes, actions, nodes, and worlds from the scene. +def cleanScene(): + # Changes the mode to object mode if it is in Edit mode. + if (bpy.context.active_object and bpy.context.active_object.mode == "EDIT"): + bpy.ops.object.editmode_toggle(); + + # Checks for hidden stuff and unhides them. + for obj in bpy.data.objects: + obj.hide_set(False); + obj.hide_select = False; + obj.hide_viewport = False; + + # Selects all the objects and then deletes. + bpy.ops.object.select_all(action = "SELECT"); + bpy.ops.object.delete(); + +# Function to spawn the "ground" by creating several cubes using a nested for loop. +def spawnGround(): + # Iterate over each grid "cell" we want a cube at. + for x in range(xNum): + for y in range(yNum): + for z in range(zNum): + # Set the location. + location = (x, y, z); + + # Add the cubes. + bpy.ops.mesh.primitive_cube_add(size = size, location = location, scale = (size, size, size)); + # Set the newly created cube as the active object. + activeObject = bpy.context.active_object; + # Add a new material slot. + # bpy.ops.object.material_slot_add(); + # Creating a new material and assigning it to the active cube. + material = bpy.data.materials.new("Material"); + material.use_nodes = True; + materialNodes = material.node_tree.nodes; + materialLinks = material.node_tree.links; + + activeObject.data.materials.append(material); + + # Change the base colour. + materialNodes['Principled BSDF'].inputs['Base Color'].default_value = (1.0, 0.47, 1.0, 1.0); + +# Calling the functions: +cleanScene(); +spawnGround(); + + +# Notes: +# - For loop for the grid: +# - x is for creating cubes in the x axis. +# - y is for creating cubes in the y axis. +# - 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. # - 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 diff --git a/TrialRecursive.py b/GenerateTerrainRecursively.py similarity index 100% rename from TrialRecursive.py rename to GenerateTerrainRecursively.py diff --git a/ImageTextureTrial.py b/ImageTextureTrial.py index a8f198b..c16a2ff 100644 --- a/ImageTextureTrial.py +++ b/ImageTextureTrial.py @@ -20,3 +20,5 @@ if ob.data.materials: else: ob.data.materials.append(mat) +# Notes: +# - Find a way to select a single face of a cube and then add the image to each face. Might have to do stuff with nodes. \ No newline at end of file