I tried putting the code from here:
inside useEffect(() => {}
but after looking here : https://github.com/BabylonJS/BabylonReactNative/tree/master/Modules/%40babylonjs/react-native
and in what was already inside the babylon react native template i managed to get to this :
if (engine) {
const scene = new Scene(engine);
setScene(scene);
//scene.createDefaultCamera(true, undefined, true);
//setCamera(scene.activeCamera!);
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene), True;
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl();
setCamera(scene.activeCamera!);
var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 10, 0), scene);
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2, segments: 32}, scene);
sphere.position = new BABYLON.Vector3(2,1,0);
var ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 6, height: 6}, scene);
const groundMaterial = new BABYLON.StandardMaterial("Ground Material", scene);
groundMaterial.diffuseColor = BABYLON.Color3.Red();
ground.material = groundMaterial;
}
}, [engine]);
At first it couldn’t find BABYLON so i had to apparently add this :
import * as BABYLON from '@babylonjs/core';
Now, i finally have a starting point that work.
I’m wondering where to go from here and i have lots of questions.
I’m guessing that following the tutorials from react native : Learn the Basics · React Native
will help me better understand the template but where can i find how to organize a babylon game project code (i come from c++ and python)
Should i put everything in useEffect(() => {}
or should i use multiple files ?
I just found this page : GitHub - Symbitic/awesome-babylonjs: A curated list of awesome things related to Babylon.js and i’m planning to buy “Going the Distance with Babylon.js”, do anyone know of any good beginner friendly ressources ?