🌓
搜索
 找回密码
 立即注册

SketchUp插件开发详解——创建球体

janelsq 2022-8-23 23:16:52 40393
在进行设计工作时,简单的造型里,除了六面体之外需要创建最多的就是球体模型了。创建球体的问题也经常在SketchUp的相关论坛里被提到,简单来说主要有下面几步:

  • 创建圆面。
  • 创建圆形路径。
  • 路径跟随。
  • 删除路径。
使用代码创建一个球体模型实际上也是相同的步骤,只是使用代码实现以上的每个过程。
创建圆面

前面我们讲解过创建圆和创建面,其实只要把这两个结合起来就可以创建出来一个圆面。
center = Geom::Point3d.new(1, 1, 1)normal = Geom::Vector3d.new(0, 1, 0)radius = 10circle_edges = entities.add_circle(center, normal, radius)face = entities.add_face(circle_edges)
这样就创建出来一个法向指向Y轴正向、半径为10的圆形面,面的法向和圆形边是一致的。
Zpo31SxQ00v1vp7M.jpg

创建圆形路径

我们知道圆面绕面内经过圆心的任意一个轴旋转一圈就构成了一个球体。在SketchUp中实现这样的旋转放样是通过沿圆形路径的路径跟随实现的,这个圆形路径有如下要求:

  • 和圆面同心,否则就会最终会产生一个环。
  • 和圆面垂直,否则SketchUp会崩溃(- - !)。
normal = Geom::Vector3d.new(0, 0, 1)radius += 1path_edges = entities.add_circle(center, normal, radius)
d3jMYOi3Yn4yN239.jpg

构造球体

最后一步组合前面两步构造的面和路径,做一次路径跟随,即可构造出来一个球体了。
face.followme(path_edges)
gASZx5QJ4L6Aj3t2.jpg

最后把路径删除
entities.erase_entities(path_edges)
完整的代码
entities = Sketchup.active_model.entitiescenter = Geom::Point3d.new(1, 1, 1)normal = Geom::Vector3d.new(0, 1, 0)radius = 10circle_edges = entities.add_circle(center, normal, radius)face = entities.add_face(circle_edges)​normal = Geom::Vector3d.new(0, 0, 1)radius += 1path_edges = entities.add_circle(center, normal, radius)face.followme(path_edges)entities.erase_entities(path_edges)
创建环

前面对创建球的讲解中提到过,如果路径和面不同心,就会形成一个环,比如把上面的路径圆心改一下:
entities = Sketchup.active_model.entitiescenter = Geom::Point3d.new(1, 1, 1)normal = Geom::Vector3d.new(0, 1, 0)radius = 10circle_edges = entities.add_circle(center, normal, radius)face = entities.add_face(circle_edges)​center = Geom::Point3d.new(10, 10, 10)normal = Geom::Vector3d.new(0, 0, 1)radius += 1path_edges = entities.add_circle(center, normal, radius)face.followme(path_edges)entities.erase_entities(path_edges)
r2VH0Gzl8T6HG4vu.jpg

欢迎关注“小众程序员”微信公众号交流讨论。

扫一扫

0 回复

高级模式
游客
返回顶部