Skip to content

Commit

Permalink
#147 feat: マスク描画の実装(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Jul 15, 2024
1 parent 0823e75 commit ab50843
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { $getCurrentWorkSpace } from "../../CoreUtil";
*
* @params {Character} character
* @params {number} layer_id
* @params {string} [mask_style=""]
* @return {string}
* @method
* @public
*/
export const execute = (
character: Character,
layer_id: number
layer_id: number,
mask_style: string = ""
): string => {

// 変形スタイルを生成
Expand All @@ -28,6 +30,6 @@ export const execute = (
const depth = character.depth;

return `
<div class="display-object layer-id-${layer_id}" data-depth="${depth}" data-layer-id="${layer_id}" style="left: ${x}px; top: ${y}px; opacity: ${alpha}; ${transform}"></div>
<div class="display-object layer-id-${layer_id}" data-depth="${depth}" data-layer-id="${layer_id}" style="left: ${x}px; top: ${y}px; opacity: ${alpha}; ${mask_style} ${transform}"></div>
`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { execute as instanceUpdateBlendModeService } from "@/core/application/In
import { execute as screenAreaHierarchyAdjustmentService } from "@/screen/application/ScreenArea/service/ScreenAreaHierarchyAdjustmentService";
import { $getDeactivated, $getReDrawState } from "@/screen/application/ScreenArea/ScreenAreaUtil";
import { execute as screenAreaReadOnlyElementService } from "@/screen/application/ScreenArea/service/ScreenAreaReadOnlyElementService";
import { execute as screenDisplayObjectGetMaskStyleService } from "@/screen/application/DisplayObject/service/ScreenDisplayObjectGetMaskStyleService";

/**
* @description Bitmapをcanvasに描画して返却する
Expand Down Expand Up @@ -48,9 +49,12 @@ export const execute = async (
// ブレンドモードを設定
instanceUpdateBlendModeService(canvas, character.blendMode);

// マスクのスタイルを取得
const maskStyle = await screenDisplayObjectGetMaskStyleService(character, layer);

// ステージに追加
element.insertAdjacentHTML("beforeend",
bitmapDisplayObjectComponent(character, layer.id)
bitmapDisplayObjectComponent(character, layer.id, maskStyle)
);

const div = element.lastElementChild as HTMLDivElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { $createTransformStyle } from "@/controller/application/TransformSetting
*
* @params {Character} character
* @params {number} layer_id
* @params {string} [mask_style=""]
* @return {string}
* @method
* @public
*/
export const execute = (
character: Character,
layer_id: number
layer_id: number,
mask_style: string = ""
): string => {

// 変形スタイルを生成
Expand All @@ -28,6 +30,6 @@ export const execute = (
const depth = character.depth;

return `
<div class="display-object layer-id-${layer_id}" data-depth="${depth}" data-layer-id="${layer_id}" style="left: ${x}px; top: ${y}px; opacity: ${alpha}; ${transform}"></div>
<div class="display-object layer-id-${layer_id}" data-depth="${depth}" data-layer-id="${layer_id}" style="left: ${x}px; top: ${y}px; opacity: ${alpha}; ${mask_style} ${transform}"></div>
`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { execute as instanceUpdateBlendModeService } from "@/core/application/In
import { execute as screenAreaHierarchyAdjustmentService } from "@/screen/application/ScreenArea/service/ScreenAreaHierarchyAdjustmentService";
import { $getDeactivated, $getReDrawState } from "@/screen/application/ScreenArea/ScreenAreaUtil";
import { execute as screenAreaReadOnlyElementService } from "@/screen/application/ScreenArea/service/ScreenAreaReadOnlyElementService";
import { execute as screenDisplayObjectGetMaskStyleService } from "@/screen/application/DisplayObject/service/ScreenDisplayObjectGetMaskStyleService";

/**
* @description MovieClipをcanvasに描画して返却する
Expand Down Expand Up @@ -45,9 +46,12 @@ export const execute = async (
// ブレンドモードを設定
instanceUpdateBlendModeService(canvas, character.blendMode);

// マスクのスタイルを取得
const maskStyle = await screenDisplayObjectGetMaskStyleService(character, layer);

// ステージに追加
element.insertAdjacentHTML("beforeend",
movieClipDisplayObjectComponent(character, layer.id)
movieClipDisplayObjectComponent(character, layer.id, maskStyle)
);

const div = element.lastElementChild as HTMLDivElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { $createTransformStyle } from "@/controller/application/TransformSetting
*
* @params {Character} character
* @params {number} layer_id
* @params {string} [mask_style=""]
* @return {string}
* @method
* @public
*/
export const execute = (
character: Character,
layer_id: number
layer_id: number,
mask_style: string = ""
): string => {

// 変形スタイルを生成
Expand All @@ -28,6 +30,6 @@ export const execute = (
const depth = character.depth;

return `
<div class="display-object layer-id-${layer_id}" data-depth="${depth}" data-layer-id="${layer_id}" style="left: ${x}px; top: ${y}px; opacity: ${alpha}; ${transform}"></div>
<div class="display-object layer-id-${layer_id}" data-depth="${depth}" data-layer-id="${layer_id}" style="left: ${x}px; top: ${y}px; opacity: ${alpha}; ${mask_style} ${transform}"></div>
`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { execute as screenAreaHierarchyAdjustmentService } from "@/screen/applic
import { execute as screenAreaReadOnlyElementService } from "@/screen/application/ScreenArea/service/ScreenAreaReadOnlyElementService";
import { execute as instanceUpdateBlendModeService } from "@/core/application/Instance/service/InstanceUpdateBlendModeService";
import { $getDeactivated, $getReDrawState } from "@/screen/application/ScreenArea/ScreenAreaUtil";
import { execute as screenDisplayObjectGetMaskStyleService } from "@/screen/application/DisplayObject/service/ScreenDisplayObjectGetMaskStyleService";

/**
* @description Shapeをcanvasに描画して返却する
Expand Down Expand Up @@ -45,9 +46,12 @@ export const execute = async (
// ブレンドモードを設定
instanceUpdateBlendModeService(canvas, character.blendMode);

// マスクのスタイルを取得
const maskStyle = await screenDisplayObjectGetMaskStyleService(character, layer);

// ステージに追加
element.insertAdjacentHTML("beforeend",
shapeDisplayObjectComponent(character, layer.id)
shapeDisplayObjectComponent(character, layer.id, maskStyle)
);

const div = element.lastElementChild as HTMLDivElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { $getCacheCanvas } from "@/cache/CacheUtil";
import { $getCurrentWorkSpace } from "@/core/application/CoreUtil";
import type { Character } from "@/core/domain/model/Character";
import type { Layer } from "@/core/domain/model/Layer";

/**
* @description マスクスタイルを取得
* Get mask style
*
* @param {Character} character
* @param {Layer} layer
* @return {Promise}
* @method
* @public
*/
export const execute = async (character: Character, layer: Layer): Promise<string> =>
{
if (layer.parentId === -1) {
return "";
}

console.log(character);
const workSpace = $getCurrentWorkSpace();
const movieClip = workSpace.scene;

const maskLayer = movieClip.getLayerById(layer.parentId);
if (!maskLayer || !maskLayer.lock) {
return "";
}

const activeCharacters = maskLayer.getActiveCharacters(movieClip.currentFrame);
if (!activeCharacters.length) {
return "";
}

const maskCharacter = activeCharacters[0];
if (!maskCharacter) {
return "";
}

const instance = workSpace.getLibrary(maskCharacter.libraryId);
if (!instance) {
return "";
}

const cacheKey = maskCharacter.cacheKey;

let canvas = $getCacheCanvas(workSpace.id, instance.id, cacheKey);
if (!canvas) {
canvas = await instance.getHTMLElement();
if (!canvas) {
return "";
}

// キャッシュに保存
// $setCacheCanvas(workSpace.id, instance.id, cacheKey, canvas);
}

const base64 = canvas.toDataURL();
const scale = window.devicePixelRatio;
const width = canvas.width / scale;
const height = canvas.height / scale;

// マスク用のスタイルを生成
let maskStyle = "";
maskStyle += `mask: url(${base64}), none;`;
maskStyle += `-webkit-mask: url(${base64}), none;`;
maskStyle += `mask-size: ${width}px ${height}px;`;
maskStyle += `-webkit-mask-size: ${width}px ${height}px;`;
maskStyle += "mask-repeat: no-repeat;";
maskStyle += "-webkit-mask-repeat: no-repeat;";
maskStyle += `mask-position: ${0}px ${0}px;`;
maskStyle += `-webkit-mask-position: ${0}px ${0}px;`;

return maskStyle;
};

0 comments on commit ab50843

Please sign in to comment.