Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Creating a castle in Blender using a script requires defining the castle's structure, materials, and details.

Here's an example script to generate a basic castle model:

```python

import bpy

# Clear existing objects

bpy.ops.object.select_all(action='DESELECT')

bpy.ops.object.select_by_type(type='MESH')

bpy.ops.object.delete()

# Set dimensions and proportions

tower_size = 7

tower_height = 15

wall_height = 7

wall_length = 50

# Create tower

bpy.ops.mesh.primitive_cube_add(size=tower_size, location=(0, 0, tower_height/2))

tower = bpy.context.active_object

tower.name = "Tower"

# Create main building (walls)

bpy.ops.mesh.primitive_cube_add(size=5, location=(0, 0, wall_height/2))

main_building = bpy.context.active_object

main_building.name = "MainBuilding"

main_building.scale = (wall_length/2, wall_length/5, wall_height)

# Link walls to the tower

bpy.ops.object.select_all(action='DESELECT')
tower.select_set(True)

main_building.select_set(True)

bpy.context.view_layer.objects.active = tower

bpy.ops.object.join()

# Create roof

roof_angle = 30 # in degrees

roof_height = 2

roof_length = wall_length * 1.1

bpy.ops.mesh.primitive_cone_add(vertices=4, radius1=roof_length/2, depth=roof_height)

roof = bpy.context.active_object

roof.name = "Roof"

roof.location.z = wall_height + tower_height + roof_height/2

roof.rotation_euler = (radians(roof_angle), 0, 0)

# Create door

door_size = 2

door_height = 4

bpy.ops.mesh.primitive_cube_add(size=door_size, location=(0, -wall_length/2, door_height/2))

door = bpy.context.active_object

door.name = "Door"

# Create windows

window_size = 3

window_height = 3

window_offset = wall_length / 4
bpy.ops.mesh.primitive_cube_add(size=window_size, location=(window_offset, -wall_length/2,
window_height/2))

window1 = bpy.context.active_object

window1.name = "Window1"

bpy.ops.mesh.primitive_cube_add(size=window_size, location=(-window_offset, -wall_length/2,


window_height/2))

window2 = bpy.context.active_object

window2.name = "Window2"

# Create grounds

ground_size = 100

ground_thickness = 0.1

bpy.ops.mesh.primitive_plane_add(size=ground_size)

ground = bpy.context.active_object

ground.name = "Ground"

ground.location.z = -ground_thickness/2

ground.scale = (wall_length, wall_length, ground_thickness)

# Save the model

bpy.ops.wm.save_as_mainfile(filepath="castle.blend")

```

To run this script in Blender:

1. Open Blender and delete the default cube.

2. Go to Scripting workspace.

3. Create a new text file.


4. Paste the script into the text editor.

5. Press the "Run Script" button or use the shortcut "Alt+P" to execute the script.

6. A castle model will be generated.

7. Save the created model by pressing "Ctrl+S" and providing a file name (e.g., "castle.blend") in the
appropriate directory.

Please note that this script only creates a basic castle model. Additional modifications and details can be
added based on your specific requirements.

You might also like