Greg Bluntzer
Greg Bluntzer

Reputation: 333

Autodesk Forge Viewer How to get coordinates of line start/stop

I am trying to do room highlighting in forge viewer.

In revit I have created lines that represent the borders of a room. After conversion to svf I know the dbids of those lines. Now I want to know the start and stop points (vertices) of those lines so that I can create a Three.Shape() of the room borders.

[EDIT] I get the fragId from dbId

function getFragIdFromDbId(viewer, dbid){
var returnValue;
 var it = viewer.model.getData().instanceTree;       
it.enumNodeFragments(dbid, function(fragId) {
  console.log("dbId: " + dbid + " FragId : " + fragId);
  returnValue =  fragId;
}, false);
return returnValue;
}

Question: Once I know the fragId is there a way to see its start and stop points(vertices)? Also will those vertices be world space or local space?

Upvotes: 2

Views: 1217

Answers (1)

Greg Bluntzer
Greg Bluntzer

Reputation: 333

This is what I ended up doing. Note make sure the model is finished loading before calling instanceTree. Also in my case the dbid and fragid where one to one, not sure if this will always be the case in the instance tree.

function getFragIdFromDbId(viewer, dbid) {
 var returnValue;
 var it = viewer.model.getData().instanceTree;
 it.enumNodeFragments(dbid, function (fragId) {
  console.log("dbId: " + dbid + " FragId : " + fragId);
  returnValue = fragId;
 }, false);
 return returnValue;
}

...

// only need the start vertex
var floatArray = [];
for (var i = 0; i < dbidArray.length; i++) {
var fragId = getFragIdFromDbId(viewer, dbidArray[i]);
var mesh = viewer.impl.getRenderProxy(viewer.model, fragId);
var matrixWorld = mesh.matrixWorld;
var lmvBufferGeometry = mesh.geometry;
var lmvFloatArray = lmvBufferGeometry.vb; //this will have an array of 6  values 0,1,2 are start vertext , 3,4,5 are end vertex

floatArray.push(lmvFloatArray[0]);
floatArray.push(lmvFloatArray[1]);
floatArray.push(lmvFloatArray[2]);

}
//use matrixWorld to convert array to worldSpace

Upvotes: 2

Related Questions