Low-Level Havok Debug Lines Visualization

I start with an array of Vector3 arrays. Each line is only two vertices. Each line is a single color and a constant width.

With CreateLineSystem, I can use

    mesh = BABYLON.CreateLineSystem("debug collision",{ lines:lines },scene)
    mesh.color = colorsByPhysicsEventType.get(event)

This works well, but because the set of lines in a LineSystem can’t grow, a new set of lines (which could variously be more or fewer lines) needs a new LineSystem. I end up dispose() and regenerate each frame.

With GreasedLine I can generate using

mesh = BABYLON.CreateGreasedLine("debug collision", 
    { 
        points: lines,
        updatable:true,
    },{
        width:.0050,
        color: colorsByPhysicsEventType.get(event),
        materialType: BABYLON.GreasedLineMeshMaterialType.MATERIAL_TYPE_SIMPLE,
    });

And I get a similar result. Works great!

However, when I use setPoints, i have to convert the array of Vector3 arrays into arrays of float arrays. Each float array has six elements the xyz coordinates of each line’s endpoints. I also don’t see any lines beyond the number of lines in the initial GreasedLine. Do I need to also provide a new widths array and/or colors array?

const points = lines.map((a)=>[...a[0].asArray(),...a[1].asArray()])
mesh.setPoints(points,{updatable:true})

With an eye on this thread about optimizing setPoints (and after I get updating working at all), I’d like to find the most efficient mechanism of updating a GreasedLineMesh that doesn’t create a lot of objects that get garbage collected every frame.

2 Likes