Created a grid using cubes.

This commit is contained in:
CJ Satnarine
2023-03-21 12:58:09 -04:00
committed by GitHub
parent acf66cdf46
commit 8e64734c35

View File

@@ -1,29 +1,39 @@
#Imports. #Imports.
import bpy; import bpy;
import random;
size = 1; size = 1;
xNumOfCubes = 3;
yNumOfCubes = 2;
zNumOfCubes = 0;
x = y = z = size / 2; x = y = z = size / 2;
#Creating the inital cube. #Creating the inital cube.
bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z)); bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z));
#I need to create an algorithm that will create the cubes in the shape of a block. # Iterate over each grid 'cell' we want a cube at.
for x in range(20):
for y in range(20):
#Set the location.
location = (x, y, z);
#Creating cubes in the X-Position. #Add the cubes.
for i in range(xNumOfCubes): bpy.ops.mesh.primitive_cube_add(size = size, location=location, scale=(1, 1, 1));
x += size;
bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z));
#Creating cubes in the Y-Position. ##Creating cubes in the X-Position.
for i in range(yNumOfCubes): #for i in range(xNumOfCubes):
y += size; # x += size;
bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z)); # bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z));
#Creating cubes in the Z-Position. ##Creating cubes in the Y-Position.
for i in range(zNumOfCubes): #for i in range(yNumOfCubes):
z += size; # y += size;
bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z)); # bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z));
##Creating cubes in the Z-Position.
#for i in range(zNumOfCubes):
# z += size;
# bpy.ops.mesh.primitive_cube_add(size = size, location = (x, y, z));
#Notes:
# - There is a cube that spawns amongst the grid that doesn't fit in with the rest.
# - To create the grid to spawn cubes in the z-axis, then I should create a new for loop within the nested loop to take create it in the z-axis.