-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
145 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/static/content/examples/basic/BasicAnimations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Animation, Vector3 } from '@babylonjs/core' | ||
import React, { FC, useEffect, useRef } from 'react' | ||
import { Engine, Scene, useScene } from 'react-babylonjs' | ||
|
||
/** | ||
* This is for optimizing animation when first mount application. | ||
* But this story works well,Animation is smooth。 | ||
*/ | ||
function WithAnimation() { | ||
// console.time('Timing'); | ||
|
||
const groupRef = useRef(null) | ||
const scene = useScene() | ||
|
||
const position = Vector3.Zero() | ||
|
||
const playAnimation = () => { | ||
if (groupRef.current) { | ||
const group = groupRef.current | ||
const animations = getSlideUpAnimation(position, -2) | ||
const animatable = scene!.beginDirectAnimation(group, animations, 0, 120, true) | ||
// console.timeLog('Timing', 'beginAnimation'); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
// console.timeLog('Timing', 'useEffect'); | ||
playAnimation() | ||
}, []) | ||
|
||
const onCreated = () => { | ||
// console.timeLog('Timing', 'onCreated'); | ||
} | ||
|
||
const spheres = getSpheres(10) | ||
|
||
return ( | ||
<transformNode name="group" ref={groupRef} position={position} onCreated={onCreated}> | ||
{spheres} | ||
</transformNode> | ||
) | ||
} | ||
|
||
function getSpheres(count: number) { | ||
const results = [] | ||
|
||
for (let i = -count / 2; i < count / 2; i++) { | ||
for (let j = -count / 2; j < count / 2; j++) { | ||
const key = `sphere-${i}-${j}` | ||
results.push( | ||
<sphere name={key} key={key} diameter={0.5} segments={16} position={new Vector3(i, 1, j)} /> | ||
) | ||
} | ||
} | ||
|
||
return results | ||
} | ||
|
||
function getSlideUpAnimation(position: Vector3, offsetY: number) { | ||
const { y } = position | ||
|
||
const keys = [ | ||
{ | ||
frame: 0, | ||
value: y + offsetY, | ||
}, | ||
{ | ||
frame: 60, | ||
value: y, | ||
}, | ||
{ | ||
frame: 120, | ||
value: y + offsetY, | ||
}, | ||
] | ||
|
||
const animation = new Animation('animation', 'position.y', 60, 0, 1) | ||
animation.setKeys(keys) | ||
|
||
return [animation] | ||
} | ||
|
||
export const BasicAnimations: FC = () => ( | ||
<div style={{ flex: 1, display: 'flex' }}> | ||
<Engine antialias adaptToDeviceRatio canvasId="babylonJS"> | ||
<Scene> | ||
<freeCamera | ||
name="camera1" | ||
position={new Vector3(0, 10, -20)} | ||
setTarget={[Vector3.Zero()]} | ||
/> | ||
<hemisphericLight name="light1" intensity={0.7} direction={Vector3.Up()} /> | ||
<WithAnimation /> | ||
</Scene> | ||
</Engine> | ||
</div> | ||
) | ||
|
||
export default BasicAnimations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: 'Animations' | ||
--- | ||
|
||
# Animations Example | ||
|
||
Animations can be done. this is just a test to see where the text would start | ||
wrapping. | ||
|
||
[devtool:BasicAnimations.tsx] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: 'Examples' | ||
--- | ||
|
||
These examples serve to highlight various ways to use the declarative approach | ||
to development. | ||
|
||
These include how materials are automatically assigned (or choosing where to | ||
assign), but also how to build a GUI and more advanced topics like post | ||
processing, multiple scenes/canvases and also how to use integrate a physics | ||
library and many more! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters