Skip to content

Commit

Permalink
feat: added isTotem prop in Avatar Component for managing default ava…
Browse files Browse the repository at this point in the history
…tar size for different layouts
  • Loading branch information
andrepat0 committed Nov 11, 2024
1 parent 0900f1a commit 9d171dc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/components/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ it('renders defualt Avatar (blob) unchanged', () => {
<Avatar
memori={memori}
tenant={tenant}
isTotem={false}
setEnablePositionControls={() => {}}
instruct={false}
avatar3dVisible={true}
setAvatar3dVisible={() => {}}
Expand All @@ -34,6 +36,8 @@ it('renders Avatar with blob and avatar in blob unchanged', () => {
}}
tenant={tenant}
instruct={false}
isTotem={false}
setEnablePositionControls={() => {}}
avatar3dVisible={true}
setAvatar3dVisible={() => {}}
hasUserActivatedSpeak={false}
Expand All @@ -50,6 +54,8 @@ it('renders Avatar with custom glb model unchanged', () => {
<Avatar
memori={memori}
integration={integration}
isTotem={false}
setEnablePositionControls={() => {}}
integrationConfig={{
...integrationConfig,
avatar: 'customglb',
Expand All @@ -74,6 +80,8 @@ it('renders Avatar with rpm 3d avatar unchanged', () => {
<Avatar
memori={memori}
integration={integration}
isTotem={false}
setEnablePositionControls={() => {}}
integrationConfig={{
...integrationConfig,
avatar: 'readyplayerme',
Expand Down
4 changes: 3 additions & 1 deletion src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface Props {
enablePositionControls?: boolean;
setEnablePositionControls: (value: boolean) => void;
avatarType?: 'blob' | 'avatar3d' | undefined;
isTotem?: boolean;
}

const Avatar: React.FC<Props> = ({
Expand All @@ -60,6 +61,7 @@ const Avatar: React.FC<Props> = ({
avatarType,
enablePositionControls,
setEnablePositionControls,
isTotem = false,
}) => {
const { t } = useTranslation();
const [isClient, setIsClient] = useState(false);
Expand Down Expand Up @@ -154,7 +156,7 @@ const Avatar: React.FC<Props> = ({
stopProcessing={stopProcessing}
resetVisemeQueue={resetVisemeQueue}
isZoomed={isZoomed}
layout={chatProps?.layout}
isTotem={isTotem}
chatEmission={chatProps?.dialogState?.emission}
setEnablePositionControls={setEnablePositionControls}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ const PositionControls: React.FC<PositionControlsProps> = ({
</div>
<div className="memori--position-controls-helper">
<p className="memori--position-controls-helper-text">
{t('Use the arrow keys to adjust the avatar height')}
<br />
{t('Use +/- to adjust the avatar depth')}
{t('write_and_speak.suggestions')}
</p>
</div>
<div className="memori--slider-container">
Expand Down
25 changes: 12 additions & 13 deletions src/components/Avatar/AvatarView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ export interface Props {
chatEmission?: any;
enablePositionControls?: boolean;
setEnablePositionControls: (value: boolean) => void;
layout?:
| 'DEFAULT'
| 'FULLPAGE'
| 'TOTEM'
| 'CHAT'
| 'WEBSITE_ASSISTANT'
| 'HIDDEN_CHAT'
| 'ZOOMED_FULL_BODY';
isTotem?: boolean;
setMeshRef?: any;
stopProcessing: () => void;
resetVisemeQueue: () => void;
Expand Down Expand Up @@ -106,25 +99,31 @@ export default function ContainerAvatarView({
updateCurrentViseme,
enablePositionControls,
setEnablePositionControls,
layout,
isTotem = false,
}: Props) {
const [cameraZ, setCameraZ] = useState(
() => getCameraSettings(halfBody, isZoomed || false).position[2]
);

const getAvatarHeight = () => {
if (layout === 'TOTEM') {
console.log('avatarHeight', getLocalConfig('avatarHeight', 50), isTotem);
if (isTotem) {
return getLocalConfig('avatarHeight', 50);
} else if (halfBody) {
return 100;
} else {
return isZoomed ? 20 : !halfBody ? 60 : 60;
return isZoomed ? 20 : 55;
}
};

const getAvatarDepth = () => {
if (layout === 'TOTEM') {
if (isTotem) {
console.log('avatarDepth', getLocalConfig('avatarDepth', 50));
return getLocalConfig('avatarDepth', 50);
} else if (halfBody) {
return 50
} else {
return isZoomed ? -80 : !halfBody ? -80 : -80;
return isZoomed ? -80 : 70;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/layouts/Totem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const TotemLayout: React.FC<LayoutProps> = ({
</div>

<div className="memori-totem-layout--avatar">
{Avatar && avatarProps && <Avatar {...avatarProps} />}
{Avatar && avatarProps && <Avatar {...avatarProps} isTotem />}
</div>

<div id="extension" />
Expand Down

0 comments on commit 9d171dc

Please sign in to comment.