-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overall Questions #60
Comments
--
|
Great thanks so much for the info! I'll try playing around with these parameters and look more into react-dom and react-reconciler and play around with them to see if I can find a way to connect nextjs with this. I think it will be a powerful combo. |
I've had some questions too, just been watching the project though but planning to start using it for an idea I had.
|
@keverw the BabylonJS GUI is not as complete as HTML/CSS! The DOM overlays will be great when they are available. With Babylon GUI you can project onto a plane as a texture. This works in VR/XR. This GUI is on a plane and can be placed anywhere in the scene (in this example, I keep moving the plane to be in front of the camera) - give it a try in VR with your controls: |
@brianzinn Yeah I seen that demo on the computer, can't wait to try VR though in general once I get my hardware. Totally agree not as complete as HTML/CSS, but with the overlay thing should help since less of a learning curve. I think the overlay for WebXR is available now but behind a flag (For Android, but since Oculus Quest uses Android under the hood not sure if it made it to that yet - looking forward to getting one myself to learn more about VR and give a try at writing some code for it) but still bleeding edge since introduced March this year. So overtime hopefully more stable and can be supported with react-babylonjs, not sure if it'd require much changes to babylonjs as it sounded like just passing in options but unsure... I guess wanting to use this for the server side probably wouldn't be very easy? Probably requires the dom to use it with react-babylonjs and nullEngine? Would be cool though but I'm guessing most likely on server will just use BJS directly since limited things would be tracked on the server and manually adding/removing stuff. |
@brianzinn So I've done some reading with the
I think overall this package has everything it needs, just some separation is needed. I think for this aspect |
I did some adjustment to separate the engine and scene and I can now do something like export const RootScene = ({ children }) => {
const id = 'portal-canvas';
return (
<Engine portalCanvas={id}>
<Scene onSceneMount={({ scene }) => {
console.log('on scene mount')
scene.clearColor = new Color4(0, 0, 0, 1)
// This creates and positions a free camera(non - mesh)
var camera = new ArcRotateCamera("camera12", 0, 0, 5, Vector3.Zero(), scene);
camera.minZ = 0;
camera.maxZ = 50;
camera.lowerRadiusLimit = 2;
camera.upperRadiusLimit = 50;
// This targets the camera to scene origin
camera.setTarget(Vector3.Zero());
camera.position = new Vector3(0, 0, 22);
camera.wheelPrecision = 50;
}}>
<canvas id={id}></canvas>
{children}
</Scene>
</Engine>
);
} |
One thing this library wants to do is abstract away enough what is going on that you wouldn't need to create your own DOM canvas element. The Engine flows through typical properties to the auto-created canvas element. You could do the same currently like this: export const RootScene = ({ children }) => {
const id = 'portal-canvas';
return (
<Engine canvasId={id}>
<Scene onSceneMount={({ scene }) => {
console.log('on scene mount')
// rest here
}}>
{children}
</Scene>
</Engine>
);
} The The Scene is a functional component and creates the renderer, which is what renders the children. It will not render regular reactDOM elements like div. You can still create and compose your children components in there - using babylonjs JSX intrinsic elements (like <box ../>, etc.) as host components, functional components or React.Components or any combination thereof. Here is where that happens: I do think there is always room for improvement and if I can figure out what is missing or how to make a cleaner separation then I will definitely welcome changes. I've shared with you there the key places. Your fork is even with master, so I couldn't see the changes/improvements you made. I like your idea to split the project to multiple package.json - it will reduce a lot the regular dev dependencies, so will investigate that. Your original comment about |
For me I have a custom layout so that they're siblings in html, where as if using the package the child you pass to engine are direct children to the canvas since. Sorry when I was referring to the reconciler I meant removing the reconciler creation from scene ie. Line 134 in aa26d55
Possibly could move it to a provider component or just providing an option to disable reconciliation. This way this package is still usable on a custom level if someone can't use the reconciler like in my case The issue here is that I'm using next.js which internally uses ReactDOM and when using reacts context they're scoped per reconciler, and from what I can, there doesn't seem to be a solution yet to share context. In this sense I have no option but to use reactDOM so that next.js can do it's thing. I also would still like the normal html components because of seo purposes. |
I know what you mean now hopefully now that you mention the context!! It needs something like a bridge to bring the context over. |
Hi @brianzinn , great library, we have been using it for a few weeks now. We are encountering the issue @ryankauk is referring to regarding the contexts as well. Was about to post a separate issue on it, but it seems they are related. (If you want I can create a separate issue?). We are using some graphql courtesy of the apollo graphql client and react hooks to fetch some data determining the scenes. It seems like the Apollo (Context) Provider doesn't provide it's context to the components within the Engine. I think this is because the context is scoped per reconciler, as @ryankauk was mentioning in his previous comment, losing things like cache. So a bridge of some sort seems like a welcome new feature. If you'd point me in the right direction I can develop this myself but I haven't a clue where to start. Or if there is a way that we can use only one react reconciler, that would also be a solution. |
@ReinierRothuis groetjes! You won't be able to use one react-reconciler, because ReactDOM will be used for your regular website, while the canvas and BabylonJS scene are rendered with a separate one that understands the BabylonJS specific elements like camera, lights, geometries, etc. Here is a working example (modified from react-konva issue) - I will add this as a storybook playground and to readme this week: const ThemeContext = React.createContext({
color: Color3.Red(),
position: Vector3.Zero(),
name: 'default context'
});
const ThemedBox = () => {
const ctx = React.useContext(ThemeContext);
return (
<box name={ctx.name} position={ctx.position}>
<standardMaterial diffuseColor={ctx.color} specularColor={Color3.Black()} />
</box>
);
};
const EngineScene = () => (
<div style={{ flex: 1, display: 'flex' }}>
<ThemeContext.Consumer>
{value => (
<Engine antialias adaptToDeviceRatio canvasId='babylonJS' >
<Scene>
<ThemeContext.Provider value={value}>
<arcRotateCamera name="arc" target={Vector3.Zero()} minZ={0.001}
alpha={-Math.PI / 4} beta={(Math.PI / 4)} radius={5 }
/>
<hemisphericLight name='light1' intensity={0.7} direction={Vector3.Up()} />
<ground name='ground1' width={6} height={6} subdivisions={2} />
<ThemedBox />
</ThemeContext.Provider>
</Scene>
</Engine>
)}
</ThemeContext.Consumer>
</div>
)
export const BridgedContext = () => (
<ThemeContext.Provider value={{
color: Color3.FromHexString('#FFAF00'),
position: new Vector3(0, 1, 0),
name: 'testing'
}}>
<EngineScene />
</ThemeContext.Provider>
); |
Thanks a lot! We worked it out with your tips. We didn't need to build a bridge, we could just instantiate another ApolloProvider inside of the engine using the method above and bridge the client over that way. With apollo it goes like this: <ApolloConsumer>
{(client): ReactElement => (
<Engine>
<Scene>
<ApolloProvider client={client}>
<RestOfYourComponents/>
</ApolloProvider>
</Scene>
</Engine>
)}
</ApolloConsumer> |
Hey there, I think this project is great just have a few questions for clarifications and remarks.
I'm new to react now so I'm wondering why the react reconciler is necessary for this project?
I'm just wondering why this package uses react-spring, babylonjs has animations built in. Do the animations not work well with react? I just think since babylonjs is already a heavy package, the necessities to get it working with react should be as minimal as possible. Maybe if using react-spring it would be a plugin to react babylonjs or a submodule of it.
Opinions and Remarks
For example:
I'm using nextjs and would like to put the scene and engine in my _app.tsx but only want the canvas a certain width and placing html content into my pages as well as the markup inside to trigger objects.
Let me know your thoughts! :)
The text was updated successfully, but these errors were encountered: