Jump to content


Photo

An introduction to VEF files

tutorial vef

10 replies to this topic

#1 argent77

argent77
  • Modders
  • 722 posts
  • Gender:Male

Posted 06 June 2013 - 03:50 AM

An introduction to VEF files

Introduction

The VEF format (short for: Visual Effect File) has been discovered not too long ago by the forum member Ascension64. Although it is relatively unknown yet, the format can be a big help if used right.

Basically a VEF file enables you to group any number of visual effects (VEF/VVC), animations (BAM), and sounds (WAV) together and specify a delay for each component to be triggered. That way you can create a series of visual effects to be played back on (a single!) command, without the hassle to put lots of Wait() or SmallWait() instructions in between.

It is also possible to use VEF files in spells. By using effect opcode #215 (Play 3D Effect) you can add a VEF file into the resource field as you can already do for BAMs or VVCs. There is a minor drawback however. The effect state 1 (Play on target (attached)) doesn't appear to be supported.

Setting up a VEF file is pretty straightforward. The format consists of a global header and an array of two kinds of components ('Component1' and 'Component2') containing the definitions of the actual effects. It doesn't really matter which one of the components you want to use. Both kinds appear to be used equally by the BG2 engine. The components don't have to be ordered chronologically as well. The game engine will do that for you.

Caution: It is possible to recursively nest a VEF file in itself. This will produce an endless loop and, in some cases, may cause the game to grind to a halt.


Creating a VEF file

The easiest way to understand the format is by creating a VEF by yourself. That's why I will provide a step-by-step instruction to create a nifty visual effect that could be used for imprisonment spells or the like.

Note: You will need a version of Near Infinity that includes VEF support to follow this tutorial. You can find it here.

Starting with Near Infinity w1.3.0, you can easily create a new VEF file by selecting the menu entry File->New Resource->VEF.
Spoiler

Enter the name A7FLASHY.VEF (or any other name you like) into the file creation dialog and click "Save". Press F5 or select Game->Refresh Tree to register the newly created file in Near Infinity.

Depending on how you have configured NI, the resource can be found in the Override or VEF folder and should look like this:
Spoiler



We are now ready to add our effects into the VEF. Each effect has to be defined within a 'component' structure. To create a new component, click on the Add... button in the bottom panel and select either 'Component1' or 'Component2'. It doesn't matter which one you choose. Both types are processed equally by the game engine. Double click the resulting table entry to open our new component for further editing. The table contains five relevant fields:
Spoiler


As this is the first component in our VEF, we want it to be triggered immediately. That's why we leave the 'Ticks until start' field as it is. I will explain this field further down below.

Now to the interesting parts. The 'Resource type' field determines what kind of resource the VEF will be looking for, when it is about to be triggered. As you can see, I have selected 'VVC/BAM'. That will cause the game engine to look for a VVC file first and fall back to a BAM resource if no VVC has been found. The same is true if you select 'VEF/VVC/BAM'. It will signal the game engine to look for the resource in the order VEF->VVC->BAM. The 'WAV' entry will cause the game engine to look for sound files only. For the effect in our example it isn't important whether you choose 'VVC/BAM' or 'VEF/VVC/BAM'.

The 'Resource' field should present you a list of available VVC and BAM files. The files in the list reflect the resource type you have chosen in the field above, so make sure you have already selected 'VVC/BAM'. As the file SPFLSRIN is available as both VVC and BAM, the game engine will choose to trigger the VVC version when you activate the VEF.

The remaining fields won't be touched in our VEF. If you set 'Ticks until loop' to a non-zero value, the animation will be looped endlessly, starting at the first frame of the animation. The specified number of ticks defines how long each pass will take until the loop starts over again. The field 'Continuous cycles?' determines whether only the first or all cycles within a BAM resource will be processed. This field will only be taken into account by the game engine if you select 'VVC/BAM' in the 'Resource type' field.

After our first component has been defined, you can close the window to return to the parent structure.

The second component should be triggered a short while after our first. So we enter a value into the field 'Ticks until start'. In our case, a value of 30 is suitable. One tick is processed in 1/30th seconds, therefore our effect will be triggered after exactly one second. As the default frame rate of animations is 15 fps, you can divide our delay value by two, if you want to find out how many frames of the animation defined in our first component have been processed, before our second component starts up. Sometimes you have to add or remove one tick to ensure a seamless transition between the animations.

