@damienmortini/three 0.1.192 → 0.1.195
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/copyExamples.js +6 -6
- package/ecs/THREEView.js +7 -7
- package/examples/loaders/BasisTextureLoader.js +659 -788
- package/examples/loaders/DRACOLoader.js +451 -565
- package/examples/loaders/GLTFLoader.js +3361 -4288
- package/examples/loaders/KTX2Loader.js +675 -790
- package/examples/objects/Lensflare.js +353 -376
- package/examples/utils/BufferGeometryUtils.js +1086 -1345
- package/examples/utils/WorkerPool.js +73 -101
- package/gpgpu/THREEGPGPUSystem.js +55 -55
- package/index.js +1 -1
- package/loader/THREELoader.js +72 -67
- package/loader/meshoptimizerdecoder/THREE.EXT_meshopt_compression.js +23 -22
- package/loader/meshoptimizerdecoder/meshopt_decoder.js +53 -50
- package/material/THREEBaseMaterial.js +3 -3
- package/material/THREEPBRMaterial.js +15 -10
- package/material/THREEShaderMaterial.js +33 -32
- package/object/THREELine.js +36 -36
- package/object/THREEMotionVectorObject.js +74 -71
- package/object/THREERibbon.js +16 -17
- package/object/THREESky.js +59 -58
- package/object/THREESprite.js +42 -43
- package/object/THREESpriteAnimation.js +42 -42
- package/object/THREEText.js +106 -104
- package/package.json +4 -4
- package/renderer/THREERenderer.js +64 -60
- package/renderer/THREEStereoRenderer.js +35 -32
- package/renderer/WebGLRenderTarget2D.js +15 -15
- package/shader/THREEBaseShader.js +1 -1
- package/types/index.d.ts +1 -1
- package/types/renderer/WebGLRenderTarget2D.d.ts +22 -22
package/object/THREESprite.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Color, DoubleSide, LinearFilter, Mesh, Object3D, PlaneGeometry, Texture } from '../../../three/src/Three.js';
|
|
2
|
+
import THREEShaderMaterial from './THREEShaderMaterial.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const CACHED_IMAGES = new Map()
|
|
4
|
+
const CACHED_IMAGES = new Map();
|
|
6
5
|
|
|
7
6
|
export default class Sprite extends Object3D {
|
|
8
7
|
constructor(image, { data, frame, scale = 1 } = {}) {
|
|
9
|
-
super()
|
|
8
|
+
super();
|
|
10
9
|
|
|
11
|
-
this._data = data
|
|
12
|
-
this._image = image
|
|
13
|
-
this._scale = scale
|
|
10
|
+
this._data = data;
|
|
11
|
+
this._image = image;
|
|
12
|
+
this._scale = scale;
|
|
14
13
|
|
|
15
14
|
// Optimise images decoding
|
|
16
|
-
let canvas = CACHED_IMAGES.get(this.image)
|
|
15
|
+
let canvas = CACHED_IMAGES.get(this.image);
|
|
17
16
|
|
|
18
17
|
if (!canvas) {
|
|
19
|
-
canvas = document.createElement('canvas')
|
|
20
|
-
canvas.width = this.image.width
|
|
21
|
-
canvas.height = this.image.height
|
|
22
|
-
const context = canvas.getContext('2d')
|
|
23
|
-
context.drawImage(this.image, 0, 0)
|
|
24
|
-
CACHED_IMAGES.set(this.image, canvas)
|
|
18
|
+
canvas = document.createElement('canvas');
|
|
19
|
+
canvas.width = this.image.width;
|
|
20
|
+
canvas.height = this.image.height;
|
|
21
|
+
const context = canvas.getContext('2d');
|
|
22
|
+
context.drawImage(this.image, 0, 0);
|
|
23
|
+
CACHED_IMAGES.set(this.image, canvas);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
this.mesh = new Mesh(new PlaneGeometry(1, 1), new THREEShaderMaterial({
|
|
@@ -32,65 +31,65 @@ export default class Sprite extends Object3D {
|
|
|
32
31
|
diffuse: new Color(0xffffff),
|
|
33
32
|
map: new Texture(canvas),
|
|
34
33
|
},
|
|
35
|
-
}))
|
|
36
|
-
this.mesh.scale.x = canvas.width * this._scale
|
|
37
|
-
this.mesh.scale.y = canvas.height * this._scale
|
|
38
|
-
this.mesh.material.map.minFilter = LinearFilter
|
|
39
|
-
this.mesh.material.map.generateMipmaps = false
|
|
40
|
-
this.mesh.material.map.needsUpdate = true
|
|
34
|
+
}));
|
|
35
|
+
this.mesh.scale.x = canvas.width * this._scale;
|
|
36
|
+
this.mesh.scale.y = canvas.height * this._scale;
|
|
37
|
+
this.mesh.material.map.minFilter = LinearFilter;
|
|
38
|
+
this.mesh.material.map.generateMipmaps = false;
|
|
39
|
+
this.mesh.material.map.needsUpdate = true;
|
|
41
40
|
|
|
42
|
-
this.add(this.mesh)
|
|
41
|
+
this.add(this.mesh);
|
|
43
42
|
|
|
44
43
|
if (frame) {
|
|
45
|
-
this.frame = frame
|
|
44
|
+
this.frame = frame;
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
get image() {
|
|
50
|
-
return this._image
|
|
49
|
+
return this._image;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
get data() {
|
|
54
|
-
return this._data
|
|
53
|
+
return this._data;
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
set material(value) {
|
|
58
|
-
this.mesh.material = value
|
|
59
|
-
this.frame = this.frame
|
|
57
|
+
this.mesh.material = value;
|
|
58
|
+
this.frame = this.frame;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
get material() {
|
|
63
|
-
return this.mesh.material
|
|
62
|
+
return this.mesh.material;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
set frame(value) {
|
|
67
66
|
if (!this.data) {
|
|
68
|
-
return
|
|
67
|
+
return;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
this._frame = value
|
|
70
|
+
this._frame = value;
|
|
72
71
|
|
|
73
|
-
const offsetRepeat = this.mesh.material.offsetRepeat
|
|
74
|
-
const frameData = this.data.frames[this._frame]
|
|
72
|
+
const offsetRepeat = this.mesh.material.offsetRepeat;
|
|
73
|
+
const frameData = this.data.frames[this._frame];
|
|
75
74
|
|
|
76
|
-
offsetRepeat.z = (frameData.rotated ? frameData.frame.h : frameData.frame.w) / this.image.width
|
|
77
|
-
offsetRepeat.w = (frameData.rotated ? frameData.frame.w : frameData.frame.h) / this.image.height
|
|
75
|
+
offsetRepeat.z = (frameData.rotated ? frameData.frame.h : frameData.frame.w) / this.image.width;
|
|
76
|
+
offsetRepeat.w = (frameData.rotated ? frameData.frame.w : frameData.frame.h) / this.image.height;
|
|
78
77
|
|
|
79
|
-
offsetRepeat.x = frameData.frame.x / this.image.width
|
|
80
|
-
offsetRepeat.y = 1. - frameData.frame.y / this.image.height - offsetRepeat.w
|
|
78
|
+
offsetRepeat.x = frameData.frame.x / this.image.width;
|
|
79
|
+
offsetRepeat.y = 1.0 - frameData.frame.y / this.image.height - offsetRepeat.w;
|
|
81
80
|
|
|
82
|
-
const scale = 1 / parseFloat(this.data.meta.scale)
|
|
81
|
+
const scale = 1 / parseFloat(this.data.meta.scale);
|
|
83
82
|
|
|
84
|
-
this.mesh.scale.x = (frameData.rotated ? frameData.frame.h : frameData.frame.w) * scale * this._scale
|
|
85
|
-
this.mesh.scale.y = (frameData.rotated ? frameData.frame.w : frameData.frame.h) * scale * this._scale
|
|
83
|
+
this.mesh.scale.x = (frameData.rotated ? frameData.frame.h : frameData.frame.w) * scale * this._scale;
|
|
84
|
+
this.mesh.scale.y = (frameData.rotated ? frameData.frame.w : frameData.frame.h) * scale * this._scale;
|
|
86
85
|
|
|
87
|
-
this.mesh.position.x = (-(frameData.sourceSize.w - frameData.frame.w) * .5 + frameData.spriteSourceSize.x + frameData.sourceSize.w * (.5 - frameData.pivot.x)) * scale * this._scale
|
|
88
|
-
this.mesh.position.y = ((frameData.sourceSize.h - frameData.frame.h) * .5 - frameData.spriteSourceSize.y - frameData.sourceSize.h * (.5 - frameData.pivot.y)) * scale * this._scale
|
|
86
|
+
this.mesh.position.x = (-(frameData.sourceSize.w - frameData.frame.w) * 0.5 + frameData.spriteSourceSize.x + frameData.sourceSize.w * (0.5 - frameData.pivot.x)) * scale * this._scale;
|
|
87
|
+
this.mesh.position.y = ((frameData.sourceSize.h - frameData.frame.h) * 0.5 - frameData.spriteSourceSize.y - frameData.sourceSize.h * (0.5 - frameData.pivot.y)) * scale * this._scale;
|
|
89
88
|
|
|
90
|
-
this.mesh.rotation.z = frameData.rotated ? Math.PI * .5 : 0
|
|
89
|
+
this.mesh.rotation.z = frameData.rotated ? Math.PI * 0.5 : 0;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
get frame() {
|
|
94
|
-
return this._frame
|
|
93
|
+
return this._frame;
|
|
95
94
|
}
|
|
96
95
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import Signal from '@damienmortini/core/util/Signal';
|
|
2
|
+
import Ticker from '@damienmortini/core/util/Ticker';
|
|
1
3
|
|
|
2
|
-
import THREESprite from './THREESprite.js'
|
|
4
|
+
import THREESprite from './THREESprite.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
import Ticker from '@damienmortini/core/util/Ticker'
|
|
6
|
-
|
|
7
|
-
const SPRITESHEETS = new Map()
|
|
6
|
+
const SPRITESHEETS = new Map();
|
|
8
7
|
|
|
9
8
|
export default class THREESpriteAnimation extends THREESprite {
|
|
10
9
|
constructor(image, data, animation, {
|
|
@@ -15,89 +14,90 @@ export default class THREESpriteAnimation extends THREESprite {
|
|
|
15
14
|
scale = 1,
|
|
16
15
|
autoplay = true,
|
|
17
16
|
} = {}) {
|
|
18
|
-
let animations = SPRITESHEETS.get(data)
|
|
17
|
+
let animations = SPRITESHEETS.get(data);
|
|
19
18
|
if (!animations) {
|
|
20
|
-
animations = new Map()
|
|
19
|
+
animations = new Map();
|
|
21
20
|
for (const key in data.frames) {
|
|
22
|
-
const match = /(.*?)([0-9]+)[$\.]/.exec(key)
|
|
23
|
-
const animationName = match[1]
|
|
24
|
-
let frames = animations.get(animationName)
|
|
21
|
+
const match = /(.*?)([0-9]+)[$\.]/.exec(key);
|
|
22
|
+
const animationName = match[1];
|
|
23
|
+
let frames = animations.get(animationName);
|
|
25
24
|
if (!frames) {
|
|
26
|
-
frames = []
|
|
27
|
-
animations.set(animationName, frames)
|
|
25
|
+
frames = [];
|
|
26
|
+
animations.set(animationName, frames);
|
|
28
27
|
}
|
|
29
|
-
const position = parseInt(match[2])
|
|
30
|
-
frames[position - 1] = key
|
|
28
|
+
const position = parseInt(match[2]);
|
|
29
|
+
frames[position - 1] = key;
|
|
31
30
|
}
|
|
32
|
-
SPRITESHEETS.set(data, animations)
|
|
31
|
+
SPRITESHEETS.set(data, animations);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
super(image, {
|
|
36
35
|
data,
|
|
37
36
|
frame: animations.get(animation)[0],
|
|
38
37
|
scale,
|
|
39
|
-
})
|
|
38
|
+
});
|
|
40
39
|
|
|
41
|
-
this.onAnimationEnd = new Signal()
|
|
40
|
+
this.onAnimationEnd = new Signal();
|
|
42
41
|
|
|
43
|
-
this._progress = 0
|
|
44
|
-
this._animations = animations
|
|
42
|
+
this._progress = 0;
|
|
43
|
+
this._animations = animations;
|
|
45
44
|
|
|
46
|
-
this.loop = loop
|
|
47
|
-
this.reverse = reverse
|
|
48
|
-
this.speed = speed
|
|
49
|
-
this.fps = fps
|
|
50
|
-
this.animation = animation
|
|
45
|
+
this.loop = loop;
|
|
46
|
+
this.reverse = reverse;
|
|
47
|
+
this.speed = speed;
|
|
48
|
+
this.fps = fps;
|
|
49
|
+
this.animation = animation;
|
|
51
50
|
|
|
52
51
|
if (autoplay) {
|
|
53
|
-
this.play()
|
|
52
|
+
this.play();
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
set animation(value) {
|
|
58
57
|
if (this._animation === value) {
|
|
59
|
-
return
|
|
58
|
+
return;
|
|
60
59
|
}
|
|
61
|
-
this._animation = value
|
|
60
|
+
this._animation = value;
|
|
62
61
|
|
|
63
|
-
this.update()
|
|
62
|
+
this.update();
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
get animation() {
|
|
67
|
-
return this._animation
|
|
66
|
+
return this._animation;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
play() {
|
|
71
|
-
Ticker.add(this._updateBound = this._updateBound || this.update.bind(this))
|
|
70
|
+
Ticker.add(this._updateBound = this._updateBound || this.update.bind(this));
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
stop() {
|
|
75
|
-
Ticker.delete(this._updateBound)
|
|
74
|
+
Ticker.delete(this._updateBound);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
set progress(value) {
|
|
79
78
|
if (this._progress === value) {
|
|
80
|
-
return
|
|
79
|
+
return;
|
|
81
80
|
}
|
|
82
|
-
const previousProgress = this._progress
|
|
83
|
-
this._progress = value
|
|
81
|
+
const previousProgress = this._progress;
|
|
82
|
+
this._progress = value;
|
|
84
83
|
if (this.loop) {
|
|
85
|
-
this._progress = ((this._progress % 1) + 1) % 1
|
|
86
|
-
}
|
|
87
|
-
|
|
84
|
+
this._progress = ((this._progress % 1) + 1) % 1;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this._progress = Math.min(Math.max(this._progress, 0), 1);
|
|
88
88
|
if (previousProgress !== this._progress && (this._progress === 1 && !this.reverse || this._progress === 0 && this.reverse)) {
|
|
89
|
-
this.onAnimationEnd.dispatch()
|
|
89
|
+
this.onAnimationEnd.dispatch();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
get progress() {
|
|
95
|
-
return this._progress
|
|
95
|
+
return this._progress;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
update() {
|
|
99
|
-
const frames = this._animations.get(this.animation)
|
|
100
|
-
this.progress += (this.speed * (this.fps / 60) * Ticker.timeScale / frames.length) * (this.reverse ? -1 : 1)
|
|
101
|
-
this.frame = frames[Math.round(this._progress * (frames.length - 1))]
|
|
99
|
+
const frames = this._animations.get(this.animation);
|
|
100
|
+
this.progress += (this.speed * (this.fps / 60) * Ticker.timeScale / frames.length) * (this.reverse ? -1 : 1);
|
|
101
|
+
this.frame = frames[Math.round(this._progress * (frames.length - 1))];
|
|
102
102
|
}
|
|
103
103
|
}
|
package/object/THREEText.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Object3D,
|
|
3
2
|
Mesh,
|
|
3
|
+
Object3D,
|
|
4
4
|
PlaneGeometry,
|
|
5
5
|
Texture,
|
|
6
|
-
} from '../../../three/src/Three.js'
|
|
7
|
-
|
|
8
|
-
import THREEShaderMaterial from '../material/THREEShaderMaterial.js'
|
|
6
|
+
} from '../../../three/src/Three.js';
|
|
7
|
+
import THREEShaderMaterial from '../material/THREEShaderMaterial.js';
|
|
9
8
|
|
|
10
9
|
export default class THREEText extends Object3D {
|
|
11
10
|
constructor({
|
|
@@ -25,217 +24,220 @@ export default class THREEText extends Object3D {
|
|
|
25
24
|
transparent: true,
|
|
26
25
|
}),
|
|
27
26
|
} = {}) {
|
|
28
|
-
super()
|
|
27
|
+
super();
|
|
29
28
|
|
|
30
|
-
this._scale = scale
|
|
29
|
+
this._scale = scale;
|
|
31
30
|
|
|
32
|
-
this._canvas = document.createElement('canvas')
|
|
33
|
-
this._context = this._canvas.getContext('2d')
|
|
31
|
+
this._canvas = document.createElement('canvas');
|
|
32
|
+
this._context = this._canvas.getContext('2d');
|
|
34
33
|
|
|
35
|
-
this._texture = new Texture(this._canvas)
|
|
34
|
+
this._texture = new Texture(this._canvas);
|
|
36
35
|
|
|
37
|
-
material.map = this._texture
|
|
36
|
+
material.map = this._texture;
|
|
38
37
|
|
|
39
|
-
this.textContent = textContent
|
|
40
|
-
this.font = font
|
|
41
|
-
this.fillStyle = fillStyle
|
|
42
|
-
this.textAlign = textAlign
|
|
43
|
-
this.maxWidth = maxWidth
|
|
44
|
-
this.shadowColor = shadowColor
|
|
45
|
-
this.shadowBlur = shadowBlur
|
|
46
|
-
this.shadowOffsetX = shadowOffsetX
|
|
47
|
-
this.shadowOffsetY = shadowOffsetY
|
|
38
|
+
this.textContent = textContent;
|
|
39
|
+
this.font = font;
|
|
40
|
+
this.fillStyle = fillStyle;
|
|
41
|
+
this.textAlign = textAlign;
|
|
42
|
+
this.maxWidth = maxWidth;
|
|
43
|
+
this.shadowColor = shadowColor;
|
|
44
|
+
this.shadowBlur = shadowBlur;
|
|
45
|
+
this.shadowOffsetX = shadowOffsetX;
|
|
46
|
+
this.shadowOffsetY = shadowOffsetY;
|
|
48
47
|
|
|
49
|
-
this._mesh = new Mesh(geometry, material)
|
|
50
|
-
this.add(this._mesh)
|
|
48
|
+
this._mesh = new Mesh(geometry, material);
|
|
49
|
+
this.add(this._mesh);
|
|
51
50
|
|
|
52
|
-
this._update()
|
|
51
|
+
this._update();
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
_updateContextProperties() {
|
|
56
|
-
this._context.font = this.font
|
|
57
|
-
this._context.fillStyle = this.fillStyle
|
|
58
|
-
this._context.shadowColor = this.shadowColor
|
|
59
|
-
this._context.shadowBlur = this.shadowBlur
|
|
60
|
-
this._context.shadowOffsetX = this.shadowOffsetX
|
|
61
|
-
this._context.shadowOffsetY = this.shadowOffsetY
|
|
62
|
-
this._context.textBaseline = 'top'
|
|
55
|
+
this._context.font = this.font;
|
|
56
|
+
this._context.fillStyle = this.fillStyle;
|
|
57
|
+
this._context.shadowColor = this.shadowColor;
|
|
58
|
+
this._context.shadowBlur = this.shadowBlur;
|
|
59
|
+
this._context.shadowOffsetX = this.shadowOffsetX;
|
|
60
|
+
this._context.shadowOffsetY = this.shadowOffsetY;
|
|
61
|
+
this._context.textBaseline = 'top';
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
_update() {
|
|
66
65
|
if (!this._mesh) {
|
|
67
|
-
return
|
|
66
|
+
return;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
this._updateContextProperties()
|
|
69
|
+
this._updateContextProperties();
|
|
71
70
|
|
|
72
|
-
const shadowOffsetX = this.shadowOffsetX - this.shadowBlur
|
|
73
|
-
const shadowOffsetY = this.shadowOffsetY - this.shadowBlur
|
|
71
|
+
const shadowOffsetX = this.shadowOffsetX - this.shadowBlur;
|
|
72
|
+
const shadowOffsetY = this.shadowOffsetY - this.shadowBlur;
|
|
74
73
|
|
|
75
|
-
const words = this.textContent.split(' ')
|
|
74
|
+
const words = this.textContent.split(' ');
|
|
76
75
|
|
|
77
|
-
const spaceWidth = this._context.measureText(' ').width
|
|
78
|
-
const wordsWidth = new Map()
|
|
76
|
+
const spaceWidth = this._context.measureText(' ').width;
|
|
77
|
+
const wordsWidth = new Map();
|
|
79
78
|
const lines = [{
|
|
80
79
|
textContent: '',
|
|
81
80
|
width: 0,
|
|
82
|
-
}]
|
|
81
|
+
}];
|
|
83
82
|
for (const word of words) {
|
|
84
83
|
if (!wordsWidth.get(word)) {
|
|
85
|
-
wordsWidth.set(word, this._context.measureText(word).width)
|
|
84
|
+
wordsWidth.set(word, this._context.measureText(word).width);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
let width = 0
|
|
90
|
-
let lineNumber = 0
|
|
88
|
+
let width = 0;
|
|
89
|
+
let lineNumber = 0;
|
|
91
90
|
for (const word of words) {
|
|
92
|
-
const newWidth = lines[lineNumber].width + wordsWidth.get(word)
|
|
91
|
+
const newWidth = lines[lineNumber].width + wordsWidth.get(word);
|
|
93
92
|
|
|
94
93
|
if (newWidth > this.maxWidth) {
|
|
95
|
-
lineNumber
|
|
94
|
+
lineNumber++;
|
|
96
95
|
lines[lineNumber] = {
|
|
97
96
|
textContent: word,
|
|
98
97
|
width: wordsWidth.get(word),
|
|
99
|
-
}
|
|
100
|
-
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
101
|
if (lines[lineNumber].textContent !== '') {
|
|
102
|
-
lines[lineNumber].textContent += ' '
|
|
102
|
+
lines[lineNumber].textContent += ' ';
|
|
103
103
|
}
|
|
104
|
-
lines[lineNumber].textContent += word
|
|
105
|
-
lines[lineNumber].width += spaceWidth + wordsWidth.get(word)
|
|
104
|
+
lines[lineNumber].textContent += word;
|
|
105
|
+
lines[lineNumber].width += spaceWidth + wordsWidth.get(word);
|
|
106
106
|
}
|
|
107
|
-
width = Math.max(width, lines[lineNumber].width)
|
|
107
|
+
width = Math.max(width, lines[lineNumber].width);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
width += this.shadowBlur * 2 + Math.abs(this.shadowOffsetX)
|
|
110
|
+
width += this.shadowBlur * 2 + Math.abs(this.shadowOffsetX);
|
|
111
111
|
|
|
112
|
-
const lineHeight = parseFloat(/\b(\d*)px/.exec(this._context.font)[1])
|
|
113
|
-
let height = lineHeight
|
|
114
|
-
height *= lines.length
|
|
115
|
-
height += this.shadowBlur * 2 + Math.abs(this.shadowOffsetY)
|
|
112
|
+
const lineHeight = parseFloat(/\b(\d*)px/.exec(this._context.font)[1]);
|
|
113
|
+
let height = lineHeight;
|
|
114
|
+
height *= lines.length;
|
|
115
|
+
height += this.shadowBlur * 2 + Math.abs(this.shadowOffsetY);
|
|
116
116
|
|
|
117
117
|
if (this._canvas.width !== width || this._canvas.height !== height) {
|
|
118
|
-
this._canvas.width = width
|
|
119
|
-
this._canvas.height = height
|
|
120
|
-
this._updateContextProperties()
|
|
118
|
+
this._canvas.width = width;
|
|
119
|
+
this._canvas.height = height;
|
|
120
|
+
this._updateContextProperties();
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
this._mesh.position.y = -shadowOffsetY * .5 * this._scale
|
|
123
|
+
this._mesh.position.y = -shadowOffsetY * 0.5 * this._scale;
|
|
124
124
|
|
|
125
125
|
if (this.textAlign === 'start' || this.textAlign === 'left') {
|
|
126
|
-
this._mesh.position.x = (this._canvas.width * .5 + Math.min(0, shadowOffsetX)) * this._scale
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
this._mesh.position.x = (this._canvas.width * 0.5 + Math.min(0, shadowOffsetX)) * this._scale;
|
|
127
|
+
}
|
|
128
|
+
else if (this.textAlign === 'end' || this.textAlign === 'right') {
|
|
129
|
+
this._mesh.position.x = (-this._canvas.width * 0.5 + Math.max(0, shadowOffsetX)) * this._scale;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this._mesh.position.x = shadowOffsetX * 0.5 * this._scale;
|
|
131
133
|
}
|
|
132
|
-
this._mesh.scale.x = this._canvas.width * this._scale
|
|
133
|
-
this._mesh.scale.y = this._canvas.height * this._scale
|
|
134
|
-
this._context.globalAlpha = 1 / 255
|
|
135
|
-
this._context.fillRect(0, 0, width, height)
|
|
136
|
-
this._context.globalAlpha = 1
|
|
134
|
+
this._mesh.scale.x = this._canvas.width * this._scale;
|
|
135
|
+
this._mesh.scale.y = this._canvas.height * this._scale;
|
|
136
|
+
this._context.globalAlpha = 1 / 255;
|
|
137
|
+
this._context.fillRect(0, 0, width, height);
|
|
138
|
+
this._context.globalAlpha = 1;
|
|
137
139
|
for (const [i, line] of lines.entries()) {
|
|
138
|
-
let offsetX
|
|
140
|
+
let offsetX;
|
|
139
141
|
switch (this.textAlign) {
|
|
140
142
|
case 'start':
|
|
141
143
|
case 'left':
|
|
142
|
-
offsetX = 0
|
|
143
|
-
break
|
|
144
|
+
offsetX = 0;
|
|
145
|
+
break;
|
|
144
146
|
case 'center':
|
|
145
|
-
offsetX = (width - line.width) * .5
|
|
146
|
-
break
|
|
147
|
+
offsetX = (width - line.width) * 0.5;
|
|
148
|
+
break;
|
|
147
149
|
case 'end':
|
|
148
150
|
case 'right':
|
|
149
|
-
offsetX = width - line.width
|
|
150
|
-
break
|
|
151
|
+
offsetX = width - line.width;
|
|
152
|
+
break;
|
|
151
153
|
}
|
|
152
|
-
this._context.fillText(line.textContent, offsetX + (shadowOffsetX < 0 ? Math.abs(shadowOffsetX) : 0), (shadowOffsetY < 0 ? Math.abs(shadowOffsetY) : 0) + lineHeight * i)
|
|
154
|
+
this._context.fillText(line.textContent, offsetX + (shadowOffsetX < 0 ? Math.abs(shadowOffsetX) : 0), (shadowOffsetY < 0 ? Math.abs(shadowOffsetY) : 0) + lineHeight * i);
|
|
153
155
|
}
|
|
154
|
-
this._texture.needsUpdate = true
|
|
156
|
+
this._texture.needsUpdate = true;
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
get material() {
|
|
158
|
-
return this._mesh.material
|
|
160
|
+
return this._mesh.material;
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
set textContent(value) {
|
|
162
|
-
this._textContent = value
|
|
163
|
-
this._update()
|
|
164
|
+
this._textContent = value;
|
|
165
|
+
this._update();
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
get textContent() {
|
|
167
|
-
return this._textContent
|
|
169
|
+
return this._textContent;
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
set font(value) {
|
|
171
|
-
this._context.font = this._font = value
|
|
172
|
-
this._update()
|
|
173
|
+
this._context.font = this._font = value;
|
|
174
|
+
this._update();
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
get font() {
|
|
176
|
-
return this._font
|
|
178
|
+
return this._font;
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
set fillStyle(value) {
|
|
180
|
-
this._context.fillStyle = this._fillStyle = value
|
|
181
|
-
this._update()
|
|
182
|
+
this._context.fillStyle = this._fillStyle = value;
|
|
183
|
+
this._update();
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
get fillStyle() {
|
|
185
|
-
return this._fillStyle
|
|
187
|
+
return this._fillStyle;
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
set textAlign(value) {
|
|
189
|
-
this._textAlign = value
|
|
190
|
-
this._update()
|
|
191
|
+
this._textAlign = value;
|
|
192
|
+
this._update();
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
get textAlign() {
|
|
194
|
-
return this._textAlign
|
|
196
|
+
return this._textAlign;
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
set maxWidth(value) {
|
|
198
|
-
this._maxWidth = value
|
|
199
|
-
this._update()
|
|
200
|
+
this._maxWidth = value;
|
|
201
|
+
this._update();
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
get maxWidth() {
|
|
203
|
-
return this._maxWidth
|
|
205
|
+
return this._maxWidth;
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
set shadowColor(value) {
|
|
207
|
-
this._context.shadowColor = this._shadowColor = value
|
|
208
|
-
this._update()
|
|
209
|
+
this._context.shadowColor = this._shadowColor = value;
|
|
210
|
+
this._update();
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
get shadowColor() {
|
|
212
|
-
return this._shadowColor
|
|
214
|
+
return this._shadowColor;
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
set shadowBlur(value) {
|
|
216
|
-
this._context.shadowBlur = this._shadowBlur = value
|
|
217
|
-
this._update()
|
|
218
|
+
this._context.shadowBlur = this._shadowBlur = value;
|
|
219
|
+
this._update();
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
get shadowBlur() {
|
|
221
|
-
return this._shadowBlur
|
|
223
|
+
return this._shadowBlur;
|
|
222
224
|
}
|
|
223
225
|
|
|
224
226
|
set shadowOffsetX(value) {
|
|
225
|
-
this._context.shadowOffsetX = this._shadowOffsetX = value
|
|
226
|
-
this._update()
|
|
227
|
+
this._context.shadowOffsetX = this._shadowOffsetX = value;
|
|
228
|
+
this._update();
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
get shadowOffsetX() {
|
|
230
|
-
return this._shadowOffsetX
|
|
232
|
+
return this._shadowOffsetX;
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
set shadowOffsetY(value) {
|
|
234
|
-
this._context.shadowOffsetY = this._shadowOffsetY = value
|
|
235
|
-
this._update()
|
|
236
|
+
this._context.shadowOffsetY = this._shadowOffsetY = value;
|
|
237
|
+
this._update();
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
get shadowOffsetY() {
|
|
239
|
-
return this._shadowOffsetY
|
|
241
|
+
return this._shadowOffsetY;
|
|
240
242
|
}
|
|
241
243
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@damienmortini/three",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.195",
|
|
4
4
|
"description": "Three.js helpers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"generateTypes": "npx -p typescript tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir types"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@damienmortini/core": "^0.2.
|
|
28
|
+
"@damienmortini/core": "^0.2.156",
|
|
29
29
|
"fs-extra": "^11.2.0",
|
|
30
|
-
"three": "0.
|
|
30
|
+
"three": "0.169.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "7a6e220a2926a826d7102270ca6b97715458c8f3"
|
|
36
36
|
}
|