diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..d13e4b8 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,615 @@ + + +
+ + +
+
++YukkuriMovieMaker4 の「Luaスクリプト」映像エフェクトで使えるサンプルと、 +利用可能な変数・関数・定数の一覧をまとめたページです。 +各サンプルはエフェクトのスクリプト欄にそのまま貼り付けて利用できます。 +スクリプトエンジンは MoonSharp (Lua 5.2 互換) です。 +
+ +
+変数・関数の詳細な仕様は、スクリプトエディタのヘルプ、または
+docs/LuaScript.ja-jp.txt を参照してください。
+
+スクリプト内では、変更可能な obj の値(座標・拡大率・回転・不透明度など)を
+書き換えると描画に反映されます。読み戻されるのは
+x, y, z, ox, oy, zoom, aspect, alpha, rx, ry, rz
+(およびラジアン版 rxr, ryr, rzr、独立スケール sx, sy)です。
+
+time はアイテム基準の経過秒数、obj.t はアイテム内の進行割合
+(0.0 ~ 1.0) です。グローバル変数の状態はフレーム間で保持されません。
+math.random は毎フレーム同じシードで初期化されるため、同一フレームでは
+同じ値を返します。安定した乱数が必要な場合は anim.rand を使います。
+
obj.alpha = math.min(time * 255, 255)
+
+obj.alpha = math.max((obj.totalframe - obj.frame) / obj.framerate * 255, 0)
+
+obj.alpha = obj.track0
+
+obj.rz = time * 90
+
+obj.zoom = obj.zoom * (1 + obj.track0 / 100)
+
+Track0 を振幅(px)、Track1 を周波数(回/秒)として使います。
+local amp = obj.track0
+local freq = obj.track1
+obj.x = obj.x + math.sin(time * anim.tau * freq) * amp
+
+local r = obj.track0
+local dx, dy = anim.polar(r, time * 90)
+obj.x = obj.x + dx
+obj.y = obj.y + dy
+
+local h = obj.track0
+obj.y = obj.y - anim.bounce(anim.pingpong(time, 1)) * h
+
+obj.x = obj.x + (anim.noise(time * 2, 0, 0) - 0.5) * 20
+obj.y = obj.y + (anim.noise(0, time * 2, 0) - 0.5) * 20
+obj.rz = (anim.noise(0, 0, time * 2) - 0.5) * 10
+
+回転中心 ox, oy をずらして振り子のように揺らします。
obj.oy = -obj.hh
+obj.rz = math.sin(time * anim.tau) * 30
+
+
+rx, ry, rz は度、rxr, ryr, rzr はラジアンです。
+ラジアン版を変更するとそちらが優先して反映されます。
+
obj.rzr = time * anim.tau
+
+obj.ry = time * 180
+
+obj.rz = anim.ease_in(obj.t) * 360
+
+local p = anim.duration(time, 0.3)
+obj.zoom = obj.zoom * anim.elastic(p)
+
+
+aspect は正で横方向に縮小、負で縦方向に縮小します。
+
obj.aspect = math.sin(time * anim.tau) * 0.5
+
+ぷにぷにと潰れる動きを sx, sy で表現します。
local s = math.sin(time * anim.tau * 2) * 0.2
+obj.sx = 1 + s
+obj.sy = 1 - s
+
+local p = anim.duration(anim.delay(time, 0.5), 1)
+obj.alpha = p * 255
+
+obj.alpha = anim.square(time, 4) * 255
+
+obj.alpha = anim.oscillate(time, 64, 255, 1)
+
+local tx, ty = 200, -100
+local p = anim.ease_in_out(obj.t)
+obj.x = anim.lerp(obj.x, tx, p)
+obj.y = anim.lerp(obj.y, ty, p)
+
+obj.x = obj.x + anim.back(obj.t) * 200
+
+obj.alpha = anim.smoothstep(0, 0.5, obj.t) * 255
+
+補間・イージング系関数の一覧です。
+| 関数 | 説明 |
|---|---|
| anim.lerp(a, b, t) | a と b を t (0.0~1.0) で線形補間 |
| anim.smoothstep(e0, e1, x) | e0~e1 をエルミート補間で滑らかに遷移 |
| anim.smootherstep(e0, e1, x) | 2次導関数まで連続な、より滑らかな遷移 |
| anim.ease_in(t) | 2次イーズイン (加速) |
| anim.ease_out(t) | 2次イーズアウト (減速) |
| anim.ease_in_out(t) | 2次イーズイン・アウト (加速後減速) |
| anim.elastic(t) | 弾むようなスプリングイージング |
| anim.back(t) | 行き過ぎてから戻るイージング |
| anim.bounce(t) | バウンドするイージング |
| anim.step(edge, x) | x が edge 以上なら 1.0、未満なら 0.0 |
| anim.bezier(t, p0, p1, p2, p3) | t における3次ベジェ曲線の値 |
obj.rz = anim.map(obj.track0, 0, 100, -180, 180)
+
+obj.x = obj.x + (anim.triangle(time, 1) - 0.5) * 200
+
+範囲・周期系関数の一覧です。
+| 関数 | 説明 |
|---|---|
| anim.clamp(v, lo, hi) | v を lo ~ hi の範囲に収める |
| anim.map(v, a1, b1, a2, b2) | 範囲 a1~b1 の v を a2~b2 に変換 |
| anim.norm(v, lo, hi) | v が lo~hi のどの割合 (0.0~1.0) かを取得 |
| anim.wrap(v, lo, hi) | v を lo ~ hi でループさせる |
| anim.pingpong(t, len) | 0 ~ len を往復する値 |
| anim.sign(v) | 符号 (正=1, 負=-1, ゼロ=0) |
| anim.fract(v) | 小数部分のみを取得 |
| anim.oscillate(t, lo, hi, freq) | freq の周波数で lo~hi を正弦波で往復 |
| anim.triangle(t, freq) | freq の周波数で 0.0~1.0 を往復する三角波 |
| anim.square(t, freq) | freq の周波数で 1.0 と 0.0 を切り替える矩形波 |
| anim.duration(t, dur) | 時間 dur に対する割合 (0.0~1.0, clamp あり) |
| anim.delay(t, d) | 時間 d 経過後から開始する時間 (0以下は0) |
local rx, ry = anim.rotate(obj.track0, 0, time * 90)
+obj.x = obj.x + rx
+obj.y = obj.y + ry
+
+local d = anim.dist(obj.x, obj.y, 0, 0)
+obj.alpha = anim.clamp(255 - d, 0, 255)
+
+ベクトル・幾何系関数の一覧です。
+| 関数 | 説明 |
|---|---|
| anim.len(x, y) | ベクトル (x, y) の長さ |
| anim.dist(x1, y1, x2, y2) | 2点間の距離 |
| anim.dot(x1, y1, x2, y2) | 2ベクトルの内積 |
| anim.normalize(x, y) | 正規化した方向ベクトル (Tuple で返却) |
| anim.polar(r, a) | 半径 r・角度 a(度) から移動量 (x, y) |
| anim.rotate(x, y, a) | (x, y) を a(度) 回転させた座標 |
+anim.rand はシード引数に基づく決定的な乱数です。レイヤー番号をシードにすると
+オブジェクトごとに異なる固定値が得られます。
+
local offset = anim.rand(-50, 50, obj.layer)
+obj.x = obj.x + offset
+
+obj.alpha = anim.noise(time, obj.layer, 0) * 255
+
+| 関数 | 説明 |
|---|---|
| anim.noise(x, y, z) | 1~3次元の滑らかなノイズ (0.0~1.0) |
| anim.rand(min, max, s) | シード s に基づく安定した乱数 |
local hue = anim.wrap(time * 60, 0, 360)
+local cr, cg, cb = anim.hsv_to_rgb(hue, 1, 1)
+local pd = obj.getpixeldata()
+local n = pd.width * pd.height
+for i = 0, n - 1 do
+ local base = i * 4
+ pd:set(base + 1, pd:get(base + 1) * cr / 255)
+ pd:set(base + 2, pd:get(base + 2) * cg / 255)
+ pd:set(base + 3, pd:get(base + 3) * cb / 255)
+end
+
+| 関数 | 説明 |
|---|---|
| anim.hsv_to_rgb(h, s, v) | HSV (色相0~360, 彩度0~1, 明度0~1) を RGB に変換 |
| anim.rgb_to_hsv(r, g, b) | RGB (0~255) を HSV に変換 |
| 定数 | 説明 |
|---|---|
| anim.tau | 円周率の2倍 (math.pi * 2) |
| anim.e | ネイピア数 (math.exp(1)) |
| anim.phi | 黄金比 ((1 + math.sqrt(5)) / 2) |
| anim.sqrt2 | 2の平方根 (math.sqrt(2)) |
+obj.getobject(tag) は、対象アイテムの「備考」欄に入力した文字列をタグとして、
+そのアイテムの描画情報を取得します。備考欄はプロパティエリアの上側にあります。
+返り値は対象アイテム自身の座標・回転・拡大率であり、グループ制御・カメラ制御による
+変形は含みません。一致するアイテムが無い場合は nil を返します。
+同じタグのアイテムが複数あるときは、現在フレームで表示中のものを優先します。
+
local src = obj.getobject("routersys")
+if src then
+ obj.x = src.x
+ obj.y = src.y
+end
+
+local target = obj.getobject("routersys")
+if target then
+ local p = anim.ease_in_out(obj.t)
+ obj.x = anim.lerp(obj.x, target.x, p)
+ obj.y = anim.lerp(obj.y, target.y, p)
+end
+
+local target = obj.getobject("routersys")
+if target then
+ local p = anim.ease_in_out(obj.t)
+ local nx = anim.lerp(obj.x, target.x, p)
+ local ny = anim.lerp(obj.y, target.y, p)
+ obj.rz = math.deg(math.atan2(target.y - obj.y, target.x - obj.x))
+ obj.x = nx
+ obj.y = ny
+end
+
+local target = obj.getobject("routersys")
+if target then
+ local dx = target.x - obj.x
+ local dy = target.y - obj.y
+ local dist = anim.len(dx, dy)
+ if dist > 0 then
+ local step = math.min(dist, obj.track0 * obj.time)
+ obj.x = obj.x + dx / dist * step
+ obj.y = obj.y + dy / dist * step
+ end
+end
+
+local target = obj.getobject("routersys")
+if target and target.exist then
+ obj.x = target.x
+ obj.y = target.y
+end
+
+local src = obj.getobject("routersys")
+if src then
+ obj.x = src.x
+ obj.y = src.y
+ obj.zoom = src.zoom
+ obj.rz = src.rz
+ obj.alpha = src.alpha
+end
+
+返り値テーブルのメンバーは以下のとおりです。
+| メンバー | 説明 |
|---|---|
| exist | 現在フレームが表示期間内か (boolean) |
| x / y / z | 描画位置 (ピクセル) |
| zoom / sx / sy | 拡大率 (1.0 で等倍) |
| rx / ry / rz | X / Y / Z 軸回転角 (度) |
| rxr / ryr / rzr | X / Y / Z 軸回転角 (ラジアン) |
| alpha | 不透明度 (0.0 ~ 255.0) |
| layer | レイヤー番号 |
+ピクセル操作は実際の入力画像へアクセスするため、初回アクセス時に画像データの +転送が発生します。座標は画像の左上を (0, 0) とし、右・下方向が正です。 +取得値はストレートアルファ相当です。 +
+ +for y = 0, obj.h - 1 do
+ for x = 0, obj.w - 1 do
+ local r, g, b, a = obj.getpixel(x, y)
+ obj.setpixel(x, y, 255 - r, g, b, a)
+ end
+end
+
+
+obj.getpixeldata() はピクセルへ直接アクセスできるプロキシを返します。
+インデックスは 1 始まりで、チャンネルは R, G, B, A の繰り返しです。
+pixel(x, y) の R チャンネルのインデックスは (y * obj.w + x) * 4 + 1 です。
+
local pd = obj.getpixeldata()
+local w = pd.width
+local h = pd.height
+for y = 0, h - 1 do
+ for x = 0, w - 1 do
+ local base = (y * w + x) * 4
+ local r = pd:get(base + 1)
+ local g = pd:get(base + 2)
+ local b = pd:get(base + 3)
+ local gray = r * 0.299 + g * 0.587 + b * 0.114
+ pd:set(base + 1, gray)
+ pd:set(base + 2, gray)
+ pd:set(base + 3, gray)
+ end
+end
+
+local pd = obj.getpixeldata()
+local w = pd.width
+local h = pd.height
+local cx = w / 2
+local cy = h / 2
+local maxd = anim.len(cx, cy)
+for y = 0, h - 1 do
+ for x = 0, w - 1 do
+ local base = (y * w + x) * 4
+ local d = anim.len(x - cx, y - cy)
+ local k = anim.clamp(1 - d / maxd, 0, 1)
+ pd:set(base + 4, pd:get(base + 4) * k)
+ end
+end
+
+
+obj.putpixeldata() は AviUtl との互換性のために存在しますが、
+このプラグインでは変更が自動的に反映されるため呼び出す必要はありません (no-op)。
+
| 関数 | 戻り値 | 説明 |
|---|---|---|
| obj.getpixel(x, y) | r, g, b, a | 指定座標のピクセルを取得 (各成分 0~255) |
| obj.setpixel(x, y, r, g, b [, a]) | なし | 指定座標へ書き込み (a 既定 255) |
| obj.getpixeldata() | PixelDataProxy | 全ピクセルへの直接アクセスプロキシ |
| obj.putpixeldata() | なし | 互換用の空実装 |
obj.x = scene.cx * obj.track0 / 100
+
+| メンバー | 説明 |
|---|---|
| scene.width | シーンの横解像度 (ピクセル) |
| scene.height | シーンの縦解像度 (ピクセル) |
| scene.cx | 横解像度の半分 (= scene.width / 2) |
| scene.cy | 縦解像度の半分 (= scene.height / 2) |
local d = ymm4.group_index * 0.1
+local p = anim.duration(anim.delay(time, d), 0.5)
+obj.alpha = p * 255
+
+obj.x = obj.x + ymm4.group_ratio * 400
+
+if ymm4.is_saving then
+ obj.alpha = 255
+else
+ obj.alpha = 128
+end
+
+| メンバー | 説明 |
|---|---|
| ymm4.group_index | グループ制御内の現在のインデックス (0始まり) |
| ymm4.group_count | グループ制御内の総アイテム数 |
| ymm4.group_ratio | グループ内の進行割合 (group_index / group_count) |
| ymm4.timeline_totalframe | タイムライン全体の総フレーム数 |
| ymm4.timeline_totaltime | タイムライン全体の総時間 (秒) |
| ymm4.time_ratio | 現在の再生位置の割合 (0.0 ~ 1.0) |
| ymm4.is_saving | 動画出力中のみ true |
| ymm4.is_playing | 再生中のみ true |
| ymm4.is_paused | 一時停止中のみ true |
| ymm4.scene_id | 現在のシーンを識別する文字列 (Guid) |
以下の変数はスクリプトのグローバルスコープで直接参照できます (すべて読み取り専用)。
+| 変数 | 説明 |
|---|---|
| time | オブジェクト基準の現在時間 (秒)。obj.time と同じ |
| frame | オブジェクト基準の現在フレーム番号。obj.frame と同じ |
| totalframe | オブジェクトの総フレーム数。obj.totalframe と同じ |
| framerate | フレームレート (fps)。obj.framerate と同じ |
| timelineframe | タイムライン先頭からの絶対フレーム番号 |
| timelinetime | タイムライン基準の現在時間 (秒) |
| layer | 配置されているレイヤー番号。obj.layer と同じ |
| obj / scene / ymm4 / anim | 各テーブル (本ページ参照) |
利用できる標準ライブラリは以下に限定されます。io, os, debug, ffi, require 等は使用できません。
+ ++abs, ceil, cos, exp, floor, fmod, huge, log, max, min, modf, pi, random, randomseed, +sin, sqrt, tan, atan, atan2, deg, rad, ldexp, frexp, sinh, cosh, tanh, type, +tointeger, maxinteger, mininteger +
+ ++format, len, sub, upper, lower, rep, reverse, find, match, gmatch, gsub, byte, char, +dump, pack, unpack, packsize +
+ +insert, remove, sort, concat, unpack, move
+ ++band, bor, bxor, bnot, lshift, rshift, arshift, extract, replace, btest, countlz, countrz +
+ ++type, tostring, tonumber, select, error, assert, print, ipairs, pairs, next, unpack, +setmetatable, getmetatable, rawget, rawset, rawequal, rawlen, pcall, xpcall +
+ +| メンバー | 説明 |
|---|---|
| obj.x / obj.y / obj.z | 描画位置 (ピクセル) |
| obj.ox / obj.oy / obj.oz | 回転中心のオフセット (ピクセル) |
| obj.zoom | 拡大率 (sx と sy の平均、1.0 で等倍) |
| obj.aspect | アスペクト比 (-1.0 ~ 1.0) |
| obj.sx / obj.sy | X / Y 方向の独立拡大率 |
| obj.alpha | 不透明度 (0.0 ~ 255.0) |
| obj.rx / obj.ry / obj.rz | X / Y / Z 軸回転角 (度) |
| obj.rxr / obj.ryr / obj.rzr | X / Y / Z 軸回転角 (ラジアン) |
| メンバー | 説明 |
|---|---|
| obj.w / obj.h | 入力画像の幅 / 高さ (ピクセル) |
| obj.hw / obj.hh | 幅 / 高さの半分 |
| obj.cx / obj.cy | 画像中心 (= hw / hh) |
| obj.cz / obj.sz | 常に 0 / 常に 1 |
| obj.diagonal | 対角線長 (sqrt(w^2 + h^2)) |
| obj.time / obj.frame | アイテム基準の経過時間 (秒) / フレーム |
| obj.totalframe / obj.totaltime | アイテムの総フレーム数 / 総時間 (秒) |
| obj.t | アイテム内の進行割合 (0.0 ~ 1.0) |
| obj.framerate | フレームレート (fps) |
| obj.layer | レイヤー番号 |
| obj.index / obj.num | グループ内のインデックス / 総数 |
| obj.track0 ~ obj.track3 | エフェクトパネルの各トラックバーの値 |
| 関数 | 説明 |
|---|---|
| obj.getobject(tag) | 他アイテムの描画情報を取得 (本ページ 12 章) |
| obj.getpixel(x, y) | ピクセル取得 |
| obj.setpixel(x, y, r, g, b [, a]) | ピクセル書き込み |
| obj.getpixeldata() | ピクセル直接アクセスプロキシ |
| obj.putpixeldata() | 互換用の空実装 |
+Luaスクリプト for YMM4 / MIT License / +https://github.com/routersys/YMM4-LuaScript +
+ + +