## 3D – Pixelate

This is a script that pixelates point clouds into a user-defined 3-dimensional grid. It also arrays same size boxes to the pixelated points. If used wisely, it could become a good tool to rationalize a nurb surface into many small boxes.

It first pixelates the points into a wanted grid. Naturally, the geometry starts to lose its shape as the pixelating factor grows.

Then it populates the points with a box that you define.

—–

Option Explicit

‘Script written by Howard Jiho Kim / crtl-i.com

Sub Pixelate

Dim strObject, arrPoint, arrObjects, box_pt(7), box

arrObjects = Rhino.GetObjects(“Select points to pixelate”)

Dim multiplier_x, m1_x, m2_x, finalHeight_x, arrEnd(2)

multiplier_x = Rhino.GetReal(“Enter Pixelating Factor for X axis (0 for Non-Pixelation): “)

Dim multiplier_y, m1_y, m2_y, finalHeight_y

multiplier_y = Rhino.GetReal(“Enter Pixelating Factor for Y axis (0 for Non-Pixelation): “)

Dim multiplier_z, m1_z, m2_z, finalHeight_z

multiplier_z = Rhino.GetReal(“Enter Pixelating Factor for Z axis (0 for Non-Pixelation): “)

Dim box_yn

box_yn = Rhino.GetInteger(“Create boxes? (1-Yes, 2-No)”)

If box_yn = 1 Then

Dim box_x, box_y, box_z, box_mid_pt(2)

box_x = Rhino.GetReal(“Enter Box size-x: “)

box_y = Rhino.GetReal(“Enter Box size-y: “)

box_z = Rhino.GetReal(“Enter Box size-z: “)

box_pt(0) = Array(0,0,0)

box_pt(1) = Array(box_x,0,0)

box_pt(2) = Array(box_x,box_y,0)

box_pt(3) = Array(0,box_y,0)

box_pt(4) = Array(0,0,box_z)

box_pt(5) = Array(box_x,0,box_z)

box_pt(6) = Array(box_x,box_y,box_z)

box_pt(7) = Array(0,box_y,box_z)

box_mid_pt(0) = box_x/2

box_mid_pt(1) = box_y/2

box_mid_pt(2) = box_z/2

box = Rhino.AddBox(box_pt)

End If

If Not IsNull(arrObjects) Then

For Each strObject In arrObjects

arrPoint=Rhino.PointCoordinates(strObject)

Rhino.Print Rhino.Pt2Str(arrPoint, 3)

If multiplier_x > 0 Then

m1_x = arrPoint(0) / multiplier_x

m1_x = Rhino.Floor(m1_x)

m2_x = (arrPoint(0) – (m1_x*multiplier_x))*2

If m2_x > multiplier_x Then m1_x = m1_x+1

finalHeight_x = m1_x * multiplier_x

arrEnd(0) = finalHeight_x

ElseIf multiplier_x=0 Then

arrEnd(0) = arrPoint(0)

End If

If multiplier_y > 0 Then

m1_y = arrPoint(1) / multiplier_y

m1_y = Rhino.Floor(m1_y)

m2_y = (arrPoint(1) – (m1_y*multiplier_y))*2

If m2_y > multiplier_y Then m1_y = m1_y+1

finalHeight_y = m1_y * multiplier_y

arrEnd(1) = finalHeight_y

ElseIf multiplier_y=0 Then

arrEnd(1) = arrPoint(1)

End If

If multiplier_z > 0 Then

m1_z = arrPoint(2) / multiplier_z

m1_z = Rhino.Floor(m1_z)

m2_z = (arrPoint(2) – (m1_z*multiplier_z))*2

If m2_z > multiplier_z Then m1_z = m1_z+1

finalHeight_z = m1_z * multiplier_z

arrEnd(2) = finalHeight_z

ElseIf multiplier_z=0 Then

arrEnd(2) = arrPoint(2)

End If

Rhino.MoveObject strObject, arrPoint, arrEnd

If box_yn = 1 Then

Rhino.CopyObject box, box_mid_pt, arrEnd

End If

Next

If box_yn = 1 Then

Rhino.DeleteObject box

End If

End If

End Sub

Pixelate