Skip to content

Commit

Permalink
[ncl] fix GLThreeSprite example (#9911)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 committed Aug 25, 2020
1 parent 08b9659 commit 3e69bc1
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions apps/native-component-list/src/screens/GL/GLThreeSprite.tsx
Expand Up @@ -37,36 +37,6 @@ export default function GLThreeSprite() {
}
}, [animate]);

React.useEffect(() => {
if (!gl.current || scene.current) {
return;
}
scene.current = new Scene();
camera.current = new PerspectiveCamera(
75,
gl.current.drawingBufferWidth / gl.current.drawingBufferHeight,
0.1,
1000
);

renderer.current = new Renderer({ gl: gl.current });
renderer.current.setSize(gl.current.drawingBufferWidth, gl.current.drawingBufferHeight);
renderer.current.setClearColor(0xffffff);

const spriteMaterial = new SpriteMaterial({
map: new TextureLoader().load(require('../../../assets/images/nikki.png')),
color: 0xffffff,
});
const sprite = new Sprite(spriteMaterial);
scene.current.add(sprite);

camera.current.position.z = 3;

animate();
renderer.current.render(scene.current, camera.current);
gl.current.endFrameEXP();
}, [gl.current, animate]);

const onLayout = React.useCallback(({ nativeEvent: { layout } }: LayoutChangeEvent) => {
if (camera.current) {
camera.current.aspect = layout.width / layout.height;
Expand All @@ -81,6 +51,30 @@ export default function GLThreeSprite() {
const onContextCreate = React.useCallback(
async (context: ExpoWebGLRenderingContext) => {
gl.current = context;
scene.current = new Scene();
camera.current = new PerspectiveCamera(
75,
gl.current.drawingBufferWidth / gl.current.drawingBufferHeight,
0.1,
1000
);

renderer.current = new Renderer({ gl: gl.current });
renderer.current.setSize(gl.current.drawingBufferWidth, gl.current.drawingBufferHeight);
renderer.current.setClearColor(0xffffff);

const spriteMaterial = new SpriteMaterial({
map: new TextureLoader().load(require('../../../assets/images/nikki.png')),
color: 0xffffff,
});
const sprite = new Sprite(spriteMaterial);
scene.current.add(sprite);

camera.current.position.z = 3;

animate();
renderer.current.render(scene.current, camera.current);
gl.current.endFrameEXP();
},
[animate]
);
Expand Down

0 comments on commit 3e69bc1

Please sign in to comment.