config.js
Glossary
- Layer - Layer of the scene. Layers parametrization can be found here: config.json.
- Drawing area - Effect drawing framebuffer (usual aspect ratio: 3x4 or 9x16).
- Visible area - Final frame framebuffer. The size is the same or less than drawing area. Equals to the screen size in pixels. Visible and drawing area centers are considered to be the same.
Information getters
Method | Description | Return type | Example values |
---|---|---|---|
Api.getFRXVersion() | FRX version | integer | 2, 3, 31 |
Api.getPlatform() | Platform name | string | "ios", "android" |
Api.drawingAreaWidth() | Drawing area width | integer | 920 |
Api.drawingAreaHeight() | Drawing area height | integer | 1280 |
Api.visibleAreaWidth() | Visible area width | integer | 1080 |
Api.visibleAreaHeight() | Visible area height | integer | 1920 |
Api.getNamedState(name) | Gets named state | any | false |
Api.modelview() | Transposed modelView matrix for each face | array object | [[1.33,1.09,...0.89],..] |
Api.projection() | Transposed projection matrix for each face | array object | [[1.33,1.09,...0.89],..] |
Api.getNamedState(name)
Boolean getter names:
- smile,
- mouth_open,
- brows_up,
- brows_down,
- has_glasses,
- eyes_state.
The name of the parametre should be passed as "string" type. For example, Api.getNamedState("smile")
returns true
if the smile is detected, otherwise - returns false
. Api.getNamedState("eyes_state")
returns array obj consists of 2 boolean values, the 1st for left and the 2nd for the right eye opening state.
Sound
Sound files configured in Sounds section in config.json. Sounds are identified by their names.
Current methods don't affect sounds in video files.
Method | Description |
---|---|
Api.playSound(fileName, isLooped, speedFactor) | Play sound fileName. |
Api.playSoundRange(fileName, startTime, stopTime, isLooped, speedFactor) | Play sound fileName in range from startTime to stopTime. |
Api.stopSound(fileName) | Stop sound. |
Api.pauseSound(fileName) | Pause sound. |
Api.setSoundVolume(fileName, volume) | Set volume of sound fileName. Volume value should be from 0 to 1. |
Video
Video and GIF files configured in Media section in config.json. It's identified by layer names. Only one video/GIF can be attached to one layer.
Method | Description |
---|---|
Api.setVideoFile(layerId, fileName) | Attach given video/GIF file to specified layer. Existing video/GIF is replaced. |
Api.playVideoRange(layerId, startTime, stopTime, isLooped, speedFactor) | Play video/GIF range. Doesn't restart currently played media. Times in seconds. |
Api.pauseVideo(layerId) | Pause the video/GIF. Next playVideo resumes from last position. |
Api.stopVideo(layerId) | Stop the video/GIF. Next playVideo start from the very beginning. |
Recognizer
Method | Description |
---|---|
Api.setRecognizerFeatures(features) | Set recognizer features to be enabled. Available values: "background", "hair", "skin_segmentation", "occlusion", "lips_segmentation", "eyes_segmentation", "lips_shine", "face_acne", "eye_bags", "hair_strand", "glasses" |
Example:
GLFX
There are 2 methods:
Method | Description |
---|---|
Api.meshfxMsg(command, instanceId, index, stringParam) | Send message to meshfx |
Api.meshfxReset() | Reset effect to initial state |
Argument | Type |
---|---|
command | string |
instanceId | int |
index | int |
stringParam | string |
spawn
Instantiates 3d mesh for specific instanceId by file name.
Mesh creating with for the 3rd instanceId loaded from SnakeAnimation03.bsm2:
!glfx_FACE can be used instead of file name. It is face mesh from FRX.
del
Deletes 3d mesh with specified instanceId
tex
Sets the file as a texture with index for specified instanceId.
Random selection from 2 variants:
In most cases textures are set in materials. This method can be used to change textures during animation playback for example. Index of texture to be changed should match the shader selectable texture index had been set in cfg.toml Samplers param of the required material.(For particular example tex_diffuse = 0 could be used)
animOnce, animOnceRev, animLoop
This set of methods can be used to control animations queue.
Play "Start" animation once:
Then play "attack" animation once in reverted way:
Then play "Idle" in a loop:
- animOnce plays animation once and switches to the next one.
- animOnceRev plays animation in a reverted way.
- animLoop plays animation in a loop without switching to the next one.
Commands with index = 0 replace active animation. index >= 1 replace animations in queue. Maximum queue size is 4.
dynImass
Sets inverted bone weight. Because of invertion, the maximum weight is 0, and the minimal is 100.
dynGravity
Creates imitation of Gravity power for particular mesh id.
dynSphere
Creates collider sphere. It helps to add a limitation to bones movements. For example, you can use it if you need to prevent skinned hair from colliding with the face.
dynDamping
Sets mesh friction. A higher value causes a lower effect. In most cases the range is from 95 to 100.
dynConstraint
Binds 2 bones.
shaderVec4
Allows setting vec4 variable in shader. Additional variable must exist in shader glfx_GLOBAL.
Shader variables declaration example:
warp
Use added mesh for morphing. Several meshes with different weight can be used - resulting morphing is a mix of all the meshes with their weights. Mesh weight should be set to 0 to exclude it.
Usually, mesh for morphing is set in cfg.toml as warp_mesh parametre value. To apply/edit morphing from JavaScript in runtime warp_mesh value should be set to "!script".
Recording
Method | Description |
---|---|
Api.recordStart(maximumDuration) | Starts video record. maximumDuration is a maximum record duration time. 0 - infinity, system maximum. |
Api.recordStop() | Stops video record. |
UI
Method | Description |
---|---|
Api.showHint(hint_message) | Show user hint. |
Api.hideHint() | Hide user hint. |
Api.print(message) | Log message. |
Example effect: fx_Snake_b1 (FaceDefault.FBX).
Haptic
Platform definition
Method | Description |
---|---|
Api.haptic_is_ios_api_available() | Returns true if iOS API is available on device. |
Api.haptic_is_android_api_available() | Returns true if Android is API available on device. |
Common API (always available)
Method | Description |
---|---|
Api.haptic_vibrate() | Trigger default vibration on all supported devices. |
iOS API: Taptic Engine (iPhone 6S, 6S Plus)
Will trigger default taptic feedback on iPhone 7 and above.
Method | Description |
---|---|
Api.haptic_peak() | Trigger Peak taptic effect. |
Api.haptic_pop() | Trigger Pop taptic effect. |
Api.haptic_canceled() | Trigger Canceled taptic effect. |
Api.haptic_try_again() | Trigger Try again taptic effect. |
Api.haptic_failed() | Trigger Failed taptic effect. |
iOS API: Haptic Feedback (iPhone 7, 7 Plus, and above)
Method | Description |
---|---|
Api.haptic_success() | Trigger success taptic effect. |
Api.haptic_warning() | Trigger warning taptic effect. |
Api.haptic_error() | Trigger error taptic effect. |
Api.haptic_light() | Trigger light taptic effect. |
Api.haptic_medium() | Trigger medium taptic effect. |
Api.haptic_heavy() | Trigger heavy taptic effect. |
Api.haptic_selection() | Trigger selection taptic effect. |
Android API
Method | Description |
---|---|
Api.haptic_vibrate_with_params(duration_ms, amplitude) | Arguments: Duration in ms (e.g. 1500); Amplitude from 1 to 255 (-1 is default, 0 means that vibration is disabled). |