-
Notifications
You must be signed in to change notification settings - Fork 23
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
27 changed files
with
3,017 additions
and
799 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
dist | ||
example | ||
src/generated |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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,29 @@ | ||
import { useState } from 'react'; | ||
import './App.css'; | ||
import Counter from './examples/Counter'; | ||
import MP4Player from './examples/MP4Player'; | ||
|
||
const EXAMPLES = { | ||
'counter': <Counter />, | ||
'mp4': <MP4Player /> | ||
}; | ||
|
||
function App() { | ||
const [currentExample, setCurrentExample] = useState<keyof typeof EXAMPLES>('counter'); | ||
|
||
return ( | ||
<> | ||
<h1>Browser Renderer Examples</h1> | ||
<div className="examples-tabs"> | ||
<button onClick={() => setCurrentExample('counter')}>Counter</button> | ||
<button onClick={() => setCurrentExample('mp4')}>MP4</button> | ||
</div> | ||
<div className="card"> | ||
{EXAMPLES[currentExample]} | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
|
||
export default App; |
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,73 @@ | ||
|
||
import { useEffect, useRef, useState } from 'react'; | ||
import { useRenderer } from './utils'; | ||
|
||
function Counter() { | ||
const canvasRef = useRef<HTMLCanvasElement | null>(null); | ||
const [count, setCount] = useState(0); | ||
const renderer = useRenderer(); | ||
|
||
useEffect(() => { | ||
if (renderer == null) { | ||
return; | ||
} | ||
|
||
renderer.updateScene( | ||
'output', | ||
{ width: 256, height: 256 }, | ||
{ | ||
type: 'view', | ||
children: [ | ||
{ | ||
type: 'view', | ||
direction: 'column', | ||
top: 0, | ||
left: 50, | ||
children: [ | ||
{ | ||
type: 'image', | ||
image_id: 'img', | ||
}, | ||
{ | ||
type: 'text', | ||
font_size: 30, | ||
font_family: 'Noto Sans', | ||
text: `Count is ${count}`, | ||
align: 'center', | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
); | ||
|
||
let pts = 0; | ||
const renderInterval = setInterval(() => { | ||
const input = { | ||
ptsMs: pts, | ||
frames: {}, | ||
}; | ||
const outputs = renderer.render(input); | ||
const frame = outputs.frames['output']; | ||
const resolution = frame.resolution; | ||
const canvas = canvasRef.current; | ||
const context = canvas!.getContext('2d'); | ||
context?.putImageData(new ImageData(frame!.data, resolution.width, resolution.height), 0, 0); | ||
|
||
pts += 30; | ||
}, 30); | ||
|
||
return () => clearInterval(renderInterval); | ||
}, [renderer, count]); | ||
|
||
return ( | ||
<> | ||
<div className="card"> | ||
<canvas ref={canvasRef} width={300} height={300}></canvas> | ||
<button onClick={() => setCount(count => count + 1)}>Count +1</button> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default Counter; |
Oops, something went wrong.