Difference between revisions of "Oolite JavaScript Reference: VisualEffect"

From Elite Wiki
m (Properties: Fix formatting)
(Properties)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''This is a new class planned for 1.77 and may be subject to significant change before 1.77 is released.'''
 
 
 
<small>'''Prototype:''' <code>[[Oolite JavaScript Reference: Entity|Entity]]</code></small><br />
 
<small>'''Prototype:''' <code>[[Oolite JavaScript Reference: Entity|Entity]]</code></small><br />
   
Line 6: Line 4:
   
 
== Properties ==
 
== Properties ==
{{oolite-prop-added|1.77}}
+
Unless otherwise stated {{oolite-prop-added|1.77}}
   
 
=== <code>beaconCode</code> ===
 
=== <code>beaconCode</code> ===
 
'''beaconCode''' : String (read-write)
 
'''beaconCode''' : String (read-write)
 
If the effect is a beacon, an identifying string. The first character is used for identification on the [[Advanced Space Compass]]. For non-beacons, this property is <code>null</code>.
 
If the effect is a beacon, an identifying string. The first character is used for identification on the [[Advanced Space Compass]]. For non-beacons, this property is <code>null</code>.
  +
  +
=== <code>beaconLabel</code> ===
  +
{{oolite-prop-added|1.79}}
  +
'''beaconLabel''' : String (read/write)
  +
A full label for the beacon. This is useful where the beacon code and the full beacon label do not begin with the same letter.
   
 
=== <code>dataKey</code> ===
 
=== <code>dataKey</code> ===
Line 21: Line 24:
   
 
=== <code>isBreakPattern</code> ===
 
=== <code>isBreakPattern</code> ===
'''allowsDocking''' : Boolean (read/write)
+
'''isBreakPattern''' : Boolean (read/write)
 
If this is true, the VisualEffect object will remain visible while break patterns on docking, launching or witchspace are being displayed (or not displayed). Normally all objects other than the break pattern itself are hidden.
 
If this is true, the VisualEffect object will remain visible while break patterns on docking, launching or witchspace are being displayed (or not displayed). Normally all objects other than the break pattern itself are hidden.
   
Line 29: Line 32:
 
'''scaleZ''' : positive Float (read/write)
 
'''scaleZ''' : positive Float (read/write)
   
Adjust the apparent size of the visual effect along each of its main axes. Subentity visual effects will be repositioned and rescaled accordingly. Subentity flashers will be repositioned, but not rescaled (as flashers are always spherical).
+
Adjust the apparent size of the visual effect along each of its main axes. Subentity visual effects will be repositioned and rescaled accordingly. Subentity flashers will be repositioned and resized to keep a roughly proportionate volume, but not rescaled (as flashers are always spherical).
   
 
effect.scaleX = effect.scaleY = effect.scaleZ = newsize;
 
effect.scaleX = effect.scaleY = effect.scaleZ = newsize;
Line 56: Line 59:
 
=== <code>scriptInfo</code> ===
 
=== <code>scriptInfo</code> ===
 
'''scriptInfo''' : Object (read-only)
 
'''scriptInfo''' : Object (read-only)
The contents of the <code>script_info</code> key in the effect’s ''[[effectdata.plist]]'' entry, if any. This may be any [[property list]] object, but the reccomended approach is to use a dictionary whose keys have a unique prefix (such as you should be using for file names, ship names etc.). A property list dictionary is converted to a JavaScript object with properties corresponding to the dictionary’s keys. All other property list types used with Oolite have directly corresponding JavaScript types.<br>
+
The contents of the <code>script_info</code> key in the effect’s ''[[effectdata.plist]]'' entry, if any. This may be any [[property list]] object, but the recommended approach is to use a dictionary whose keys have a unique prefix (such as you should be using for file names, ship names etc.). A property list dictionary is converted to a JavaScript object with properties corresponding to the dictionary’s keys. All other property list types used with Oolite have directly corresponding JavaScript types.<br>
 
When using numeric values in the scriptInfo, the JS engine is not able to detect the type reliably on all systems, so you always must explicitly convert its content to a number by using parseInt(scriptInfo.myKey) or parseFloat(scriptInfo.myKey).
 
When using numeric values in the scriptInfo, the JS engine is not able to detect the type reliably on all systems, so you always must explicitly convert its content to a number by using parseInt(scriptInfo.myKey) or parseFloat(scriptInfo.myKey).
   
Line 67: Line 70:
 
'''shaderVector2''' : Vector (read/write)
 
'''shaderVector2''' : Vector (read/write)
 
Since visual effects have very few intrinsic properties, some arbitrary parameters which may be bound as shader uniforms are provided.
 
Since visual effects have very few intrinsic properties, some arbitrary parameters which may be bound as shader uniforms are provided.
  +
  +
=== <code>subEntities</code> ===
  +
'''subEntities''' : Array (read-only)
  +
A list of those subentities which are also visual effects
   
 
== Methods ==
 
== Methods ==
Line 86: Line 93:
 
function '''remove'''()
 
function '''remove'''()
 
Immediately removes the effect from the universe.
 
Immediately removes the effect from the universe.
  +
  +
=== <code>restoreSubEntities</code> ===
  +
function '''restoreSubEntities'''()
  +
Restores all missing subentities. Returns the number of subentities restored.
   
 
=== <code>scale</code> ===
 
=== <code>scale</code> ===
Line 114: Line 125:
 
Effects scripts have one property, <code>this.visualEffect</code>, which is a reference to the visual effect this is a script for. They have the following event handlers.
 
Effects scripts have one property, <code>this.visualEffect</code>, which is a reference to the visual effect this is a script for. They have the following event handlers.
   
=== effectRemoved ===
+
=== <code>effectRemoved</code> ===
   
 
The <code>effectRemoved</code> handler is called when the effect is removed from the universe, either by the [[#remove|remove]] function, or automatically when the player leaves the system. This is a good place to clean up any frame callbacks or timers associated with this effect.
 
The <code>effectRemoved</code> handler is called when the effect is removed from the universe, either by the [[#remove|remove]] function, or automatically when the player leaves the system. This is a good place to clean up any frame callbacks or timers associated with this effect.
Line 123: Line 134:
 
}
 
}
   
=== effectSpawned ===
+
=== <code>effectSpawned</code> ===
   
 
The <code>effectSpawned</code> handler is called on the first update after the effect is added to the universe.
 
The <code>effectSpawned</code> handler is called on the first update after the effect is added to the universe.

Latest revision as of 14:56, 12 October 2013

Prototype: Entity

The VisualEffect class is an Entity representing a visible but non-solid object defined from effectdata.plist. It has all the properties and methods of an Entity, and several others.

Properties

Unless otherwise stated This property was added in Oolite test release 1.77.

beaconCode

beaconCode : String (read-write)

If the effect is a beacon, an identifying string. The first character is used for identification on the Advanced Space Compass. For non-beacons, this property is null.

beaconLabel

This property was added in Oolite test release 1.79.

beaconLabel : String (read/write)

A full label for the beacon. This is useful where the beacon code and the full beacon label do not begin with the same letter.

dataKey

dataKey : String (read-only)

The data key from effectdata.plist used to generate this visual effect.

hullHeatLevel

hullHeatLevel : Float (read/write)

While visual effects do not have a temperature as such, this property is provided to allow easy compatibility with the default Oolite shader for ships.

isBreakPattern

isBreakPattern : Boolean (read/write)

If this is true, the VisualEffect object will remain visible while break patterns on docking, launching or witchspace are being displayed (or not displayed). Normally all objects other than the break pattern itself are hidden.

scaleX, scaleY, scaleZ

scaleX : positive Float (read/write)
scaleY : positive Float (read/write)
scaleZ : positive Float (read/write)

Adjust the apparent size of the visual effect along each of its main axes. Subentity visual effects will be repositioned and rescaled accordingly. Subentity flashers will be repositioned and resized to keep a roughly proportionate volume, but not rescaled (as flashers are always spherical).

effect.scaleX = effect.scaleY = effect.scaleZ = newsize;

is equivalent to

effect.scale(newsize);

if you need to rescale the effect uniformly

scannerDisplayColor1

scannerDisplayColor1 : Colour specifier (read/write)

The first of two colours used by the ship’s scanner “lollipop”. When read, this will always be an array of four numbers in the range 0..1 (representing red, green, blue and alpha components). Any colour specifier format may be assigned to it. Assigning null will restore the value from effectdata.plist.

If both this and scannerDisplayColor2 are set to null, and no value is set for either in effectdata.plist then the effect will not appear on scanners.

See also: scannerDisplayColor2

scannerDisplayColor2

scannerDisplayColor2 : Colour specifier (read/write)

The second scanner colour. If both scannerDisplayColor1 and scannerDisplayColor2 are specified, the scanner lollipop will alternate between the two colours.

See also: scannerDisplayColor1

script

script : Script (read-only)

The effect’s script. See the "Effect Scripts" section below for more details.

scriptInfo

scriptInfo : Object (read-only)

The contents of the script_info key in the effect’s effectdata.plist entry, if any. This may be any property list object, but the recommended approach is to use a dictionary whose keys have a unique prefix (such as you should be using for file names, ship names etc.). A property list dictionary is converted to a JavaScript object with properties corresponding to the dictionary’s keys. All other property list types used with Oolite have directly corresponding JavaScript types.
When using numeric values in the scriptInfo, the JS engine is not able to detect the type reliably on all systems, so you always must explicitly convert its content to a number by using parseInt(scriptInfo.myKey) or parseFloat(scriptInfo.myKey).

shader*

shaderFloat1 : Number (read/write)
shaderFloat2 : Number (read/write)
shaderInt1 : Number (read/write)
shaderInt2 : Number (read/write)
shaderVector1 : Vector (read/write)
shaderVector2 : Vector (read/write)

Since visual effects have very few intrinsic properties, some arbitrary parameters which may be bound as shader uniforms are provided.

subEntities

subEntities : Array (read-only)

A list of those subentities which are also visual effects

Methods

This method was added in Oolite test release 1.77.

getMaterials

function getMaterials() : Object

getMaterials() returns the effect's current materials dictionary, or if none present an empty dictionary.

See also: setMaterials(), getShaders()

getShaders

function getShaders() : Object

getShaders() returns the effect's current shaders dictionary, or if none present an empty dictionary.

See also: setShaders(), getMaterials()

remove

function remove()

Immediately removes the effect from the universe.

restoreSubEntities

function restoreSubEntities()

Restores all missing subentities. Returns the number of subentities restored.

scale

function scale(factor : Number)

Multiplies the size of the visual effect by factor. Subentities will be rescaled as well, and moved further from the centre of the effect as appropriate. An error will occur if factor is less than or equal to zero.

Note that this function resizes relative to the objects original size, not its current size. scale(1) will therefore always return to the original size.

setMaterials

function setMaterials(materialDictionary : Object [, shaderDictionary : Object]) : Boolean

Set the materials of the effect’s model. This works exactly like the materials dictionary in effectdata.plist. The optional shaderDictionary argument overrides materialDictionary if shaders are active.

Example:

effect.setMaterials({"my_effect_diffuse.png": { diffuse_map: "my_effect_damaged_diffuse.png" }});

See also: setShaders(), getMaterials()

setShaders

function setShaders(shaderDictionary : Object) : Boolean

Set the shader materials of the effect’s model. Equivalent to setMaterials() with the materialDictionary value set to the effect’s current material dictionary.

See also: setMaterials(), getShaders()

Effect Scripts

Visual Effects may have an effect script attached to them. These work in a similar way to ship scripts, but define different handlers and properties. As with ship scripts, there will be a separate independent copy of the script for each visual effect.

Effects scripts have one property, this.visualEffect, which is a reference to the visual effect this is a script for. They have the following event handlers.

effectRemoved

The effectRemoved handler is called when the effect is removed from the universe, either by the remove function, or automatically when the player leaves the system. This is a good place to clean up any frame callbacks or timers associated with this effect.

this.effectRemoved = function()
{
     // Your code here
}

effectSpawned

The effectSpawned handler is called on the first update after the effect is added to the universe.

this.effectSpawned = function()
{
     // Your code here
}