While rendering the model using reactjs with npm @Babylonjs/core packages. My model is lacking and taking more time to load and sometimes my model color is going white. Also, I am getting some warnings like:
**
page-flip.browser.js:1 [Violation] Added non-passive event listener to a scroll-blocking ‘touchstart’ event. Consider marking event handler as ‘passive’ to make the page more responsive. See Chrome Platform Status
**
My Code is :
import React from 'react'
import { Scene, Engine, Vector3, HemisphericLight, SceneLoader, ArcRotateCamera, Color4, ValidatedNativeDataStream } from "@babylonjs/core"
import { useEffect } from 'react'
import "@babylonjs/loaders"
import './canvas.css'
import { useRef } from 'react'
const Canvas = ({ poppet }) => {
let isLoadOne = false;
const canvas=useRef({})
canvas.current=document.querySelector('canvas');
let engine = new Engine(canvas.current, true);
useEffect(() => {
(async () => {
let scene = new Scene(engine)
try {
scene = await createScene(canvas.current, scene, poppet)
if (!isLoadOne) {
isLoadOne = true;
await engine.runRenderLoop(async () => {
await scene.render();
})
}
} catch (e) {
console.log(e)
}
})()
}, [poppet])
const createScene = async (canvas, scene, fileName = "barrel.glb") => {
const camera = new ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2, -2, new Vector3(0, 0.5, 0), scene, true)
camera.attachControl(canvas, true);
camera.detachControl();
const hemiLight = new HemisphericLight("light1", new Vector3(0, 1, 0), scene);
hemiLight.intensity = 4
await SceneLoader.ImportMeshAsync(null, "./models/", fileName, scene)
scene.clearColor = new Color4(0, 0, 0, 0)
return scene
}
return (
<canvas></canvas>
)
}
export default Canvas
I am a beginner. Please help me out with this issue.
Thank you