Created
May 3, 2021 09:44
-
-
Save retorillo/1ecd40fa43514b4038e09e6d784d45a8 to your computer and use it in GitHub Desktop.
Live2D Cubism Editorに読み込むためにPSDファイルからすべてのマスクを除去します。「塗り」が100%以外である場合(おそらくLive2D未対応)や、ブレンドモードがデフォルト以外の場合に警告を出力してくれます
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 0; | |
var warning = []; | |
var targets = []; | |
function preprocess(root) { | |
if (!root) root = activeDocument; | |
for (var c = 0; c < root.layers.length; c++) { | |
var disabled = []; | |
if (root.layers[c].typename === 'ArtLayer') { | |
var path = getpath(root.layers[c]); | |
var visible = root.layers[c].visible; | |
try { root.layers[c].vectorMaskDensity = 0; disabled.push('V'); } catch (e) {} | |
try { root.layers[c].layerMaskDensity = 0; disabled.push('L'); } catch (e) {} | |
root.layers[c].visible = visible; | |
if (disabled.length > 0) | |
targets.push(root.layers[c]); | |
$.writeln('[' + disabled.join(', ') + ']\t' + path); | |
if (root.layers[c].fillOpacity != 100) | |
warning.push('【警告】塗りが100%ではありません: ' + path); | |
if (root.layers[c].blendMode != BlendMode.NORMAL) | |
warning.push('【警告】ブレンドモードが「' + root.layers[c].blendMode + '」です: ' + path); | |
} | |
else if (root.layers[c].typename === 'LayerSet') { | |
preprocess(root.layers[c]); | |
} | |
count++; | |
} | |
} | |
function getpath(layer) { | |
var leaves = []; | |
var L = layer; | |
while (L && (L.typename != 'Document')) { leaves.push(L.name); L = L.parent; } | |
return leaves.reverse().join(' > '); | |
} | |
preprocess(); | |
for (var c = 0; c < targets.length; c++) { | |
var layer = targets[c]; | |
layer.allLocked = false; | |
var blendMode = layer.blendMode; | |
var opacity = layer.opacity; | |
var fillOpacity = layer.fillOpacity; | |
layer.opacity = 100; | |
layer.blendMode = BlendMode.NORMAL; | |
$.writeln('処理中: ' + getpath(layer)); | |
var set = layer.parent.layerSets.add(); | |
set.name = layer.name; | |
set.moveAfter(layer); | |
layer.move(set, ElementPlacement.INSIDE); | |
layer = set.merge(); | |
layer.blendMode = blendMode; | |
layer.opacity = opacity; | |
layer.fillOpacity = fillOpacity; | |
} | |
for (var c = 0; c < warning.length; c++) { | |
$.writeln(warning[c]) | |
} | |
$.writeln(warning.length + '個の警告が見つかりました'); | |
$.writeln('全' + count + 'のレイヤーの内' + targets.length + '個のレイヤーからマスクを削除しました。コンソール出力のLはレイヤーマスク、Vはベクトルマスクを表しています'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment