質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

Three.js

Three.jsはWebGLをサポートしているJavaScriptの3D描画用ライブラリです。

3DCG

コンピュータの演算により、3次元空間の仮想物体を、2次元平面上で表現する手法である。

Q&A

解決済

1回答

1935閲覧

Three.jsでモデルが表示されない

hajifu

総合スコア88

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

Three.js

Three.jsはWebGLをサポートしているJavaScriptの3D描画用ライブラリです。

3DCG

コンピュータの演算により、3次元空間の仮想物体を、2次元平面上で表現する手法である。

0グッド

0クリップ

投稿2020/08/23 17:27

編集2020/08/23 17:29

ARに興味があり、全く初心者なのですが Amazon Sumerianを使ってみました。
Webアプリにモデルを表示するのをチュートリアルに沿ってやってみたのですが、canvasが真っ黒になってしまいモデルが表示されません。
テンプレート部はこのような感じで

html

1<div class="fill-height"> 2 <div id="ar-container" class="d-flex justify-center align-center"> 3 <canvas ref="canvas" id="ar-canvas" @resize="onResize" /> 4 </div> 5</div>

初期化処理はNuxtのmountedフックで下記のように書いています

js

1import { Scene, WebGLRenderer, AmbientLight, PerspectiveCamera } from 'three' 2import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js' 3 4const gltfUrl = '/scene/root.gltf' 5 6// 中略 7mounted() { 8 const canvas = this.$refs.canvas 9 const renderer = new WebGLRenderer({ canvas }) 10 renderer.setSize(canvas.clientWidth, canvas.clientHeight, false) 11 const scene = new Scene() 12 this.renderer = renderer 13 14 const camera = new PerspectiveCamera(45, canvas.clientWidth / canvas.clientHeight, 1, 500) 15 camera.position.set(200, 40, 0) 16 camera.lookAt(0, 0, 0) 17 scene.add(camera) 18 this.camera = camera 19 20 const light = new AmbientLight() 21 scene.add(light) 22 this.light = light 23 24 const loader = new GLTFLoader() 25 26 await loader.load(gltfUrl, gltf => { 27 scene.add(...gltf.scene.children) 28 }) 29 this.loader = loader 30 31 const animate = () => { 32 renderer.render(scene, camera) 33 requestAnimationFrame(animate) 34 } 35 36 animate() 37}

すると下記のように真っ黒な画面が表示されます。。。
表示画面
コンソールには特にエラーなど出ていないのですが、これは失敗しているのか、それとも成功しているけどカメラやライトが変みたいなことなのでしょうか??

ちなみにモデルは、今スクショをとろうとしていたら消えてしまっていたのでお見せできないのですが、Sumerianのボックスをひとつ置いただけのものでした。

何か解決する方法やヒントを教えていただければ幸いです。
宜しくお願いいたします。

※自分はVueとNuxtは少しできますがThree.jsは使ったことなく、3dモデルなどの知識は皆無といったレベルです

gtlfファイルはこんな感じです

