A-Frame: https://aframe.io
AR.js: https://github.com/jeromeetienne/AR.js
謝辞:ここで紹介するソフトウエアの作者に感謝します.
参考Webページ
https://medium.com/@akashkuttappa/using-3d-models-with-ar-js-and-a-frame-84d462efe498
システム Python を使うことができる(その場合,Python のインストールは行わない)
システム Python を用いるときは,pip, setuptools の更新は次のコマンドで行う.
sudo apt -y update sudo apt -y install python3-pip python3-setuptools
Ubuntu で,システム Python 以外の Python をインストールしたい場合は pyenv が便利である: 別ページで説明している.
Python の URL: http://www.python.org/
【Python, pip の使い方】
Python, pip は,次のコマンドで起動できる.
【Python 開発環境のインストール】
JupyterLab, spyder, nteract (Python 開発環境) のインストールは, Windows でコマンドプロンプトを管理者として実行し, 次のコマンドを実行.
python -m pip install -U pip setuptools jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder
詳しくは,: 別ページで説明している.
JupyterLab, spyder, nteract (Python 開発環境) のインストール: : 別ページで説明している.
ここで行うこと:hiro マーカーにより,箱(Box)を表示する Web ページを作る.Web サーバを稼働させ,Web ブラウザでこの Web ページが動くようにする.
名前は何でもよいが,日本語を含まないものがよい.
次のページに記載のサンプルプログラムのうち,マーカーベースの AR のものを使う.(タイプミスと思われる部分を修正,a-box を使うように変更,URLを最新にものに修正など).
https://ar-js-org.github.io/AR.js-Docs/#getting-started
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
<title>marker AR</title>
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<!-- we import arjs version without NFT but with marker + location based support -->
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script>
</head>
<body style="margin:0px; overflow:hidden;">
<a-scene embedded arjs>
<a-marker preset="hiro">
<a-box position="0 0.5 0" wireframe="true"></a-box>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
</body>
</html>
次のコマンドを実行
python -m http.server 80
※ カメラの使用の許可についての表示が出た場合には許可する.
https://github.com/AR-js-org/AR.js/blob/master/data/images/hiro.png
カメラで,マーカー画像 hiro.pngを撮影すると,箱が現れるので確認する.
.obj 形式ファイル,.mtl 形式ファイルを準備する. できたファイルは次のとおりである.
ここでは,Blender を用いる.
Windows でのBlender のインストールは,別ページで説明している.
Blender の使い方については,別ページにまとめている.
いま作成した作業用のフォルダ(ディレクトリ)に, b.html のようなファイル名で保存する.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
<title>marker AR</title>
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<!-- we import arjs version without NFT but with marker + location based support -->
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script>
</head>
<body style="margin:0px; overflow:hidden;">
<a-scene embedded arjs>
<a-marker preset="hiro">
<a-entity
position="0 0 0"
scale="0.5 0.5 0.5"
obj-model="obj:url(./a.obj); mtl:url(./a.mtl)">
</a-entity>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
</body>
</html>
もし,Web サーバが稼働していなければ,次の手順で稼働させる.
次のコマンドを実行
python -m http.server 80
https://github.com/AR-js-org/AR.js/blob/master/data/images/hiro.png
カメラで,マーカー画像 hiro.pngを撮影すると,3次元オブジェクトが現れるので確認する.
マーカーの場所,大きさ,傾きの応じて3次元オブジェクトが表示される.