September 26, 2008

RhinoScript | Polyline to Curve (Endpoints and midpoints as CP)




최근 프로젝트에서 사용한 스크립트 중 하나이다. 폴리라인의 각 끝점과 가운데 점들을 Control Point로 하는 커브를 생성하는 스크립트다. 가끔 유용하게 쓰일때가 있을 것 같아 올려둔다. 프로젝트에서는 다이어그램을 그리기 위해 사용되었다.




Option Explicit
Sub Poly2CrvMid ()

  Dim arrCrvs,strCrv, arrPoints,arrPoint
  Dim K,i,arrNPt,hh,kk

  arrCrvs = Rhino.GetObjects("Select curves", 4)

  If IsNull(arrCrvs) Then Exit Sub

  ReDim arrCC(UBound(arrCrvs))

  hh=0
  For Each strCrv In arrCrvs
   If Rhino.IsPolyline(strCrv) Then
   arrPoints = Rhino.PolylineVertices(strCrv)

   If IsArray(arrPoints) Then
    k=UBound(arrPoints)
    kk=(k+1)*2-2

    ReDim arrNPt(kk)

    Dim nn : nn=0

    For i=1 To kk Step 2
    arrNPt(i) = Array((arrPoints(nn)(0)+arrPoints(nn+1)(0))/2, (arrPoints(nn)(1)+arrPoints(nn+1)(1))/2, (arrPoints(nn)(2)+arrPoints(nn+1)(2))/2 )
    nn=nn+1
   Next
   nn=0
   For i=0 To kk Step 2
    arrNPt(i) = arrPoints(nn)
    nn=nn+1
   Next

   arrCC(hh) = Rhino.AddCurve (arrNPt ,3)
   hh=hh+1

   End If
  End If
Next

Rhino.SelectObjects arrCC

End Sub

Poly2CrvMid




* jh8226님, 만약 mid 포인트를 사용하지 않고 폴리곤의 끝점을 그대로 Degree=3인 커브로 변환한다면 더 간단해집니다. 참조하세요. 마지막 부분을 바꾸시면 됩니다. If IsArray(arrPoints) Then - End If 부분을 아래와 같이 바꿔주면 됩니다.

   If IsArray(arrPoints) Then
  
     arrCC(hh) = Rhino.AddCurve (arrPoints ,3)
     hh=hh+1
   End If

4 comments:

Anonymous said...

hi!
i was wondering if you have a script like this for polysurfaces?

if you do, could you please e-mail to angelicbebe@Hotmail.com

thanks!

yoon said...

Hi,
Do you mean polysurface to one curved surface ? or flat curves from every surface boundary ?

STU said...

works good. thanks!

Village Talkies said...

Thank you for your informative post!!!
Village Talkies a top-quality professional corporate video production company in Bangalore and also best explainer video company in Bangalore & animation video makers in Bangalore, Chennai, India & Maryland, Baltimore, USA provides Corporate & Brand films, Promotional, Marketing videos & Training videos, Product demo videos, Employee videos, Product video explainers, eLearning videos, 2d Animation, 3d Animation, Motion Graphics, Whiteboard Explainer videos Client Testimonial Videos, Video Presentation and more for all start-ups, industries, and corporate companies. From scripting to corporate video production services, explainer & 3d, 2d animation video production , our solutions are customized to your budget, timeline, and to meet the company goals and objectives.
As a best video production company in Bangalore, we produce quality and creative videos to our clients.