just code for swarm and light effect

George,
To be perfectly honest, I haven’t had much time to work on this lately. I’m even considering putting it on hold till I can rid myself of this nagging vidcard problem. I’m really starting to get quite disturbed by it….. <!– s:oops: –><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarrassed" /><!– s:oops: –>
I really do appreciate all your help with this, and I will let you know how it goes, how much more hair I lose, etc.
Les

—too long – set Material Sub deleted so copy from previous–

Language = VBScript

Option Explicit andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’require variable declarations

Class SwarmClass
andnbsp; andnbsp; andnbsp; andnbsp;’this class describes the flower
andnbsp; andnbsp;Public andnbsp; andnbsp;SwarmRadius
andnbsp; andnbsp;Public andnbsp; andnbsp;NumParticles
andnbsp; andnbsp;Public andnbsp; andnbsp;SizeParticles

End Class

andnbsp; andnbsp;Public andnbsp; andnbsp;NumMaterials
andnbsp; andnbsp;Public andnbsp; andnbsp;Scene
andnbsp; andnbsp;Public andnbsp; andnbsp;Face andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; ‘The face we are creating at anytime in the proggy
andnbsp; andnbsp;Const andnbsp; andnbsp; Pi= 3.14159265358979
andnbsp; andnbsp;Public andnbsp; andnbsp;S andnbsp; ‘the swarm of objects
‘*********************************************************************************
‘ Purpose: Creates a Swarm of planes
‘*********************************************************************************

Sub Main (3DCApp)

‘ andnbsp; andnbsp;Dim Scene andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’The current active scene
andnbsp; andnbsp;Dim SceneRootFrame andnbsp; ‘The root frame of the scene
andnbsp; andnbsp;Dim SwarmFrame andnbsp; andnbsp; andnbsp; ‘a frame for our object andnbsp; andnbsp;
andnbsp; andnbsp;Dim Swarm andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’what we are making
andnbsp; andnbsp; andnbsp;
andnbsp; andnbsp;Dim SwarmX andnbsp; andnbsp; andnbsp; andnbsp;
andnbsp; andnbsp;Dim SwarmY
andnbsp; andnbsp;Dim SwarmZ andnbsp; andnbsp; andnbsp; andnbsp;’where to put the swarm

andnbsp; andnbsp;Dim Theta andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’angle for making circle stuff
andnbsp; andnbsp;Dim Phi
andnbsp; andnbsp;Dim Pi2 andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’2 * pi
andnbsp; andnbsp;Pi2=2*Pi
andnbsp; andnbsp;Dim i andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’just a little loopy

andnbsp; andnbsp;Dim Materials() andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;

andnbsp; andnbsp;Dim ThisX andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’for the current element made in the loop
andnbsp; andnbsp;Dim ThisY
andnbsp; andnbsp;Dim ThisZ
andnbsp; andnbsp;Dim ThisRadius

andnbsp; andnbsp;Dim SwarmPointCounter andnbsp; ‘for counting what has been made
andnbsp; andnbsp;Dim SwarmLoop andnbsp; andnbsp; andnbsp; andnbsp;’for looping
andnbsp; andnbsp;
andnbsp; andnbsp;Dim PointsArray(3,3) andnbsp; ‘to hold coordinates of the face
andnbsp; andnbsp;Dim t1x
andnbsp; andnbsp;Dim t1y
andnbsp; andnbsp;Dim t1z
andnbsp; andnbsp;Dim t2x
andnbsp; andnbsp;Dim t2y
andnbsp; andnbsp;Dim t2z
andnbsp; andnbsp;Dim t3x
andnbsp; andnbsp;Dim t3y
andnbsp; andnbsp;Dim t3z
andnbsp; andnbsp;Dim YAxisRotation
andnbsp; andnbsp;Dim ZAxisRotation

set S=New SwarmClass
MakeLens
‘MakeTest
‘MakeFirefly

andnbsp; ‘ get the scene
andnbsp; andnbsp;Set Scene = 3DCApp.GetActiveScene
andnbsp; andnbsp;’find the index of the objects
‘ andnbsp; andnbsp;MaterialsObjectIndex = inputbox(andquot;What object for materials?andquot;,,0)
andnbsp;’get the root frame
andnbsp; andnbsp; andnbsp; andnbsp;Set SceneRootFrame = Scene.GetRootFrame
andnbsp; andnbsp; andnbsp; andnbsp;Set SwarmFrame = Scene.CreateFrame
andnbsp; andnbsp; andnbsp; andnbsp;SceneRootFrame.AddChild SwarmFrame
andnbsp; andnbsp; andnbsp; andnbsp;SwarmFrame.SetName andquot;Swarm Frameandquot;
andnbsp; andnbsp; andnbsp; andnbsp;Set Swarm = Scene.CreateObject()
andnbsp; andnbsp; andnbsp; andnbsp;

andnbsp; andnbsp; andnbsp; andnbsp;’add a dummy normal to the object (we need one to add the points)
andnbsp; andnbsp; andnbsp; andnbsp; Swarm.AddNormal 0,0,-1

andnbsp; andnbsp;NumMaterials=6
andnbsp; andnbsp;Redim Materials (NumMaterials-1)
andnbsp; andnbsp;SetUpMaterials Materials

andnbsp; andnbsp;SwarmX=0 andnbsp; andnbsp; ‘where the Swarm is put in the model
andnbsp; andnbsp;SwarmY=0
andnbsp; andnbsp;SwarmZ=0

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; ‘first point in face always at origin
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(0,0)=0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(0,1)=0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(0,2)=0

andnbsp; andnbsp;’Main loop to create faces in Swarm Objec
andnbsp; andnbsp;For SwarmLoop = 1 to S.NumParticles
andnbsp; andnbsp; andnbsp; andnbsp;Randomize
andnbsp; andnbsp; andnbsp; andnbsp;’find radius of point andnbsp;
andnbsp; andnbsp; andnbsp; andnbsp;ThisRadius=S.SwarmRadius*Rnd andnbsp; andnbsp; andnbsp;’random radius in the sphere
andnbsp; andnbsp; andnbsp; andnbsp;’where is it?
andnbsp; andnbsp; andnbsp; andnbsp;Theta=2*Pi*rnd
andnbsp; andnbsp; andnbsp; andnbsp;Phi=Pi*rnd
andnbsp; andnbsp; andnbsp; andnbsp;ThisX = SwarmX+ThisRadius*sin(Theta)*cos(Phi)
andnbsp; andnbsp; andnbsp; andnbsp;ThisY = SwarmY+ThisRadius * sin(Phi)
andnbsp; andnbsp; andnbsp; andnbsp;ThisZ = SwarmZ+ThisRadius * cos(Theta)*cos(Phi) andnbsp; andnbsp;

andnbsp; andnbsp; andnbsp; andnbsp; ‘Now we create the petals points for just this petal andnbsp;
andnbsp; andnbsp; andnbsp; andnbsp; ‘Lets make the faces in the petal before moving on

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Set Face = Swarm.CreateFace
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’we have to add 4 points per face as they will all have different UVs
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’add the quad points to the object andnbsp;

‘THIS IS JUST QUICK – HAVEN’T WORKED OUT REAL andnbsp;POINT COORDS
‘make a little plane on the horizontal at the origin

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(0,0)=0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(0,1)=0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(0,2)=0

‘the rest are assigned in the RotatePoint command later
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(1,0)=S.SizeParticles
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(1,1)=0
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(1,2)=0”

‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(2,0)=S.SizeParticles
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(2,1)=S.SizeParticles
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(2,2)=0

‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(3,0)=0
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(3,1)=S.SizeParticles
‘ andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; PointsArray(3,2)=0

‘make two random rotations
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; YAxisRotation=rnd*2*pi
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; ZAxisRotation=rnd*2*pi ‘not really the z axis, but vector created by first side of quad

‘now rotate randomly around y axis
‘first point doesn’t move from origin

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; 3DCapp.RotatePoint S.SizeParticles,0,0,0,1,0,YAxisRotation,PointsArray(1,0),PointsArray(1,1),PointsArray(1,2)
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; 3DCapp.RotatePoint S.SizeParticles,S.SizeParticles,0,0,1,0,YAxisRotation,t2x,t2y,t2z
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; 3DCapp.RotatePoint 0,S.SizeParticles,0,0,1,0,YAxisRotation,t3x,t3y,t3z

‘now rotate 3 and 4 around vector created by first side

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; 3DCapp.RotatePoint t2x,t2y,t2z,PointsArray(1,0),PointsArray(1,1),PointsArray(1,2),ZAxisRotation,_
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;PointsArray(2,0),PointsArray(2,1),PointsArray(2,2)
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; 3DCapp.RotatePoint t3x,t3y,t3z,PointsArray(1,0),PointsArray(1,1),PointsArray(1,2),ZAxisRotation,_
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;PointsArray(3,0),PointsArray(3,1),PointsArray(3,2)

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; For i=0 to 3

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; Swarm.AddPoint ThisX+PointsArray(i,0),ThisY+PointsArray(i,1),ThisZ+PointsArray(i,2)

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; Next andnbsp; andnbsp; ‘ii

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’ Swarm.AddPoint ThisX-S.SizeParticles,ThisY-S.SizeParticles,ThisZ-S.SizeParticles
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’ Swarm.AddPoint ThisX-S.SizeParticles,ThisY+S.SizeParticles,ThisZ-S.SizeParticles
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’ Swarm.AddPoint ThisX+S.SizeParticles,ThisY+S.SizeParticles,ThisZ+S.SizeParticles andnbsp;
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’ Swarm.AddPoint ThisX+S.SizeParticles,ThisY-S.SizeParticles,ThisZ+S.SizeParticles
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;

andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’add the points and the normal to the face
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Face.AddPointAndNormal 0+SwarmPointCounter,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Face.AddPointAndNormal 1+SwarmPointCounter,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Face.AddPointAndNormal 2+SwarmPointCounter,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Face.AddPointAndNormal 3+SwarmPointCounter,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Swarm.SetPointTextureCoordinate 0+SwarmPointCounter,-1,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Swarm.SetPointTextureCoordinate 1+SwarmPointCounter,-1,-1
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Swarm.SetPointTextureCoordinate 2+SwarmPointCounter,0,-1
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Swarm.SetPointTextureCoordinate 3+SwarmPointCounter,0,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;SwarmPointCounter=SwarmPointCounter+4
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; ‘apply the material to the face
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Face.SetMaterial Materials(0)
andnbsp; andnbsp;Next andnbsp; ‘SwarmLoop
andnbsp; andnbsp; andnbsp; andnbsp;
‘msgbox(andquot;finished all loopingandquot;)

‘add the object to the created frame
andnbsp; andnbsp; andnbsp; andnbsp;’this also triggers the update to the database
andnbsp; andnbsp; andnbsp; andnbsp;SwarmFrame.AddObject Swarm

andnbsp; andnbsp; andnbsp; andnbsp;’set the object name – note that we can’t do this until
andnbsp; andnbsp; andnbsp; andnbsp;’the object is added to a frame
andnbsp; andnbsp; andnbsp; andnbsp;Swarm.SetName andquot;Swarmandquot;

end sub

sub MakeLens
with S

andnbsp; andnbsp; andnbsp;.SwarmRadius=1
andnbsp; andnbsp; andnbsp;.NumParticles=3000
andnbsp; andnbsp; andnbsp;.SizeParticles=.01
end with

End sub

sub MakeTest
with S

andnbsp; andnbsp; andnbsp;.SwarmRadius=10
andnbsp; andnbsp; andnbsp;.NumParticles=100
andnbsp; andnbsp; andnbsp;.SizeParticles=1
end with

End sub

George,
I think I got it……..hehehe.
I’m including a picture of the swarm that I created with the last script, and here’s another question.
Looking at the lower center area of the swarm, where it appears to be almost solid, to increase the area that the andquot;almost solid areaandquot; covers, would I just increase the number of faces from 3000 to ???. The effect I’m trying for is a glowing look, and this script is pretty close. That’s why I’m wondering about making the swarm more dense.

Next question; Is it possible to set a transparency level that would be about andquot;0andquot; at the center, and increase that transparency factor/value outward through the swarm, so that the outer areas would be more transparent, creating the glow look.

I didn’t want to change the script until I asked you this. Also, if you would like, you can send scripts in email again to conserve space here.
Les

ok so now you’re finally cooking <!– s:-) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile" /><!– s:-) –>

for the density question, play around with the size of the particles and the radius. andnbsp;Did you solve the problem of the hemispherical distrubution?

I’m expecting you to change the script as part of your learning process <!– s:-) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile" /><!– s:-) –>

Changing the transparency of the objects is trickier. andnbsp;you could create a texture and apply it depending on radius – change the texture each time you make a particle – probably computationally inefficient, though possible. andnbsp;You could also make a number of materials in an array with a transparency gradient. andnbsp;My default, if you understood the tutorial, is 6 different materials in my pallete. andnbsp;I would set up the 6 on my paint strip, then apply Materials[0].. Materials[5] according to radius.

Good luck
G

You must be logged in to reply in this thread.

4 posts