Skip to content

Commit

Permalink
Merge pull request #54 from readyplayerme/ACT-19-Background-color-gra…
Browse files Browse the repository at this point in the history
…dients

feat: add color property to background prop
  • Loading branch information
Zaehiel authored Sep 21, 2023
2 parents 85655fd + aaaec33 commit 1e4e1a5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/components/Avatar/Avatar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface AvatarProps extends LightingProps, EnvironmentProps, Omit<BaseM
cameraInitialDistance?: number;
/**
* Apply styling to canvas DOM element.
* Note that background property can not be set via style prop, it will always be overridden to `transparent`.
* Instead, use `background` prop for that purpose.
*/
style?: CSSProperties;
/**
Expand All @@ -98,8 +100,10 @@ export interface AvatarProps extends LightingProps, EnvironmentProps, Omit<BaseM
*/
emotion?: Emotion;
/**
* Applies Box background in the scene with a provided image.
* Allows adding a background image and background color to the scene.
* Make sure that image is loadable to prevent bg errors.
* background.src - Accepts URL string.
* background.color - Accepts Hexadeximal, RGB, X11 color name, HSL string, doesn't support CSS gradients.
*/
background?: Background;
/**
Expand Down Expand Up @@ -276,7 +280,7 @@ const Avatar: FC<AvatarProps> = ({
{shadows && <Shadow />}
{background?.src && <Box {...background} />}
{capture && <Capture {...capture} />}
{style?.background && <BackgroundColor color={style.background as string} />}
{background?.color && <BackgroundColor color={background.color} />}
<EffectComposer autoClear={false}>
<Bloom
luminanceThreshold={bloom?.luminanceThreshold}
Expand Down
9 changes: 7 additions & 2 deletions src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ Static.args = {
intensity: 0.1,
materialIntensity: 3.3
},
style: { background: 'rgb(9,20,26)' },
background: {
color: 'rgb(9,20,26)'
},
style: {},
/* eslint-disable no-console */
onLoaded: () => console.info('EVENT: static avatar loaded'),
onLoading: () => console.info('EVENT: loading static avatar')
Expand Down Expand Up @@ -127,7 +130,9 @@ Showcase.args = {
intensity: 1,
materialIntensity: 1
},
style: { background: '#282038' },
background: {
color: '#282038'
},
dpr: 2,
ambientLightColor: '#ffffff',
dirLightColor: '#ffffff',
Expand Down
6 changes: 3 additions & 3 deletions src/components/Avatar/Examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const Bloom: StoryFn<BloomConfiguration> = (args: BloomConfiguration | un
dirLightIntensity={2.2}
spotLightIntensity={0.5}
environment="apartment"
style={{
background: 'rgb(9,20,26)'
background={{
color: 'rgb(9,20,26)'
}}
/>
);
Expand Down Expand Up @@ -110,7 +110,7 @@ SpawnEffectAndAnimation.args = {
cameraInitialDistance: CAMERA.CONTROLS.FULL_BODY.MAX_DISTANCE,
modelSrc: getStoryAssetPath('male-emissive.glb'),
animationSrc: getStoryAssetPath('male-idle.glb'),
style: { background: 'rgb(9,20,26)' }
background: { color: 'rgb(9,20,26)' }
};
SpawnEffectAndAnimation.argTypes = {
...ignoreArgTypesOnExamples,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Background/Box/Box.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Mesh, TextureLoader } from 'three';
import { useLoader } from '@react-three/fiber';
import { MeshProps } from '@react-three/fiber/dist/declarations/src/three-types';

export type Background = { src?: string } & MeshProps;
export type Background = { src?: string; color?: string } & MeshProps;

export const Box: FC<Background> = ({ src = '', ...baseProps }) => {
const ref = useRef<Mesh>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/components/BaseCanvas/BaseCanvas.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const BaseCanvas: FC<BaseCanvasProps> = ({
key={fov}
className={`${styles['base-canvas']} ${className ?? ''}`}
shadows="soft"
gl={{ preserveDrawingBuffer: true, toneMappingExposure: 0.5 }}
gl={{ preserveDrawingBuffer: true, toneMappingExposure: 0.5, alpha: true }}
dpr={dpr}
camera={{ fov, position }}
resize={{ scroll: true, debounce: { scroll: 50, resize: 0 } }}
Expand Down

0 comments on commit 1e4e1a5

Please sign in to comment.