使用 indexedDB 存储 Three.js 网格对象
利用本教程我试图看看是否可以通过大网格来节省带宽使用indexedDB 缓存它。
因此,在加载器回调函数中,我正在执行...
object = new THREE.Mesh( geometry, material );
webkitIndexedDB.open("MyNewDB").onsuccess = function(event) {
window.db = event.srcElement.result;
window.db.setVersion("1.0").onsuccess = function(event) {
var objectStore = window.db.createObjectStore("meshes", { keyPath: "item_id" });
objectStore.add({item_id: 0, mesh: object}); // <= this is the crucial line
};
};
但是,将包含 object
的对象添加到数据库的最后一行会导致以下错误。
未捕获错误:DATA_CLONE_ERR:DOM 异常 25
我不确定这真正意味着什么,但一定有办法解决它,不是吗?
Utilising this tutorial I'm trying to see if I can save bandwidth with a large mesh by caching it with indexedDB.
So inside the loader callback function I'm doing...
object = new THREE.Mesh( geometry, material );
webkitIndexedDB.open("MyNewDB").onsuccess = function(event) {
window.db = event.srcElement.result;
window.db.setVersion("1.0").onsuccess = function(event) {
var objectStore = window.db.createObjectStore("meshes", { keyPath: "item_id" });
objectStore.add({item_id: 0, mesh: object}); // <= this is the crucial line
};
};
however the last line where an object containing object
is added to the database causes the following error.
Uncaught Error: DATA_CLONE_ERR: DOM Exception 25
I'm not sure what this really means but there must be a way around it no?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着您的
THREE.Mesh
object
格式错误,但并未违反索引、唯一性或类似内容。当我尝试将具有未执行函数的对象存储为成员时,我看到此错误。规范中的技术定义是:
如果您尝试存储名称空间的对象状态,那么您就完蛋了。如果您存储纯数据,我会尝试对 THREE.Mesh() 对象进行深层复制,检查
typeof
是否为“function”。编辑:我进一步研究了这一点。 IndexedDB 使用 HTML5 结构化克隆算法将对象复制到对象存储中。根据规范,Error 和 Function 对象无法克隆并抛出
DATA_CLONE_ERR< /代码>。这就是你所看到的。
It means your
THREE.Mesh
object
is malformed, but not in a way that's violating indexes, uniqueness, or anything like that. I see this error when I try to store objects that have un-executed functions as members.The technical definition from the spec is:
If you're trying to store object state of a namespace you're hosed. If you're storing plain data I would try doing a deep copy of the THREE.Mesh() object checking
typeof
for 'function.'EDIT: I looked into this further. IndexedDB copies objects into the object store using the HTML5 structured clone algorithm. According to the spec, Error and Function objects cannot be cloned and throw a
DATA_CLONE_ERR
. That's what you're seeing.