使用 File API 将资产加载到 Three.js [英] Loading assets into three.js using File API

查看:33
本文介绍了使用 File API 将资产加载到 Three.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用 文件 API.

three.js 加载器可以很好地处理我托管的文件.我的理解是加载程序使用 ajax 来检索文件.

The three.js loaders work great on files that I host. My understanding is that the loader uses ajax to retrieve the file.

我希望能够从客户端的磁盘加载文件以进行查看.这如何实现?

I'd like to be able to load the file from disk on the client to view it. How might this be accomplished?

推荐答案

您可以覆盖或热修补"加载程序的 load() 函数以满足您的需要.

You can override or "hot patch" the loaders' load() function to fit your needs.

将您的覆盖放在任何其他与 THREE.js 相关的代码之前.例如:

Put your overrides before any other THREE.js -related code. For example:

THREE.OBJLoader.prototype.load = function(url) {
  // copy the function from OBJLoader.js source and change the AJAX calls to File API calls
}

看起来不像其他的,ColladaLoader 没有使用原型来实现,所以它不是那么简单.如果需要Collada支持,需要在Loader创建后进行,直接在loader实例上覆盖该函数.这种方法应该也适用于 OBJLoader 和其他人.但是你不能事先这样做,你需要在你的实际模型加载函数/回调中有代码.

It seems that unlike the others, ColladaLoader is not implemented using prototypes, so it's not as straightforward. If you need Collada support, you need to do it after Loader creation, and override the function directly on the loader instance. This approach should work also for OBJLoader and others. But you can't do this beforehand, you need to have the code in your actual model loading function/callback.

var myloader = new THREE.ColladaLoader();

myloader.load = function(url) {
  // copy the function from ColladaLoader.js source and change the AJAX calls to File API calls
}

我在 ImageLoader 中使用了类似的方法,使用画布将非二次幂纹理自动调整为适当的尺寸.

I use similar approach in ImageLoader to automatically resize non-power-of-two textures to proper dimensions using canvas.

这篇关于使用 File API 将资产加载到 Three.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