<?php
$template = <<<END
<!-- block_glb:3Dモデル表示セクション -->
<section class="block_glb">
<table class="ta1">
<tr>
<th>{val item/title}</th>
<td>
    <div class="view">
      <model-viewer
        src="user_data/{val item/glb_file}"
        ios-src="./toy_biplane_idle.usdz"
        quick-look-browsers="safari chrome"
        alt="3D Model"
        exposure="1"
        camera-controls
        auto-rotate
        ar
        ar-scale="auto"
        camera-orbit="auto auto auto"
        interaction-prompt="auto"
        style="width: 100%; height: 100%">
      </model-viewer>
    </div>
</td>
</tr>
<!--{def item/contents}-->
<tr>
<th>説明</th>
<td class="markdown-body">{rval item/contents}</td>
</tr>
<!--{/def}-->
</table>
</section>
END;

$script = <<<END
    <script
      type="module"
      src="https://cdn.jsdelivr.net/npm/@google/model-viewer@latest/dist/model-viewer.min.js"></script>
END;

$block_glb = array(
	"title" => "GLBファイル表示",
	"name" => "block_glb",			// 名称、重複すると正しく動作しません
	"template" => $template,		// ブロックのテンプレート
	"js_file" => "glb.js",
	"css_file" => "glb.css",
	"javascript" => $script,		// ブロックの追加スクリプト
	"input" => array(
		"help" => array(
			"title" => "使い方",
			"type" => "comment",
			"link" => DOCUMENT1 . "/?act=block_glb",
			"class" => "notice",
		),
		"title" => array(
			"title" => "タイトル",
			"type" => "text",
		),
		"glb" => array(
			"title" => "GLBファイル",
			"type" => "file",
		),
		"contents" => array(
			"title" => "説明",
			"type" => "textarea",
		),
	),
	"func" => "func_block_glb",
);

block_add($block_glb);

function func_block_glb($def, $info)
{
	if ($info["glb"]) {
		$f = Image::getData($info["glb"]);
		if ($f) {
			$info["glb_file"] = $f["save_name"];
		}
	}
	return $info;
}
