@renderlayer/textures 0.0.8 → 0.0.11

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.
@@ -2,11 +2,11 @@ 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 sourceid = 0;
5
+ let _sourceId = 0;
6
6
  class Source {
7
7
  constructor(data = null) {
8
8
  this.isSource = true;
9
- Object.defineProperty(this, "id", { value: sourceid++ });
9
+ Object.defineProperty(this, "id", { value: _sourceId++ });
10
10
  this.uuid = generateUUID();
11
11
  this.data = data;
12
12
  this.version = 0;
@@ -65,11 +65,11 @@ function serializeImage(image) {
65
65
  }
66
66
  }
67
67
 
68
- let textureId = 0;
68
+ let _textureId = 0;
69
69
  class Texture extends EventDispatcher {
70
70
  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
71
  super();
72
- Object.defineProperty(this, "id", { value: textureId++ });
72
+ Object.defineProperty(this, "id", { value: _textureId++ });
73
73
  this.uuid = generateUUID();
74
74
  this.isTexture = true;
75
75
  this.name = "";
@@ -105,8 +105,8 @@ class Texture extends EventDispatcher {
105
105
  get image() {
106
106
  return this.source.data;
107
107
  }
108
- set image(value = null) {
109
- this.source.data = value;
108
+ set image(value) {
109
+ this.source.data = value ? value : null;
110
110
  }
111
111
  updateMatrix() {
112
112
  this.matrix.setUvTransform(
@@ -119,9 +119,11 @@ class Texture extends EventDispatcher {
119
119
  this.center.y
120
120
  );
121
121
  }
122
+ /** @returns {this} */
122
123
  clone() {
123
124
  return new this.constructor().copy(this);
124
125
  }
126
+ /** @param {Texture} source */
125
127
  copy(source) {
126
128
  this.name = source.name;
127
129
  this.source = source.source;
@@ -194,6 +196,7 @@ class Texture extends EventDispatcher {
194
196
  dispose() {
195
197
  this.dispatchEvent({ type: "dispose" });
196
198
  }
199
+ /** @param {Vector2} uv */
197
200
  transformUv(uv) {
198
201
  if (this.mapping !== UVMapping)
199
202
  return uv;
@@ -249,10 +252,19 @@ Texture.DEFAULT_MAPPING = UVMapping;
249
252
  Texture.DEFAULT_ANISOTROPY = 1;
250
253
 
251
254
  class CubeTexture extends Texture {
252
- constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
253
- images = images !== void 0 ? images : [];
254
- mapping = mapping !== void 0 ? mapping : CubeReflectionMapping;
255
- super(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace);
255
+ constructor(images = [], mapping = CubeReflectionMapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace) {
256
+ super(
257
+ images,
258
+ mapping,
259
+ wrapS,
260
+ wrapT,
261
+ magFilter,
262
+ minFilter,
263
+ format,
264
+ type,
265
+ anisotropy,
266
+ colorSpace
267
+ );
256
268
  this.isCubeTexture = true;
257
269
  this.flipY = false;
258
270
  }
@@ -303,4 +315,33 @@ class DataTexture extends Texture {
303
315
  }
304
316
  }
305
317
 
306
- export { CubeTexture, Data3DTexture, DataArrayTexture, DataTexture, Source, Texture };
318
+ class VideoTexture extends Texture {
319
+ constructor(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
320
+ super(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
321
+ this.isVideoTexture = true;
322
+ this.minFilter = minFilter !== void 0 ? minFilter : LinearFilter;
323
+ this.magFilter = magFilter !== void 0 ? magFilter : LinearFilter;
324
+ this.generateMipmaps = false;
325
+ const scope = this;
326
+ function updateVideo() {
327
+ scope.needsUpdate = true;
328
+ video.requestVideoFrameCallback(updateVideo);
329
+ }
330
+ if ("requestVideoFrameCallback" in video) {
331
+ video.requestVideoFrameCallback(updateVideo);
332
+ }
333
+ }
334
+ /** @returns {this} */
335
+ clone() {
336
+ return new this.constructor(this.image).copy(this);
337
+ }
338
+ update() {
339
+ const video = this.image;
340
+ const hasVideoFrameCallback = "requestVideoFrameCallback" in video;
341
+ if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
342
+ this.needsUpdate = true;
343
+ }
344
+ }
345
+ }
346
+
347
+ 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.8",
4
+ "version": "0.0.11",
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/math": "~0.0.5",
32
- "@renderlayer/core": "~0.0.2",
33
- "@renderlayer/shared": "~0.0.2"
32
+ "@renderlayer/core": "~0.0.7",
33
+ "@renderlayer/math": "~0.0.11",
34
+ "@renderlayer/shared": "~0.0.6"
34
35
  }
35
36
  }