emeraldengine 2.0.2 → 2.1.0
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/imports/Drawable.js +31 -26
- package/imports/InstancedTexture.js +9 -4
- package/package.json +1 -1
package/imports/Drawable.js
CHANGED
|
@@ -50,7 +50,7 @@ class Drawable {
|
|
|
50
50
|
this.texture = null;
|
|
51
51
|
this.useTexture = useTexture;
|
|
52
52
|
if (useTexture) {
|
|
53
|
-
this.initTexture().then(() => {});
|
|
53
|
+
this.initTexture().then(() => { });
|
|
54
54
|
}
|
|
55
55
|
this.frameWidth = frameWidth;
|
|
56
56
|
this.frameHeight = frameHeight;
|
|
@@ -73,7 +73,7 @@ class Drawable {
|
|
|
73
73
|
this.parentObject = null;
|
|
74
74
|
this.isActive = false;
|
|
75
75
|
this.isWireframe = false;
|
|
76
|
-
this.callbackFunction = () => {};
|
|
76
|
+
this.callbackFunction = () => { };
|
|
77
77
|
this.pixelart = pixelart;
|
|
78
78
|
this.useLighting = useLighting; // Default to true to maintain existing behavior
|
|
79
79
|
}
|
|
@@ -430,13 +430,18 @@ class Drawable {
|
|
|
430
430
|
const col = this.currentFrame % this.framesPerRow;
|
|
431
431
|
const row = Math.floor(this.currentFrame / this.framesPerRow);
|
|
432
432
|
|
|
433
|
-
|
|
434
|
-
|
|
433
|
+
const halfTexelWidth = 0.5 / this.textureWidth;
|
|
434
|
+
const halfTexelHeight = 0.5 / this.textureHeight;
|
|
435
|
+
|
|
436
|
+
texLeft = ((col + 1) * this.frameWidth) / this.textureWidth - halfTexelWidth;
|
|
437
|
+
texRight = (col * this.frameWidth) / this.textureWidth + halfTexelWidth;
|
|
435
438
|
texTop =
|
|
436
439
|
(this.textureHeight - row * this.frameHeight - this.frameHeight) /
|
|
437
|
-
this.textureHeight
|
|
440
|
+
this.textureHeight +
|
|
441
|
+
halfTexelHeight;
|
|
438
442
|
texBottom =
|
|
439
|
-
(this.textureHeight - row * this.frameHeight) / this.textureHeight
|
|
443
|
+
(this.textureHeight - row * this.frameHeight) / this.textureHeight -
|
|
444
|
+
halfTexelHeight;
|
|
440
445
|
} else {
|
|
441
446
|
// Static image
|
|
442
447
|
texLeft = 1.0;
|
|
@@ -447,25 +452,25 @@ class Drawable {
|
|
|
447
452
|
// If mirrored change texLeft and texRight in places
|
|
448
453
|
const texCoords = this.mirrored
|
|
449
454
|
? new Float32Array([
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
455
|
+
texRight,
|
|
456
|
+
texBottom,
|
|
457
|
+
texLeft,
|
|
458
|
+
texBottom,
|
|
459
|
+
texRight,
|
|
460
|
+
texTop,
|
|
461
|
+
texLeft,
|
|
462
|
+
texTop,
|
|
463
|
+
])
|
|
459
464
|
: new Float32Array([
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
465
|
+
texLeft,
|
|
466
|
+
texBottom,
|
|
467
|
+
texRight,
|
|
468
|
+
texBottom,
|
|
469
|
+
texLeft,
|
|
470
|
+
texTop,
|
|
471
|
+
texRight,
|
|
472
|
+
texTop,
|
|
473
|
+
]);
|
|
469
474
|
// Update texture coordinate buffer
|
|
470
475
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.texCoordBuffer);
|
|
471
476
|
this.gl.bufferData(this.gl.ARRAY_BUFFER, texCoords, this.gl.STATIC_DRAW);
|
|
@@ -493,9 +498,9 @@ class Drawable {
|
|
|
493
498
|
vertexCount = this.vertices.length / 2;
|
|
494
499
|
}
|
|
495
500
|
|
|
496
|
-
if(this.isWireframe) {
|
|
501
|
+
if (this.isWireframe) {
|
|
497
502
|
// Fix the wireframe for square
|
|
498
|
-
if(this.vertices.length === 8) {
|
|
503
|
+
if (this.vertices.length === 8) {
|
|
499
504
|
let tempBuffer = this.gl.createBuffer();
|
|
500
505
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, tempBuffer);
|
|
501
506
|
|
|
@@ -406,13 +406,18 @@ class InstancedTexture extends Drawable {
|
|
|
406
406
|
const col = frame % this.framesPerRow;
|
|
407
407
|
const row = Math.floor(frame / this.framesPerRow);
|
|
408
408
|
|
|
409
|
-
|
|
410
|
-
|
|
409
|
+
const halfTexelWidth = 0.5 / this.textureWidth;
|
|
410
|
+
const halfTexelHeight = 0.5 / this.textureHeight;
|
|
411
|
+
|
|
412
|
+
texLeft = ((col + 1) * this.frameWidth) / this.textureWidth - halfTexelWidth;
|
|
413
|
+
texRight = (col * this.frameWidth) / this.textureWidth + halfTexelWidth;
|
|
411
414
|
texTop =
|
|
412
415
|
(this.textureHeight - row * this.frameHeight - this.frameHeight) /
|
|
413
|
-
|
|
416
|
+
this.textureHeight +
|
|
417
|
+
halfTexelHeight;
|
|
414
418
|
texBottom =
|
|
415
|
-
(this.textureHeight - row * this.frameHeight) / this.textureHeight
|
|
419
|
+
(this.textureHeight - row * this.frameHeight) / this.textureHeight -
|
|
420
|
+
halfTexelHeight;
|
|
416
421
|
} else {
|
|
417
422
|
// Static image
|
|
418
423
|
texLeft = 1.0;
|