Overview
I tried out annotations in Sketchfab, so this is a personal note for future reference.
Ultimately, I created the following viewer.
https://nakamura196.github.io/SketchfabAnnotationViewer/

Data Used
We will use the “Ishibuchi Family Globe” from the “Kikuchi City / Digital Archive.”
https://adeac.jp/kikuchi-city/catalog/e0001
Usage Example
First, I uploaded the 3D data to Sketchfab.
Then I added annotations. As a result, the following page was prepared.

Using the API
Please also refer to the following repository.
https://github.com/nakamura196/SketchfabAnnotationViewer
With the following script, I was able to retrieve a list of annotations, specify the annotation to display initially, and focus on a selected annotation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sketchfab Annotation Viewer</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans">
<!-- メインコンテナ -->
<div class="max-w-4xl mx-auto py-10 px-4">
<!-- ヘッダー -->
<h1 class="text-2xl font-bold text-gray-800 text-center mb-6">
Sketchfab Annotation Viewer
</h1>
<!-- 3Dビューア -->
<div class="mb-6">
<iframe
id="api-frame"
width="100%"
height="480"
class="rounded shadow-md border border-gray-300"
src=""
allowfullscreen
></iframe>
</div>
<!-- アノテーションリスト -->
<h2 class="text-xl font-semibold text-gray-700 mb-4">Annotations</h2>
<ul id="annotation-list" class="space-y-2">
<!-- アノテーション項目はJavaScriptで追加 -->
</ul>
</div>
<script src="https://static.sketchfab.com/api/sketchfab-viewer-1.12.1.js"></script>
<script src="script.js"></script>
</body>
</html>
// Sketchfab Viewerを埋め込むためのiframeを取得
const iframe = document.getElementById('api-frame');
const client = new Sketchfab(iframe);
const urlParams = new URLSearchParams(window.location.search);
// SketchfabモデルIDを指定
const modelId = urlParams.get('id') || '02add905e79c446994f971cbcf443815'; // 'id'パラメータを取得
const pos = parseInt(urlParams.get('pos'), 10) || 0;
// APIのオプションを指定してモデルをロード
client.init(modelId, {
success: function (api) {
api.start();
api.addEventListener('viewerready', function () {
setupAnnotations(api);
focusAnnotation(api, pos); // 最初のアノテーションにフォーカス
});
},
error: function () {
console.error('Sketchfab Viewer failed to load');
},
});
function setupAnnotations(api) {
api.getAnnotationList(function (err, annotations) {
if (err) {
console.error('Failed to fetch annotations');
return;
}
// アノテーション一覧をHTMLに追加
const annotationListContainer = document.getElementById('annotation-list');
annotations.forEach((annotation, index) => {
const annotationItem = document.createElement('li');
annotationItem.textContent = annotation.name; // アノテーションタイトル
annotationItem.addEventListener('click', () => {
focusAnnotation(api, index); // クリック時にフォーカス
});
annotationListContainer.appendChild(annotationItem);
});
});
}
function focusAnnotation(api, annotationIndex) {
api.gotoAnnotation(annotationIndex, {
preventCameraAnimation: false, // アニメーションを許可
});
// api.showAnnotation(annotationIndex); // アノテーションを表示
// api.showAnnotationTooltip(annotationIndex); // アノテーションツールチップを表示
}
Summary
I hope this serves as a useful reference for applying annotations to 3D data.