krpano has a small and simple dynamic scripting language.
With it krpano can be customized in many ways.
A command or function is called 'action' in krpano.
It's possible to use existing actions and also to define new ones.
The scripting language is dynamic and untyped by default, only
some predefined variables are typed, but that is normally not relevant because inside the
scripts all type conversions will be done automatically.
This documentation is about global krpano variables and objects, about the actions calling syntax and about all pre-defined krpano actions / functions.
the name of an <action> element that was defined anywhere in the xml or...
the name of a krpano variable / attribute that contains krpano action code or is linking to an Actionscript3 (Flash) or a Javascript (HTML5) function.
Whitespace characters (like space, tab, new-lines) will be ignored as long they are not inside quotes
(single or double quote characters).
If there is more than one action call, the calls should be ended with a semicolon.
The action calls will be processed in sequence one after the other.
The parameters that could be or should be passed to the action depends on the particular action itself.
See here the documentation of that action for more.
When passing more than one parameter, then the parameters need to be separated by commas.
All parameters will be passed as they are written as text to the action.
When the parameter is a variable, then only the name of the variable will be passed - but not the value of the variable!
To pass the value of a variable the get(variable) action need to be used. Note - some actions are resolving variables automatically to their value, but this depends on the particular action itself!
To be able to use whitespace characters and commas inside a parameter value, the parameter must be enclosed by
single ' or double quotes ".
The expression syntax will be used in if checks,
in conditional loops (for, loop)
and in the calc action.
It can be used to evaluate logical conditions, calculate mathematical expressions or to concatenate strings.
The basic syntax is:
a OPERATOR b
Where the a or b terms can be either:
variables,
values,
strings (inside single-quotes ' or double-quotes "),
Returns a string of a number rounded to given decimal places (dp).
When using -1 for dp, an automatic number of decimal places will be used, from 1 to 6, no trailing zeros.
When using non-strict comparisons (by using == or
!= when the strict mode setting is false)
then it will be assumed that the given values are either variables or strings.
That means when a variable with the given name exists, then the value of that variable will be used in the comparison.
But when the variable doesn't exists, then the given name will be used as string.
In strict comparisons the strings must be explicitly marked by quotes.
Variables will resolve either to their value or to null if they don't exists.
* Note - due of xml syntax limitations, the usage of the characters <, >, &
might be not possible (e.g. inside xml attributes or inside xml elements without CDATA tag).
Therefore it's recommended to use the alternative syntax.
Every xml element with a name attribute is an element / item of an Array.
The name of the xml element is the name of the Array and the name attribute defines the name of the Array element / item.
An Array in krpano is always an Array of objects.
Such Array-item object can contain any kind of custom properties / attributes.
Arrays can be predefined or defined dynamically at runtime by setting an Array item value - when setting an item value the first time, then automatically an Array will be created.
Static XML Syntax: (when defining in the xml structure)
The global object allows directly accessing the global variable scope.
The usage of global can be necessary inside local- or layer/hotspot scope
code to be able to access a global variable when a variable with the same name is already defined the current scope.
The local object is only available inside local-scope actions
and allows directly accessing the current local variable scope.
This can be used to ensure defining new variables at the local scope when there might be already global variables with the same names.
The mouse.x and mouse.y coordinates are relative to the left top edge of the area.
The mouse.stagex and mouse.stagey coordinates are relative to the left top edge of the whole stage / screen / window.
The mouse.downx and mouse.downy variables store the position where the mouse button was last pressed down (for left and right buttons).
The coordinates itself are relative to the left top edge of the area.
The mouse.clickx and mouse.clicky variables are special case ones -
they store the position where the click from onsingleclick or ondoubleclick events had happend.
The coordinates itself are relative to the left top edge of the area.
The 'raw' unscaled and non-rounded delta values of the mouse wheel rotation.
The normal wheeldelta values are limited to integer values and
can be too inaccurate for some usages (plugins).
Note - in the krpano Flash viewer, the raw values are only available when using the default krpano embedding script and
only in windowed-mode (not in Fullscreen mode)!
In the krpano HTML5 viewer, the raw values are always available.
The fullscreen variable can be used to check or to change the current state of the fullscreen mode.
When the variable will be changed, then also the fullscreen mode will be changed.
Before using the fullscreen setting, it should be verified if the current browser / device actually supports
the fullscreen mode. This can be done with the xml fullscreensupport devices setting
and the device.fullscreensupport variable.
Due Flashplayer and HTML5 security limitations the switching to the fullscreen mode
will be only possible as reaction to an user input like a mouse click or a keypress!
That means it's only possible switch to fullscreen mode in an onclick or onkeydown event!
When the HTML5 fullscreen mode is not supported by the browser (like on iOS),
then the fullscreen setting will only change the size of the viewer html element to match the size of the
full browser window.
Due technical limitations this will not work from inside an <iframe> and can be problematic in nested html structures.
When trying to use the HTML5 fullscreen mode from within an <iframe>,
it is necessary to add the allowfullscreen parameter
(and the non-standard browser versions of it) to the <iframe> declaration. This tells the browser that this iframe is allowed to switch to Fullscreen mode.
A global overall scaling setting.
The stagescale setting will scale all krpano elements and sizes.
By scaling all elements, the krpano stage-size (screen-size / resolution) itself will be scaled inversely by this value -
e.g. a value of 0.5 will scale-down all elements by 50% while increasing the internal stage-sizes by 200% at the same time.
The default stagescale value depends on the device, the browser, the Javascript window.devicePixelRatio value.
browser.platform
In HTML5 this will be the 'platform' string of the browser.
The same as navigator.platform in Javascript.
In Flash it will be always "Flash".
browser.domain
The domain name of the current webpage (without leading 'www.' if there is one).
browser.protocol
The protocol part of the current webpage url, e.g. 'http', 'https' or 'file'.
Flash notes - in the Flash viewer these information will be only available when using the krpano embedding script.
When directly embedding the swf file, then these information aren't available.
The device object provides information about the current device/system.
It's the dynamic/scripting equivalent to the xml devices attribute.
The attributes/properties of the device object can be checked anytime by scripting code, e.g. by the if() action.
These variables can be used to set a force to move the view / the pano.
Their main usage is for keyboard or button movement control.
When they will be set to a value other than 0.0, the view will start slowly accelerating (controlled by
control.keybaccelerate) and then move with a maximum speed
(controlled by control.keybspeed) until they will be set back to 0.0, then
the movement will slow down (controlled by control.keybfriction).
Lock the automatic multi-resolution level selection to a fixed level.
Set lockmultireslevel to "current" to lock the level to the current level.
To release the level locking set lockmultireslevel back to "-1".
The current loading progress as linear value from 0.0 to 1.0.
It could be used to create custom loading animations - e.g.
use the onxmlcomplete event for starting the loading animation,
and the onloadcomplete event for stopping it.
The xml.filecontent variable contains the content of the last loaded xml file.
The content will not change when loading a new pano via loadscene() or loadxml().
The xml.content variable contains the xml-content of the last loaded pano.
When a <scene> gets loaded or
loadxml() be used, then the variable contains only the scene-xml-code or the given loadxml() xml-code.
A backup of the values from the initial <view> element defined in the current xml or scene.
E.g. get the initial view.hlookat value via xml.view.hlookat.
Note - only the values that were defined in the xml are stored here, no default values.
That means before using a value from that object, it would be necessary to check if these variables actually exists
- e.g. via if(xml.view.fov !== null, ...);.
When no value will be given and the variable already exsits,
then the variable with its current value will be converted to the given type.
When no value will be given and the variable doesn't exsits, then
these the default values are used: boolean=false, number=NaN (Not a Number), integer=0, string=null.
When the type is object or array, no value can be set.
The get(var) action is a special action that can be only used as parameter
when calling other actions or when accessing array elements.
Parameters:
variable
Any variable.
When the variable doesn't exists, get() will return null.
Note - some actions are automatically trying to resolve their given parameters to their values.
For these actions using get(var) would be not necessary.
The copy() action copies the content from one variable to the other one.
By default this is the same as:
set(destination, get(source)).
Parameters:
destination
The destination variable.
When the variable doesn't exists, it will be created.
source
The source variable.
When the variable doesn't exists, null will be set to the destination variable.
typeconversion(optionally)
When set to true (the default):
When both variables have different types, then the value of the source variable will be converted to the type of the destination variable.
When set to false:
Copy the value and the type of the source variable to the destination variable.
Calls the given actions when the condition is true or when it will become true.
When the condition is currently not true, then the callwhen() action will wait as long until the condition will become true.
Parameters:
id(optionally)
An optional unique id for the callwhen.
This id can be used to stop a waiting callwhen by calling stopcallwhen(id).
First the startactions will be called, then the condition be checked and when it is true -
then the loopactions will be called, then the nextactions and then it starts checking
the condition and the loop again.
Parameters:
startactions
The actions that will be called / executed before the for loop starts.
As long as the condition is true the loopactions will be called repeatedly.
The normal loop() action will continue with the following actions when the loop itself is done.
The asyncloop() will continue intermediately with the following actions and execute the
loopactions once per frame. When the async looping is finally done, then the doneactions will be called.
The renderloop() action will execute the loopactions once every frame.
To stop the loop the stoprenderloop() action need to be called inside the loopactions.
Parameters:
loopactions
The actions that will be repeatedly called / executed every frame.
Can be a krpano action-code string or a Javascript function.
Examples
krpano-Action-Code Example:
renderloop(
... do something ...
if(...done with rendering...,
stoprenderloop();
);
);
Javascript-Code Example:
krpano.actions.renderloop(function(){
... do something ...
if(...done with rendering...){
krpano.actions.stoprenderloop();
}
});
The switch action switches the value of the given variable between / through several states.
Every time when the switch action will be called the value will be switched / changed.
When only the variable itself without value parameters will be given, then the variable will
be switched between true and false.
When there are two or more values given as parameters then the variable will switch through all
of these values (from left to right).
Break / stop the execution of action calls from the current flow and the also the action calls from one nesting level up
(e.g. when called inside an if() call then also the flow outside that if will be stopped).
When used inside a for() or loop() loop, the break() call will also stop that loop.
Call krpano action code with using a specific plugin / layer or hotspot element as caller.
This can be used for direct property access or to simulate event calls on these elements.
Parameters:
caller
The element that should be used as caller.
Can be only a <plugin> / <layer> or <hotspot> element.
actions
Any krpano action code.
The code will be executed in the 'context' of the caller - that means 'direct' access to its properties.
Set a variable to the a value - like a set() call - but in the scope of the parent action.
This could be used to return / pass back a result from an inner local scope action to an outer one.
Parameters:
variable
The variable name.
The variable will be created when it doesn't exists.
value
The new value for this variable.
When the variable already exists, then the value will be converted to the type of that variable.
Link the current local scope to the events of the given element.
When an event of that element (e.g. onclick) will be called, then the same scope will be used
in the event code. By default events are always using the global scope.
Note - when having linked to a scope, it is necessary to use caller to address the element scope itself!
Copy all attributes from one object to another one.
Note - the parameters of the copyattributes() action need to be the objects, not the names/paths of the objects!
That means it might be necessary to use the get() action to resolve the names/paths.
Parameters:
destobject
The destination object - the object where the attributes will be copied to.
Existing attributes will be overwritten.
srcobject
The source object - all attributes from that object will be copied to the destination object.
Dispatches / calls the given event from all <events> elements.
Parameters:
eventname
The name of the event.
instantly(optionally)
A Boolean setting (true or false, false by default).
When set to true, the events will be called and executed instantly,
when not set or set to false, the events will be called after the current actions calls.
These actions increase or decrease variable (with saturation or limiting).
Parameters:
variable
The variable to increase or decrease.
byvalue(optionally)
Increase or decrease the variable by this value.
When not set, the variable will be increased or decreased by 1.
max / min(optionally)
Defines maximum and minimum values.
When one limit will be reached then the value will be set back to the other limit value.
This can be used to let the varibale either wrap around
a defined range or to clip at at specific limit (with min=max).
Note - The inc() and dec() actions will convert the variable type to 'integer'!
The Math object provides constants and actions for mathematical calculations.
The most Math actions can be called in two ways - either by just passing the name of the variable - then
variable will be used as parameter and the result of the calculation will be stored back to the variable,
or by specifying an additionally parameter where the result should be stored.
The txtadd action can be used to add/connect several texts / values together.
The action can be used with 2 or more parameters. When using only two parameters (destination and a text)
then the text will be added to current value of the destination variable.
Parameters:
destination
The destination variable where the connected text will be stored.
The variable will be created when it doesn't exists.
txt1, txt2, txt3, ... (optionally)
The texts that will be connected together.
When using only one txt parameter then this text will be added to the content of current destination variable.
Note - when the content of a variable should be used - then the get()
action must be used to resolve the variable!
The tween action can be used for a time-controlled animation / change of a variable.
The action will dynamically change the current value of the variable to the given value.
Color support:
When tweening a variable with a name that contains the word 'color', then the values will be automatically
interpreted as 32bit ARGB colors and each color channel will be processed individually.
Multiple variable support: It is possible to tween several variables together at once.
Therefore specify several variables, values and tweentypes separated by | characters.
When several variables were specified, but only one value and/or only one tweentype, then all variables will tween to the same value and/or use the same tweentype.
The time and the done- and updatecalls will be always the same for all given variables.
Parameters:
variable
The variable that should be changed.
Use the | character to specify several variables.
When the variable name contains the word 'color', then process the variable value as 32bit ARGB color value.
value
The destination value for this variable.
When tweening percent values - add a '%' character to the value.
Use the | character to specify several values for several variables.
Note - to tween to the value of another variable use the get() action to get the value of the other variable!
The time in seconds for the change from the current value to the destination value
(0.5 seconds by default).
Instead of using a fixed time for the change it is possible to define
the maximum moving distance for the value and a time for that distance (not supported when tweening multiple variables).
This allows to use a short time for a short distance and long time for a long distance.
This can be done by using the distance function:
distance(maxdistance,maxtime)
maxdistance - the maximum distance between the start and the destination value
maxtime - the time in seconds for this maximum distance
tweentype(optionally)
The tweening / interpolation type (easeOutQuad by default).
See here for all available tween types: tweentypes.
donecall(optionally)
The action commands that should be executed when the tween is done and the destination value has been reached.
Instead of normal actions, it is also possible to use the special keyword WAIT here.
In this case the user interface and the execution of the following actions will be
blocked until the destination value has been reached.
updatecall(optionally)
These action will be called every time (=every frame!) when the value will be updated / changed!
WARNING - use with care! When heavly used this can reduce the framerate!
Note - only the layer, plugin, hotspot and event elements with keep="true"
will be kept when loading new panos!
Parameters:
xmlpath(for loadpano)
The path/url of the new pano xml file to be loaded (use null for none).
When a relative path will be used then the file will be loaded from the
basedir folder, which is %FIRSTXML% by default.
That means that the paths in all loadpano calls are relative to the first loaded xml file.
xmlstring(for loadxml)
The content of a xml file as string / text to be loaded (should be escaped).
scenename(for loadscene)
The name of the <scene> element that should to be loaded.
These variables will be set after parsing / resolving the xml but before starting to load the pano images.
This way these variables can be used either to overwrite settings from the xml or to set addtional ones.
Variables can be defined as var1=val1 pairs separated by &.
Note - When the selected blending mode will be not supported (e.g. when using a 'WebGL only' mode and only Flash or CSS3D is available),
then it will automatically fallback to the default blending mode.
loaddone(optionally)
Actions code or a Javascript function to call when the loading is done.
Experimental API HTML5-only
Dynamically load and add xml content.
This will not change any current elements or trigger any events.
Only <actions> with autorun="preinit" will get called.
If the xml contains <image> elements, then they will be skipped.
Parameters:
url
The url of the xml file to load and include.
string
The xml code to include as string.
loaddone(optionally)
Actions code or a Javascript function to call when the loading is done.
Move the view from current looking position to the given position.
Note - the user interface and all other actions are blocked during the movement. That means
the next action will be executed when the current action was done. The oninterrupt
action can be used to make these actions interrupt able by the user.
Parameters:
toH
Horizontal destination looking direction (-180 to +180, wraparound possible).
toV
Vertical destination looking direction (-90 to +90).
hotspotname(for looktohotspot, optionally)
The name of the hotspot.
This will be use the hotspot position (ath/atv) as destination position.
When no name will be defined and looktohotspot() will be called from a hotspot element then
that hotspot itself will be used.
fov(optionally)
The destination fov (0 to 179).
The looktohotspot action will use automatically the size of the hotspot as destination fov
when the fov was not set. The other actions keep the current fov when not set.
motiontype(optionally)
The type of the motion.
Possible settings:
linear(speed) - a linear motion
speed = moving speed in degrees/second
smooth(accel,break,maxspeed) - accelerated smooth movement (=default)
accel = acceleration in degrees/secondĀ² (default=720)
break = negative acceleration in degrees/secondĀ² (default=-720)
maxspeed = maximum moving speed in degrees/second (default=720)
The use the shortest possible way from the current to the destination position.
Possible settings: true or false (default=true).
nonblocking(optionally, lookto only)
When set to true, then the lookto action will not wait for completing the movement
before continue executing the the following actions. The user-interface will also be not blocked.
When the lookto movement is done then the donecall action will be called (when defined).
donecall(optionally, lookto only, only when nonblocking is true)
This action will be called when the nonblocking lookto movement is done.
Get the spherical distance between the fromH / fromV and toH / toV lookto points (in degrees).
The result will be always between 0.0 and 180.0 (more than 180 degree distance is not possible on a sphere).
Parameters:
result
The name of the variable where the distance value will be stored.
The variable will be created when it doesn't exists.
When calling this function directly by Javascript, the result parameter can be null, the result will be returned as Javascript return value in this case.
toH
Horizontal looking-to position (-180 to +180, wraparound possible).
Can be a variable name or a value.
toV
Vertical looking-to position (-90 to +90).
Can be a variable name or a value.
fromH(optionally)
Horizontal looking-from position (-180 to +180, wraparound possible).
Can be a variable name or a value.
When not defined, the current horizontal looking direction (view.hlookat) will be used by default.
fromV(optionally)
Vertical looking-from position (-90 to +90).
Can be a variable name or a value.
When not defined, the current vertical looking direction (view.vlookat) will be used by default.
Note - The user interface and all following actions will be blocked during the waiting. That means
the next action in the current call will be executed when the current wait action is done. The oninterrupt
action can be used to make this action interruptable by the user.
Parameters:
parameter
any number - this the time the action will wait in seconds
LOAD - wait until loading is finished
BLEND - wait until loading and blending are finished
This action can be used before starting a set of actions (like lookto, looktohotspot,
moveto, zoomto, wait and tween with WAIT as donecall) that are blocking the user interface.
When any of these actions will be interrupted by the user (e.g. by a click) then the these
actions will be stopped and the in the oninterrupt action defined actions be executed.
Parameters:
actions
The action commands to call on a user interrupt.
Addtionally there is a special command possible here: break - this will just break the current actions.
Actions for converting between screen and spherical coordinates.
The screentosphere action will convert the x/y variables to the h/v variables and
the spheretoscreen action the h/v variables to the x/y variables.
Parameters:
x / y
Variables with screen coordinates in the pixels from the left top edge.
h / v
Variables with spherical coordinates in the degrees (360x180).
stereoside(optionally)
For stereo rendering - define to which screen side the coordinates should be mapped.
Possible settings: l for the left side or r
for right side or not-set/undefined for normal non-stereo screen coordinates.
Notes:
The x,y,h,v parameters must be variable names, using values is not possible!
When a variable doesn't exist, it will be created.
Show / trace details (value and type) about a variable in the output log.
When the variable is an object, then also all object properties will be shown.
Notes:
Debug messages will be only shown when the debugmode setting is enabled.
Consider enabling the consolelog setting in the html file
to see these messages also in the browser console.
Doing many traces is affecting the rendering performance!
Especially avoid constantly tracing messages every frame!