THREE.MeshLine
THREE.MeshLine copied to clipboard
Positions array is empty when using MeshLine.setGeometry(THREE.Geometry)
Passing a THREE.Geometry
to MeshLine.setGeometry()
is not working. MeshLine.positions
is empty, and MeshLine.next
and .previous
are [undefined, ...]
.
Versions are Three.js 102 and MeshLine 1.2
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(-10, 0, -5))
geometry.vertices.push(new THREE.Vector3(10, 0, -5))
var line = new MeshLine();
line.setGeometry(geometry);
// Console output
console.log('Positions', line.positions)
[Log] Positions – [] (0)
console.log('Previous', line.previous)
[Log] Previous – [undefined, undefined, undefined, …] (6)
console.log('Next', line.next)
[Log] Next – [undefined, undefined, undefined, …] (6)
Using a Float32Array works.
var geometry = new Float32Array([-10, 0, -5, 10, 0, -5])
var line = new MeshLine();
line.setGeometry(geometry);
// Console output
console.log('Positions', line.positions)
[Log] Positions – [-10, 0, -5, …] (12)
console.log('Previous', line.previous)
[Log] Previous – [-10, 0, -5, …] (12)
console.log('Next', line.next)
[Log] Next – [10, 0, -5, …] (12)
@HowardACornwell I had this issue this week. In case you're still stuck, it was because I was using the three-full npm package, which provides Typescript support to three.js.
My THREE.Geometry
was using the three-full
namespace instead of the three.js namespace, so in the source code for line.setGeometry(g)
, the following line failed (which is where the positions get added):
if (g instanceof THREE.Geometry) {
.....
}
I realised then that three.js provides it's own Typescript support, so I removed three-full
from my project and modified it to use the three.js type definitions instead. Everything worked fine then.
P.S This would also explain why your code works using Float32Array
, since the positions are added in a different code block, where the condition is:
if (g instanceof Float32Array || g instanceof Array) {
......
}
which is true in your case.