NCF参数化建筑论坛

标题: 使用Python编写连续展平程序连载(转) [打印本页]

作者: RichieBall    时间: 2012-11-28 19:37
标题: 使用Python编写连续展平程序连载(转)
转自: http://cadesign.cn/bbs/thread-81-1-1.html

首先看下图解的过程:




                               
登录/注册后可看大图


GH程序:

                               
登录/注册后可看大图

■ 折面的建立方法是使用Rectangular组件建立网格并成面获取每个面的法向及反向向量,沿两个向量移动上下两点,使用Sort Points组件重新组织点的数据顺序,用Delaunay Mesh建立折面;对于折面的连续展平使用Grasshopper目前自身的组件构建程序有些困难,可以使用Python语言来完成。对于没有Python语言编程能力的设计师,如果遇到类似的情况,可以直接调用已经编写好的“Python编写的连续展平程序”达到展平的目的;

                               
登录/注册后可看大图

Python程序:
import rhinoscriptsyntax as rs
mesh=mesh  #导入外部程序的Mesh面;

meshes=rs.ExplodeMeshes(mesh) #分解单一Mesh面为多个;

xymeshes=[]
for i in range(len(meshes)):
    if i ==0: #处理分解后第一个Mesh面的展平位置;
        mesh0point=rs.MeshVertices(meshes)
        mesh0points=[]
        for r in mesh0point:
            mesh0points.append([r[0],r[1],r[2]])
        
        xymesh0=rs.OrientObject(meshes,mesh0points,\
        [[0,10,0],[10,0,0],[0,0,0]],1)
        xymeshes.append(xymesh0)

    else: #余下Mesh面的循环遍历;
        vertices2=rs.MeshVertices(meshes)
        vertices1=rs.MeshVertices(meshes[i-1])

        vertices2lst=[]
        vertices1lst=[]
        for q in vertices2:
            vertices2lst.append([q[0],q[1],q[2]])
        for p in vertices1:
            vertices1lst.append([p[0],p[1],p[2]])
      
#找到相邻两个面的共同顶点;
       ver=[m for m in vertices1lst for n in vertices2lst if m==n]
        a=ver[0]
        b=ver[1]
#找到相邻两个面共同顶点的索引;
        indexa=vertices1lst.index(a)
        indexb=vertices1lst.index(b)
        #找到相邻两个面不共边的顶点;
        cref=[m for m in vertices1lst if m not in ver][0]
        cv=[m for m in vertices2lst if m not in ver][0]   
        #定义面的延展方向;
        refvertice=rs.MeshVertices(xymeshes[i-1])
        refvertices=[]
        for x in refvertice:
            refvertices.append([x[0],x[1],x[2]])
        indexc=[c for c in range(0,3) if c !=indexa and c!=indexb]
        print(indexc)
        refverticespoint=rs.MirrorObject(rs.AddPoint(refvertices[indexc[0]]),refvertices[indexa],refvertices[indexb])
        mirrorpoint=[rs.PointCoordinates(refverticespoint)]

        for z in mirrorpoint:
            mirrorpoint=[z[0],z[1],z[2]]
        
#获得面的延展;
  xymesh=rs.OrientObject(meshes,[a,b,cv],[refvertices[indexa],refvertices[indexb],mirrorpoint],1)
        xymeshes.append(xymesh)
        print(xymesh)
   
    vertices2lst=[]
    vertices1lst=[]
    ver=[]
print(xymeshes) #可以用Print函数检查结果;

■ Python连续展平程序编写的关键是找到三维空间中与平面位置中对应点的位置,使用If条件语句来判断每一个三角面的顶点是否为同一个点,如果不共点,该点则为两个相邻三角面相互对位上的点;

--Richie



作者: 活建鬼    时间: 2012-11-28 20:22

很不错的分享!之前的那两个帖子让我印象深刻~~~另,这些教程是你原创的么?
作者: phoenixding    时间: 2012-11-28 22:44
赞啊!虽然我现在还看不懂...
作者: ping58972    时间: 2012-11-28 23:14
嗯 这个值得 支持  谢谢分享 加油~~~
作者: zhiaixu2010    时间: 2012-11-29 08:12
活建鬼 发表于 2012-11-28 20:22
很不错的分享!之前的那两个帖子让我印象深刻~~~另,这些教程是你原创的么?

richie貌似是北林的老师哦...
作者: 455420779    时间: 2012-11-29 15:17
[attach]36773[/attach]很实用的东西,但是我想问一下,这个运算器是什么,我输入“explode”怎么出不来,我的版本是[attach]36774[/attach]

作者: 455420779    时间: 2012-11-29 16:05
[attach]36775[/attach]还有个问题,为什么我的python运算器显示有问题?把程序拷贝到运算器的过程中有什么要注意的吗
作者: jasonroc    时间: 2012-11-29 17:35
赞啊!python 看来得学了。。。
作者: RichieBall    时间: 2012-11-29 21:28
本帖最后由 RichieBall 于 2012-11-29 21:32 编辑

En, 好像是2009年末开始接触GH, 把NCF的所有帖子都读了,编些程序和大家分享 ;
把程序连上Python组件, 就不会是红的了, 同时mesh接入端右键选择List Access;
GH的Mesh处理得需要安装一些Add -ons:
Mesh Analysis and Utility Components:官方网址:http://www.grasshopper3d.com/profiles/blogs/mesh-analysis-and-utility





欢迎光临 NCF参数化建筑论坛 (http://www.ncf-china.com/) Powered by Discuz! X3.2