Select 'VVC/BAM' again and select SPPLANAR.VVC in the 'Resource' field. The resulting component should now look like this:
Spoiler



For our third component we set the field 'Ticks after start' to 70 and select the BAM resource SPIMPPT.BAM, as seen in the screenshot.
Spoiler



Our fourth and last component contains a sound effect. That's because the previous component makes use of a simple BAM file, which isn't associated with a sound resource. We use the same number of ticks as for the previous component and choose WAV in the 'Resource type' field. The file list of the Resource field should now display all available WAV resources of the game. Select the file EFF_P92.WAV as shown below:
Spoiler



The resulting VEF resource should now look like this:
Spoiler


Note: The order of the components within the VEF file doesn't really matter. The game engine looks only for the starting delay and orders the components appropriately.

Save the changes you've made to the VEF file and we are done.

If you want to test it without creating a VEF by yourself, you can try out this pre-built one: Attached File  a7flashy.zip   189bytes   125 downloads

To trigger the VEF resource within the game, you can either use a script action, for example
CreateVisualEffectObject("A7FLASHY", "Edwin")

...or place it into a spell or item by using effect opcode #215 (Play 3D Effect). You can not set effect state=1, however.

Note: For testing purposes, you can also open the CLUA console and enter CLUAConsole:CreateVEFVidCell("A7FLASHY") to trigger our VEF resource at the center of the screen.

If everything went well, you should see a sequence of visual effects as shown below:
Spoiler



To do the same sequence of effects the old way, you would have to come up with something like this:
CreateVisualEffectObject("SPFLSRIN", "Edwin")
SmallWait(15)
CreateVisualEffectObject("SPPLANAR", "Edwin")
SmallWait(20)
CreateVisualEffectObject("SPIMPPT", "Edwin")
ActionOverride("Edwin", PlaySound("EFF_P92"))

As you can see, you can save a lot of code (and trouble) by using VEF files instead. This is especially true when you need to trigger the same sequence more than once or use more complex VEFs.

This tutorial has covered only a small part of what you can do with VEF files. Using the ability to nest VEF resources, you can easily produce a great number of complex sequences in short time. The same would have been accomplished by putting down dozens or even hundreds of lines of repetitive script code that would become unmanageable very soon.

Edited by argent77, 24 June 2013 - 09:47 AM.


#2 Ascension64

Ascension64
  • Modders
  • 452 posts
  • Gender:Male

Posted 07 June 2013 - 02:17 AM

I never tested this, but what happens if you change the game's frame rate? Will stuff go out of sync if you decided to use cutscene actions with a single VEF?

Edited by Ascension64, 07 June 2013 - 02:17 AM.


#3 argent77

argent77
  • Modders
  • 722 posts
  • Gender:Male

Posted 07 June 2013 - 04:34 AM

I have just tested it by doubling and halving the value of the 'Maximum Frame Rate' entry in my baldur.ini. In both cases the delays and speed rates of the animations within the VEF were reflecting the new speed rate of the game perfectly, i.e. there were no gaps or overlappings when playing back the different animation segments.

As a side note, if you specify a negative value in the 'Ticks until start' field, it will be treated as 0 by the game engine.

#4 argent77

argent77
  • Modders
  • 722 posts
  • Gender:Male

Posted 24 June 2013 - 09:51 AM

Updated tutorial to take the latest changes of Near Infinity into account.

#5 Gwendolyne

Gwendolyne
  • Members
  • 152 posts
  • Gender:Male
  • Location:France

Posted 18 September 2013 - 09:51 PM

I try to create a VEF file with a splitted bam file.

The goal is to play the three cycles together, just like the "draw all cycles" option in DLTCEP.

All my attempts failed : using the single bam, creating 3 vvc files playing one cycle and mixing them with 0 "tick" in a VEF file.

Does anyone have a single clue how to make it ?

Attached File  GWFILET.rar   115.5KB   107 downloads

Edited by Gwendolyne, 18 September 2013 - 09:53 PM.

CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel

#6 argent77

argent77
  • Modders
  • 722 posts
  • Gender:Male

Posted 19 September 2013 - 01:48 AM

