Help - Viewer Extension to modified Linework | LineBatch

Hi Speckle Community,

I’m working on a modified version of the custom 3d visual for a Power-BI project. I am trying to add an extension that moves the model elements vertically (similar to the explode extension but a little different).

The issue I’m hitting is that my model has the floor plan geometry as linework elements and not meshes. The extension examples that I’ve looked at modify geometry though the batchObject which comes from the meshBatch class. Linework goes into a LineBatch class that doesn’t seem to support modification.

Does anyone know how to manipulate the lines in a LineBatch similar to a MeshBatch?

The images below show the issue. the first image shows the floor plans and linework correctly. The second images shows that went the geometry is moved vertically, the linework doesn’t move with it.


ps. In case it matters, all the linework is grouped into block instances for each building and floor. I was hopeful that I could modify the transform of the block instances, but the batcher does not appear to respect that hierarchy.

Hi @miketalbott

You are indeed right, the current BatchObject implementation from the viewer library does not support Line or Point based geometries. This means that there is no out-of-the-box way of transforming lines and points at runtime like you can do with meshes. We are loosely planning on adding this feature to lines and points in the future.

The good news is that you can still do it! One thing we’ve been trying to stick to, is to let users be able to mix in with our viewer library, stock three.js stuff that they might be already familiar with. In that spirit, a LineBatch has a renderObject that gets added to the three.js scene which is a subclass of a Mesh, more specifically a LineSegments2. That means we have access to it’s underlying geometry and attributes, so we can get to work on them!

I’ve made two live examples for you. The first one is probably what you are looking for and it shows how to transform entire LineBatchs. For completeness’s sake, I’ve also made a second live example which exemplifies how individual lines objects can be transformed. More specifically, in this second example you need to select one or more lines that will get transformed by the values you set in the UI.

Some notes:

  • I’m only translating in the examples for the sake of simplicity, but you can apply a more complicated transformation to the lines using the same code.
  • Examples don’t keep complete track of each line object’s current transformation, but rather a delta translation is always applied to them, again for the sake of simplicity.
  • Examples are not properly conforming to the underlying RTE (relative to eye rendering) that the viewer runs by default. This means that if your line geometries are in need of a floating point precision greater than 32bit, like in the case where they are thousands of kilometers away from the world origin, this approach will probably not be RTE accurate and you will loose precision. We can change the examples to conform to proper RTE, but I guess we’ll cross that bridge when we’ll get to it :slight_smile:
  • Because we’re transforming lines by changing the actual geometry position attribute values, this approach can prove inefficient for a very large number of lines. Faster solutions exist but are more complicated

We’re always happy to see people build their own applications/spinoffs with the speckle viewer. :slight_smile: Maybe you’d like to showcase what you are working on :wink:

Let us know if you need help with anything else!

Cheers

Alex!

This is amazing! Thank you so much for taking the time to demonstrate the power of speckle.

I was poking at the LineSegment2 but just wasn’t able to get changes to update the renderer. I’ll take a closer look at your examples. I’m sure they will unlock the solution.

I’ll report back when I get a chance to dig back into this.

Thanks again!

1 Like