From 8710762b99e4b9dd4ceb21482716c41e17be2b99 Mon Sep 17 00:00:00 2001 From: Marco Stagni Date: Sun, 28 Jun 2026 19:01:15 +0100 Subject: [PATCH] feat(textures): support configurable texture offset Apply and persist Texture.offset alongside the existing repeat handling in Element.setTexture, so offset round-trips through serialization and game builds the same way repeat does. Add Element.setTextureOptions(type, options) to update an already-assigned texture's repeat/offset by merging into its recorded options and re-applying, without reloading the texture. Co-Authored-By: Claude Opus 4.8 --- src/entities/Element.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/entities/Element.js b/src/entities/Element.js index 70839f2..54cd749 100644 --- a/src/entities/Element.js +++ b/src/entities/Element.js @@ -924,9 +924,15 @@ export default class Element extends Entity { } if (textureId) { - const { repeat = { x: 1, y: 1 }, wrap = RepeatWrapping, assetPath } = options; + const { + repeat = { x: 1, y: 1 }, + offset = { x: 0, y: 0 }, + wrap = RepeatWrapping, + assetPath, + } = options; const textureOptions = { repeat, + offset, wrap, }; @@ -943,6 +949,7 @@ export default class Element extends Entity { texture.wrapS = textureOptions.wrap; texture.wrapT = textureOptions.wrap; texture.repeat.set(textureOptions.repeat.x, textureOptions.repeat.y); + texture.offset.set(textureOptions.offset.x, textureOptions.offset.y); // Set sRGB encoding for color textures (map, emissiveMap, specularMap) // This is required for textures to display with correct colors @@ -962,6 +969,19 @@ export default class Element extends Entity { } } + setTextureOptions(textureType = TEXTURES.MAP, options = {}) { + const existing = this.textures.get(textureType); + + if (!existing) { + return; + } + + const { id, assetPath, options: currentOptions = {} } = existing; + const mergedOptions = { ...currentOptions, ...options }; + + this.setTexture(id, textureType, { ...mergedOptions, assetPath }); + } + getTexture(textureType = TEXTURES.MAP) { return this.getBody().material[textureType]; }