com.hikky.heliodorlib
Version:
This is the library for Vket Cloud SDK.
389 lines (337 loc) • 10.8 kB
JavaScript
const g_Status = document.getElementById('status');
const g_Log = document.getElementById('log');
const g_GUIdebugTab = document.getElementById('GUIdebugTab');
const g_GUIdebug = document.getElementById('GUIdebug');
var g_WorldID = "";
var g_Spot = "";
// heliodor_post.jsのpostRunの起動先をStartにする必要がある
//Module['postRun'] = function() {
// console.log('Start ParticleEditor.');
// Start(1, 0, 0, false, "Scene/particleworld.json");
//}
ParamsInit();
function ParamsInit()
{
var params = (new URL(document.location)).searchParams;
var ParamSpot = params.get('spot');
if (ParamSpot != null) {
g_Spot = ParamSpot;
}
}
function hel_skyway_start()
{
console.log('Start ParticleEditor.');
Start(1, 0, 0, false, "Scene/particleworld.json");
}
//
function Start(Type, CharaType, Param1, MultiPlay, StrParam0)
{
// g_Status.style.visibility = 'visible';
// g_Log.style.visibility = 'visible';
g_Status.style.visibility = 'hidden';
g_Log.style.visibility = 'hidden';
hel_setCanvasFileName("Canvas/CanvasList.json");
hel_start(Type, CharaType, Param1, MultiPlay, StrParam0);
}
//
function hel_action_bridge(name, text)
{
if (name == "SceneItem_TextPlane_Write") {
hel_setText(ETextParamType_SceneItem, "TextPlane_Clear,TextPlane1");
hel_setText(ETextParamType_SceneItem, "TextPlane_Write,TextPlane1," + text);
}
else if (name == "HideWorldIcon") {
hel_canvas_SetGUIShow("HUD", "WorldIcon", false);
}
else if (name == "HideHUD") {
hel_canvas_SetLayoutShow("HUD", false);
}
else if (name == "HUD_SetNumofPlayer") {
hel_canvas_SetGUIText("HUD", "NumofPlayerText", text);
}
else if (name == "ReplaceWorldIcon") {
hel_canvas_SetGUIImage("HUD", "WorldIcon", "https://pbs.twimg.com/profile_images/1262574886859313152/ufgFNKJ4_400x400.jpg");
hel_canvas_SetGUIImage("HUD_po", "WorldIcon", "https://pbs.twimg.com/profile_images/1262574886859313152/ufgFNKJ4_400x400.jpg");
hel_canvas_SetGUIImage("HUD", "hud_emote_thumbsup", "https://pbs.twimg.com/profile_images/1262574886859313152/ufgFNKJ4_400x400.jpg");
}
else if (name == "PlayVideo") {
hel_action_PlayVideo(text);
}
else if (name == "CopyVideoFrame") {
hel_video_copy_frame_pixels_to_wasm(text);
}
else if (name == "WarpPlayer") {
hel_player_Warp(-3.0, 1.0, -7.0, 45.0);
}
else if (name == "EnablePlayerMove") {
hel_player_SetMoveEnable(true);
}
else if (name == "DisablePlayerMove") {
hel_player_SetMoveEnable(false);
}
else if (name == "start_screen_sharing") {
hel_skyway_start_screen_sharing();
}
}
function hel_action_PlayVideo(text)
{
/* var params = text.split(',');
var ItemName = params[0];
var MaterialName = params[1];
var URL = params[2];
*/
hel_setText(ETextParamType_PlayVideo, text);
}
function hel_onloaded()
{
console.log("hel_onloaded");
}
////////////////////////////////////////////////////////////////////////////////////////////
// ParticleEditor用
//------------------------------------------------------------------------------------------
let textInput = document.getElementById('textInput');
textInput.style.visibility = 'hidden';
textInput.addEventListener('input', textInputChange);
// テキストエディット表示切替
function textInputShow(show, left, top, text){
let textInput = document.getElementById('textInput');
if (show) {
textInput.style.visibility = 'visible';
textInput.style.position = 'absolute';
textInput.style.left = left + 'px';
textInput.style.top = top + 'px';
textInput.style.width = '100px';
textInput.style.border = 'hidden';
textInput.value = text;
} else {
textInput.style.visibility = 'hidden';
textInput.value = '';
}
}
// テキストエディットに文字列設定
function textInputUpdate(text){
textInput.value = text;
}
// テキストエディットの内容が変更された
function textInputChange()
{
let textInput = document.getElementById('textInput');
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'TextInputChange',
'',
['string'],
[textInput.value]
);
}
}
// 現在開いているディレクトリハンドル
let DirectoryHandle;
// パーティクルフォルダを開く
async function openParticleFolder() {
try {
DirectoryHandle = await window.showDirectoryPicker({mode: 'read'});
console.log('Load from ' + DirectoryHandle.name)
await loadParticle(DirectoryHandle.name)
} catch (error) {
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'CloseFileDialog',
'',
['string'],
['']
);
}
}
}
// パーティクルファイルを読み込む
async function loadParticle(name) {
const filename = name + '.hep'
const fh = await DirectoryHandle.getFileHandle(filename);
const file = await fh.getFile();
const reader = new FileReader();
reader.onload = async function () {
const ary_u8 = new Uint8Array(reader.result);
console.log( file.name + ',' + ary_u8.length ) ;
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'LoadParticle',
'',
['string', 'array', 'number'],
[file.name, ary_u8, ary_u8.length]
);
}
}
reader.readAsArrayBuffer(file);
}
// テクスチャファイルを読み込む
async function loadTexture(filename) {
// console.log( 'loadTexture : ' + filename ) ;
const ndh = await DirectoryHandle.getDirectoryHandle('tex', {create: false});
const fh = await ndh.getFileHandle(filename);
const file = await fh.getFile();
const reader = new FileReader();
reader.onload = function () {
const ary_u8 = new Uint8Array(reader.result);
console.log( file.name + ',' + ary_u8.length ) ;
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'AddTexture',
'',
['string', 'array', 'number'],
[file.name, ary_u8, ary_u8.length]
);
}
}
reader.readAsArrayBuffer(file);
}
// テクスチャファイルを開く
async function openTexture(){
const options = {
types: [
{
description: 'Images',
accept: {
'image/png': ['.png']
}
}
],
};
try {
const fh_list = await window.showOpenFilePicker(options);
const file = await fh_list[0].getFile();
const reader = new FileReader();
reader.onload = function () {
// console.log( reader.result ) ;
const ary_u8 = new Uint8Array(reader.result);
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'LoadTexture',
'',
['string', 'array', 'number'],
[file.name, ary_u8, ary_u8.length]
);
}
}
reader.readAsArrayBuffer(file);
} catch (error) {
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'CloseFileDialog',
'',
['string'],
['']
);
}
}
}
// 保存先フォルダを選択
async function saveParticleFolder() {
try {
DirectoryHandle = await window.showDirectoryPicker({mode: 'readwrite'});
console.log('Save to ' + DirectoryHandle.name)
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'SaveParticleName',
'',
['string'],
[DirectoryHandle.name]
);
}
} catch (error) {
if (HeliModule.ccall !== void 0) {
HeliModule.ccall(
'CloseFileDialog',
'',
['string'],
['']
);
}
}
}
// パーティクルファイル保存
async function saveParticle(filename, content) {
const fh = await DirectoryHandle.getFileHandle(filename, {create: true});
const stream = await fh.createWritable();
await stream.write(content);
await stream.close();
}
// テクスチャファイル保存
async function saveTexture(filename,texfolder, content) {
const ndh = await DirectoryHandle.getDirectoryHandle(texfolder, {create: true});
const fh = await ndh.getFileHandle(filename, {create: true});
const stream = await fh.createWritable();
await stream.write(content);
await stream.close();
}
// バッチファイル保存
async function saveBatch(filename,content) {
const fh = await DirectoryHandle.getFileHandle(filename, {create: true});
const stream = await fh.createWritable();
await stream.write(content);
await stream.close();
}
////////////////////////////////////////////////////////////////////////////////////////////
g_on_video_frame_capture = function(uint8Array, gotVideoRectX, gotVideoRectY, gotVideoRectWidth, gotVideoRectHeight) {
const getAverageColor = (x, y, detectionAreaWidth, detectionAreaHeight) => {
const left = x;
const right = x + detectionAreaWidth;
const top = y;
const bottom = y + detectionAreaHeight;
const horizontal_center = left + Math.floor(detectionAreaWidth / 2);
const vertical_center = top + Math.floor(detectionAreaHeight / 2);
const getColor = (x_, y_) => {
const r = uint8Array[(x_ * 4) + (4 * gotVideoRectWidth) * y_];
const g = uint8Array[(x_ * 4) + (4 * gotVideoRectWidth) * y_ + 1];
const b = uint8Array[(x_ * 4) + (4 * gotVideoRectWidth) * y_ + 2];
return [r, g, b];
};
const pixel0 = getColor(horizontal_center, vertical_center);
const pixel1 = getColor(horizontal_center + 1, vertical_center);
const pixel2 = getColor(horizontal_center, vertical_center + 1);
const pixel3 = getColor(horizontal_center + 1, vertical_center + 1);
const average_r = (pixel0[0] + pixel1[0] + pixel2[0] + pixel3[0]) / 4;
const average_g = (pixel0[1] + pixel1[1] + pixel2[1] + pixel3[1]) / 4;
const average_b = (pixel0[2] + pixel1[2] + pixel2[2] + pixel3[2]) / 4;
return [average_r, average_g, average_b];
}
const systemBackGroundRgb = getAverageColor(0, gotVideoRectHeight - 2, 0, 0);
const beginOrEndThreshold = 250;
if (systemBackGroundRgb[0] > beginOrEndThreshold && systemBackGroundRgb[1] > beginOrEndThreshold && systemBackGroundRgb[2] > beginOrEndThreshold) {
console.log('Begin or End');
}
const realRatio = g_Video.videoWidth / g_VideoInfo.videowidth;
for (const key in g_VideoInfo.eventmap) {
const val = g_VideoInfo.eventmap[key];
const rgb = getAverageColor(
Math.floor(val[0] * realRatio),
Math.floor(val[1] * realRatio),
Math.floor(val[2] * realRatio),
Math.floor(val[3] * realRatio)
);
console.log(`${key}: (${rgb[0]}, ${rgb[1]}, ${rgb[2]})`);
if (rgb[2] > 250) {
hel_setText(ETextParamType_PlayItem, 'Particle,0');
setTimeout(()=>{
hel_setText(ETextParamType_StopItem, 'Particle');
}, 3000);
g_video_particle_on = true;
} else {
// if (typeof g_video_particle_on !== 'undefined' && g_video_particle_on) {
// hel_setText(ETextParamType_StopItem, 'Particle');
// }
}
if (rgb[1] > 125) {
hel_setText(ETextParamType_ShowItem, 'SnowBall');
g_video_object_show_on = true;
setTimeout(()=>{
hel_setText(ETextParamType_HideItem, 'SnowBall');
},3000);
// } else {
// if (typeof g_video_object_show_on !== 'undefined' && g_video_object_show_on) {
// hel_setText(ETextParamType_HideItem, 'SnowBall');
// g_video_object_show_on = false;
// }
}
}
}