@renderlayer/textures 0.0.8 → 0.0.12
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 +55 -17
- package/package.json +6 -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
|
|
@@ -2,18 +2,17 @@ import { ImageUtils, ClampToEdgeWrapping, LinearFilter, LinearMipmapLinearFilter
|
|
|
2
2
|
import { EventDispatcher } from '@renderlayer/core';
|
|
3
3
|
import { generateUUID, Vector2, Matrix3 } from '@renderlayer/math';
|
|
4
4
|
|
|
5
|
-
let
|
|
5
|
+
let _sourceId = 0;
|
|
6
6
|
class Source {
|
|
7
7
|
constructor(data = null) {
|
|
8
8
|
this.isSource = true;
|
|
9
|
-
Object.defineProperty(this, "id", { value:
|
|
9
|
+
Object.defineProperty(this, "id", { value: _sourceId++ });
|
|
10
10
|
this.uuid = generateUUID();
|
|
11
11
|
this.data = data;
|
|
12
12
|
this.version = 0;
|
|
13
13
|
}
|
|
14
14
|
set needsUpdate(value) {
|
|
15
|
-
if (value === true)
|
|
16
|
-
this.version++;
|
|
15
|
+
if (value === true) this.version++;
|
|
17
16
|
}
|
|
18
17
|
toJSON(meta) {
|
|
19
18
|
const isRootObject = meta === void 0 || typeof meta === "string";
|
|
@@ -65,11 +64,11 @@ function serializeImage(image) {
|
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
let
|
|
67
|
+
let _textureId = 0;
|
|
69
68
|
class Texture extends EventDispatcher {
|
|
70
69
|
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
70
|
super();
|
|
72
|
-
Object.defineProperty(this, "id", { value:
|
|
71
|
+
Object.defineProperty(this, "id", { value: _textureId++ });
|
|
73
72
|
this.uuid = generateUUID();
|
|
74
73
|
this.isTexture = true;
|
|
75
74
|
this.name = "";
|
|
@@ -105,8 +104,8 @@ class Texture extends EventDispatcher {
|
|
|
105
104
|
get image() {
|
|
106
105
|
return this.source.data;
|
|
107
106
|
}
|
|
108
|
-
set image(value
|
|
109
|
-
this.source.data = value;
|
|
107
|
+
set image(value) {
|
|
108
|
+
this.source.data = value ? value : null;
|
|
110
109
|
}
|
|
111
110
|
updateMatrix() {
|
|
112
111
|
this.matrix.setUvTransform(
|
|
@@ -119,9 +118,11 @@ class Texture extends EventDispatcher {
|
|
|
119
118
|
this.center.y
|
|
120
119
|
);
|
|
121
120
|
}
|
|
121
|
+
/** @returns {this} */
|
|
122
122
|
clone() {
|
|
123
123
|
return new this.constructor().copy(this);
|
|
124
124
|
}
|
|
125
|
+
/** @param {Texture} source */
|
|
125
126
|
copy(source) {
|
|
126
127
|
this.name = source.name;
|
|
127
128
|
this.source = source.source;
|
|
@@ -184,8 +185,7 @@ class Texture extends EventDispatcher {
|
|
|
184
185
|
premultiplyAlpha: this.premultiplyAlpha,
|
|
185
186
|
unpackAlignment: this.unpackAlignment
|
|
186
187
|
};
|
|
187
|
-
if (Object.keys(this.userData).length > 0)
|
|
188
|
-
output.userData = this.userData;
|
|
188
|
+
if (Object.keys(this.userData).length > 0) output.userData = this.userData;
|
|
189
189
|
if (!isRootObject) {
|
|
190
190
|
meta.textures[this.uuid] = output;
|
|
191
191
|
}
|
|
@@ -194,9 +194,9 @@ class Texture extends EventDispatcher {
|
|
|
194
194
|
dispose() {
|
|
195
195
|
this.dispatchEvent({ type: "dispose" });
|
|
196
196
|
}
|
|
197
|
+
/** @param {Vector2} uv */
|
|
197
198
|
transformUv(uv) {
|
|
198
|
-
if (this.mapping !== UVMapping)
|
|
199
|
-
return uv;
|
|
199
|
+
if (this.mapping !== UVMapping) return uv;
|
|
200
200
|
uv.applyMatrix3(this.matrix);
|
|
201
201
|
if (uv.x < 0 || uv.x > 1) {
|
|
202
202
|
switch (this.wrapS) {
|
|
@@ -249,10 +249,19 @@ Texture.DEFAULT_MAPPING = UVMapping;
|
|
|
249
249
|
Texture.DEFAULT_ANISOTROPY = 1;
|
|
250
250
|
|
|
251
251
|
class CubeTexture extends Texture {
|
|
252
|
-
constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
252
|
+
constructor(images = [], mapping = CubeReflectionMapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
|
|
253
|
+
super(
|
|
254
|
+
images,
|
|
255
|
+
mapping,
|
|
256
|
+
wrapS,
|
|
257
|
+
wrapT,
|
|
258
|
+
magFilter,
|
|
259
|
+
minFilter,
|
|
260
|
+
format,
|
|
261
|
+
type,
|
|
262
|
+
anisotropy,
|
|
263
|
+
colorSpace
|
|
264
|
+
);
|
|
256
265
|
this.isCubeTexture = true;
|
|
257
266
|
this.flipY = false;
|
|
258
267
|
}
|
|
@@ -303,4 +312,33 @@ class DataTexture extends Texture {
|
|
|
303
312
|
}
|
|
304
313
|
}
|
|
305
314
|
|
|
306
|
-
|
|
315
|
+
class VideoTexture extends Texture {
|
|
316
|
+
constructor(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
|
|
317
|
+
super(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
|
|
318
|
+
this.isVideoTexture = true;
|
|
319
|
+
this.minFilter = minFilter !== void 0 ? minFilter : LinearFilter;
|
|
320
|
+
this.magFilter = magFilter !== void 0 ? magFilter : LinearFilter;
|
|
321
|
+
this.generateMipmaps = false;
|
|
322
|
+
const scope = this;
|
|
323
|
+
function updateVideo() {
|
|
324
|
+
scope.needsUpdate = true;
|
|
325
|
+
video.requestVideoFrameCallback(updateVideo);
|
|
326
|
+
}
|
|
327
|
+
if ("requestVideoFrameCallback" in video) {
|
|
328
|
+
video.requestVideoFrameCallback(updateVideo);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/** @returns {this} */
|
|
332
|
+
clone() {
|
|
333
|
+
return new this.constructor(this.image).copy(this);
|
|
334
|
+
}
|
|
335
|
+
update() {
|
|
336
|
+
const video = this.image;
|
|
337
|
+
const hasVideoFrameCallback = "requestVideoFrameCallback" in video;
|
|
338
|
+
if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
|
|
339
|
+
this.needsUpdate = true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export { CubeTexture, Data3DTexture, DataArrayTexture, DataTexture, Source, Texture, VideoTexture };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "@renderlayer/textures",
|
|
3
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
4
5
|
"description": "@renderlayer/textures",
|
|
5
|
-
"type": "module",
|
|
6
6
|
"module": "./dist/textures.esm-bundler.js",
|
|
7
7
|
"exports": "./dist/textures.esm-bundler.js",
|
|
8
8
|
"files": [
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"keywords": [
|
|
23
23
|
"renderlayer", "textures", "cube"
|
|
24
24
|
],
|
|
25
|
+
"author": "Ed Preston",
|
|
25
26
|
"license": "MIT",
|
|
26
27
|
"bugs": {
|
|
27
28
|
"url": "https://github.com/epreston/renderlayer/issues"
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/epreston/renderlayer/blob/main/packages/textures#readme",
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@renderlayer/
|
|
32
|
-
"@renderlayer/
|
|
33
|
-
"@renderlayer/shared": "~0.0.
|
|
32
|
+
"@renderlayer/core": "~0.0.8",
|
|
33
|
+
"@renderlayer/math": "~0.0.14",
|
|
34
|
+
"@renderlayer/shared": "~0.0.8"
|
|
34
35
|
}
|
|
35
36
|
}
|