Skip to content

Commit

Permalink
feat(Texture): restrict maximum size of textures to 128 pixels in nor…
Browse files Browse the repository at this point in the history
…mal variant
  • Loading branch information
meszaros-lajos-gyorgy committed Sep 20, 2023
1 parent 9a8bd6e commit 8edf2a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Since `1.4.0` the `Settings` class has a `variant` field with 2 values: `"normal
In normal mode:

- jpg textures will be exported with 70% quality as opposed to 100%
- all textures except the icons (ending in `[icon].bmp`) will be resized to half the original resolution
- all textures except icons (ending in `[icon].bmp`) will be resized to have a maximum width and height of 128 pixels.

## Other docs

Expand Down
22 changes: 20 additions & 2 deletions src/Texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,26 @@ export class Texture extends ThreeJsTextue {

let quality = 100
if (settings.variant !== 'premium' && !this.filename.endsWith('[icon].bmp')) {
image.resize(Math.floor(this._width / 2), Math.floor(this._height / 2), { fit: 'cover' })
quality = 70

let maxWidth = 128
let maxHeight = 128

if (this._width > maxWidth || this._height > maxHeight) {
const isPortrait = this._width < this._height
const isLandscape = this._width > this._height

if (isPortrait) {
maxWidth = (maxWidth / this._width) * this._height
} else if (isLandscape) {
maxHeight = (maxHeight / this._height) * this._width
}

const newWidth = Math.max(maxWidth, this._width)
const newHeight = Math.max(maxHeight, this._height)

image.resize(newWidth, newHeight, { fit: 'cover' })
}
}

if (isBMP) {
Expand Down Expand Up @@ -196,7 +214,7 @@ export class Texture extends ThreeJsTextue {
let newSize = powerOfTwo
let quality = 100
if (settings.variant !== 'premium' && !this.filename.endsWith('[icon].bmp')) {
newSize = newSize / 2
newSize = Math.max(128, newSize)
quality = 70
}

Expand Down

0 comments on commit 8edf2a2

Please sign in to comment.