|
|
<!DOCTYPE html>
|
|
|
<html lang="zh">
|
|
|
|
|
|
<head>
|
|
|
<meta charset="utf-8" />
|
|
|
<base href="../../../" />
|
|
|
<script src="page.js"></script>
|
|
|
<link type="text/css" rel="stylesheet" href="page.css" />
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
[page:Loader] →
|
|
|
|
|
|
<h1>KTX2加载器([name])</h1>
|
|
|
|
|
|
<p class="desc">
|
|
|
KTX 2.0 GPU 纹理容器的加载程序。<br><br>
|
|
|
|
|
|
[link:http://github.khronos.org/KTX-Specification/ KTX 2.0] 是各种 GPU 纹理格式的容器格式。该加载器支持 Basis Universal GPU
|
|
|
纹理,可以快速转码为多种 GPU 纹理压缩格式。虽然 KTX 2.0 还允许其他特定于硬件的格式,但此加载程序尚未解析它们。
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
该加载程序解析 KTX 2.0 容器并将其转码为受支持的 GPU 压缩纹理格式。所需的 WASM 转码器和 JS 包装器可从
|
|
|
[link:https://github.com/mrdoob/three.js/tree/dev/examples/jsm/libs/basis examples/jsm/libs/basis] 目录中获取。
|
|
|
</p>
|
|
|
|
|
|
<h2>导入</h2>
|
|
|
|
|
|
<p>
|
|
|
[name] 是一个附加组件,必须显式导入。请参阅 [link:#manual/introduction/Installation Installation / Addons]。
|
|
|
</p>
|
|
|
|
|
|
<code>
|
|
|
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
|
|
|
</code>
|
|
|
|
|
|
<h2>代码示例</h2>
|
|
|
|
|
|
<code>
|
|
|
var ktx2Loader = new KTX2Loader();
|
|
|
ktx2Loader.setTranscoderPath( 'examples/jsm/libs/basis/' );
|
|
|
ktx2Loader.detectSupport( renderer );
|
|
|
ktx2Loader.load( 'diffuse.ktx2', function ( texture ) {
|
|
|
|
|
|
var material = new THREE.MeshStandardMaterial( { map: texture } );
|
|
|
|
|
|
}, function () {
|
|
|
|
|
|
console.log( 'onProgress' );
|
|
|
|
|
|
}, function ( e ) {
|
|
|
|
|
|
console.error( e );
|
|
|
|
|
|
} );
|
|
|
</code>
|
|
|
|
|
|
<h2>例子</h2>
|
|
|
|
|
|
<p>
|
|
|
[example:webgl_loader_texture_ktx2]
|
|
|
</p>
|
|
|
|
|
|
<h2>浏览器兼容性</h2>
|
|
|
|
|
|
<p>
|
|
|
该加载器依赖于旧版浏览器不支持的 Web Assembly。
|
|
|
</p>
|
|
|
|
|
|
<br>
|
|
|
<hr>
|
|
|
|
|
|
<h2>构造函数</h2>
|
|
|
|
|
|
<h3>[name]( [param:LoadingManager manager] )</h3>
|
|
|
<p>
|
|
|
[page:LoadingManager manager] — 供加载器使用的 [page:LoadingManager] 。默认值为 [page:LoadingManager
|
|
|
THREE.DefaultLoadingManager]。
|
|
|
</p>
|
|
|
<p>
|
|
|
创建一个新的 [name]。
|
|
|
</p>
|
|
|
|
|
|
<h2>属性</h2>
|
|
|
<p>有关常用属性,请参阅 [page:Loader] 基类</p>
|
|
|
|
|
|
<h2>Methods</h2>
|
|
|
<p>有关常用方法,请参阅 [page:Loader] 基类</p>
|
|
|
|
|
|
<h3>[method:CompressedTexture load]( [param:String url], [param:Function onLoad], [param:Function onProgress],
|
|
|
[param:Function onError] )</h3>
|
|
|
<p>
|
|
|
[page:String url] — 包含 `.ktx2` 文件路径/URL 的字符串。<br />
|
|
|
[page:Function onLoad] — 加载成功完成后调用的函数。<br />
|
|
|
[page:Function onProgress] — (可选)加载过程中调用的函数。参数将是 XMLHttpRequest 实例,其中包含 .[page:Integer total] 和 .[page:Integer
|
|
|
loaded] 字节。如果服务器没有设置 Content-Length,.[page:Integer total] 将为 0。<br />
|
|
|
[page:Function onError] — (可选)加载期间发生错误时调用的函数。该函数接收错误作为参数。<br />
|
|
|
</p>
|
|
|
<p>
|
|
|
从 url 加载并在转码后 [page:CompressedTexture] 调用 `onLoad` 函数。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this detectSupport]( [param:WebGLRenderer renderer] )</h3>
|
|
|
<p>
|
|
|
[page:WebGLRenderer renderer] — 渲染器实例。
|
|
|
</p>
|
|
|
<p>
|
|
|
检测可用压缩纹理格式的硬件支持,以确定转码器的输出格式。必须在加载纹理之前调用。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this setTranscoderPath]( [param:String path] )</h3>
|
|
|
<p>
|
|
|
[page:String path] — 包含 WASM 转码器和 JS 包装器的文件夹路径。
|
|
|
</p>
|
|
|
<p>
|
|
|
WASM 转码器和 JS 包装器可从 [link:https://github.com/mrdoob/three.js/tree/dev/examples/jsm/libs/basis
|
|
|
examples/jsm/libs/basis] 目录中获取。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this setWorkerLimit]( [param:Number limit] )</h3>
|
|
|
<p>
|
|
|
[page:Number limit] — 最大 worker 数量。默认值为 '4'。
|
|
|
</p>
|
|
|
<p>
|
|
|
设置此实例要分配的最大 Web Worker 数量。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this dispose]()</h3>
|
|
|
<p>
|
|
|
处置加载器对象,取消分配创建的所有 Web Worker。
|
|
|
</p>
|
|
|
|
|
|
<h2>源代码</h2>
|
|
|
|
|
|
<p>
|
|
|
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/KTX2Loader.js examples/jsm/loaders/KTX2Loader.js]
|
|
|
</p>
|
|
|
</body>
|
|
|
|
|
|
</html>
|