[Solved] Reloading a particle script?
Posted: Fri Nov 08, 2013 8:33 pm
In order to reload a particle script you must reload the material script (that the particle script uses) after the particle script is reloaded.
I'm not sure if this is the proper way, but it does work for me. If anyone knows a reason why I shouldn't do it this way let me know.
New working example.
I'm not sure if this is the proper way, but it does work for me. If anyone knows a reason why I shouldn't do it this way let me know.
New working example.
Code: Select all
#CameraSpeed = 10
IncludeFile "Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
Declare CreateParticleScript()
Result.q=FileSize("Data/Particles/TestParticle.particle")
If Result>0
DeleteFile("Data/Particles/TestParticle.particle")
EndIf
If InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
Add3DArchive("Data/Textures" , #PB_3DArchive_FileSystem)
Add3DArchive("Data/Scripts" , #PB_3DArchive_FileSystem)
Add3DArchive("Data/Particles" , #PB_3DArchive_FileSystem)
Parse3DScripts()
KeyboardMode(#PB_Keyboard_International)
; Particles
;
CreateParticleScript()
ReloadMaterial("Particle/JetEngine1", "TestParticle.particle", #True)
ReloadMaterial("Examples/Flare", "Examples.material", #True)
Result=GetScriptParticleEmitter(0, "Particle/JetEngine1")
If Result=0
MessageRequester("Information","Could not find particle emitter!")
EndIf
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 300, #PB_Absolute)
Repeat
Screen3DEvents()
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.005
MouseY = -MouseDeltaY() * #CameraSpeed * 0.005
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure CreateParticleScript()
If CreateFile(0, "Data/Particles/TestParticle.particle")
Restore Material
Line$ = "//Particle Test"
While Line$<> "END"
WriteStringN(0, Line$)
Read.s Line$
Wend
CloseFile(0)
Else
MessageRequester("Information","Can not create the file!")
EndIf
EndProcedure
DataSection
Material:
Data.s "// A jet engine (of sorts)"
Data.s "particle_system Particle/JetEngine1"
Data.s "{"
Data.s " material Examples/Flare"
Data.s " particle_width 25"
Data.s " particle_height 25"
Data.s " cull_each false"
Data.s " quota 200"
Data.s " billboard_type point"
Data.s " emitter Point"
Data.s " {"
Data.s " angle 5"
Data.s " emission_rate 100"
Data.s " time_to_live 1"
Data.s " direction 0 -1 0"
Data.s " velocity_min 250"
Data.s " velocity_max 300"
Data.s " colour_range_start 1 1 0.5"
Data.s " colour_range_end 1 0.8 0.3"
Data.s " }"
Data.s " affector ColourFader"
Data.s " {"
Data.s " red -0.25"
Data.s " green -1"
Data.s " blue -1"
Data.s " }"
Data.s "}"
Data.s "END"
EndDataSection