You can't address BAM cycles in VEF files directly. The easiest way to accomplish this is by creating a VVC for each cycle and add the VVCs to the VEF. If you want to play all cycles simultaneously, just leave the "Ticks until start" value to 0 for all VEF entries.

You can use this test sample to see if it works. (For a quick in-game test, use the CLUA command CLUAConsole:CreateVEFVidCell("GWANIM").)

Edit: VEF files can only be used for stationary effects, so don't use effect opcode #215 (Play visual effect) with param2 set to 1 (Over target attached).

Edited by argent77, 19 September 2013 - 01:53 AM.


#7 Gwendolyne

Gwendolyne
  • Members
  • 152 posts
  • Gender:Male
  • Location:France

Posted 19 September 2013 - 04:45 AM

Thanks for the sample ! :)

In fact, I finally managed to create a VEF file that works : the same ! ;)

But I have another pb : GWFILET.VEF refers to 3 VEF Files. The 1st one GWFILET1 is the empty net that is going down. The 3rd GWFILET3 is the net full of fishes going up.
The 2d GWFILET2 is the empty net staying down for about 2 mn before GWFILET3 starts. This last one doesn't work : the bam file has the same structure but with only one frame splitted into three parts. I use the "Ticks until loop" set to 1 to display it continuously, but it only displays the top part of the net (cycle 1), and not cycles 2 and 3 (all of them using vvc files as for GWFILET1 and GWFILET3).

Maybe have I missed something ?

CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel

#8 argent77

argent77
  • Modders
  • 722 posts
  • Gender:Male

Posted 20 September 2013 - 01:54 AM

Did you set "Ticks until loop" for all segments in the VEF? If not, the remaining parts will probably be shown only for a split second.

#9 Ascension64

Ascension64
  • Modders
  • 452 posts
  • Gender:Male

Posted 20 September 2013 - 01:54 AM

You need to Continuous cycles, not ticks until loop (the latter is how many updates until the animation restarts). This would need to be set for your last resource only (not in the primary VEF).

Edited by Ascension64, 20 September 2013 - 01:55 AM.


#10 Gwendolyne

Gwendolyne
  • Members
  • 152 posts
  • Gender:Male
  • Location:France

Posted 04 September 2015 - 01:51 PM

I have got a problem with a trigger script :

IF
  Clicked([ANYONE])
  Global("GWRoue","GW0001",5)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    StartCutSceneMode()
    CutSceneId(Myself)
    DisplayStringHead(Myself,@2001038)    // ~La roue est difficile à tourner, mais vous y parvenez tout de même. Vous entendez le craquement du monte-charge qui descend.~
    StaticSequence("Roue",0)
    Wait(2)
    CreateCreature("GWSpy01",[660.2445],0)
    CreateCreature("GWSpy02",[905.2360],0)
    CreateCreature("GWSpy03",[900.2740],0)
    MoveViewPoint([880.2360],VERY_FAST)
    Wait(3)
    CreateVisualEffect("GWASC1DE",[728.2128])
    SmallWait(2)
    AmbientActivate("ElevateurH",FALSE)
    Wait(6)
    SmallWait(7)
    AmbientActivate("ElevateurB",TRUE)
    StaticSequence("Roue",3)
    SmallWait(10)
    ActionOverride("GWSpy01",DestroySelf())
    ActionOverride("GWSpy02",DestroySelf())
    ActionOverride("GWSpy03",DestroySelf())
    EndCutSceneMode()
    SetGlobal("GWRoue","GW0001",6)
    TriggerActivation("Elevator",TRUE)
    SetInterrupt(TRUE)
END

GWASC1DE is a VEF file displaying 4 vvc files at the same time (a splitted bam file). I checked it with success using the CLUAConsole:CreateVEFVidCell("GWASC1DE") command.

 

But launched with above script above, the animation is not displayed. I can only hear the sound associated with the fiirst vvc file.

 

Any idea?

 


CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel

#11 Gwendolyne

Gwendolyne
  • Members
  • 152 posts
  • Gender:Male
  • Location:France

Posted 12 September 2015 - 12:48 AM

Sorry: problem solved.

 

My cutspy creatures were wrongly coded. blush.png


CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel



Reply to this topic



  



Also tagged with one or more of these keywords: tutorial, vef

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users