Slavik
November 13, 2024, 2:13pm
1
Hi everyone!
I’m new to the babylon.js and have trouble with instances.
This is how i create main mesh with normal material, also tried with material for instances
this.main.mesh = BB.MeshBuilder.CreateRibbon(
`main`,
{
pathArray: paths,
sideOrientation: 2
},
this.scene
);
this.main.mesh.isVisible = true;
this.main.mesh.material = this.gMat;
And this is instance with Hahok
as engine and PhysicsAggregate
const instance: InstancedMesh = MeshBuilder.CreateRibbon(
`G-${GX}-${GZ}`, {
pathArray: paths,
sideOrientation: 1,
instance: this.main.mesh
},
this.scene
);
const groundAggregate = new PhysicsAggregate(
instance,
PhysicsShapeType.MESH,
{
friction: 0.9,
mass: 0
},
this.scene
);
if (this.devSettings.debug.meshes && map.physicsBody) {
this.physicsViewer.showBody(instance.physicsBody);
}
No matter what i do, material / color is not displayed on the instance, only grid from debugger
Also like that produce same result
const instance = this.main.mesh.createInstance(`G-${GX}-${GZ}`);
labris
November 13, 2024, 2:39pm
2
Slavik:
MeshBuilder.CreateRibbon
Here the optional parameter instance
is an instance of an existing Ribbon object to be updated with the passed pathArray
parameter.
So if you want to create a separate instance of the main.mesh
, this should work
const instance = this.main.mesh.createInstance(
G-${GX}-${GZ});
Slavik
November 13, 2024, 2:50pm
3
You right.
This code idd produce instance, my mistale.
const instance = this.main.mesh.createInstance(G-${GX}-${GZ});
But i can’t update “pathArray” in that case, after instance is created, right ?
And if so, i can’t make new shape out of it ?
And how is it possible that i can see whole terrain via Havok debug ?
labris
November 13, 2024, 2:55pm
4
You may use clones in this case.
A simple example in PG will help a lot.
Slavik
November 13, 2024, 2:55pm
5
I tried to do something like that, in the hope that i can adjust positions, but no effect
const _map = this.main.mesh.createInstance(`G-${GX}-${GZ}`);
map = BB.MeshBuilder.CreateRibbon(`G-${GX}-${GZ}`, { pathArray: paths, instance: _map }, this.scene);
Slavik
November 13, 2024, 2:56pm
6
And clone, is it just like creating new Mesh, or cheap as instance ?
I think instancing may be is not suitable for my task
labris
November 13, 2024, 3:00pm
7
It is cheaper than new Mesh, but not so cheap as instance
But with clones you may need makeGeometryUnique()
to create a un-shared specific occurence of the geometry for the mesh.