-
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.
fix slugs with trailing /index test examples nesting categories add examples
- Loading branch information
Showing
14 changed files
with
2,471 additions
and
2,519 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
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
--- | ||
title: 'Basic' | ||
--- | ||
|
||
# Basic Examples | ||
|
||
--- | ||
|
||
No specific category | ||
|
||
- [Animations](./animations) | ||
- [Moving Boxes](./moving-boxes) |
55 changes: 55 additions & 0 deletions
55
packages/static/content/examples/basic/moving-boxes/MovingBoxes.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,55 @@ | ||
import { Color3 } from '@babylonjs/core/Maths/math.color' | ||
import { Vector3 } from '@babylonjs/core/Maths/math.vector' | ||
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh' | ||
import { Nullable } from '@babylonjs/core/types' | ||
import React, { FC, useEffect, useRef } from 'react' | ||
import { Engine, Scene, useScene } from 'react-babylonjs' | ||
|
||
type MovingBoxProps = { | ||
rotationAxis: 'x' | 'y' | 'z' | ||
position: Vector3 | ||
color: Color3 | ||
} | ||
|
||
const rpm = 5 | ||
const MovingBox: FC<MovingBoxProps> = (props: MovingBoxProps) => { | ||
// access Babylon Scene | ||
const scene = useScene() | ||
// access refs to Babylon objects in scene like DOM nodes | ||
const boxRef = useRef<Nullable<AbstractMesh>>(null) | ||
|
||
// there is also a built-in hook called useBeforeRender that does will do this: | ||
useEffect(() => { | ||
if (boxRef.current !== null && scene) { | ||
const onBeforeRender = () => { | ||
let deltaTimeInMillis = scene.getEngine().getDeltaTime() | ||
boxRef.current!.rotation[props.rotationAxis] += | ||
(rpm / 60) * Math.PI * 2 * (deltaTimeInMillis / 1000) | ||
} | ||
|
||
scene.registerBeforeRender(onBeforeRender) | ||
return () => { | ||
scene.unregisterBeforeRender(onBeforeRender) | ||
} | ||
} | ||
}, [boxRef.current]) | ||
|
||
return ( | ||
<box name="box" ref={boxRef} size={2} position={props.position}> | ||
<standardMaterial name="box-mat" diffuseColor={props.color} specularColor={Color3.Black()} /> | ||
</box> | ||
) | ||
} | ||
|
||
export default () => ( | ||
<div style={{ flex: 1, display: 'flex' }}> | ||
<Engine antialias adaptToDeviceRatio canvasId="babylonJS"> | ||
<Scene> | ||
<freeCamera name="camera1" position={new Vector3(0, 5, -10)} setTarget={[Vector3.Zero()]} /> | ||
<hemisphericLight name="light1" intensity={0.7} direction={Vector3.Up()} /> | ||
<MovingBox color={Color3.Red()} position={new Vector3(-2, 0, 0)} rotationAxis="y" /> | ||
<MovingBox color={Color3.Yellow()} position={new Vector3(2, 0, 0)} rotationAxis="x" /> | ||
</Scene> | ||
</Engine> | ||
</div> | ||
) |
9 changes: 9 additions & 0 deletions
9
packages/static/content/examples/basic/moving-boxes/index.mdx
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,9 @@ | ||
--- | ||
title: 'Moving Boxes' | ||
--- | ||
|
||
# Moving Boxes Example | ||
|
||
This highlights how you can compose a scene with other React components. | ||
|
||
[devtool:MovingBoxes.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
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// organize-imports-ignore | ||
export * from './theme' // eslint-disable-line | ||
import Layout from './layout' | ||
import Link from './link' | ||
import mdxComponents from './mdxComponents' | ||
import ThemeProvider from './theme/themeProvider' | ||
|
||
export * from './theme' // eslint-disable-line | ||
export { mdxComponents, ThemeProvider, Layout, Link } |
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
Oops, something went wrong.