Banuba WebAR JavaScript API Reference
    Preparing search index...

    Class Effect

    An AR effect, filter or mask

    Index

    Constructors

    • Creates an effect from Url

      Parameters

      • source: string

      Returns Effect

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

      Parameters

      • source: Request

      Returns Effect

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

      Parameters

      • source: Blob

      Returns Effect

      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

      Use Effect.evalJs instead.

      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<string | undefined>

      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: ArrayBufferLike | ArrayLike<number>

      Returns void

      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>

      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>

      const octopus = await Effect.preload("/path/to/Octopus.zip")
      
      // 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[]>

      const [octopus, policeman] = await Effect.preload(["effects/Octopus.zip", "effects/Policeman.zip"])
      
      // 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 },
      )