emeraldengine 2.0.1 → 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
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;
|
|
@@ -16,8 +16,6 @@ class EventManager {
|
|
|
16
16
|
this.keyDownListeners = new Map();
|
|
17
17
|
this.keyUpListeners = new Map();
|
|
18
18
|
this.clickListeners = new Map();
|
|
19
|
-
this.canvasWidth = canvas.width;
|
|
20
|
-
this.canvasHeight = canvas.height;
|
|
21
19
|
this.hoverListeners = new Map();
|
|
22
20
|
this.lastHoveredObject = null;
|
|
23
21
|
this.lastHoveredInstance = null;
|
|
@@ -187,9 +185,9 @@ class EventManager {
|
|
|
187
185
|
|
|
188
186
|
// Convert to world coordinates
|
|
189
187
|
const worldX =
|
|
190
|
-
canvasX - this.
|
|
188
|
+
canvasX - this.canvas.width / 2 - this.camera.transform.position.x;
|
|
191
189
|
const worldY =
|
|
192
|
-
this.
|
|
190
|
+
this.canvas.height / 2 - canvasY - this.camera.transform.position.y;
|
|
193
191
|
|
|
194
192
|
this.scene.objects.forEach((sceneObject) => {
|
|
195
193
|
if (!sceneObject.isActive) return; // Skip inactive objects
|
|
@@ -326,9 +324,9 @@ class EventManager {
|
|
|
326
324
|
|
|
327
325
|
// Convert to world coordinates
|
|
328
326
|
const worldX =
|
|
329
|
-
canvasX - this.
|
|
327
|
+
canvasX - this.canvas.width / 2 - this.camera.transform.position.x;
|
|
330
328
|
const worldY =
|
|
331
|
-
this.
|
|
329
|
+
this.canvas.height / 2 - canvasY - this.camera.transform.position.y;
|
|
332
330
|
this.mousePosition.x = worldX;
|
|
333
331
|
this.mousePosition.y = worldY;
|
|
334
332
|
let hoveredObject = null;
|