-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from readyplayerme/feature/self-host-environme…
…nt-presets Feature - new environment presets
- Loading branch information
Showing
4 changed files
with
28 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
import React, { FC, useMemo } from 'react'; | ||
import { Environment as DreiEnvironment } from '@react-three/drei'; | ||
import { PresetsType } from '@react-three/drei/helpers/environment-assets'; | ||
|
||
export const allowedPresets = { | ||
sunset: 'sunset', | ||
dawn: 'dawn', | ||
night: 'night', | ||
warehouse: 'warehouse', | ||
forest: 'forest', | ||
apartment: 'apartment', | ||
studio: 'studio', | ||
city: 'city', | ||
park: 'park', | ||
lobby: 'lobby' | ||
}; | ||
import { environmentPresets, getPresetEnvironmentMap, EnvironmentPresets } from 'src/services/EnvironmentMap.service'; | ||
|
||
export interface EnvironmentProps { | ||
environment: string; | ||
environment: string | EnvironmentPresets; | ||
} | ||
|
||
export const Environment: FC<EnvironmentProps> = ({ environment }) => { | ||
const config = useMemo<{ preset: PresetsType | undefined; files: string | undefined }>(() => { | ||
const isStaticPreset = environment in allowedPresets; | ||
const preset = isStaticPreset ? (environment as PresetsType) : undefined; | ||
const files = isStaticPreset ? undefined : environment; | ||
const config = useMemo<{ files: string }>(() => { | ||
const isStaticPreset = environment in environmentPresets; | ||
const files = isStaticPreset ? getPresetEnvironmentMap(environment as EnvironmentPresets) : environment; | ||
|
||
return { | ||
preset, | ||
files | ||
}; | ||
}, [environment]); | ||
|
||
return <DreiEnvironment preset={config.preset} files={config.files} />; | ||
return <DreiEnvironment files={config.files} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const environmentPresets = { | ||
hub: 'hub', | ||
sunset: 'sunset', | ||
dawn: 'dawn', | ||
night: 'night', | ||
warehouse: 'warehouse', | ||
forest: 'forest', | ||
apartment: 'apartment', | ||
studio: 'studio', | ||
city: 'city', | ||
park: 'park', | ||
lobby: 'lobby' | ||
}; | ||
export type EnvironmentPresets = keyof typeof environmentPresets; | ||
|
||
export const getPresetEnvironmentMap = (preset: EnvironmentPresets) => | ||
`https://readyplayerme-assets.s3.amazonaws.com/environment/${preset}.hdr`; |