Skip to content

Commit 85b3326

Browse files
authored
Merge pull request #103 from decentraland/feat/zoom-scale
feat: added zoom scale param
2 parents e98a929 + bb3db1e commit 85b3326

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This webapp renders an interactive 3D preview of a wearable or an avatar. It can
1515
- `bodyShape`: which body shape to use, possible values are `urn:decentraland:off-chain:base-avatars:BaseMale` or `urn:decentraland:off-chain:base-avatars:BaseFemale`.
1616
- `emote`: the emote that the avatar will play. Default value is `idle`, other possible values are: `clap`, `dab`, `dance`, `fashion`, `fashion-2`, `fashion-3`,`fashion-4`, `love`, `money`, `fist-pump` and `head-explode`.
1717
- `zoom`: the level of zoom, it must be a number between 1 and 100.
18+
- `zoomScale`: a multiplier for the zoom level. By default is `1` but it can be increased to get extra zoom.
1819
- `camera`: which camera type to use, either `interactive` or `static`. By default it uses the `interactive` one.
1920
- `projection`: which projection type to use, either `orthographic` or `perspective`. By default it uses the `perspective` one.
2021
- `offsetX`: apply an offset in the X position of the scene. By default is `0`.
@@ -181,6 +182,7 @@ window.addEventListener('message', handleMessage)
181182
```
182183

183184
Now you can use it like this:
185+
184186
```ts
185187
const screenshot = await sendRequest('scene', 'getScreenshot', [512, 512]) // "data:image/png;base64..."
186188
```

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@babylonjs/inspector": "^4.2.2",
99
"@babylonjs/loaders": "^4.2.2",
1010
"@babylonjs/materials": "^4.2.2",
11-
"@dcl/schemas": "^9.7.0",
11+
"@dcl/schemas": "^9.9.0",
1212
"@dcl/ui-env": "^1.2.0",
1313
"@testing-library/jest-dom": "^5.15.0",
1414
"@testing-library/react": "^11.2.7",

src/hooks/useOptions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const useOptions = () => {
1616
const cameraXParam = params.get('cameraX') as string | null
1717
const cameraYParam = params.get('cameraY') as string | null
1818
const cameraZParam = params.get('cameraZ') as string | null
19+
const zoomScaleParam = params.get('zoomScale') as string | null
1920
const wheelZoomParam = params.get('wheelZoom') as string | null
2021
const wheelPrecisionParam = params.get('wheelPrecision') as string | null
2122
const wheelStartParam = params.get('wheelStart') as string | null
@@ -60,6 +61,7 @@ export const useOptions = () => {
6061
wheelPrecision: wheelPrecisionParam ? parseFloat(wheelPrecisionParam) : null,
6162
wheelStart: wheelStartParam ? parseFloat(wheelStartParam) : null,
6263
zoom: parseZoom(params.get('zoom')),
64+
zoomScale: zoomScaleParam ? parseFloat(zoomScaleParam) : null,
6365
bodyShape:
6466
bodyShapeParam === 'female' || bodyShapeParam === BodyShape.FEMALE
6567
? BodyShape.FEMALE

src/lib/babylon/scene.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export async function createScene(
145145
// Setup Camera
146146
const camera = new ArcRotateCamera('camera', 0, 0, 0, new Vector3(0, 0, 0), root)
147147
camera.position = new Vector3(config.cameraX, config.cameraY, config.cameraZ)
148+
camera.minZ = 0.1
148149

149150
switch (config.projection) {
150151
case PreviewProjection.PERSPECTIVE: {

src/lib/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ export async function createConfig(options: PreviewOptions = {}): Promise<Previe
364364
customWearable = wearables[1]
365365
}
366366

367+
// the zoom scale values is used to achieve extra zoom. It was implemented as a separate option to don't break the behavior of the zoom property. By default is 1 and it makes no change to the regular zoom.
368+
const zoomScale =
369+
typeof options.zoomScale !== 'number' || isNaN(options.zoomScale) || options.zoomScale <= 0 ? 1 : options.zoomScale
370+
367371
return {
368372
// item is the most important prop, if not preset we use the blob prop, and if none, we use the last emote from the list (if any)
369373
item: item ?? blob ?? customWearable ?? emotes.pop(),
@@ -387,7 +391,7 @@ export async function createConfig(options: PreviewOptions = {}): Promise<Previe
387391
cameraX,
388392
cameraY,
389393
cameraZ,
390-
zoom: typeof options.zoom === 'number' ? computeZoom(options.zoom) : zoom,
394+
zoom: (typeof options.zoom === 'number' ? computeZoom(options.zoom) : zoom) * zoomScale,
391395
wheelZoom,
392396
wheelPrecision,
393397
wheelStart,

0 commit comments

Comments
 (0)