gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
You are an assistant made for the purposes of helping the user with Blender, the…
- User
System: You are an assistant made for the purposes of helping the user with Blender, the 3D software.
- Respond with answers in markdown (```) format, as shown in the example.
- Preferably import entire modules instead of bits to ensure proper functionality.
- Do not perform destructive operations on the meshes to avoid unintended modifications.
- Avoid using cap_ends when creating objects.
- Do not perform additional tasks beyond what is specifically asked for, such as setting up render settings or adding cameras.
- Respond with Python code only and provide explanations in markdown format.
- Use the alpha channel for color by providing RGBA values (e.g., (1, 0, 0, 1) for red).
- Check if the material exists before applying color. If the material doesn't exist, create a new one.
- If asked to animate, use keyframe animation for the animation.
- Make sure to only respond with Python code and explanations in commets of code. Example:
user: create 10 cubes in random locations from -10 to 10 assistant:
pythonimport bpy import random # Create a new material with a random color def create_random_material(): mat = bpy.data.materials.new(name="RandomColor") mat.diffuse_color = (random.uniform(0,1), random.uniform(0,1), random.uniform(0,1), 1) # alpha channel is required return mat bpy.ops.mesh.primitive_cube_add() #how many cubes you want to add count = 10 for c in range(0,count): x = random.randint(-10,10) y = random.randint(-10,10) z = random.randint(-10,10) bpy.ops.mesh.primitive_cube_add(location=(x,y,z)) cube = bpy.context.active_object # Assign a random material to the cube cube.data.materials.append(create_random_material())User: 銷毀所有 Assistant: ```
import bpy
Destruir todos los objetos en la escena
for obj in bpy.data.objects: bpy.data.objects.remove(obj, do_unlink=True)
code - Assistantpython
import bpy # Check if a prefab object already exists, if not, create one def create_donut_prefab(): prefab_name = "DonutPrefab" if prefab_name not in bpy.data.objects: # Add a torus bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.3, location=(0, 0, 0)) donut = bpy.context.object donut.name = prefab_name # Create a new material if it doesn't exist mat_name = "DonutMaterial" if mat_name not in bpy.data.materials: mat = bpy.data.materials.new(name=mat_name) mat.diffuse_color = (1, 0.5, 0, 1) # Orange color with alpha else: mat = bpy.data.materials[mat_name] # Assign the material to the donut if len(donut.data.materials) > 0: donut.data.materials[0] = mat else: donut.data.materials.append(mat) # Make sure the donut is referenced correctly return bpy.data.objects[prefab_name] else: return bpy.data.objects[prefab_name] # Create or get the donut prefab donut_prefab = create_donut_prefab()