Hello,
I am new to three.js. I am extending an existing application (three.js version 73) and have troubles updating a mesh.
The apllication (actually a chart) renders Lines and uses a BufferGeometry.
The positions in the BufferGeomerty are updated and they are displayed ok.
I added 2 meshes to visualize upper and lower limits.
This works when it is rendered the first time.
When the data is updated the meshes are not shown.
This is what my code looks like
- Create Buffergeometry and lines/meshes
const GPU_DATA_LEN = 1000;
this._geom = new THREE.BufferGeometry();
this._geom.dynamic = true;
this._geom.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( GPU_DATA_LEN * 3 ), 3 ) );
if( line ) {
this._mat = new THREE.LineBasicMaterial();
this._mat.color = new THREE.Color(this._color);
this._mat.needsUpdate = true;
this._line = new THREE.Line(this._geom, this._mat);
}
else {
this._mat = new THREE.MeshBasicMaterial({
color: this._color === null ? 0 : this._color,
//color: fillStyle < 0 ? 'blue' : 'green',
transparent: true,
opacity: .15
});
this._line = new THREE.Mesh( this._geom, this._mat );
}
2a. Update of lines
Get the positions attribute and update the position
updateLines( xValues, step ) {
const len = xValues.length;
const attr = this._geom.getAttribute('position');
for (; i < len; i++, k += step) {
attr.setXY(i, xValues[i], this._data[k]);
}
attr.needsUpdate = true;
this._line.matrix.multiplyMatrices(
this._axis.transformMatrix(),
(new THREE.Matrix4()).makeScale(xScale, 1, 1)
);
}
2b. Update of meshes
_updateShape( xValues ) {
const shape = Shape();
shape.moveto();
shape.lineto();
...
this._geom.fromGeometry( new THREE.ShapeGeometry( shape ));
// get Transform-Matrix for y scale and y offset
const m = this._axis.transformMatrix();
const m2 = (new THREE.Matrix4()).makeScale(xScale, 1, 1);
this._line.applyMatrix( m );
this._line.applyMatrix( m2 );
}
I assume that the way the BufferGeometry is handled is not correct.
Maybe someone has a hint why it is not working.
Regards
Rüdiger