@renderlayer/textures 0.0.11 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/textures.esm-bundler.js +126 -59
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# @renderlayer/textures
|
|
2
2
|
|
|
3
|
+
Texture abstractions used by `@renderlayer` packages.
|
|
4
|
+
|
|
3
5
|
[![NPM version][npm-badge]][npm-url]
|
|
6
|
+
[![License][license-badge]][license-url]
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i @renderlayer/textures
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
This package is released under the [MIT License][license-url]
|
|
4
17
|
|
|
5
18
|
[npm-badge]: https://img.shields.io/npm/v/@renderlayer/textures
|
|
6
19
|
[npm-url]: https://www.npmjs.com/package/@renderlayer/textures
|
|
20
|
+
[license-badge]: https://img.shields.io/npm/l/renderlayer.svg?cacheSeconds=2592000
|
|
21
|
+
[license-url]: https://github.com/epreston/renderlayer/blob/main/LICENSE
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import { ImageUtils, ClampToEdgeWrapping, LinearFilter, LinearMipmapLinearFilter, RGBAFormat, UnsignedByteType, NoColorSpace,
|
|
1
|
+
import { ImageUtils, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipmapLinearFilter, RGBAFormat, UnsignedByteType, NoColorSpace, MirroredRepeatWrapping, RepeatWrapping, CubeReflectionMapping, NearestFilter } from '@renderlayer/shared';
|
|
2
2
|
import { EventDispatcher } from '@renderlayer/core';
|
|
3
3
|
import { generateUUID, Vector2, Matrix3 } from '@renderlayer/math';
|
|
4
4
|
|
|
5
|
-
let _sourceId = 0;
|
|
6
5
|
class Source {
|
|
6
|
+
#id = _sourceId++;
|
|
7
|
+
uuid = generateUUID();
|
|
8
|
+
data;
|
|
9
|
+
// obj or array
|
|
10
|
+
version = 0;
|
|
7
11
|
constructor(data = null) {
|
|
8
|
-
this.isSource = true;
|
|
9
|
-
Object.defineProperty(this, "id", { value: _sourceId++ });
|
|
10
|
-
this.uuid = generateUUID();
|
|
11
12
|
this.data = data;
|
|
12
|
-
|
|
13
|
+
}
|
|
14
|
+
get isSource() {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
get id() {
|
|
18
|
+
return this.#id;
|
|
13
19
|
}
|
|
14
20
|
set needsUpdate(value) {
|
|
15
|
-
if (value === true)
|
|
16
|
-
this.version++;
|
|
21
|
+
if (value === true) this.version++;
|
|
17
22
|
}
|
|
18
23
|
toJSON(meta) {
|
|
19
24
|
const isRootObject = meta === void 0 || typeof meta === "string";
|
|
20
25
|
if (!isRootObject && meta.images[this.uuid] !== void 0) {
|
|
21
26
|
return meta.images[this.uuid];
|
|
22
27
|
}
|
|
23
|
-
const output = {
|
|
24
|
-
uuid: this.uuid,
|
|
25
|
-
url: ""
|
|
26
|
-
};
|
|
28
|
+
const output = { uuid: this.uuid, url: "" };
|
|
27
29
|
const data = this.data;
|
|
28
30
|
if (data !== null) {
|
|
29
31
|
let url;
|
|
@@ -31,13 +33,13 @@ class Source {
|
|
|
31
33
|
url = [];
|
|
32
34
|
for (let i = 0, l = data.length; i < l; i++) {
|
|
33
35
|
if (data[i].isDataTexture) {
|
|
34
|
-
url.push(
|
|
36
|
+
url.push(_serializeImage(data[i].image));
|
|
35
37
|
} else {
|
|
36
|
-
url.push(
|
|
38
|
+
url.push(_serializeImage(data[i]));
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
} else {
|
|
40
|
-
url =
|
|
42
|
+
url = _serializeImage(data);
|
|
41
43
|
}
|
|
42
44
|
output.url = url;
|
|
43
45
|
}
|
|
@@ -47,7 +49,8 @@ class Source {
|
|
|
47
49
|
return output;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
let _sourceId = 0;
|
|
53
|
+
function _serializeImage(image) {
|
|
51
54
|
if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
52
55
|
return ImageUtils.getDataURL(image);
|
|
53
56
|
} else {
|
|
@@ -65,42 +68,63 @@ function serializeImage(image) {
|
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
let _textureId = 0;
|
|
69
71
|
class Texture extends EventDispatcher {
|
|
72
|
+
static DEFAULT_IMAGE = null;
|
|
73
|
+
static DEFAULT_MAPPING = UVMapping;
|
|
74
|
+
static DEFAULT_ANISOTROPY = 1;
|
|
75
|
+
#id = _textureId++;
|
|
76
|
+
uuid = generateUUID();
|
|
77
|
+
name = "";
|
|
78
|
+
source;
|
|
79
|
+
mipmaps = [];
|
|
80
|
+
mapping = Texture.DEFAULT_MAPPING;
|
|
81
|
+
channel = 0;
|
|
82
|
+
wrapS = ClampToEdgeWrapping;
|
|
83
|
+
wrapT = ClampToEdgeWrapping;
|
|
84
|
+
magFilter = LinearFilter;
|
|
85
|
+
minFilter = LinearMipmapLinearFilter;
|
|
86
|
+
anisotropy = Texture.DEFAULT_ANISOTROPY;
|
|
87
|
+
format = RGBAFormat;
|
|
88
|
+
internalFormat = null;
|
|
89
|
+
type = UnsignedByteType;
|
|
90
|
+
offset = new Vector2(0, 0);
|
|
91
|
+
repeat = new Vector2(1, 1);
|
|
92
|
+
center = new Vector2(0, 0);
|
|
93
|
+
rotation = 0;
|
|
94
|
+
matrixAutoUpdate = true;
|
|
95
|
+
matrix = new Matrix3();
|
|
96
|
+
generateMipmaps = true;
|
|
97
|
+
premultiplyAlpha = false;
|
|
98
|
+
flipY = true;
|
|
99
|
+
// valid values: 1, 2, 4, 8
|
|
100
|
+
// see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml
|
|
101
|
+
unpackAlignment = 4;
|
|
102
|
+
colorSpace = NoColorSpace;
|
|
103
|
+
userData = {};
|
|
104
|
+
version = 0;
|
|
105
|
+
onUpdate = null;
|
|
106
|
+
isRenderTargetTexture = false;
|
|
107
|
+
// indicates whether this texture should be processed by
|
|
108
|
+
// PMREMGenerator or not (only relevant for render target textures)
|
|
109
|
+
needsPMREMUpdate = false;
|
|
70
110
|
constructor(image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace) {
|
|
71
111
|
super();
|
|
72
|
-
Object.defineProperty(this, "id", { value: _textureId++ });
|
|
73
|
-
this.uuid = generateUUID();
|
|
74
|
-
this.isTexture = true;
|
|
75
|
-
this.name = "";
|
|
76
112
|
this.source = new Source(image);
|
|
77
|
-
this.mipmaps = [];
|
|
78
113
|
this.mapping = mapping;
|
|
79
|
-
this.channel = 0;
|
|
80
114
|
this.wrapS = wrapS;
|
|
81
115
|
this.wrapT = wrapT;
|
|
82
116
|
this.magFilter = magFilter;
|
|
83
117
|
this.minFilter = minFilter;
|
|
84
118
|
this.anisotropy = anisotropy;
|
|
85
119
|
this.format = format;
|
|
86
|
-
this.internalFormat = null;
|
|
87
120
|
this.type = type;
|
|
88
|
-
this.offset = new Vector2(0, 0);
|
|
89
|
-
this.repeat = new Vector2(1, 1);
|
|
90
|
-
this.center = new Vector2(0, 0);
|
|
91
|
-
this.rotation = 0;
|
|
92
|
-
this.matrixAutoUpdate = true;
|
|
93
|
-
this.matrix = new Matrix3();
|
|
94
|
-
this.generateMipmaps = true;
|
|
95
|
-
this.premultiplyAlpha = false;
|
|
96
|
-
this.flipY = true;
|
|
97
|
-
this.unpackAlignment = 4;
|
|
98
121
|
this.colorSpace = colorSpace;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
}
|
|
123
|
+
get isTexture() {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
get id() {
|
|
127
|
+
return this.#id;
|
|
104
128
|
}
|
|
105
129
|
get image() {
|
|
106
130
|
return this.source.data;
|
|
@@ -108,6 +132,12 @@ class Texture extends EventDispatcher {
|
|
|
108
132
|
set image(value) {
|
|
109
133
|
this.source.data = value ? value : null;
|
|
110
134
|
}
|
|
135
|
+
set needsUpdate(value) {
|
|
136
|
+
if (value === true) {
|
|
137
|
+
this.version++;
|
|
138
|
+
this.source.needsUpdate = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
111
141
|
updateMatrix() {
|
|
112
142
|
this.matrix.setUvTransform(
|
|
113
143
|
this.offset.x,
|
|
@@ -186,8 +216,7 @@ class Texture extends EventDispatcher {
|
|
|
186
216
|
premultiplyAlpha: this.premultiplyAlpha,
|
|
187
217
|
unpackAlignment: this.unpackAlignment
|
|
188
218
|
};
|
|
189
|
-
if (Object.keys(this.userData).length > 0)
|
|
190
|
-
output.userData = this.userData;
|
|
219
|
+
if (Object.keys(this.userData).length > 0) output.userData = this.userData;
|
|
191
220
|
if (!isRootObject) {
|
|
192
221
|
meta.textures[this.uuid] = output;
|
|
193
222
|
}
|
|
@@ -198,8 +227,7 @@ class Texture extends EventDispatcher {
|
|
|
198
227
|
}
|
|
199
228
|
/** @param {Vector2} uv */
|
|
200
229
|
transformUv(uv) {
|
|
201
|
-
if (this.mapping !== UVMapping)
|
|
202
|
-
return uv;
|
|
230
|
+
if (this.mapping !== UVMapping) return uv;
|
|
203
231
|
uv.applyMatrix3(this.matrix);
|
|
204
232
|
if (uv.x < 0 || uv.x > 1) {
|
|
205
233
|
switch (this.wrapS) {
|
|
@@ -240,16 +268,45 @@ class Texture extends EventDispatcher {
|
|
|
240
268
|
}
|
|
241
269
|
return uv;
|
|
242
270
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
271
|
+
}
|
|
272
|
+
let _textureId = 0;
|
|
273
|
+
|
|
274
|
+
class CompressedTexture extends Texture {
|
|
275
|
+
constructor(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace) {
|
|
276
|
+
super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
|
|
277
|
+
this.image = { width, height };
|
|
278
|
+
this.mipmaps = mipmaps;
|
|
279
|
+
this.flipY = false;
|
|
280
|
+
this.generateMipmaps = false;
|
|
281
|
+
}
|
|
282
|
+
get isCompressedTexture() {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
class CompressedArrayTexture extends CompressedTexture {
|
|
288
|
+
wrapR = ClampToEdgeWrapping;
|
|
289
|
+
constructor(mipmaps, width, height, depth, format, type) {
|
|
290
|
+
super(mipmaps, width, height, format, type);
|
|
291
|
+
this.image.depth = depth;
|
|
292
|
+
}
|
|
293
|
+
get isCompressedArrayTexture() {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
class CompressedCubeTexture extends CompressedTexture {
|
|
299
|
+
constructor(images, format, type) {
|
|
300
|
+
super(void 0, images[0].width, images[0].height, format, type, CubeReflectionMapping);
|
|
301
|
+
this.image = images;
|
|
302
|
+
}
|
|
303
|
+
get isCompressedCubeTexture() {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
get isCubeTexture() {
|
|
307
|
+
return true;
|
|
248
308
|
}
|
|
249
309
|
}
|
|
250
|
-
Texture.DEFAULT_IMAGE = null;
|
|
251
|
-
Texture.DEFAULT_MAPPING = UVMapping;
|
|
252
|
-
Texture.DEFAULT_ANISOTROPY = 1;
|
|
253
310
|
|
|
254
311
|
class CubeTexture extends Texture {
|
|
255
312
|
constructor(images = [], mapping = CubeReflectionMapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
|
|
@@ -265,9 +322,11 @@ class CubeTexture extends Texture {
|
|
|
265
322
|
anisotropy,
|
|
266
323
|
colorSpace
|
|
267
324
|
);
|
|
268
|
-
this.isCubeTexture = true;
|
|
269
325
|
this.flipY = false;
|
|
270
326
|
}
|
|
327
|
+
get isCubeTexture() {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
271
330
|
get images() {
|
|
272
331
|
return this.image;
|
|
273
332
|
}
|
|
@@ -277,48 +336,53 @@ class CubeTexture extends Texture {
|
|
|
277
336
|
}
|
|
278
337
|
|
|
279
338
|
class Data3DTexture extends Texture {
|
|
339
|
+
wrapR = ClampToEdgeWrapping;
|
|
280
340
|
constructor(data = null, width = 1, height = 1, depth = 1) {
|
|
281
341
|
super(null);
|
|
282
|
-
this.isData3DTexture = true;
|
|
283
342
|
this.image = { data, width, height, depth };
|
|
284
343
|
this.magFilter = NearestFilter;
|
|
285
344
|
this.minFilter = NearestFilter;
|
|
286
|
-
this.wrapR = ClampToEdgeWrapping;
|
|
287
345
|
this.generateMipmaps = false;
|
|
288
346
|
this.flipY = false;
|
|
289
347
|
this.unpackAlignment = 1;
|
|
290
348
|
}
|
|
349
|
+
get isData3DTexture() {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
291
352
|
}
|
|
292
353
|
|
|
293
354
|
class DataArrayTexture extends Texture {
|
|
355
|
+
wrapR = ClampToEdgeWrapping;
|
|
294
356
|
constructor(data = null, width = 1, height = 1, depth = 1) {
|
|
295
357
|
super(null);
|
|
296
|
-
this.isDataArrayTexture = true;
|
|
297
358
|
this.image = { data, width, height, depth };
|
|
298
359
|
this.magFilter = NearestFilter;
|
|
299
360
|
this.minFilter = NearestFilter;
|
|
300
|
-
this.wrapR = ClampToEdgeWrapping;
|
|
301
361
|
this.generateMipmaps = false;
|
|
302
362
|
this.flipY = false;
|
|
303
363
|
this.unpackAlignment = 1;
|
|
304
364
|
}
|
|
365
|
+
get isDataArrayTexture() {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
305
368
|
}
|
|
306
369
|
|
|
307
370
|
class DataTexture extends Texture {
|
|
308
371
|
constructor(data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace) {
|
|
309
372
|
super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
|
|
310
|
-
this.isDataTexture = true;
|
|
311
373
|
this.image = { data, width, height };
|
|
312
374
|
this.generateMipmaps = false;
|
|
313
375
|
this.flipY = false;
|
|
314
376
|
this.unpackAlignment = 1;
|
|
315
377
|
}
|
|
378
|
+
get isDataTexture() {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
316
381
|
}
|
|
317
382
|
|
|
318
383
|
class VideoTexture extends Texture {
|
|
319
384
|
constructor(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
|
|
320
385
|
super(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
321
|
-
this.isVideoTexture = true;
|
|
322
386
|
this.minFilter = minFilter !== void 0 ? minFilter : LinearFilter;
|
|
323
387
|
this.magFilter = magFilter !== void 0 ? magFilter : LinearFilter;
|
|
324
388
|
this.generateMipmaps = false;
|
|
@@ -331,6 +395,9 @@ class VideoTexture extends Texture {
|
|
|
331
395
|
video.requestVideoFrameCallback(updateVideo);
|
|
332
396
|
}
|
|
333
397
|
}
|
|
398
|
+
get isVideoTexture() {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
334
401
|
/** @returns {this} */
|
|
335
402
|
clone() {
|
|
336
403
|
return new this.constructor(this.image).copy(this);
|
|
@@ -344,4 +411,4 @@ class VideoTexture extends Texture {
|
|
|
344
411
|
}
|
|
345
412
|
}
|
|
346
413
|
|
|
347
|
-
export { CubeTexture, Data3DTexture, DataArrayTexture, DataTexture, Source, Texture, VideoTexture };
|
|
414
|
+
export { CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CubeTexture, Data3DTexture, DataArrayTexture, DataTexture, Source, Texture, VideoTexture };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@renderlayer/textures",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.14",
|
|
5
5
|
"description": "@renderlayer/textures",
|
|
6
6
|
"module": "./dist/textures.esm-bundler.js",
|
|
7
7
|
"exports": "./dist/textures.esm-bundler.js",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"directory": "packages/textures"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
|
-
"renderlayer",
|
|
23
|
+
"renderlayer",
|
|
24
|
+
"textures",
|
|
25
|
+
"cube"
|
|
24
26
|
],
|
|
25
27
|
"author": "Ed Preston",
|
|
26
28
|
"license": "MIT",
|
|
@@ -29,8 +31,8 @@
|
|
|
29
31
|
},
|
|
30
32
|
"homepage": "https://github.com/epreston/renderlayer/blob/main/packages/textures#readme",
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@renderlayer/core": "~0.0.
|
|
33
|
-
"@renderlayer/math": "~0.0.
|
|
34
|
-
"@renderlayer/shared": "~0.0.
|
|
34
|
+
"@renderlayer/core": "~0.0.9",
|
|
35
|
+
"@renderlayer/math": "~0.0.15",
|
|
36
|
+
"@renderlayer/shared": "~0.0.9"
|
|
35
37
|
}
|
|
36
38
|
}
|