11import config from '@ir-engine/common/src/config'
22import {
3+ Easing ,
34 Entity ,
45 UUIDComponent ,
56 UndefinedEntity ,
@@ -18,7 +19,7 @@ import {
1819} from '@ir-engine/engine/src/interaction/components/InteractableComponent'
1920import { ImageComponent } from '@ir-engine/engine/src/scene/components/ImageComponent'
2021import { LinkComponent } from '@ir-engine/engine/src/scene/components/LinkComponent'
21- import { MediaComponent } from '@ir-engine/engine/src/scene/components/MediaComponent'
22+ import { MediaComponent , setTime } from '@ir-engine/engine/src/scene/components/MediaComponent'
2223import { ParticleSystemComponent } from '@ir-engine/engine/src/scene/components/ParticleSystemComponent'
2324import { PrimitiveGeometryComponent } from '@ir-engine/engine/src/scene/components/PrimitiveGeometryComponent'
2425import { SDFComponent } from '@ir-engine/engine/src/scene/components/SDFComponent'
@@ -39,10 +40,11 @@ import { setVisibleComponent } from '@ir-engine/spatial/src/renderer/components/
3940import { ObjectLayerMasks } from '@ir-engine/spatial/src/renderer/constants/ObjectLayers'
4041import { EntityTreeComponent } from '@ir-engine/spatial/src/transform/components/EntityTree'
4142import React , { useEffect } from 'react'
42- import { MathUtils } from 'three'
43+ import { MathUtils , Quaternion } from 'three'
4344import { useAvatars } from '../../engine/TestUtils'
4445import { useExampleEntity } from '../utils/common/entityUtils'
4546import ComponentNamesUI from './ComponentNamesUI'
47+ import { Q_IDENTITY , Q_Y_180 } from '@ir-engine/spatial/src/common/constants/MathConstants'
4648
4749export const metadata = {
4850 title : 'Components Examples' ,
@@ -80,6 +82,63 @@ export const subComponentExamples = [
8082 return null
8183 }
8284 } ,
85+ {
86+ name : 'Transitions' ,
87+ description : 'Add transitions to your scene' ,
88+ Reactor : ( props : { parent : Entity ; onLoad : ( entity : Entity ) => void } ) => {
89+ const { parent, onLoad } = props
90+ const entity = useExampleEntity ( parent )
91+ const gltfComponent = useOptionalComponent ( entity , GLTFComponent )
92+
93+ useEffect ( ( ) => {
94+ setComponent ( entity , NameComponent , 'Transition-Example' )
95+ setComponent ( entity , GLTFComponent , {
96+ cameraOcclusion : true ,
97+ src :
98+ config . client . fileServer +
99+ '/projects/ir-engine/ir-development-test-suite/assets/GLTF/Flight%20Helmet/FlightHelmet.gltf'
100+ } )
101+ setVisibleComponent ( entity , true )
102+ getComponent ( entity , TransformComponent ) . scale . set ( 3 , 3 , 3 )
103+
104+ let id :any
105+
106+ const transitionA = ( ) => {
107+ TransformComponent . setTransition ( entity , 'position.y' , 2 , {
108+ duration : 1000 ,
109+ easing : Easing . exponential . inOut
110+ } )
111+ TransformComponent . setTransition ( entity , 'rotation' , Q_Y_180 , {
112+ duration : 500 ,
113+ easing : Easing . exponential . inOut
114+ } )
115+ id = setTimeout ( transitionB , 1000 )
116+ }
117+
118+ const transitionB = ( ) => {
119+ TransformComponent . setTransition ( entity , 'position.y' , 0 , {
120+ duration : 1000 ,
121+ easing : Easing . exponential . inOut
122+ } )
123+ TransformComponent . setTransition ( entity , 'rotation' , Q_IDENTITY , {
124+ duration : 500 ,
125+ easing : Easing . exponential . inOut
126+ } )
127+ id = setTimeout ( transitionA , 1000 )
128+ }
129+
130+ transitionA ( )
131+
132+ return ( ) => clearTimeout ( id )
133+ } , [ ] )
134+
135+ useEffect ( ( ) => {
136+ if ( gltfComponent ?. progress . value === 100 ) onLoad ( entity )
137+ } , [ gltfComponent ?. progress ] )
138+
139+ return null
140+ }
141+ } ,
83142 {
84143 name : 'Avatars' ,
85144 description : 'Add avatars to your scene' ,
0 commit comments