Page 1 of 3

Fog settings and Region

PostPosted: Wed Apr 21, 2010 2:29 am
by tachzusamm
Is it possible to have a different fog density, depending on a region?
Something similar to what Cyan did in Minkata, although I would prefer an abrupt transition.

Re: Fog settings and Region

PostPosted: Wed Apr 21, 2010 2:49 am
by Aloys
Yes, it is definitely possible. Dlanor post an overview of the code a while ago here. It should definitely be possible to trigger it using a region, but I haven't seen anyone describe a precise step-by-step process yet.

Re: Fog settings and Region

PostPosted: Wed Apr 21, 2010 3:08 am
by tachzusamm
Thank you for this link, sounds promising.

(Seems again there are so many good hints spreaded around in the forums, sort of hidden in threads, and a small chance to find them when you don't have bookmarks already. Do we need a WIKI page, maybe called "valuable ideas and procedures" to just collect them, like a list of bookmarks with a short description?)

Now I have to find out how to attach the functions to a region.
Looking at the AlcScript reference, I have no idea how to link Python code to a region.

Does somebody know if regions can trigger a callback, like "regionEntered" or "regionLeft"?

Re: Fog settings and Region

PostPosted: Wed Apr 21, 2010 10:14 am
by diafero
I know that regions can trigger a Python code, but I don't know how :(

Oh, and regarding the wiki page - if you have some of these links, just go ahead and start one :) (for example, that thread about how to disable the Relto book could also be added)

Re: Fog settings and Region

PostPosted: Wed Apr 21, 2010 9:09 pm
by Lontahv
I'm pretty sure Minkata's fog/dust was done with particle systems. I haven't looked but I'd assume there's some kind of exclusion region in the kivas.

Re: Fog settings and Region

PostPosted: Wed Apr 21, 2010 9:47 pm
by GPNMilano
Lontahv wrote:I'm pretty sure Minkata's fog/dust was done with particle systems. I haven't looked but I'd assume there's some kind of exclusion region in the kivas.


You'd be correct on one and incorrect on the other. Minkata's fog is both particle systems and the fog settings in the fni file. Region sensors control the actual fog tweening it with a python file called xFogDistTweener. Inside the caves the fog is set with a pythonfile called xFogSet. Finally the dust itself is particle systems. So it's both fog and systems working together, the fog being controlled by regions.

EDITS:

tachzusamm wrote:Now I have to find out how to attach the functions to a region.
Looking at the AlcScript reference, I have no idea how to link Python code to a region.

Does somebody know if regions can trigger a callback, like "regionEntered" or "regionLeft"?


Had to track down some alcscript from Dorehn's imagers but here's the alcscript for triggering a pythonfile with regions.

This is the code that gets attached to a region.
Code: Select all
RegionName:
    logic:
        modifiers:
          - name: NameOfYourLogicModifier_Enter
            cursor: up
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
                trignum: -1
            activators:
              - type: objectinvolume
                remote: RegionName
          - name: NameOfYourLogicModifier_Exit
            cursor: up
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: exit
                trignum: -1
            activators:
              - type: objectinvolume
                remote: RegionName
      


Then whatever you use for your pythonfilemod you'd have it be activated by the Enter section of the logic mod above.

Re: Fog settings and Region

PostPosted: Thu Apr 22, 2010 5:54 am
by tachzusamm
Thank you for the reply; I think I understand now (partly) how the AlcScript should look like.

But I still feel a bit helpless. What is a pythonfilemod?
I have browsed the forums to get an answer, and found that such a pythonfilemod does call a python file finally. Is this correct?
And, besides that, "which" function in a python file is called then?

So, how do I "create/use/install/attach" such a pythonfilemod? Is it a Python file as well, or another AlcScript part, or a Blender object? Or something totally different, or part of an existing function in plasma?

Although I've written some Python import/export scripts for Blender in the past, I feel stupid now.

What I currently understand (hopefully) is:
a) The AlcScript defines that when a region is entered, the "NameOfYourLogicModifier_Enter" pythonfilemod is called. (Is saying "called" right?)
b) ...
?)
f) Finally a function in a script I do write by myself is called, which does for example change the fog density:
Code: Select all
    def MySetFogDensity_onEnter(self, ...):
        fogStart = -20
        fogEnd = 100
        fogDens = 0.5
        PtFogSetDefLinear(fogStart, fogEnd, fogDens)


But, umm, what needs to be done between ?

Seems I need an example, or a reference / link where to get further information.

Re: Fog settings and Region

PostPosted: Thu Apr 22, 2010 10:11 am
by D'Lanor
You can add the pythonfilemod to any object but here it is attached the region:

