Playgroundで外部アセットを使用する
Using External Assets In the Playground
こちらが本家
iwaken.icon
Playgroundで外部から自分のモデルをロードしたい場合、そのサイトはcorsに準拠し、httpsプロトコルを使用する必要があります。
そのソリューションをいくつか紹介
github.comから
raw.githubusercontent.comを使う場合
Githubのレポジトリをpublicにする
3Dファイルを置く
例: https://github.com/BabylonJS/MeshesLibrary/blob/master/PBR_Spheres.glb
URLから
/blob/を取り除き
https://github.com をhttps://raw.githubusercontent.comに置き換える
結果こうなった
https://raw.githubusercontent.com/BabylonJS/MeshesLibrary/master/PBR_Spheres.glb
これをコード上で書くとこう
code:js
// 方法1)パスとファイル名を分けて指定する場合
BABYLON.SceneLoader.ImportMesh("","https://raw.githubusercontent.com/BabylonJS/MeshesLibrary/master/","PBR_Spheres.glb", scene);
// 方法2)パスとファイル名をつなげて指定する(URLを直接指定する)場合
BABYLON.SceneLoader.ImportMesh("","https://raw.githubusercontent.com/BabylonJS/MeshesLibrary/master/PBR_Spheres.glb","", scene);
※ cx20.icon 方法2を追記
raw.githack.comを使う場合
Githubのレポジトリにある3DファイルのURLを下図の赤枠の部分に貼り付けるとCDNで公開する為のURLが取得できます。
https://raw.githack.com/
https://scrapbox.io/files/6493ba46c98f7a001b2ddcee.png
#つまづいた時に解決した #備忘録 #glTF #CDN