Aframe Dynamic导入GLTF文件
因此,我有一个简单的GLTF文件,我想在运行时用A型框架导入它。
我已经尝试将GLTF字符串转换为URL并加载它,但是这给出了组件:GLTF模型:WARN无法读取未定义的属性(读取'0')
警告。这是我尝试的代码:
<a-scene>
<a-entity id="entity" position="0 2 -5"></a-entity>
</a-scene>
<script>
const gltfString = `{"cacessors":[{"bufferView":0,"byteOffset":0,"count":3,"componentType":5126,"extras":{},"type":"VEC3","min":[-0.5,-0.5,0.0],"max":[0.5,0.5,0.0]},{"bufferView":0,"byteOffset":12,"count":3,"componentType":5126,"extras":{},"type":"VEC3"}],"asset":{"extras":{},"version":"2.0"},"buffers":[{"byteLength":72,"uri":"data:application/octet-stream;base64,AAAAAAAAAD8AAAAAAACAPwAAAAAAAAAAAAAAvwAAAL8AAAAAAAAAAAAAgD8AAAAAAAAAPwAAAL8AAAAAAAAAAAAAAAAAAIA/","extras":{}}],"bufferViews":[{"buffer":0,"byteLength":72,"byteStride":24,"target":34962,"extras":{}}],"extras":{},"meshes":[{"extras":{},"primitives":[{"attributes":{"POSITION":0,"COLOR_0":1},"extras":{}}]}],"nodes":[{"extras":{},"mesh":0}],"scenes":[{"extras":{},"nodes":[0]}]}`;
const gltfBlob = new Blob([gltfString]); // convert string to blob
const gltfUrl = URL.createObjectURL(gltfBlob, {type: "text/plain"}); // blob to URL
document.addEventListener('DOMContentLoaded', function (event) {
const entity = document.querySelector('#entity');
console.log(entity) // blob:http://localhost:5500/4efe2c0d-5568-4928-8820-2e686b5b0c2a
bruhEntity.setAttribute('gltf-model', `url(${gltfUrl})`);
});
</script>
实现这一目标的方法是什么?
So I have a simply gltf file and i would like to import it with a-frame during runtime.
I already tried to convert the gltf string to a URL and load it, however this gives a components:gltf-model:warn Cannot read properties of undefined (reading '0')
warning. This is the code i tried:
<a-scene>
<a-entity id="entity" position="0 2 -5"></a-entity>
</a-scene>
<script>
const gltfString = `{"cacessors":[{"bufferView":0,"byteOffset":0,"count":3,"componentType":5126,"extras":{},"type":"VEC3","min":[-0.5,-0.5,0.0],"max":[0.5,0.5,0.0]},{"bufferView":0,"byteOffset":12,"count":3,"componentType":5126,"extras":{},"type":"VEC3"}],"asset":{"extras":{},"version":"2.0"},"buffers":[{"byteLength":72,"uri":"data:application/octet-stream;base64,AAAAAAAAAD8AAAAAAACAPwAAAAAAAAAAAAAAvwAAAL8AAAAAAAAAAAAAgD8AAAAAAAAAPwAAAL8AAAAAAAAAAAAAAAAAAIA/","extras":{}}],"bufferViews":[{"buffer":0,"byteLength":72,"byteStride":24,"target":34962,"extras":{}}],"extras":{},"meshes":[{"extras":{},"primitives":[{"attributes":{"POSITION":0,"COLOR_0":1},"extras":{}}]}],"nodes":[{"extras":{},"mesh":0}],"scenes":[{"extras":{},"nodes":[0]}]}`;
const gltfBlob = new Blob([gltfString]); // convert string to blob
const gltfUrl = URL.createObjectURL(gltfBlob, {type: "text/plain"}); // blob to URL
document.addEventListener('DOMContentLoaded', function (event) {
const entity = document.querySelector('#entity');
console.log(entity) // blob:http://localhost:5500/4efe2c0d-5568-4928-8820-2e686b5b0c2a
bruhEntity.setAttribute('gltf-model', `url(${gltfUrl})`);
});
</script>
What would be the way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字符串中有一个错别字,这是找出问题的简单方法:
test.gltf
中。从这个问题
。
There was a typo in the string, here's a simple way to find out whats wrong:
test.gltf
.this.json.accessors is undefined
)cacessors
toaccessors