Hello Dear Community!
I am using babylonJs in my react functional component . the old version was using class component and everything was perfect. but now it’s time to add the updates so I need to make it a functional component . but I am facing now an issue during the new implementation . actually I have an array of data that must be imported . so my loop is in the ‘OnSceneReady’
Problem : the scene keeps re-rendering every second !
sceneStates?.data?.forEach((item, index) => {
let importName = item.shape.obj_path?.split("/shapes/").pop();
let importId = item.id;
AddCharacterToScene(importName, importId, item, scene, "get", index);
});
And this the addCharacterToScene function
const AddCharacterToScene = (
instanceName,
instanceId,
instance,
scene,
type,
indexOfShape
) => {
BABYLON.SceneLoader.ImportMesh(
"",
`BLOB-URL`,
instanceName,
scene,
(meshes) => {
// var root = new BABYLON.Mesh(`pivot`, scene);
var root = new BABYLON.TransformNode("root");
meshes.forEach((mesh) => {
// leave meshes already parented to maintain model hierarchy:
if (!mesh.parent) {
mesh.parent = root;
mesh.name = instanceId;
mesh.checkCollisions = true;
}
});
root.name = instanceId;
let rootChildren = root.getChildren();
let rootLength = rootChildren.length;
rootChildren.map((item) => {
item.name = root.name;
editClickedMesh(item);
});
rootChildren[rootLength - 1].isVisible = !instance.is_face_hidden;
root.position.z = instance.position_z;
root.position.x = instance.position_x;
root.scaling = new BABYLON.Vector3(
instance.scale_x,
instance.scale_y,
instance.scale_z
);
root.rotation.y = instance.angle;
attachOwnPointerDragBehavior(root, instanceId);
addLabel(root, instance.label ? instance.label : "");
addToMeshArray(root);
}
);
};
Any Suggestions will be very appreciated, And Please if there is any clear documentation of an exemplary implementation of babylonJs with react functional component
Thank You