{ "asset": { "generator": "Amazon Sumerian", "version": "2.0" }, "cameras": [ { "name": "Default Camera", "type": "perspective", "perspective": { "aspectRatio": 1, "yfov": 0.7853981633974483, "zfar": 1000, "znear": 1 } } ], "nodes": [ { "name": "Default Camera", "camera": 0, "rotation": [ -0.004824238008088496, -0.9813484047269434, -0.1905645404834078, 0.024843332664362804 ], "scale": [ 1, 1, 1 ], "translation": [ 2.403656682831947, 7.360146616014571, -18.15123686461488 ] }, { "name": "Key - Directional", "extensions": { "KHR_lights_punctual": { "light": 0 } }, "rotation": [ -0.0948595598902012, 0.11955889871169392, -0.14019607206387738, 0.9782905473396666 ], "scale": [ 0.9999998569971704, 0.9999998569971704, 0.9999998569971704 ], "translation": [ 3.840765953063965, 5.725151062011719, 6.723899841308594 ] }, { "name": "Rim - Directional", "extensions": { "KHR_lights_punctual": { "light": 1 } }, "rotation": [ -0.007935453473895075, 0.936498758480699, 0.34801447925863915, 0.042344139719820297 ], "scale": [ 1.0000002646568553, 1.0000002646568553, 1.0000002646568553 ], "translation": [ 4.528846740722656, 9.009954452514648, -9.487277030944824 ] }, { "name": "Default Dynamic Lights", "rotation": [ 0, 0, 0, 1 ], "scale": [ 1, 1, 1 ], "translation": [ 0, 0, 0 ], "children": [ 1, 2 ] }, { "name": "Box", "mesh": 0, "rotation": [ 0, 0, 0, 1 ], "scale": [ 1, 1, 1 ], "translation": [ 0, 0, 0 ] }, { "name": "Light", "extensions": { "KHR_lights_punctual": { "light": 2 } }, "rotation": [ 0, 0, 0, 1 ], "scale": [ 1, 1, 1 ], "translation": [ 0, 0, 0 ] } ], "extensions": { "KHR_lights_punctual": { "lights": [ { "name": "Key - Directional", "color": [ 0.92477783203125, 0.8875688601181507, 0.856960791015625 ], "intensity": 1, "type": "directional" }, { "name": "Rim - Directional", "color": [ 1, 1, 1 ], "intensity": 1, "type": "directional" }, { "name": "Light", "color": [ 1, 1, 1 ], "intensity": 1, "type": "directional" } ] } }, "extensionsUsed": [ "KHR_lights_punctual" ], "buffers": [ { "byteLength": 804, "uri": "Box-textureModeUniform.bin" } ], "bufferViews": [ { "buffer": 0, "byteOffset": 0, "byteLength": 36, "target": 34963 }, { "buffer": 0, "byteOffset": 36, "byteLength": 288, "byteStride": 12, "target": 34962 }, { "buffer": 0, "byteOffset": 324, "byteLength": 288, "byteStride": 12, "target": 34962 }, { "buffer": 0, "byteOffset": 612, "byteLength": 192, "byteStride": 8, "target": 34962 } ], "accessors": [ { "bufferView": 0, "byteOffset": 0, "componentType": 5121, "count": 36, "max": [ 23 ], "min": [ 0 ], "type": "SCALAR" }, { "bufferView": 1, "byteOffset": 0, "componentType": 5126, "count": 24, "max": [ 0.5, 0.5, 0.5 ], "min": [ -0.5, -0.5, -0.5 ], "type": "VEC3" }, { "bufferView": 2, "byteOffset": 0, "componentType": 5126, "count": 24, "max": [ 1, 1, 1 ], "min": [ -1, -1, -1 ], "type": "VEC3" }, { "bufferView": 3, "byteOffset": 0, "componentType": 5126, "count": 24, "max": [ 1, 1 ], "min": [ 0, 0 ], "type": "VEC2" } ], "meshes": [ { "name": "Box", "primitives": [ { "attributes": { "POSITION": 1, "NORMAL": 2, "TEXCOORD_0": 3 }, "indices": 0, "mode": 4, "material": 0 } ] } ], "materials": [ { "name": "Default Material", "pbrMetallicRoughness": { "baseColorFactor": [ 0.8, 0.8, 0.8, 1 ], "roughnessFactor": 0.936 }, "emissiveFactor": [ 0, 0, 0 ] } ], "scenes": [ { "name": "Practice-1", "nodes": [ 0, 3, 4, 5 ] } ], "scene": 0 }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

dameo

2020/08/25 04:46 編集

編集したら文章が消えてしまいました...内容変わってるかもしれませんが、、、 gltf内で参照される*.binがないので、誰もモデルを見ることが出来ません。数字だけで何かを判断するのは難しい上に、vueやnuxtなど関係ないものが入ってると答えられる人がどんどん減ってしまいます。 私も3Dやthree.jsはよく知りませんが、とりあえず似たようなコードで動くものを書いてみました。 ご参考までに。 sed 's/^\xc2\xa0/ /;s/$/$/g;s/`/`/g;s/ /\x20\x20/g' <<__END_OF_TERMINAL_CODE__ >three_sample.html <!DOCTYPE html> <html lang="ja"> <head>   <script type="module">     import * as THREE from "https://unpkg.com/three@0.119.1/build/three.module.js";     import {GLTFLoader} from "https://unpkg.com/three@0.119.1/examples/jsm/loaders/GLTFLoader.js";     window.addEventListener('DOMContentLoaded', async(e) => {       const canvas = document.querySelector('canvas#target');       const renderer = new THREE.WebGLRenderer({ canvas })       renderer.setSize(canvas.clientWidth, canvas.clientHeight, false)       const scene = new THREE.Scene()       const camera = new THREE.PerspectiveCamera(45, canvas.clientWidth / canvas.clientHeight, 1, 50)       camera.position.set(1.5, 1.5, 1.5)       camera.lookAt(0, 0, 0)       scene.add(camera)       const light = new THREE.AmbientLight(0xFFFFFF, 10.0)       scene.add(light)       const manager = new THREE.LoadingManager();       const loader = new GLTFLoader(manager);       const gltfUrl = "root.gltf"       await loader.load(gltfUrl, gltf => {         scene.add(...gltf.scene.children)       })       const animate = () => {         renderer.render(scene, camera)         requestAnimationFrame(animate)       }       animate()     });   </script> </head> <body>   <canvas id="target" height="700" width="1000"></canvas> </body> </html> __END_OF_TERMINAL_CODE__ root.gltfは、↓をお借りしました。 https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Box/glTF-Embedded/Box.gltf file:///~では残念ながらCORSで動かないので、適当な鯖に静的に載せれば見れると思います。
hajifu

2020/08/26 14:36

ありがとうございます! 公式サンプルの狐にしてみたら、表示されました!動いたりはしませんが… まだ解決できていませんが、もしかしたら、最初に自分で作ったやつは透明?あるいは暗すぎているのかもしれないと思いました。
guest

回答1

0

自己解決

Babylon.jsの方でやってみるとうまくいきました!
ボックスのモデルは、どうやらサイズが小さすぎて豆粒みたいになっていて表示できないようでした。
Three.jsでは静止画になってしまうのはよくわかりませんでしたが、一応表示できたので解決済みにしたいと思います…

投稿2020/08/26 14:59

hajifu

総合スコア88

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問