加载资产注入使用File API three.js加载、资产、File、js

由网友(男神大妈)分享简介:我想创建导入3D模型使用的文件API 。 I'd like to create the functionality to import a 3D model to view in the browser by using the File API. 在three.js装载机上,我的主机文件的工作很大。我的理解是,加...

我想创建导入3D模型使用的文件API 。

I'd like to create the functionality to import a 3D model to view in the browser by using the File 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 - 相关code之前。例如:

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支持,需要加载创建后这样做了,直接覆盖功能的加载器实例。这种方法应该也适用于OBJLoader等​​。但你不能做到这一点事先,你需要有code。在您的实际模型加载功能/回调。

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.

阅读全文

相关推荐

最新文章