|
|
@@ -74,77 +74,108 @@ class DataTextureLoader extends Loader {
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( texData.image !== undefined ) {
|
|
|
+ scope._applyTexData( texture, texData );
|
|
|
|
|
|
- texture.image = texData.image;
|
|
|
+ if ( onLoad ) onLoad( texture, texData );
|
|
|
|
|
|
- } else if ( texData.data !== undefined ) {
|
|
|
+ }, onProgress, onError );
|
|
|
|
|
|
- texture.image.width = texData.width;
|
|
|
- texture.image.height = texData.height;
|
|
|
- texture.image.data = texData.data;
|
|
|
|
|
|
- }
|
|
|
+ return texture;
|
|
|
|
|
|
- texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
|
|
|
- texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
|
|
|
+ }
|
|
|
|
|
|
- texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
|
|
|
- texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
|
|
|
+ /**
|
|
|
+ * Parses the given buffer and returns a configured data texture. Use this method
|
|
|
+ * for parsing texture data that is already in memory (e.g. drag and drop or data
|
|
|
+ * loaded from a server) without going through {@link DataTextureLoader#load}.
|
|
|
+ *
|
|
|
+ * @param {ArrayBuffer} buffer - The raw texture data.
|
|
|
+ * @return {DataTexture} The data texture.
|
|
|
+ */
|
|
|
+ createDataTexture( buffer ) {
|
|
|
|
|
|
- texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
|
|
|
+ const texture = new DataTexture();
|
|
|
|
|
|
- if ( texData.colorSpace !== undefined ) {
|
|
|
+ this._applyTexData( texture, this.parse( buffer ) );
|
|
|
|
|
|
- texture.colorSpace = texData.colorSpace;
|
|
|
+ return texture;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( texData.flipY !== undefined ) {
|
|
|
+ /**
|
|
|
+ * Applies the given parsed texture data to the given data texture.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {DataTexture} texture - The data texture.
|
|
|
+ * @param {DataTextureLoader~TexData} texData - The parsed texture data.
|
|
|
+ */
|
|
|
+ _applyTexData( texture, texData ) {
|
|
|
|
|
|
- texture.flipY = texData.flipY;
|
|
|
+ if ( texData.image !== undefined ) {
|
|
|
|
|
|
- }
|
|
|
+ texture.image = texData.image;
|
|
|
|
|
|
- if ( texData.format !== undefined ) {
|
|
|
+ } else if ( texData.data !== undefined ) {
|
|
|
|
|
|
- texture.format = texData.format;
|
|
|
+ texture.image.width = texData.width;
|
|
|
+ texture.image.height = texData.height;
|
|
|
+ texture.image.data = texData.data;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( texData.type !== undefined ) {
|
|
|
+ texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
|
|
|
+ texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
|
|
|
|
|
|
- texture.type = texData.type;
|
|
|
+ texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
|
|
|
+ texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
|
|
|
|
|
|
- }
|
|
|
+ texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
|
|
|
|
|
|
- if ( texData.mipmaps !== undefined ) {
|
|
|
+ if ( texData.colorSpace !== undefined ) {
|
|
|
|
|
|
- texture.mipmaps = texData.mipmaps;
|
|
|
- texture.minFilter = LinearMipmapLinearFilter; // presumably...
|
|
|
+ texture.colorSpace = texData.colorSpace;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( texData.mipmapCount === 1 ) {
|
|
|
+ if ( texData.flipY !== undefined ) {
|
|
|
|
|
|
- texture.minFilter = LinearFilter;
|
|
|
+ texture.flipY = texData.flipY;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( texData.generateMipmaps !== undefined ) {
|
|
|
+ if ( texData.format !== undefined ) {
|
|
|
|
|
|
- texture.generateMipmaps = texData.generateMipmaps;
|
|
|
+ texture.format = texData.format;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- texture.needsUpdate = true;
|
|
|
+ if ( texData.type !== undefined ) {
|
|
|
|
|
|
- if ( onLoad ) onLoad( texture, texData );
|
|
|
+ texture.type = texData.type;
|
|
|
|
|
|
- }, onProgress, onError );
|
|
|
+ }
|
|
|
|
|
|
+ if ( texData.mipmaps !== undefined ) {
|
|
|
|
|
|
- return texture;
|
|
|
+ texture.mipmaps = texData.mipmaps;
|
|
|
+ texture.minFilter = LinearMipmapLinearFilter; // presumably...
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( texData.mipmapCount === 1 ) {
|
|
|
+
|
|
|
+ texture.minFilter = LinearFilter;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( texData.generateMipmaps !== undefined ) {
|
|
|
+
|
|
|
+ texture.generateMipmaps = texData.generateMipmaps;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ texture.needsUpdate = true;
|
|
|
|
|
|
}
|
|
|
|