前言
首先,不要迷信大模型。但同样不能忽视大模型。DeepSeek 除了能够进行深度对话,同时也已经开始具备了一些写复杂代码的能力。回答LeetCode上的代码题,可以认为是从记忆库里提取的,是个搜索过程。但下面这两个例子,不得不说大模型已经具备了一些“智能”。
两个例子
在开始介绍这两个例子之前,写点爽文:
以爽文的口吻介绍
惊叹!DeepSeek 大模型重塑三维建模新格局
在当今科技飞速发展的时代,大模型技术正以前所未有的速度渗透到各个领域,为传统行业带来了颠覆性的变革。今天,我们要为大家介绍的 DeepSeek 大模型,在三维建模领域展现出了令人瞩目的实力。
你是否还在为复杂的三维建模任务而头疼不已?那些繁琐的操作、精确到毫厘的设计要求,常常让设计师们耗费大量的时间和精力。但现在,DeepSeek 大模型的出现,为这一困境带来了转机。
以建筑建模为例,这向来是个极具挑战性的任务,需要考虑众多因素,如建筑结构、空间布局、外观设计等。DeepSeek 大模型却能轻松应对。当被要求用 Ruby 语言编写 SketchUp 脚本绘制高层建筑时,它的表现令人惊叹。
对于普通的长方体高层建筑,DeepSeek 不仅能迅速给出用 Ruby 编写的 SketchUp 脚本,还能将建筑的每一个细节都设计到位。它自动创建多层楼板结构,沿建筑外围精准放置结构柱,并且添加带有透明效果的连续玻璃幕墙系统。而且,整个设计使用真实世界单位,采用参数化设计,方便用户随时调整建筑尺寸。这意味着,设计师只需轻松修改几个参数,就能得到不同规格的建筑模型,大大提高了设计效率。
但 DeepSeek 的能力远不止于此。当面对更复杂的设计要求,如绘制一栋从上往下看呈现英文字母 C 型、带退台处理的高层建筑时,它依然游刃有余。它能巧妙地处理 20 层以上的退台变化,自动处理过渡结构,自动沿建筑外轮廓布置结构柱并跳过凹槽区域,幕墙系统还能智能识别建筑外轮廓。这种复杂设计的实现,充分展示了 DeepSeek 大模型强大的逻辑思维和对细节的把控能力。
当然,大模型给出的代码并非完美无缺,可能会存在一些小问题,例如 API 接口使用的差异、部分代码逻辑在特定环境下的优化等。但不可否认的是,在没有编译器帮助的情况下,它直接写出的代码已经具备了很高的质量,为设计师们提供了非常好的基础框架,大大减少了设计的前期工作量。
DeepSeek 大模型在三维建模领域的出色表现,为建筑设计、室内设计、游戏场景搭建等众多三维建模相关行业带来了新的可能。它让设计变得更加高效、便捷,激发了设计师们更多的创意。如果你也在从事三维建模相关工作,不妨试试借助 DeepSeek 大模型的力量,开启全新的设计之旅,相信它会给你带来意想不到的惊喜!
如果想要重现,可以将问题输入到DeepSeek。但给出的代码有少于bug,后面会附上修改之后的代码。总体来说,在没有编译器帮助的情况下,AI大模型直接写出的代码已经具备了很高的质量。
第一个例子
最终效果:
问题
用Ruby语言写SketchUp的脚本,绘制一栋高层建筑,每层的长度为20米,宽度30米,外面做成玻璃幕墙的形式,放置适当数量的柱子,楼板也需要有。
答案
以下是用 Ruby 编写的 SketchUp 脚本,用于创建具有玻璃幕墙的高层建筑:
# 单位转换方法:将米转换为 SketchUp 内部单位(英寸)
class Numeric
def m
self * 39.3701
end
end
# 创建楼板
def create_floor(entities, length, width, z, thickness)
points = [
Geom::Point3d.new(0, 0, z),
Geom::Point3d.new(length, 0, z),
Geom::Point3d.new(length, width, z),
Geom::Point3d.new(0, width, z)
]
face = entities.add_face(points)
face.pushpull(thickness)
end
# 计算外围柱子位置
def calculate_perimeter_positions(length, width, spacing)
positions = []
# 南边(y = 0)
x = 0.0
while x <= length
positions << [x, 0.0]
x += spacing
end
# 东边(x = length)
y = spacing # 跳过已包含的角点
while y < width
positions << [length, y]
y += spacing
end
# 北边(y = width)
x = length
while x >= 0
positions << [x, width]
x -= spacing
end
# 西边(x = 0)
y = width - spacing # 跳过已包含的角点
while y > 0
positions << [0.0, y]
y -= spacing
end
positions.uniq
end
# 创建柱子
def create_columns(entities, length, width, z, floor_thickness, floor_height, column_size, spacing)
column_height = floor_height - floor_thickness
base_z = z + floor_thickness
positions = calculate_perimeter_positions(length, width, spacing)
positions.each do |x, y|
offset = column_size / 2.0
points = [
Geom::Point3d.new(x - offset, y - offset, base_z),
Geom::Point3d.new(x + offset, y - offset, base_z),
Geom::Point3d.new(x + offset, y + offset, base_z),
Geom::Point3d.new(x - offset, y + offset, base_z)
]
face = entities.add_face(points)
face.pushpull(column_height)
end
end
# 创建玻璃幕墙
def create_curtain_wall(entities, length, width, z_base, height)
# 创建四个外墙
walls = []
# 南墙
walls << entities.add_face(
Geom::Point3d.new(0, 0, z_base),
Geom::Point3d.new(length, 0, z_base),
Geom::Point3d.new(length, 0, z_base + height),
Geom::Point3d.new(0, 0, z_base + height)
)
# 东墙
walls << entities.add_face(
Geom::Point3d.new(length, 0, z_base),
Geom::Point3d.new(length, width, z_base),
Geom::Point3d.new(length, width, z_base + height),
Geom::Point3d.new(length, 0, z_base + height)
)
# 北墙
walls << entities.add_face(
Geom::Point3d.new(length, width, z_base),
Geom::Point3d.new(0, width, z_base),
Geom::Point3d.new(0, width, z_base + height),
Geom::Point3d.new(length, width, z_base + height)
)
# 西墙
walls << entities.add_face(
Geom::Point3d.new(0, width, z_base),
Geom::Point3d.new(0, 0, z_base),
Geom::Point3d.new(0, 0, z_base + height),
Geom::Point3d.new(0, width, z_base + height)
)
# 应用玻璃材质
glass = entities.model.materials.add("Glass")
glass.color = [200, 230, 255]
glass.transparency = 0.7
walls.each do |wall|
wall.material = glass
wall.back_material = glass
end
end
# 主程序
model = Sketchup.active_model
entities = model.entities
model.start_operation("Create High-rise Building", true)
# 建筑参数设置
building_length = 20.0.m # 长度
building_width = 30.0.m # 宽度
num_floors = 15 # 楼层数
floor_height = 3.5.m # 层高
floor_thickness = 0.3.m # 楼板厚度
column_spacing = 5.0.m # 柱子间距
column_size = 0.6.m # 柱子尺寸
# 逐层创建建筑
num_floors.times do |floor|
current_z = floor * floor_height
# 创建楼板
create_floor(entities, building_length, building_width, current_z, floor_thickness)
# 创建柱子
create_columns(entities,
building_length,
building_width,
current_z,
floor_thickness,
floor_height,
column_size,
column_spacing)
# 创建玻璃幕墙(从楼板顶部开始)
curtain_z = current_z + floor_thickness
curtain_height = floor_height - floor_thickness
create_curtain_wall(entities,
building_length,
building_width,
curtain_z,
curtain_height)
end
model.commit_operation
脚本说明:
-
参数设置:
- 建筑尺寸:20米(长)×30米(宽)
- 楼层数:15层
- 层高:3.5米
- 楼板厚度:0.3米
- 柱子尺寸:0.6米见方
- 柱子间距:5米
-
主要功能:
- 自动创建多层楼板结构
- 沿建筑外围创建结构柱
- 添加连续的玻璃幕墙系统
- 使用半透明蓝色材质模拟玻璃效果
-
特点:
- 使用真实世界单位(米)进行设计
- 参数化设计,方便调整建筑尺寸
- 自动计算柱子布局位置
- 玻璃幕墙带透明效果
要调整建筑参数,可以直接修改代码中的参数部分(如 num_floors
、column_spacing
等)。运行脚本后,SketchUp 将自动生成具有现代风格玻璃幕墙的高层建筑模型。
修改后的代码
唯一的修改,可能是训练数据的问题,API 接口有变化(我用的是2022版本)把:
glass.transparency= 0.7
改为
glass.alpha = 0.7
最终代码:
# 单位转换方法:将米转换为 SketchUp 内部单位(英寸)
class Numeric
def m
self * 39.3701
end
end
# 创建楼板
def create_floor(entities, length, width, z, thickness)
points = [
Geom::Point3d.new(0, 0, z),
Geom::Point3d.new(length, 0, z),
Geom::Point3d.new(length, width, z),
Geom::Point3d.new(0, width, z)
]
face = entities.add_face(points)
face.pushpull(thickness)
end
# 计算外围柱子位置
def calculate_perimeter_positions(length, width, spacing)
positions = []
# 南边(y = 0)
x = 0.0
while x <= length
positions << [x, 0.0]
x += spacing
end
# 东边(x = length)
y = spacing # 跳过已包含的角点
while y < width
positions << [length, y]
y += spacing
end
# 北边(y = width)
x = length
while x >= 0
positions << [x, width]
x -= spacing
end
# 西边(x = 0)
y = width - spacing # 跳过已包含的角点
while y > 0
positions << [0.0, y]
y -= spacing
end
positions.uniq
end
# 创建柱子
def create_columns(entities, length, width, z, floor_thickness, floor_height, column_size, spacing)
column_height = floor_height - floor_thickness
base_z = z + floor_thickness
positions = calculate_perimeter_positions(length, width, spacing)
positions.each do |x, y|
offset = column_size / 2.0
points = [
Geom::Point3d.new(x - offset, y - offset, base_z),
Geom::Point3d.new(x + offset, y - offset, base_z),
Geom::Point3d.new(x + offset, y + offset, base_z),
Geom::Point3d.new(x - offset, y + offset, base_z)
]
face = entities.add_face(points)
face.pushpull(column_height)
end
end
# 创建玻璃幕墙
def create_curtain_wall(entities, length, width, z_base, height)
# 创建四个外墙
walls = []
# 南墙
walls << entities.add_face(
Geom::Point3d.new(0, 0, z_base),
Geom::Point3d.new(length, 0, z_base),
Geom::Point3d.new(length, 0, z_base + height),
Geom::Point3d.new(0, 0, z_base + height)
)
# 东墙
walls << entities.add_face(
Geom::Point3d.new(length, 0, z_base),
Geom::Point3d.new(length, width, z_base),
Geom::Point3d.new(length, width, z_base + height),
Geom::Point3d.new(length, 0, z_base + height)
)
# 北墙
walls << entities.add_face(
Geom::Point3d.new(length, width, z_base),
Geom::Point3d.new(0, width, z_base),
Geom::Point3d.new(0, width, z_base + height),
Geom::Point3d.new(length, width, z_base + height)
)
# 西墙
walls << entities.add_face(
Geom::Point3d.new(0, width, z_base),
Geom::Point3d.new(0, 0, z_base),
Geom::Point3d.new(0, 0, z_base + height),
Geom::Point3d.new(0, width, z_base + height)
)
# 应用玻璃材质
glass = entities.model.materials.add("Glass")
glass.color = [200, 230, 255]
glass.alpha = 0.7
walls.each do |wall|
wall.material = glass
wall.back_material = glass
end
end
# 主程序
model = Sketchup.active_model
entities = model.entities
model.start_operation("Create High-rise Building", true)
# 建筑参数设置
building_length = 20.0.m # 长度
building_width = 30.0.m # 宽度
num_floors = 15 # 楼层数
floor_height = 3.5.m # 层高
floor_thickness = 0.3.m # 楼板厚度
column_spacing = 5.0.m # 柱子间距
column_size = 0.6.m # 柱子尺寸
# 逐层创建建筑
num_floors.times do |floor|
current_z = floor * floor_height
# 创建楼板
create_floor(entities, building_length, building_width, current_z, floor_thickness)
# 创建柱子
create_columns(entities,
building_length,
building_width,
current_z,
floor_thickness,
floor_height,
column_size,
column_spacing)
# 创建玻璃幕墙(从楼板顶部开始)
curtain_z = current_z + floor_thickness
curtain_height = floor_height - floor_thickness
create_curtain_wall(entities,
building_length,
building_width,
curtain_z,
curtain_height)
end
model.commit_operation
第二个例子
最终效果:
问题
用Ruby语言写SketchUp的脚本,绘制一栋高层建筑,总高32层,每层的总长度为40米,总宽度30米,从上往下看呈现英文字母C,即不是一个长方形,而是凹字型。并且在20层以上做了退台处理,总长度不变,但宽度变为25米。建筑外面做成玻璃幕墙的形式,放置适当数量的柱子,楼板也需要有。
答案
以下是实现凹字形高层建筑带退台处理的SketchUp Ruby脚本:
# 单位转换方法:将米转换为 SketchUp 内部单位(英寸)
class Numeric
def m
self * 39.3701
end
end
# 创建C型楼板
def create_c_shaped_floor(entities, total_length, total_width, z, thickness, is_recessed)
# C型参数
recess_depth = is_recessed ? 5.m : 10.m # 凹槽深度(退台后缩小)
recess_width = 15.m # 凹槽宽度
adjusted_width = is_recessed ? 25.m : total_width
base_width = (adjusted_width - recess_depth) / 2
points = [
# 外轮廓
Geom::Point3d.new(0, 0, z),
Geom::Point3d.new(total_length, 0, z),
Geom::Point3d.new(total_length, adjusted_width, z),
# 凹槽部分
Geom::Point3d.new(total_length - recess_width, adjusted_width, z),
Geom::Point3d.new(total_length - recess_width, adjusted_width - recess_depth, z),
Geom::Point3d.new(recess_width, adjusted_width - recess_depth, z),
Geom::Point3d.new(recess_width, adjusted_width, z),
Geom::Point3d.new(0, adjusted_width, z)
]
# 创建楼板面并推拉厚度
face = entities.add_face(points)
face.reverse! if face.normal.z < 0
face.pushpull(thickness)
end
# 生成结构柱
def create_columns(entities, floor_shape, z, floor_thickness, floor_height, column_size)
column_height = floor_height - floor_thickness
base_z = z + floor_thickness
# 沿楼板外边缘生成柱子
edge_points = floor_shape.vertices.map(&:position)
column_spacing = 5.m
edge_points.each_cons(2) do |start_pt, end_pt|
distance = start_pt.distance(end_pt)
num_columns = (distance / column_spacing).floor
next if num_columns < 1
direction_vector = end_pt - start_pt
step = direction_vector / num_columns
(0..num_columns).each do |i|
position = start_pt + step * i
# 跳过凹槽区域
next if position.y > 15.m && position.x.between?(10.m, 30.m)
# 创建柱体
offset = column_size / 2.0
column_points = [
[position.x - offset, position.y - offset],
[position.x + offset, position.y - offset],
[position.x + offset, position.y + offset],
[position.x - offset, position.y + offset]
].map { |x,y| Geom::Point3d.new(x, y, base_z) }
face = entities.add_face(column_points)
face.pushpull(column_height)
end
end
end
# 创建幕墙系统
def create_curtain_wall(entities, floor_shape, z_base, height)
glass = entities.model.materials.add("幕墙玻璃")
glass.color = [180, 220, 250]
glass.transparency = 0.75
floor_shape.edges.each do |edge|
next if edge.soft? # 跳过楼板内部边缘
# 创建幕墙面
points = [
edge.start.position,
edge.end.position,
edge.end.position + Geom::Vector3d.new(0, 0, height),
edge.start.position + Geom::Vector3d.new(0, 0, height)
]
wall_face = entities.add_face(points)
wall_face.material = glass
wall_face.back_material = glass
end
end
# 主程序
model = Sketchup.active_model
entities = model.entities
model.start_operation("创建C型退台高层建筑", true)
# 建筑参数
total_floors = 32
total_length = 40.m
base_width = 30.m
recessed_width = 25.m # 20层以上宽度
floor_height = 3.8.m
floor_thickness = 0.35.m
column_size = 0.7.m
# 逐层创建
total_floors.times do |floor|
current_z = floor * floor_height
is_top_floor = (floor >= 20)
# 创建楼板
floor_group = entities.add_group
floor_shape = create_c_shaped_floor(floor_group.entities,
total_length,
is_top_floor ? recessed_width : base_width,
current_z,
floor_thickness,
is_top_floor)
# 创建结构柱
create_columns(floor_group.entities,
floor_shape,
current_z,
floor_thickness,
floor_height,
column_size)
# 创建幕墙
curtain_z = current_z + floor_thickness
curtain_height = floor_height - floor_thickness
create_curtain_wall(floor_group.entities,
floor_shape,
curtain_z,
curtain_height)
# 退台处理(20层以上内缩)
if floor == 20
# 创建过渡结构
transition_height = 2.m
transition_group = entities.add_group
transition_points = [
[0, 0, current_z],
[total_length, 0, current_z],
[total_length, recessed_width, current_z],
[total_length - 10.m, recessed_width, current_z],
[total_length - 10.m, base_width, current_z],
[10.m, base_width, current_z],
[10.m, recessed_width, current_z],
[0, recessed_width, current_z]
].map { |x,y,z| Geom::Point3d.new(x, y, z) }
transition_face = transition_group.entities.add_face(transition_points)
transition_face.pushpull(transition_height)
end
end
model.commit_operation
脚本特性说明:
-
C型建筑结构:
- 底部20层保持30米宽度,顶部12层缩减至25米
- 通过参数化凹槽设计(凹槽深度10米/5米,宽度15米)
- 自动处理20层的过渡结构
-
智能结构生成:
- 自动沿建筑外轮廓布置结构柱
- 自动跳过凹槽区域的柱子生成
- 幕墙系统智能识别建筑外轮廓
-
参数配置:
total_floors = 32 # 总楼层数 total_length = 40.m # 建筑总长度 base_width = 30.m # 20层以下宽度 recessed_width = 25.m # 20层以上宽度 floor_height = 3.8.m # 标准层高
-
特殊处理:
- 20层设置2米高的过渡结构
- 幕墙使用半透明蓝色玻璃材质
- 柱子自动避开凹槽区域
-
可视化效果:
- 玻璃幕墙透明度75%
- 结构柱尺寸0.7米见方
- 楼板厚度0.35米
运行时会在SketchUp中生成一个包含:
- 32层C型主体结构
- 20层以上的退台处理
- 全玻璃幕墙系统
- 自动布局的结构柱
的现代高层建筑模型。可通过调整参数中的尺寸数值修改建筑比例关系。
修改后的代码
除了和上面同样的 transparency
转 alpha
,另一个修改的地方,主要是Geom::Vector3d
这个类没有重载和数字的 *
号和 /
号,需要将
direction_vector = end_pt - start_pt
step = direction_vector / num_columns
(0..num_columns).each do |i|
position = start_pt + step * i
修改为
direction_vector = end_pt - start_pt
step = Geom::Vector3d.new(direction_vector.x / num_columns,direction_vector.y / num_columns,direction_vector.z / num_columns)
(0..num_columns).each do |i|
position = start_pt + Geom::Vector3d.new(step.x * i,step.y * i,step.z * i)
最终代码:
# 单位转换方法:将米转换为 SketchUp 内部单位(英寸)
class Numeric
def m
self * 39.3701
end
end
# 创建C型楼板
def create_c_shaped_floor(entities, total_length, total_width, z, thickness, is_recessed)
# C型参数
recess_depth = is_recessed ? 5.m : 10.m # 凹槽深度(退台后缩小)
recess_width = 15.m # 凹槽宽度
adjusted_width = is_recessed ? 25.m : total_width
base_width = (adjusted_width - recess_depth) / 2
points = [
# 外轮廓
Geom::Point3d.new(0, 0, z),
Geom::Point3d.new(total_length, 0, z),
Geom::Point3d.new(total_length, adjusted_width, z),
# 凹槽部分
Geom::Point3d.new(total_length - recess_width, adjusted_width, z),
Geom::Point3d.new(total_length - recess_width, adjusted_width - recess_depth, z),
Geom::Point3d.new(recess_width, adjusted_width - recess_depth, z),
Geom::Point3d.new(recess_width, adjusted_width, z),
Geom::Point3d.new(0, adjusted_width, z)
]
# 创建楼板面并推拉厚度
face = entities.add_face(points)
face.reverse! if face.normal.z < 0
face.pushpull(thickness)
return face
end
# 生成结构柱
def create_columns(entities, floor_shape, z, floor_thickness, floor_height, column_size)
column_height = floor_height - floor_thickness
base_z = z + floor_thickness
# 沿楼板外边缘生成柱子
edge_points = floor_shape.vertices.map(&:position)
column_spacing = 5.m
edge_points.each_cons(2) do |start_pt, end_pt|
distance = start_pt.distance(end_pt)
num_columns = (distance / column_spacing).floor
next if num_columns < 1
direction_vector = end_pt - start_pt
step = Geom::Vector3d.new(direction_vector.x / num_columns,direction_vector.y / num_columns,direction_vector.z / num_columns)
(0..num_columns).each do |i|
position = start_pt + Geom::Vector3d.new(step.x * i,step.y * i,step.z * i)
# 跳过凹槽区域
next if position.y > 15.m && position.x.between?(10.m, 30.m)
# 创建柱体
offset = column_size / 2.0
column_points = [
[position.x - offset, position.y - offset],
[position.x + offset, position.y - offset],
[position.x + offset, position.y + offset],
[position.x - offset, position.y + offset]
].map { |x,y| Geom::Point3d.new(x, y, base_z) }
face = entities.add_face(column_points)
face.pushpull(column_height)
end
end
end
# 创建幕墙系统
def create_curtain_wall(entities, floor_shape, z_base, height)
glass = entities.model.materials.add("幕墙玻璃")
glass.color = [180, 220, 250]
glass.alpha = 0.75
floor_shape.edges.each do |edge|
next if edge.soft? # 跳过楼板内部边缘
# 创建幕墙面
points = [
edge.start.position,
edge.end.position,
edge.end.position + Geom::Vector3d.new(0, 0, height),
edge.start.position + Geom::Vector3d.new(0, 0, height)
]
wall_face = entities.add_face(points)
wall_face.material = glass
wall_face.back_material = glass
end
end
# 主程序
model = Sketchup.active_model
entities = model.entities
model.start_operation("创建C型退台高层建筑", true)
# 建筑参数
total_floors = 32
total_length = 40.m
base_width = 30.m
recessed_width = 25.m # 20层以上宽度
floor_height = 3.8.m
floor_thickness = 0.35.m
column_size = 0.7.m
# 逐层创建
total_floors.times do |floor|
current_z = floor * floor_height
is_top_floor = (floor >= 20)
# 创建楼板
floor_group = entities.add_group
floor_shape = create_c_shaped_floor(floor_group.entities,
total_length,
is_top_floor ? recessed_width : base_width,
current_z,
floor_thickness,
is_top_floor)
# 创建结构柱
create_columns(floor_group.entities,
floor_shape,
current_z,
floor_thickness,
floor_height,
column_size)
# 创建幕墙
curtain_z = current_z + floor_thickness
curtain_height = floor_height - floor_thickness
create_curtain_wall(floor_group.entities,
floor_shape,
curtain_z,
curtain_height)
# 退台处理(20层以上内缩)
if floor == 20
# 创建过渡结构
transition_height = 2.m
transition_group = entities.add_group
transition_points = [
[0, 0, current_z],
[total_length, 0, current_z],
[total_length, recessed_width, current_z],
[total_length - 10.m, recessed_width, current_z],
[total_length - 10.m, base_width, current_z],
[10.m, base_width, current_z],
[10.m, recessed_width, current_z],
[0, recessed_width, current_z]
].map { |x,y,z| Geom::Point3d.new(x, y, z) }
transition_face = transition_group.entities.add_face(transition_points)
transition_face.pushpull(transition_height)
end
end
model.commit_operation