React for Babylon 3D engine
‘react-babylonjs’ integrates the Babylon.js real time 3D engine with React
react-babylonjs
lets you build your scene and components using a familiar
declarative syntax with the benefits of reusable components and hooks. The
Babylon.js API is mostly covered declaratively thanks to code generation and
even custom props allow you to declaratively add shadows, physics, 3D models,
attach 2D/3D UI to meshes, etc.
Fully supports hooks. Full support for TypeScript with auto-completion on
elements and compile time checks. Context API and hooks provide easy access to
Scene/Engine/Canvas.
No third party dependencies outside of React + babylon.js
https://brianzinn.github.io/react-babylonjs/
~50 sample web pages with viewable source code on:
github pages examples.
No online examples for native, but you can integrate usingEngineCanvasContext.Provider
:
import React, { useState } from 'react';
import { View } from 'react-native';
import { EngineView, useEngine } from '@babylonjs/react-native';
import { Camera } from '@babylonjs/core';
import { EngineCanvasContext, Scene } from 'react-babylonjs';
const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
const engine = useEngine();
const [camera, setCamera] = useState<Camera>();
return (
<View style={props.style}>
<EngineCanvasContext.Provider value={{ engine, canvas: null }}>
{engine &&
<Scene>
<arcRotateCamera
name="camera1"
onCreated={camera => setCamera(camera)}
/>
<hemisphericLight name="light1" ></hemisphericLight>
{ /* rest of declarative scene/components here */ }
</Scene>
}
</EngineCanvasContext.Provider>
<EngineView camera={camera} displayFrameRate={true} ></EngineView>
</View>
);
};
react-babylon-spring
-CascadedShadowGenerator
, createPortal
and Html
(project HTML in scene -drei
). Also, stories forRenderOnDemand
to customize render loops.<pointsCloudSystem ...></pointsCloudSystem>
as hostreact-babylon-spring
integration and added GH action for StorybookisPaused
Engine prop to skipThanks also to all the people who have contributed with
issues/questions/discussions. All the great ideas and requests are why this
project evolved beyond an experiment.
Made with ♥