Open Source Platform
for interconnected virtual worlds

Content Scripting Client side particle effect

From RexWiki

Free moving particle script

The following script launches a particle system client side. The movement is not replicated on the server. You need to have the particle script assets "smoke_small" and "fire_small" present on the server.

import rxactor
import rxavatar
import sys
import clr

asm = clr.LoadAssemblyByName('OpenSim.Region.ScriptEngine.Common')
Vector3 = asm.OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3

import random
import math

class EffectTest(rxactor.Actor):
    def GetScriptClassName():
        return "sampleclienteffect.EffectTest"

    def EventCreated(self):
        super(self.__class__,self).EventCreated()
        print "sampleclienteffect.EffectTest EventCreated"

    def EventTouch(self,vAvatar):
        self.CurrentTest = 0
        self.AgentId = vAvatar.AgentId

        self.llShout(0,"fire!")
        tempavatar = self.MyWorld.AllAvatars[self.AgentId]

        self.Spawnloc = tempavatar.llGetPos()
        self.Spawnrot = Vector3(1,0,0) * tempavatar.llGetRot()
        pos = self.Spawnloc + 0.4 * self.Spawnrot
        rot = self.llEuler2Rot(Vector3(0,math.pi*0.5,0))
        duration = 2.5
        speed = 5.5
        vAvatar.rexSetClientSideEffect("smoke_small",47,0,duration,pos,tempavatar.llGetRot(),speed)
        # distance to travel is speed * time
        pos = self.Spawnloc + speed * duration * self.Spawnrot
        vAvatar.rexSetClientSideEffect("fire_small",47,duration,8.201,pos,self.llEuler2Rot(Vector3(0,0,0)),0)

The notable function is rexSetClientSideEffect()

def rexSetClientSideEffect(self,assetName,assetType,vTimeUntilLaunch,vTimeUntilDeath,vPos,vRot,vSpeed):

where:

  • assetName is the name of the particle script to use
  • assetType is the type of the asset, 47 in case of particle scripts
  • vTimeUntilLaunch is time in seconds until the effect is launched on the client. Set to zero to launch immediatelly.
  • vTimeUntilDeath the duration of the effect. The particle system gets completely destroyed after this duration. The duration is counted after the effect is launched.
  • vPos position of the effect in the world
  • vRot rotation of the particle system. Affects it's movement if vSpeed > 0
  • vSpeed speed at which the particle system moves. The system moves at the direction specified by vRot. Set to zero to make it stationary.


Particle script attached to the camera

You can also create particle system that is attached to the camera. Uses are f.ex. dust particles floating around in a room, snow or water effects and so on.

def rexSetCameraClientSideEffect(self,enable,assetName,assetType,vPos,vRot):

where:

  • enable if True, enable the effect, False to disable
  • assetName name of the particle script to use
  • assetType is the type of the asset, 47 in case of particle scripts
  • vPos offset position from the camera
  • vRot offset rotation from the camera