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]; }