-
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.
#164 WIP - Error: "Expected host context to exist. This error is like…
…ly caused by a bug in React. Please file an issue."
- Loading branch information
Showing
4 changed files
with
65 additions
and
7 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
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,51 @@ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import '@babylonjs/inspector'; | ||
import { Engine, Scene, useBeforeRender, createPortal } from '../../../../dist/react-babylonjs'; | ||
import { Vector3 } from '@babylonjs/core/Maths/math' | ||
import '../../style.css' | ||
|
||
export default { title: 'Babylon Basic' }; | ||
|
||
const rpm = 5; | ||
|
||
function WithCreatePortal() { | ||
const transformNodeRef = useRef(null); | ||
const [_, setReady] = useState(false); | ||
|
||
useBeforeRender((scene) => { | ||
if (transformNodeRef.current !== null) { | ||
const deltaTimeInMillis = scene.getEngine().getDeltaTime(); | ||
transformNodeRef.current.rotation.y += ((rpm / 60) * Math.PI * 2 * (deltaTimeInMillis / 1000)); | ||
} | ||
}) | ||
|
||
useEffect(() => { | ||
console.log('trigger re-render when transform node is set.'); | ||
setReady(true); | ||
}, [transformNodeRef.current]) | ||
|
||
return ( | ||
<> | ||
<transformNode name="transform-node" ref={transformNodeRef}> | ||
{(transformNodeRef.current) && | ||
createPortal(<box position={new Vector3(0, 1, 0)} />, transformNodeRef.current) | ||
} | ||
<ground name='ground1' width={6} height={6} subdivisions={2} position={new Vector3(0, 0, 0)} /> | ||
</transformNode> | ||
</> | ||
) | ||
} | ||
|
||
export const CreatePortal = () => ( | ||
<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()} /> | ||
<WithCreatePortal /> | ||
</Scene> | ||
</Engine> | ||
</div> | ||
) |