I have initialed a line mesh entity but was unable to update the position of the mesh vertex.
// Create mesh instance
var meshInstance = new pc.MeshInstance(node, mesh, material);
// Create model
var model = new pc.Model();
model.graph = node;
model.meshInstances = [meshInstance];
// Create child entity
var childEntity = new pc.Entity();
childEntity.name = "LineEntity";
childEntity.addComponent('model', {
type: 'asset'
});
childEntity.model.model = model;
// Add the child entity to the current entity
this.entity.addChild(childEntity);
// Store the child entity for future use (e.g., to enable/disable it)
this.lineEntity = childEntity;
I would like to update the vertex in game but I couldn’t access the mesh and got undefined error in meshInstance.mesh
// an array for use in mesh vertex array
var positions = new Float32Array([
pos0.x, pos0.y, pos0.z, // pos 0
pos1.x, pos1.y, pos1.z, // pos 1
pos2.x, pos2.y, pos2.z, // pos 2
pos3.x, pos3.y, pos3.z // pos 3
]);
// update mesh Position if lineEntity is ready
if (this.lineEntity) {
this.lineEntity.model.meshInstance.mesh.setPositions(positions);
this.lineEntity.model.meshInstance.mesh.update();
}