@@ -23,14 +23,13 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
23
23
Ethereal Engine. All Rights Reserved.
24
24
*/
25
25
26
- import React , { useEffect , useRef } from 'react'
26
+ import React , { useEffect } from 'react'
27
27
import { useTranslation } from 'react-i18next'
28
28
29
29
import ConfirmDialog from '@etherealengine/client-core/src/common/components/ConfirmDialog'
30
30
import InputFile from '@etherealengine/client-core/src/common/components/InputFile'
31
31
import InputRadio from '@etherealengine/client-core/src/common/components/InputRadio'
32
32
import InputText from '@etherealengine/client-core/src/common/components/InputText'
33
- import LoadingView from '@etherealengine/client-core/src/common/components/LoadingView'
34
33
import { getCanvasBlob , isValidHttpUrl } from '@etherealengine/client-core/src/common/utils'
35
34
import {
36
35
AVATAR_FILE_ALLOWED_EXTENSIONS ,
@@ -43,8 +42,6 @@ import {
43
42
THUMBNAIL_WIDTH
44
43
} from '@etherealengine/common/src/constants/AvatarConstants'
45
44
import { AssetLoader } from '@etherealengine/engine/src/assets/classes/AssetLoader'
46
- import { AvatarRigComponent } from '@etherealengine/engine/src/avatar/components/AvatarAnimationComponent'
47
- import { getOptionalComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
48
45
import { AvatarType } from '@etherealengine/engine/src/schemas/user/avatar.schema'
49
46
import { useHookstate } from '@etherealengine/hyperflux'
50
47
import Box from '@etherealengine/ui/src/primitives/mui/Box'
@@ -55,12 +52,10 @@ import DialogTitle from '@etherealengine/ui/src/primitives/mui/DialogTitle'
55
52
import FormControl from '@etherealengine/ui/src/primitives/mui/FormControl'
56
53
import FormHelperText from '@etherealengine/ui/src/primitives/mui/FormHelperText'
57
54
import Icon from '@etherealengine/ui/src/primitives/mui/Icon'
58
- import Tooltip from '@etherealengine/ui/src/primitives/mui/Tooltip'
59
55
import Typography from '@etherealengine/ui/src/primitives/mui/Typography'
60
56
57
+ import AvatarPreview from '../../../common/components/AvatarPreview'
61
58
import { NotificationService } from '../../../common/services/NotificationService'
62
- import { loadAvatarForPreview , resetAnimationLogic } from '../../../user/components/Panel3D/helperFunctions'
63
- import { useRender3DPanelSystem } from '../../../user/components/Panel3D/useRender3DPanelSystem'
64
59
import { AvatarService } from '../../../user/services/AvatarService'
65
60
import { userHasAccess } from '../../../user/userHasAccess'
66
61
import DrawerView from '../../common/DrawerView'
@@ -102,14 +97,11 @@ const defaultState = {
102
97
103
98
const AvatarDrawerContent = ( { open, mode, selectedAvatar, onClose } : Props ) => {
104
99
const { t } = useTranslation ( )
105
- const panelRef = useRef ( ) as React . MutableRefObject < HTMLDivElement >
106
100
const editMode = useHookstate ( false )
107
101
const state = useHookstate ( { ...defaultState } )
108
102
const avatarLoading = useHookstate ( false )
109
103
const showConfirm = useHookstate ( ConfirmState . None )
110
-
111
- const renderPanel = useRender3DPanelSystem ( panelRef )
112
- const { entity, camera, scene, renderer } = renderPanel . state
104
+ const avatarSrc = useHookstate ( '' )
113
105
114
106
const hasWriteAccess = userHasAccess ( 'static_resource:write' )
115
107
const viewMode = mode === AvatarDrawerMode . ViewEdit && ! editMode . value
@@ -165,22 +157,7 @@ const AvatarDrawerContent = ({ open, mode, selectedAvatar, onClose }: Props) =>
165
157
}
166
158
}
167
159
168
- if ( url ) {
169
- avatarLoading . set ( true )
170
- resetAnimationLogic ( entity . value )
171
- const avatar = await loadAvatarForPreview ( entity . value , url )
172
- const avatarRigComponent = getOptionalComponent ( entity . value , AvatarRigComponent )
173
- if ( avatarRigComponent ) {
174
- avatarRigComponent . rig . head . node . getWorldPosition ( camera . value . position )
175
- camera . value . position . y += 0.2
176
- camera . value . position . z = 0.6
177
- }
178
- avatarLoading . set ( false )
179
- if ( avatar ) {
180
- avatar . name = 'avatar'
181
- scene . value . add ( avatar )
182
- }
183
- }
160
+ avatarSrc . set ( url )
184
161
}
185
162
186
163
const handleCancel = ( ) => {
@@ -210,6 +187,7 @@ const AvatarDrawerContent = ({ open, mode, selectedAvatar, onClose }: Props) =>
210
187
} )
211
188
: ''
212
189
} )
190
+ state . avatarFile . set ( files [ 0 ] )
213
191
break
214
192
}
215
193
case 'thumbnailFile' : {
@@ -222,6 +200,7 @@ const AvatarDrawerContent = ({ open, mode, selectedAvatar, onClose }: Props) =>
222
200
} )
223
201
: ''
224
202
} )
203
+ state . thumbnailUrl . set ( files [ 0 ] . name )
225
204
break
226
205
}
227
206
}
@@ -337,8 +316,10 @@ const AvatarDrawerContent = ({ open, mode, selectedAvatar, onClose }: Props) =>
337
316
canvas . width = THUMBNAIL_WIDTH
338
317
canvas . height = THUMBNAIL_HEIGHT
339
318
319
+ const avatarCanvas = document . getElementById ( 'stage' ) ?. firstChild as CanvasImageSource
320
+
340
321
const newContext = canvas . getContext ( '2d' )
341
- newContext ?. drawImage ( renderer . value . domElement , 0 , 0 , canvas . width , canvas . height )
322
+ newContext ?. drawImage ( avatarCanvas , 0 , 0 , canvas . width , canvas . height )
342
323
343
324
const blob = await getCanvasBlob ( canvas )
344
325
if ( isFile ) {
@@ -418,74 +399,11 @@ const AvatarDrawerContent = ({ open, mode, selectedAvatar, onClose }: Props) =>
418
399
/>
419
400
) }
420
401
421
- { editMode . value && (
422
- < Box
423
- className = { styles . preview }
424
- style = { { width : THUMBNAIL_WIDTH + 'px' , height : THUMBNAIL_HEIGHT + 'px' , position : 'relative' } }
425
- >
426
- < div ref = { panelRef } id = "stage" style = { { width : THUMBNAIL_WIDTH + 'px' , height : THUMBNAIL_HEIGHT + 'px' } } />
427
-
428
- { avatarLoading . value && (
429
- < LoadingView
430
- title = { t ( 'admin:components.avatar.loading' ) }
431
- variant = "body2"
432
- sx = { { position : 'absolute' , top : 0 } }
433
- />
434
- ) }
435
-
436
- { ( ( state . source . value === 'file' && ! state . avatarFile . value ) ||
437
- ( state . source . value === 'url' && ! state . avatarUrl . value ) ) && (
438
- < Typography
439
- sx = { {
440
- position : 'absolute' ,
441
- display : 'flex' ,
442
- justifyContent : 'center' ,
443
- alignItems : 'center' ,
444
- height : '100%' ,
445
- width : '100%' ,
446
- fontSize : 14 ,
447
- top : 0
448
- } }
449
- >
450
- { t ( 'admin:components.avatar.avatarPreview' ) }
451
- </ Typography >
452
- ) }
453
-
454
- < Tooltip
455
- arrow
456
- title = {
457
- < Box sx = { { width : 100 } } >
458
- < Typography variant = "subtitle2" sx = { { fontWeight : 'bold' } } >
459
- { t ( 'user:avatar.rotate' ) } :
460
- </ Typography >
461
- < Typography variant = "body2" sx = { { display : 'flex' , justifyContent : 'center' } } >
462
- { t ( 'admin:components.avatar.leftClick' ) }
463
- < Icon type = "Mouse" fontSize = "small" />
464
- </ Typography >
465
-
466
- < br />
467
-
468
- < Typography variant = "subtitle2" sx = { { fontWeight : 'bold' } } >
469
- { t ( 'user:avatar.pan' ) } :
470
- </ Typography >
471
- < Typography variant = "body2" sx = { { display : 'flex' , justifyContent : 'center' } } >
472
- { t ( 'admin:components.avatar.rightClick' ) } < Icon type = "Mouse" fontSize = "small" />
473
- </ Typography >
474
-
475
- < br />
476
-
477
- < Typography variant = "subtitle2" sx = { { fontWeight : 'bold' } } >
478
- { t ( 'admin:components.avatar.zoom' ) } :
479
- </ Typography >
480
- < Typography variant = "body2" sx = { { display : 'flex' , justifyContent : 'center' } } >
481
- { t ( 'admin:components.avatar.scroll' ) } < Icon type = "Mouse" fontSize = "small" />
482
- </ Typography >
483
- </ Box >
484
- }
485
- >
486
- < Icon type = "Help" sx = { { position : 'absolute' , top : 0 , right : 0 , margin : 1 } } />
487
- </ Tooltip >
488
- </ Box >
402
+ { ! viewMode && (
403
+ < AvatarPreview
404
+ avatarUrl = { avatarSrc . value }
405
+ sx = { { width : `${ THUMBNAIL_WIDTH } px` , height : `${ THUMBNAIL_HEIGHT } px` , m : 'auto' } }
406
+ />
489
407
) }
490
408
491
409
{ state . source . value === 'file' && (
0 commit comments