@renderlayer/textures 0.0.12 → 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/dist/textures.esm-bundler.js +123 -53
- package/package.json +7 -5
|
@@ -1,15 +1,21 @@
|
|
|
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
21
|
if (value === true) this.version++;
|
|
@@ -19,10 +25,7 @@ class Source {
|
|
|
19
25
|
if (!isRootObject && meta.images[this.uuid] !== void 0) {
|
|
20
26
|
return meta.images[this.uuid];
|
|
21
27
|
}
|
|
22
|
-
const output = {
|
|
23
|
-
uuid: this.uuid,
|
|
24
|
-
url: ""
|
|
25
|
-
};
|
|
28
|
+
const output = { uuid: this.uuid, url: "" };
|
|
26
29
|
const data = this.data;
|
|
27
30
|
if (data !== null) {
|
|
28
31
|
let url;
|
|
@@ -30,13 +33,13 @@ class Source {
|
|
|
30
33
|
url = [];
|
|
31
34
|
for (let i = 0, l = data.length; i < l; i++) {
|
|
32
35
|
if (data[i].isDataTexture) {
|
|
33
|
-
url.push(
|
|
36
|
+
url.push(_serializeImage(data[i].image));
|
|
34
37
|
} else {
|
|
35
|
-
url.push(
|
|
38
|
+
url.push(_serializeImage(data[i]));
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
} else {
|
|
39
|
-
url =
|
|
42
|
+
url = _serializeImage(data);
|
|
40
43
|
}
|
|
41
44
|
output.url = url;
|
|
42
45
|
}
|
|
@@ -46,7 +49,8 @@ class Source {
|
|
|
46
49
|
return output;
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
let _sourceId = 0;
|
|
53
|
+
function _serializeImage(image) {
|
|
50
54
|
if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
51
55
|
return ImageUtils.getDataURL(image);
|
|
52
56
|
} else {
|
|
@@ -64,42 +68,63 @@ function serializeImage(image) {
|
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
let _textureId = 0;
|
|
68
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;
|
|
69
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) {
|
|
70
111
|
super();
|
|
71
|
-
Object.defineProperty(this, "id", { value: _textureId++ });
|
|
72
|
-
this.uuid = generateUUID();
|
|
73
|
-
this.isTexture = true;
|
|
74
|
-
this.name = "";
|
|
75
112
|
this.source = new Source(image);
|
|
76
|
-
this.mipmaps = [];
|
|
77
113
|
this.mapping = mapping;
|
|
78
|
-
this.channel = 0;
|
|
79
114
|
this.wrapS = wrapS;
|
|
80
115
|
this.wrapT = wrapT;
|
|
81
116
|
this.magFilter = magFilter;
|
|
82
117
|
this.minFilter = minFilter;
|
|
83
118
|
this.anisotropy = anisotropy;
|
|
84
119
|
this.format = format;
|
|
85
|
-
this.internalFormat = null;
|
|
86
120
|
this.type = type;
|
|
87
|
-
this.offset = new Vector2(0, 0);
|
|
88
|
-
this.repeat = new Vector2(1, 1);
|
|
89
|
-
this.center = new Vector2(0, 0);
|
|
90
|
-
this.rotation = 0;
|
|
91
|
-
this.matrixAutoUpdate = true;
|
|
92
|
-
this.matrix = new Matrix3();
|
|
93
|
-
this.generateMipmaps = true;
|
|
94
|
-
this.premultiplyAlpha = false;
|
|
95
|
-
this.flipY = true;
|
|
96
|
-
this.unpackAlignment = 4;
|
|
97
121
|
this.colorSpace = colorSpace;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
122
|
+
}
|
|
123
|
+
get isTexture() {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
get id() {
|
|
127
|
+
return this.#id;
|
|
103
128
|
}
|
|
104
129
|
get image() {
|
|
105
130
|
return this.source.data;
|
|
@@ -107,6 +132,12 @@ class Texture extends EventDispatcher {
|
|
|
107
132
|
set image(value) {
|
|
108
133
|
this.source.data = value ? value : null;
|
|
109
134
|
}
|
|
135
|
+
set needsUpdate(value) {
|
|
136
|
+
if (value === true) {
|
|
137
|
+
this.version++;
|
|
138
|
+
this.source.needsUpdate = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
110
141
|
updateMatrix() {
|
|
111
142
|
this.matrix.setUvTransform(
|
|
112
143
|
this.offset.x,
|
|
@@ -237,16 +268,45 @@ class Texture extends EventDispatcher {
|
|
|
237
268
|
}
|
|
238
269
|
return uv;
|
|
239
270
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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;
|
|
245
308
|
}
|
|
246
309
|
}
|
|
247
|
-
Texture.DEFAULT_IMAGE = null;
|
|
248
|
-
Texture.DEFAULT_MAPPING = UVMapping;
|
|
249
|
-
Texture.DEFAULT_ANISOTROPY = 1;
|
|
250
310
|
|
|
251
311
|
class CubeTexture extends Texture {
|
|
252
312
|
constructor(images = [], mapping = CubeReflectionMapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
|
|
@@ -262,9 +322,11 @@ class CubeTexture extends Texture {
|
|
|
262
322
|
anisotropy,
|
|
263
323
|
colorSpace
|
|
264
324
|
);
|
|
265
|
-
this.isCubeTexture = true;
|
|
266
325
|
this.flipY = false;
|
|
267
326
|
}
|
|
327
|
+
get isCubeTexture() {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
268
330
|
get images() {
|
|
269
331
|
return this.image;
|
|
270
332
|
}
|
|
@@ -274,48 +336,53 @@ class CubeTexture extends Texture {
|
|
|
274
336
|
}
|
|
275
337
|
|
|
276
338
|
class Data3DTexture extends Texture {
|
|
339
|
+
wrapR = ClampToEdgeWrapping;
|
|
277
340
|
constructor(data = null, width = 1, height = 1, depth = 1) {
|
|
278
341
|
super(null);
|
|
279
|
-
this.isData3DTexture = true;
|
|
280
342
|
this.image = { data, width, height, depth };
|
|
281
343
|
this.magFilter = NearestFilter;
|
|
282
344
|
this.minFilter = NearestFilter;
|
|
283
|
-
this.wrapR = ClampToEdgeWrapping;
|
|
284
345
|
this.generateMipmaps = false;
|
|
285
346
|
this.flipY = false;
|
|
286
347
|
this.unpackAlignment = 1;
|
|
287
348
|
}
|
|
349
|
+
get isData3DTexture() {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
288
352
|
}
|
|
289
353
|
|
|
290
354
|
class DataArrayTexture extends Texture {
|
|
355
|
+
wrapR = ClampToEdgeWrapping;
|
|
291
356
|
constructor(data = null, width = 1, height = 1, depth = 1) {
|
|
292
357
|
super(null);
|
|
293
|
-
this.isDataArrayTexture = true;
|
|
294
358
|
this.image = { data, width, height, depth };
|
|
295
359
|
this.magFilter = NearestFilter;
|
|
296
360
|
this.minFilter = NearestFilter;
|
|
297
|
-
this.wrapR = ClampToEdgeWrapping;
|
|
298
361
|
this.generateMipmaps = false;
|
|
299
362
|
this.flipY = false;
|
|
300
363
|
this.unpackAlignment = 1;
|
|
301
364
|
}
|
|
365
|
+
get isDataArrayTexture() {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
302
368
|
}
|
|
303
369
|
|
|
304
370
|
class DataTexture extends Texture {
|
|
305
371
|
constructor(data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace) {
|
|
306
372
|
super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
|
|
307
|
-
this.isDataTexture = true;
|
|
308
373
|
this.image = { data, width, height };
|
|
309
374
|
this.generateMipmaps = false;
|
|
310
375
|
this.flipY = false;
|
|
311
376
|
this.unpackAlignment = 1;
|
|
312
377
|
}
|
|
378
|
+
get isDataTexture() {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
313
381
|
}
|
|
314
382
|
|
|
315
383
|
class VideoTexture extends Texture {
|
|
316
384
|
constructor(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
|
|
317
385
|
super(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
318
|
-
this.isVideoTexture = true;
|
|
319
386
|
this.minFilter = minFilter !== void 0 ? minFilter : LinearFilter;
|
|
320
387
|
this.magFilter = magFilter !== void 0 ? magFilter : LinearFilter;
|
|
321
388
|
this.generateMipmaps = false;
|
|
@@ -328,6 +395,9 @@ class VideoTexture extends Texture {
|
|
|
328
395
|
video.requestVideoFrameCallback(updateVideo);
|
|
329
396
|
}
|
|
330
397
|
}
|
|
398
|
+
get isVideoTexture() {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
331
401
|
/** @returns {this} */
|
|
332
402
|
clone() {
|
|
333
403
|
return new this.constructor(this.image).copy(this);
|
|
@@ -341,4 +411,4 @@ class VideoTexture extends Texture {
|
|
|
341
411
|
}
|
|
342
412
|
}
|
|
343
413
|
|
|
344
|
-
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
|
}
|