簡體   English   中英

在 Django 中使用 gltf 加載器加載三個 JS model

[英]Load Three JS model with gltf loader in Django

我正在嘗試在本地環境的 Django(3.0.3) 應用程序中加載三個 JS model。

模板:

<script>
    var address_to_model ="{% static 'models/matilda/scene.gltf' %}"; // Pass this variable to .js file
</script>
<script src="{% static 'js/matilda.js' %}"></script>

matilda.js:

var loader = new THREE.GLTFLoader( );
loader.load( address_to_model, function ( gltf ) {
        scene.add( gltf.scene );
    }, undefined, function ( error ) {
        console.error( error );
} );
renderer.outputEncoding = THREE.sRGBEncoding;

頁面加載時沒有任何 Django 錯誤,它顯示 ThreeJS window 正在工作,但 model 未加載,在 Chrome 錯誤控制台中,我收到此錯誤:

獲取http://127.0.0.1:8000/matilda/models/matilda/scene.gltf 404(未找到)

我認為它不應該檢查這個 URL 因為我沒有在 urls.py 中解決它並且這個地址中沒有任何內容。 它應該使用collectstatic命令加載收集在“static/models/matilada”中的 model。

I check these links but they do not help: * Django {% static 'path' %} in javascript file * Correctly accessing django static files from external javascript * Django: External JS using framework doesn't load * https://pypi. org/project/django-js-urls/

您需要在 IP 地址上托管網站,以便加載threejs gltf model。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM