Skip to content

Commit

Permalink
feat: add TextDecoder polyfill & EXRLoader works
Browse files Browse the repository at this point in the history
  • Loading branch information
deepkolos committed Jan 27, 2021
1 parent 4cda31b commit 25ff7c7
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ PLATFORM.dispose();
2. RGBELoader & PMREMGenerator
3. SVGLoader
4. OBJLoader
5. EXRLoader

#### Controls

Expand Down
7 changes: 5 additions & 2 deletions build/three.js
Expand Up @@ -271,6 +271,7 @@
exports.$window = null;
exports.$document = null;
exports.$DOMParser = null;
exports.$TextDecoder = null;
exports.$XMLHttpRequest = null;
exports.$OffscreenCanvas = null;
exports.$HTMLCanvasElement = null;
Expand All @@ -296,6 +297,7 @@
exports.$createImageBitmap = globals.createImageBitmap;
exports.$URL = exports.$window.URL;
exports.$DOMParser = exports.$window.DOMParser;
exports.$TextDecoder = exports.$window.TextDecoder;
exports.$requestAnimationFrame = exports.$window.requestAnimationFrame;
exports.$window.cancelAnimationFrame;
};
Expand All @@ -308,6 +310,7 @@
exports.$window = null;
exports.$document = null;
exports.$DOMParser = null;
exports.$TextDecoder = null;
exports.$XMLHttpRequest = null;
exports.$OffscreenCanvas = null;
exports.$HTMLCanvasElement = null;
Expand Down Expand Up @@ -30185,8 +30188,8 @@

var LoaderUtils = {
decodeText: function decodeText(array) {
if (typeof TextDecoder !== 'undefined') {
return new TextDecoder().decode(array);
if (typeof exports.$TextDecoder !== 'undefined') {
return new exports.$TextDecoder().decode(array);
} // Avoid the String.fromCharCode.apply(null, array) shortcut, which
// throws a "maximum call stack size exceeded" error for large arrays.

Expand Down
2 changes: 1 addition & 1 deletion build/three.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions build/three.module.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/platfromize.js
Expand Up @@ -8,6 +8,7 @@ export const platformVariables = [
'window',
'document',
'DOMParser',
'TextDecoder',
'XMLHttpRequest',
'OffscreenCanvas',
'HTMLCanvasElement',
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/libs/rhino3dm/rhino3dm.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions examples/jsm/loaders/EXRLoader.js
@@ -1,3 +1,4 @@
import { $TextDecoder } from '../../../build/three.module.js';
import { DataTextureLoader, FloatType, HalfFloatType, UnsignedByteType, RGBEFormat, RGBAFormat, LinearEncoding, LinearFilter, RGBEEncoding, NearestFilter, DataUtils } from '../../../build/three.module.js';
import { Inflate } from '../libs/inflate.module.min.js';

Expand Down Expand Up @@ -1707,7 +1708,7 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype

}

var stringValue = new TextDecoder().decode(
var stringValue = new $TextDecoder().decode(
uintBuffer.slice( offset.value, offset.value + endOffset )
);

Expand All @@ -1719,7 +1720,7 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype

function parseFixedLengthString( buffer, offset, size ) {

var stringValue = new TextDecoder().decode(
var stringValue = new $TextDecoder().decode(
new Uint8Array( buffer ).slice( offset.value, offset.value + size )
);

Expand Down
4 changes: 4 additions & 0 deletions src/Platform.js
Expand Up @@ -4,6 +4,7 @@ let $Blob = null;
let $window = null;
let $document = null;
let $DOMParser = null;
let $TextDecoder = null;
let $XMLHttpRequest = null;
let $OffscreenCanvas = null;
let $HTMLCanvasElement = null;
Expand All @@ -30,6 +31,7 @@ class Platform {

$URL = $window.URL;
$DOMParser = $window.DOMParser;
$TextDecoder = $window.TextDecoder;
$requestAnimationFrame = $window.requestAnimationFrame;
$cancelAnimationFrame = $window.cancelAnimationFrame;
}
Expand All @@ -43,6 +45,7 @@ class Platform {
$window = null;
$document = null;
$DOMParser = null;
$TextDecoder = null;
$XMLHttpRequest = null;
$OffscreenCanvas = null;
$HTMLCanvasElement = null;
Expand All @@ -61,6 +64,7 @@ export {
PLATFORM,
$document,
$DOMParser,
$TextDecoder,
$XMLHttpRequest,
$OffscreenCanvas,
$HTMLCanvasElement,
Expand Down
2 changes: 2 additions & 0 deletions src/WechatPlatform/index.js
Expand Up @@ -6,6 +6,7 @@ import XMLHttpRequest from './XMLHttpRequest';
import copyProperties from '../libs/copyProperties';
// import { DOMParser } from 'xmldom';
import { $DOMParser as DOMParser } from '../libs/DOMParser';
import { $TextDecoder as TextDecoder } from '../libs/TextDecoder';

function OffscreenCanvas() {
return wx.createOffscreenCanvas();
Expand Down Expand Up @@ -41,6 +42,7 @@ export class WechatPlatform {
},
},
DOMParser,
TextDecoder,
};

[this.canvas, this.document, this.window].forEach(i => {
Expand Down
10 changes: 10 additions & 0 deletions src/libs/TextDecoder.js
@@ -0,0 +1,10 @@
export class $TextDecoder {
/**
* 不支持 UTF-8 code points 大于 1 字节
* @see https://stackoverflow.com/questions/17191945/conversion-between-utf-8-arraybuffer-and-string
* @param {Uint8Array} uint8Array
*/
decode(uint8Array) {
return String.fromCharCode.apply(null, uint8Array);
}
}

0 comments on commit 25ff7c7

Please sign in to comment.