加载资产注入使用File API three.js [英] Loading assets into three.js using File API

查看:149
本文介绍了加载资产注入使用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.

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

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