Railsにこれから初めて触れる方を対象にしたチュートリアルです
AR.js
を使用してAR機能を組み込むチュートリアルです
まず、rails new
を実行し、Railsアプリのひな型を作成します
rails new arjs
次に、作成したRailsアプリのディレクトリへと移動します
cd arjs
先ほどのrails new
でsqlite3
のインストールがエラーになっている場合は、以下のようにバージョンを修正します
gem 'sqlite3', '1.3.13'
その後、bundle install
を実行します
bundle install
これでOKです!
rails g controller
コマンドを使用して、View
を作成します
rails g controller web index
その後、config/routes.rb
を編集します
Rails.application.routes.draw do
root 'web#index'
get 'web/index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
View
の作成はこれでOKです!
それではAR.js
を導入していきたいと思います
app/views/web/index.html
を以下のように変更します
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.6.2/aframe/build/aframe-ar.js"></script>
<a-scene embedded arjs>
<a-marker preset="hiro">
<a-box position='0 0.5 0' material='color: black;'></a-box>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
あとは、rails s
を実行し、localhost:3000
にアクセスしてください
画面全体がカメラとして動作していると思います 最後に、以下の画像を読み込んでみてください
黒い四角が表示されていればOKです!