11import { useAnimation , useVariable } from "../src/lib/animation"
2- import { DrawText } from "../src/lib/animation/effect/draw-text"
32import { BEZIER_SMOOTH } from "../src/lib/animation/functions"
43import { Clip } from "../src/lib/clip"
54import { seconds } from "../src/lib/frame"
65import { FillFrame } from "../src/lib/layout/fill-frame"
76import { Project , type ProjectSettings } from "../src/lib/project"
87import { TimeLine } from "../src/lib/timeline"
8+ import {
9+ THREE ,
10+ ThreeCanvas ,
11+ disposeThreeObject ,
12+ } from "../src/lib/webgl/three"
913
1014export const PROJECT_SETTINGS : ProjectSettings = {
1115 name : "framescript-template" ,
@@ -14,28 +18,72 @@ export const PROJECT_SETTINGS: ProjectSettings = {
1418 fps : 60 ,
1519}
1620
17- const HelloScene = ( ) => {
18- const progress = useVariable ( 0 )
19- const color = useVariable ( "#FFFFFF" )
21+ const CubeScene = ( ) => {
22+ const rotationY = useVariable ( 0 )
23+ const rotationX = useVariable ( 0 )
24+ const positionX = useVariable ( 0 )
25+ const scale = useVariable ( 1 )
2026
2127 useAnimation ( async ( context ) => {
2228 await context . parallel ( [
23- context . move ( progress ) . to ( 1 , seconds ( 3 ) , BEZIER_SMOOTH ) ,
24- context . move ( color ) . to ( "#75a9bd" , seconds ( 3 ) , BEZIER_SMOOTH ) ,
29+ context . move ( rotationY ) . to ( Math . PI * 2 , seconds ( 4 ) , BEZIER_SMOOTH ) ,
30+ context . move ( positionX ) . to ( 2 , seconds ( 2 ) , BEZIER_SMOOTH ) ,
2531 ] )
26- await context . sleep ( seconds ( 1 ) )
27- await context . move ( progress ) . to ( 0 , seconds ( 3 ) , BEZIER_SMOOTH )
32+ await context . parallel ( [
33+ context . move ( positionX ) . to ( - 2 , seconds ( 2 ) , BEZIER_SMOOTH ) ,
34+ context . move ( rotationX ) . to ( Math . PI , seconds ( 2 ) , BEZIER_SMOOTH ) ,
35+ ] )
36+ await context . parallel ( [
37+ context . move ( positionX ) . to ( 0 , seconds ( 2 ) , BEZIER_SMOOTH ) ,
38+ context . move ( scale ) . to ( 1.5 , seconds ( 1 ) , BEZIER_SMOOTH ) ,
39+ context
40+ . move ( rotationY )
41+ . to ( Math . PI * 4 , seconds ( 2 ) , BEZIER_SMOOTH ) ,
42+ ] )
43+ await context . move ( scale ) . to ( 1 , seconds ( 2 ) , BEZIER_SMOOTH )
2844 } , [ ] )
2945
3046 return (
31- < FillFrame style = { { alignItems : "center" , justifyContent : "center" } } >
32- < DrawText
33- text = "Hello, world!"
34- fontUrl = "assets/NotoSerifCJKJP-Medium.ttf"
35- strokeWidth = { 2 }
36- progress = { progress }
37- strokeColor = { color . use ( ) }
38- fillColor = { color . use ( ) }
47+ < FillFrame style = { { backgroundColor : "#000000" } } >
48+ < ThreeCanvas
49+ clearColor = { 0x000000 }
50+ clearAlpha = { 1 }
51+ setup = { ( { size } ) => {
52+ const scene = new THREE . Scene ( )
53+ const camera = new THREE . PerspectiveCamera (
54+ 45 ,
55+ size . cssWidth / size . cssHeight ,
56+ 0.1 ,
57+ 100 ,
58+ )
59+ camera . position . set ( 0 , 0 , 6 )
60+
61+ const ambient = new THREE . AmbientLight ( 0xffffff , 0.4 )
62+ scene . add ( ambient )
63+
64+ const directional = new THREE . DirectionalLight ( 0xffffff , 1.0 )
65+ directional . position . set ( 3 , 4 , 5 )
66+ scene . add ( directional )
67+
68+ const cube = new THREE . Mesh (
69+ new THREE . BoxGeometry ( 1.5 , 1.5 , 1.5 ) ,
70+ new THREE . MeshStandardMaterial ( { color : 0x2266ff } ) ,
71+ )
72+ scene . add ( cube )
73+
74+ return {
75+ scene,
76+ camera,
77+ update : ( { frame } ) => {
78+ cube . rotation . y = rotationY . get ( frame )
79+ cube . rotation . x = rotationX . get ( frame )
80+ cube . position . x = positionX . get ( frame )
81+ const s = scale . get ( frame )
82+ cube . scale . set ( s , s , s )
83+ } ,
84+ dispose : ( ) => disposeThreeObject ( cube ) ,
85+ }
86+ } }
3987 />
4088 </ FillFrame >
4189 )
@@ -45,8 +93,8 @@ export const PROJECT = () => {
4593 return (
4694 < Project >
4795 < TimeLine >
48- < Clip label = "Hello " >
49- < HelloScene />
96+ < Clip label = "Cube " >
97+ < CubeScene />
5098 </ Clip >
5199 </ TimeLine >
52100 </ Project >
0 commit comments