An AR effect, filter or mask

Hierarchy

  • Effect

Constructors

  • Creates an effect from Url

    Parameters

    • source: string

    Returns Effect

    Example

    const octopus = new Effect("/path/to/Octopus.zip")
    
  • Creates an effect from Request

    Parameters

    • source: Request

    Returns Effect

    Example

    const octopus = new Effect(new Request(
    "/path/to/Octopus.zip",
    { headers: { etag: "\"8b13dff520339ba88a610ceb58d4fa6b\"" } },
    ))
  • Creates an effect from Blob

    Parameters

    • source: Blob

    Returns Effect

    Example

    const file = $("#file-upload").files[0] // File is subclass of Blob
    const octopus = new Effect(file)

Methods

  • Evaluates JavaScript method in context of the effect.

    The method won't evaluate if the effect is not applied to a player

    Parameters

    • methodName: string
    • methodJSONParams: string = ""

    Returns void

    Deprecated

    Use evalJs instead.

    Example

    const makeup = new Effect("/path/to/Makeup.zip")

    await player.applyEffect(makeup)

    // ...

    const electricBlueColor = "0.09 0.25 0.38"

    makeup.callJsMethod("Eyes.color", JSON.stringify(electricBlueColor))
  • Evaluates JavaScript in context of the effect.

    The script won't evaluate if the effect is not applied to a player

    Parameters

    • code: string

    Returns Promise<undefined | string>

    Example

    const makeup = new Effect("/path/to/Makeup.zip")

    await player.applyEffect(makeup)

    // ...

    const electricBlueColor = "0.09 0.25 0.38"

    await makeup.evalJs(`Eyes.color("${electricBlueColor}")`)
  • Parameters

    • path: string
    • array: ArrayLike<number> | ArrayBufferLike

    Returns void

    Example

    const makeup = new Effect("/path/to/Makeup.zip")
    const filename = "nude_makeup.png"
    const buffer = await fetch("/path/to/${filename}").then(r => r.arrayBuffer())

    // ...

    await makeup.writeFile(filename, buffer)
    await makeup.evalJs(`Makeup.set("${filename}")`)
  • Parameters

    • path: string
    • blob: Blob

    Returns Promise<void>

    Example

    const makeup = new Effect("/path/to/Makeup.zip")
    const filename = "nude_makeup.png"
    const file = $("#file-upload").files[0]

    // ...

    await makeup.writeFile(filename, file)
    await makeup.evalJs(`Makeup.set("${filename}")`)
  • Creates an effect by preloading it from Url

    Parameters

    Returns Promise<Effect>

    Example

    const octopus = await Effect.preload("/path/to/Octopus.zip")
    

    Example

    // with a progress listener
    const onProgress = ({ total, transferred }) => {
    console.log(`Effect is loaded on ${100 * transferred / total}%`)
    }
    const octopus = await Effect.preload("/path/to/Octopus.zip", { onProgress })
  • Creates an array of effects by preloading them from a list of Urls

    Parameters

    Returns Promise<Effect[]>

    Example

    const [octopus, policeman] = await Effect.preload(["effects/Octopus.zip", "effects/Policeman.zip"])
    

    Example

    // with a progress listener
    const onProgress = (effectIndex, { total, transferred }) => {
    console.log(`Effect #${effectIndex} is loaded on ${100 * transferred / total}%`)
    }
    const [octopus, policeman] = await Effect.preload(
    ["effects/Octopus.zip", "effects/Policeman.zip"],
    { onProgress },
    )