Code: Select all
RegionName:
    logic:
        modifiers:
          - name: NameOfYourLogicModifier_Enter
            cursor: up
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
                trignum: -1
            activators:
              - type: objectinvolume
                remote: RegionName
            actions:
              - type: pythonfile
                ref: :NameOfPythonFileMod
          - name: NameOfYourLogicModifier_Exit
            cursor: up
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: exit
                trignum: -1
            activators:
              - type: objectinvolume
                remote: RegionName
            actions:
              - type: pythonfile
                ref: :NameOfPythonFileMod
        actions:
          - type: pythonfile
            name: NameOfPythonFileMod
            pythonfile:
                file: YourPythonFile
                parameters:
                  - type: activator
                    ref: logicmod:NameOfYourLogicModifier_Enter
                  - type: activator
                    ref: logicmod:NameOfYourLogicModifier_Exit

Your Python code would look like this then.

Code: Select all
from Plasma import *
from PlasmaTypes import *
actEnter = ptAttribActivator(1, 'Enter region activator')
actExit = ptAttribActivator(2, 'Exit region activator')
class YourPythonFile(ptModifier,):

    def __init__(self):
        ptModifier.__init__(self)
        self.version = 1
        print ('__init__%s v.%s' % (self.__class__.__name__,
         self.version))



    def OnNotify(self, state, id, events):
        if (not PtWasLocallyNotified(self.key)):
            return
        if ((id == actEnter.id) and state):
            self.MySetFogDensity_onEnter()
        elif ((id == actExit.id) and state):
            self.MySetFogDensity_onExit()



# your code here


# glue section here

Re: Fog settings and Region

PostPosted: Thu Apr 22, 2010 2:35 pm
by tachzusamm
Thank you for your advice.
So if I get it right, I have to replace "NameOfYourLogicModifier_Enter" with "actEnter" (same with Exit), and "YourPythonFile" just with the name of the Python file.

Like this:

Code: Select all
Region_FogChange:
    logic:
        modifiers:
          - name: actEnter
            cursor: up
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
                trignum: -1
            activators:
              - type: objectinvolume
                remote: Region_FogChange
            actions:
              - type: pythonfile
                ref: :NameOfPythonFileMod
          - name: actExit
            cursor: up
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: exit
                trignum: -1
            activators:
              - type: objectinvolume
                remote: Region_FogChange
            actions:
              - type: pythonfile
                ref: :NameOfPythonFileMod
        actions:
          - type: pythonfile
            name: NameOfPythonFileMod
            pythonfile:
                file: TestAge_FogChange.py
                parameters:
                  - type: activator
                    ref: logicmod:actEnter
                  - type: activator
                    ref: logicmod:actExit


and Python code:

Code: Select all
from Plasma import *
from PlasmaTypes import *
actEnter = ptAttribActivator(1, 'Enter region activator')
actExit = ptAttribActivator(2, 'Exit region activator')
class TestAge_FogChange(ptModifier,):

    def __init__(self):
        ptModifier.__init__(self)
        self.version = 1
        print ('__init__%s v.%s' % (self.__class__.__name__,
         self.version))



    def OnNotify(self, state, id, events):
        if (not PtWasLocallyNotified(self.key)):
            return
        if ((id == actEnter.id) and state):
            self.MySetFogDensity_onEnter()
        elif ((id == actExit.id) and state):
            self.MySetFogDensity_onExit()



    def MySetFogDensity_onEnter(self):
        PtFogSetDefLinear(-20, 100, 0.5)


    def MySetFogDensity_onExit(self):
        PtFogSetDefLinear(1, 1000, 0.1)


# glue section



Well... call me stupid, but I still don't get it. What about ":NameOfPythonFileMod"?
Because I don't know what a pythonfilemod is, I have no idea what it's name could be...

Is it just a name I can freely choose (or just keep it named "NameOfPythonFileMod") and all references to this name are those directly inside the AlcScript?

Re: Fog settings and Region

PostPosted: Thu Apr 22, 2010 3:23 pm
by D'Lanor
tachzusamm wrote:Thank you for your advice.
So if I get it right, I have to replace "NameOfYourLogicModifier_Enter" with "actEnter" (same with Exit),

Both names would work. The name in the Python file does not need to match the name in the Alcscript.

tachzusamm wrote:and "YourPythonFile" just with the name of the Python file.

Correct.

tachzusamm wrote:Well... call me stupid, but I still don't get it. What about ":NameOfPythonFileMod"?
Because I don't know what a pythonfilemod is, I have no idea what it's name could be...

Basically a pythonfilemod is used to make your Plasma objects "known" to the Python file. The parameters of your pythonfilemod are picked up in order of appearance in the Python file by those PtAttrib... classes. I remember when I figured that out it was a big eye opener.

tachzusamm wrote:Is it just a name I can freely choose (or just keep it named "NameOfPythonFileMod") and all references to this name are those directly inside the AlcScript?

You can freely choose the name.