Hello,
I am trying to extract the three.js geometry from a Speckle object in the viewer. Ideally, I want to access the geometry using the Speckle object ID or Node ID.
So far, my attempts have been unsuccessful. I’ve tried the discussion on how to achieve this (Accessing threejs objects through viewer). However, this method requires accessing certain rendering view, but I received a bunch of these views. My challenge is identifying the correct object geometry, as the three.js geometry object varies in each view that i got somehow. Any code as to achieve it correctly will be best.
My attempt:
const worldTree = speckleViewer.getWorldTree();
const worldNodeById = worldTree.findId('82ab4d34ff57a4020912f4dd8841fefb')[0];//giving here the nodeID wich is the same as speckleObjectId
const rvsObj = renderTree.getRenderViewsForNode(worldNodeById);//getting multiple views for single node
const renderView = rvsObj[0];//getting first one as an example, but i need to understand logic which will be correct?
const threeObject = treeScene.getObjectByProperty('uuid',renderView.batchId);
I also tried to obtain a single view with the method:
const rvsObj = renderTree.getRenderViewForNodeId(id: string)
,
but it consistently returns [null].
Another approach I attempted was based on a suggestion here (Best approach to add CSS2DRenderer objects to speckle viewer). This involved locating the exact point of a user click. According to the documentation, the method
const pointLocation = selectionInfo.hits[0].point;
should return a Vector3 type representing a point in 3d-space. So there is (X,Y,Z)
The next step involves projecting this onto the user screen using
speckleViewer.Utils.NDCToScreen(x: number, y: number)
, which requires only two coordinates but we got 3 in the previous method. I am currently confused about how to proceed effectively.
The ultimate goal is to dynamically label a bunch of elements. I’ve also found an example on the official three.js page that seems straightforward. For those facing similar issues, here are some sources I’ve found and will leave here for the future:
https://threejs.org/examples/?q=label#css2d_label