web analytics
VIOLENT  VOLUMES

Voxelizer Rhinoscript

Voxel Chair black

Voxel Chair white

 

I made a voxelizer rhinoscript for a project I have in my mind. took me few days to find the

fastest algorithm but I think I ended up with common one.I tried few other ways to make

voxels but they always missed some voxels that should be made..

below is just the gist of the script

For dz = 0 to sizeZ
	' check each level of contours
	Rhino.EnableRedraw (False)
	Rhino.Print "processing step " & dz & "/" & sizeZ

	For dy = 0 to sizeY

		For dx = 0 to sizeX

			containment = 0 

			'Points to shoot
			arrPtXY = Rhino.XformCPlaneToWorld (Array(dx*IntervalX+0.5*IntervalX, dy*IntervalY+0.5*IntervalY, 0.5*IntervalZ), arrGridPlane)
			arrPtXZ = Rhino.XformCPlaneToWorld (Array(dx*IntervalX+0.5*IntervalX, 0.5*IntervalY, dz*IntervalZ+0.5*IntervalZ), arrGridPlane)
			arrPtYZ = Rhino.XformCPlaneToWorld (Array(0.5*IntervalX, dy*IntervalY+0.5*IntervalY, dz*IntervalZ+0.5*IntervalZ), arrGridPlane)

			'Projected points
			arrXYProjects = Rhino.ProjectPointToMesh (arrPtXY, strMesh, arrPtZaxis)
			arrXZProjects = Rhino.ProjectPointToMesh (arrPtXZ, strMesh, arrPtYaxis)
			arrYZProjects = Rhino.ProjectPointToMesh (arrPtYZ, strMesh, arrPtXaxis)

			'Testbox in Cplane coordinate
			arrTestBox(0) = Array(dx*IntervalX, dy*IntervalY, dz*IntervalZ)
			arrTestBox(1) = Array((dx+1)*IntervalX, dy*IntervalY, dz*IntervalZ)
			arrTestBox(2) = Array((dx+1)*IntervalX, (dy+1)*IntervalY, dz*IntervalZ)
			arrTestBox(3) = Array(dx*IntervalX, (dy+1)*IntervalY, dz*IntervalZ)

			arrTestBox(4) = Array(dx*IntervalX, dy*IntervalY, (dz+1)*IntervalZ)
			arrTestBox(5) = Array((dx+1)*IntervalX, dy*IntervalY, (dz+1)*IntervalZ)
			arrTestBox(6) = Array((dx+1)*IntervalX, (dy+1)*IntervalY, (dz+1)*IntervalZ)
			arrTestBox(7) = Array(dx*IntervalX, (dy+1)*IntervalY, (dz+1)*IntervalZ)

			'See if the projected points are in the Textbox
			If IsArray(arrXYProjects) Then
				For i = 0 to UBound(arrXYProjects)
					If IsPointInBox(Rhino.XformWorldToCPlane (arrXYProjects(i), arrGridPlane), arrTestBox) Then
						containment = 1
					End If
				Next

			End If

			If IsArray(arrXZProjects) Then

				If containment = 0 Then
					For j = 0 to UBound(arrXZProjects)
						If IsPointInBox(Rhino.XformWorldToCPlane (arrXZProjects(j), arrGridPlane), arrTestBox) Then
							containment = 1
						End If
					Next
				End If

			End If

			If IsArray(arrYZProjects) Then
				If containment = 0 Then
					For k = 0 to UBound(arrYZProjects)
						If IsPointInBox(Rhino.XformWorldToCPlane (arrYZProjects(k), arrGridPlane), arrTestBox) Then
							containment = 1
						End If
					Next
				End If
			End If

			If containment = 1 Then
				'Rhino.Print dx  & " - " & dy & " - "  & dz
				arrMakeBox(0) = Rhino.XformCPlaneToWorld (arrTestBox(0), arrGridPlane)
				arrMakeBox(1) = Rhino.XformCPlaneToWorld (arrTestBox(1), arrGridPlane)
				arrMakeBox(2) = Rhino.XformCPlaneToWorld (arrTestBox(2), arrGridPlane)
				arrMakeBox(3) = Rhino.XformCPlaneToWorld (arrTestBox(3), arrGridPlane)

				arrMakeBox(4) = Rhino.XformCPlaneToWorld (arrTestBox(4), arrGridPlane)
				arrMakeBox(5) = Rhino.XformCPlaneToWorld (arrTestBox(5), arrGridPlane)
				arrMakeBox(6) = Rhino.XformCPlaneToWorld (arrTestBox(6), arrGridPlane)
				arrMakeBox(7) = Rhino.XformCPlaneToWorld (arrTestBox(7), arrGridPlane)

				Rhino.AddBox arrMakeBox

			End IF

		Next
	Next
	Rhino.EnableRedraw (True)
Next

still have a lot of tweeking to do..

for now, it has some bugs .. and incredibly slow for large number of blocks. but it does the job I need !


Categorised as: Generative design, Product


One Comment

  1. Toby says:

    I’ve never used Rhinoscripts before but is it possible to get a full copy of the script to try out on a similar project?

    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

* Copy This Password *

* Type Or Paste Password Here *