Sei sulla pagina 1di 8

u r b a n f u t u r e o r g a n i z a t i o n

particles for GH3D 101: part 2

Ok, so where we left off last session…

Emitter: check
Timer: check
Particles: check
Particle Control… not yet.

Let’s try to get a little more control on the way in which the particle sprays by controlling the random
distribution.

Drag a new slider and call this rndSpray (for random spray) with domain parameters (0 .0 to 180.0)
Create an input on the VB component called rndSpray and give this a Double hint.
Connect the rndSpray slider to the rndSpray input as such:

Open the VB component


As we’re going to perform specific rotations on the intial vector, we can remove the entire yPos vector
declaration and also update the vector declaration to:

Dim vec As New Vector3d(1, 0, 0)

Now we want to create a rotation domain of 180 degrees (which would be a range from -90 to 90).

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

Let’s say that:

Rnd * 180

would result in a random generation of numbers within the domain (0 to 180)

We are actually after a domain of (-90 to 90) so we subtract 90 from the random generation.

Rnd * 180 - 90

(in this case we don’t need to block the Rnd*180 as VB processes in a sequential manner) this provides
a domain of (-90 to 90)

Our rndSpray of 0 – 180 can be implemented using:

Dim rndRot As Double = Rnd * rndSpray - (rndSpray / 2)

As RhinoCommon uses radian rotation (rather than degrees) we need to convert this from our degrees to
radians. We can build a function for this to simplify the code.

Sub degToRad(ByRef deg As Double)


deg = deg / 180 * Math.Pi
End Sub

We need to then pass the rndRot through the function:

degToRad(rndRot)

If we want to produce a randomly distributed start vector, we can use the vector3d.Rotate operation on
the newly creates vec – we can pass the degToRad function for the angle parameter:

vec.Rotate(degToRad(rndRot), Vector3d.ZAxis)

Done. So when we run the particle test, it should now control the random distribution of spray.

Let’s now include variable control of spray direction.


Drag another double param component to the canvas (with a range of 0> 360) and create a new double
input for the VB component – let’s call this input variable dir.

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

Open the VB component and we need to add one more line below the vec.Rotate in order to control the
initial direction.

vec.Rotate(degToRad(dir), Vector3d.ZAxis)

Lastly we’ll introduce a velocity control within the component.


Drag a double slider to the canvas and rename velocity (1.0 > 10 domain)

As velocity only relies on distance per second, we should really be referencing the timer values as well as
a distance variable. At this point we can just use a slider to represent a units/second calculation with a
static internal variable representing our timer click - later we will include our one internal timer (based on
Giulio Piacentino’s code) and can more accurately simulate m/s calculations.

Create a new double input called velocity for the VB component


Add one more line above both vec.Rotate operations as follows:

vec = vec * velocity

Now the script allows for spray distribution and direction. The entire code should now read as follows:

Private Sub RunScript(ByVal inPt As Point3d, ByVal run As Double, ByVal


rndSpray As Double, ByVal dir As Double, ByRef A As Object)

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

If(run) Then
Dim vec As New Vector3d(1, 0, 0)

Dim rndRot As Double = Rnd * rndSpray - (rndSpray / 2)

vec = vec * velocity

vec.Rotate(degToRad(dir), Vector3d.ZAxis)
vec.Rotate(degToRad(rndRot), Vector3d.ZAxis)
vecList.Add(vec)

Dim newPt As New Point3d


newPt = inPt
ptList.Add(newPt)
For i As Int32 = 0 To ptList.Count - 1
ptList(i) = ptList(i) + vecList(i)
Next
A = ptList
Else
vecList.Clear
ptList.Clear
End If

End Sub

'<Custom additional code>


Dim vecList As New List (Of Vector3d)
Dim ptList As New List(Of Point3d)

Function degToRad(ByRef deg As Double) As Double


Dim rad As Double = deg / 180 * Math.Pi
Return rad
End Function

Ok for now that’s enough characteristics for the actual emitter.

You can download the rhino + grasshopper package here

Spatial Modifiers

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

gravity, m.c. escher. 1952. lithograph and watercolour

We can move onto developing our own spatial modifier. Spatial modifiers can be seen as forces that
may affect the particle within the system.

sp ati al m odif i er:


{h arm on ic ; m agn e tic f i e ld ; tur b u le nc e; gr a v it y}

Firstly we’ll look at introducing an attraction node. For this we can use a simple point distance logic
between attraction node centre and particle. Rather than jam two additional inputs into the VB
component, we should start to think about economizing our stream data. Below illustrates a more
intuitive direction in stream management, where a reduction of inputs for each component can clarify the
system’s organizational logic. In further tutorials we will explore writing your own classes in Visual Studio.
VS development allows for the implementation of custom Grasshopper components – a great advantage
of this meant that you can provide default settings for component inputs (meaning that you don’t always
need to plug streams in order for the component to work).

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

organized data stream

Right. Let’s start off with just generating an attractor node.

Let’s rename out VB component ‘particle engine’


Create a new point object within rhino and place it at location (100, 50, 0)
Drag a new point param (‘node’) onto the canvas and reference the newly created point.
Also drag two sliders: one will be a ‘range’ (5.0 > 100.0 ) and the other a ‘force’ (0.0 > 10)
We should also drag a Data Param component and rename to ‘modifier data’
Connect (using the shift key) all three new modifier variables into ‘modifier data’ (node, range, force)

Let’s create a new input to ‘particle engine’ called ‘modifier’ and give it a List Access (remember we are
now going to use the ‘modifier data’ list to obtain the specific modifier variables).
Connect the ‘modifier data’ to the ‘modifier’ input.

You should now have a canvas that looks like this:

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

Currently there’s no visual feedback for what data the attractor contains. If we are applying a point
distance logic force we could represent this range by including a circle boundary. Using a simple XY / XZ
/ YZ Plane component and circle component it should give some visual cue to how the modifier operates.

Canvas view

geometry view of node and range parameter

So how do we have the node affect the particle?

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org


u r b a n f u t u r e o r g a n i z a t i o n

As we have the ‘modifier’ data as a list, we can refer to each list item as a specific parameter within the
‘particle engine’

Harmonic; magnetic field; turbulence, gravity

Speed Input
Num per Cycle

u rb a n f ut u re o rg a ni zati o n ● 1 8 4 s t j o h ns road. gl ebe. nsw. 2037 ● + 61 295716336 ● www. au -urbanf ut ure.org

Potrebbero piacerti anche