Grasshopper

algorithmic modeling for Rhino

i quite new in VB and i need put life for particles generated by script soo,

i have a list of 3d points and i want to give them life, i working on same thing in processing then i put life count loop x=0 ++1 if x = lifespan then remove from list  but in Vb i dont know where to start with that ,should i make class for this or something alse.

Any ideas or reference for this function

 

my code

 


Private Sub RunScript(ByVal inPt As Point3d, ByVal run As Boolean, ByVal rndSpray As Double, ByVal dir As Double, ByVal vel As Object, ByVal modifier As List(Of Object), ByVal lifespan As Integer, ByRef A As Object)
If (run) Then
Dim vec As New Vector3d(1, 0, 0)
Dim rndRot As Double = Rnd * rndSpray - (rndSpray / 2)
vec = vec * vel
vec.Rotate(degToRad(rndRot), Vector3d.ZAxis)
vec.Rotate(degToRad(dir), Vector3d.ZAxis)
vecList.Add(vec)

Dim pt As Point3d = inPt
ptList.Add(pt)

For i As Int32 = 0 To ptList.Count - 1
forceSUB(modifier, ptList(i), vecList(i))
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

Sub forceSUB (ByVal modData As List(Of Object), ByVal particle As Point3d, ByRef particleVec As Vector3d)
Dim modNode As Point3d = modData(0)
Dim modRange As Double = modData(1)
Dim modForce As Double = modData(2)

Dim dist As Double = modNode.DistanceTo(particle)
If (dist < modRange) Then
Dim vecForce As Vector3d = modNode - particle
vecForce.Unitize
Dim attForce As Double = modForce / dist ^ 2
vecForce = vecForce * attForce

particleVec = particleVec + vecForce
End If
End Sub
'</Custom additional code>

End Class

Views: 425

Replies to This Discussion

Hi John,

 

I haven't read your code (I'm of duty :), but these are the two typical solutions for this:

 

  1. Create a class or structure that contains both a point and a date (this would be my preferred solution). You can also easily add additional properties later on this way.
  2. Create a second list with dates. This method means you don't have to make a new type, but it does mean you have to closely manage both your arrays (more if you want to add additional properties later) to ensure they remain 'in sync'.

 

If this code is only ever supposed to be used by you, you can create a simple class with public members:

 

Public Class Particle

  Public Point As Point3d

  Public LifeTime as DateTime

End Class

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi,

I wonder if there is any possible way to add a lifeSpan to certain objetcs using just GH components. In a system where particles collide with objects, I want those particles to "die" once the target is reached. I´ve been trying to match distance "walked" with DATE comp. but has not been a successful method..any alternative way? THNKS!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service