Implimented grabbing every face of a cube.

This commit is contained in:
CJSatnarine
2023-05-08 12:56:53 -04:00
parent 66bc3decdf
commit de4d565505

View File

@@ -1,5 +1,6 @@
#Imports. #Imports.
import bpy; import bpy;
import bmesh;
import random; import random;
# Variables: # Variables:
@@ -8,9 +9,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 = 3; xNum = 1;
yNum = 3; yNum = 1;
zNum = 3; zNum = 1;
# 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.
@@ -51,8 +52,6 @@ def spawnGround():
# Object View Layer variable. # Object View Layer variable.
activeObjectViewLayer = bpy.context.view_layer.objects.active; activeObjectViewLayer = bpy.context.view_layer.objects.active;
# Add a new material slot. # Add a new material slot.
# bpy.ops.object.material_slot_add(); # bpy.ops.object.material_slot_add();
@@ -63,6 +62,25 @@ def spawnGround():
materialNodes = material.node_tree.nodes; materialNodes = material.node_tree.nodes;
materialLinks = material.node_tree.links; materialLinks = material.node_tree.links;
# Selecting each face and then assigning the material to that face.
for i in range(6):
# Checks if the object is currently in edit mode, and if not, sets it into edit mode.
if (bpy.context.active_object.mode == "OBJECT"):
bpy.ops.object.editmode_toggle();
bm = bmesh.from_edit_mesh(activeObject.data);
# Make sure the bmesh is up-to-date with the mesh data.
bm.faces.ensure_lookup_table();
# Set selecting the faces to be true.
bm.faces[i].select = True;
# Show the updates in the viewport.
bmesh.update_edit_mesh(activeObject.data);
print('face ', i, ' grabbed');
# Add the material.
activeObject.data.materials.append(material); activeObject.data.materials.append(material);
# Change the texture of the cube. # Change the texture of the cube.