2

我正在尝试将 webgl-texture-utils ( https://github.com/toji/webgl-texture-utils ) 与 Three.js (r56) 一起使用以利用 DDS 和 CRN ( http://code.google .com/p/crunch/ ) 纹理。

我无法弄清楚如何使用 in 返回的textureLoader.load(src, callback);纹理THREE.Texture(image, mapping);

THREE.Texture 需要 javascript Image() 对象,但 texture-utils 会返回 Firebug 报告的XrayWrapper [Object WebGLTexture {}内容,我认为它是一些原生 WebGL 纹理类型。

我可以以某种方式使用该纹理作为 THREE.Texture 的图像吗?

这是我尝试过的一些代码:

var mapping = new THREE.UVMapping();

var image = new Image();
var map = null;

var usetexturetools = true;

if (!usetexturetools) { 

  // normal way of loading

  map = new THREE.Texture( image, mapping );
  var loader = new THREE.ImageLoader();
  loader.addEventListener( 'load', function ( event ) {
    map.image = event.content;
    map.needsUpdate = true;
  });
  loader.addEventListener( 'error', function ( event ) {
    window.console.log("error loading " + texture);
  });
  loader.crossOrigin = 'anonymous';
  loader.load(texture, image);

} else {

 // using webgl-texture-tools - not working because i don't know how to use the object returned by textureLoader.load() with THREE.Texture..

 var textureLoader = new TextureUtil.TextureLoader(renderer.getContext());

 map = new THREE.Texture(textureLoader.load(texture, function(loaded) {
    window.console.log(loaded);
    map.needsUpdate = true;
 }), mapping );

}

map.sourceFile = texture;
map.wrapS = THREE.RepeatWrapping;
map.wrapT = THREE.RepeatWrapping;

map.offset.x = this.getParameter("texture_offset_x");
map.offset.y = this.getParameter("texture_offset_y");

map.repeat.x = this.getParameter("texture_scale_x");
map.repeat.y = this.getParameter("texture_scale_y");

编辑:我想我可以创建一个 webgl-texture-utils 的分支,而不是创建和返回 WebGLTexture,只会返回原始数据,因此,我可以在 THREE.DataTexture() 中使用该数据。当我开始时,我会尝试...查看源代码看起来可能需要做很多工作,但除非出现任何问题,否则我会尝试。

4

0 回答 0