Skip to content

Instantly share code, notes, and snippets.

@wallabyway
Created January 22, 2018 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallabyway/9dd68b7db00bc4c73281f22798462b9f to your computer and use it in GitHub Desktop.
Save wallabyway/9dd68b7db00bc4c73281f22798462b9f to your computer and use it in GitHub Desktop.
// serializes Area-Measurement objects to JSON
this.getJson = function() {
// remove all indicator objects to avoid circular reference
const list = _measurementsManager.measurementsList;
Object.keys(list).map(i=>{ delete(list[i].indicator) });
var tmp = JSON.stringify(list);
Object.keys(list).map(i=>{ list[i].attachIndicator(_viewer, this, avem.MeasureToolIndicator) })
return tmp;
}
// de-serializes JSON into Area-Measurement objects
this.loadJson = function(json) {
for (var key in json)
this.addMeasurement(json[key])
}
this.addPick = function(inp) {
var json = JSON.parse(JSON.stringify(inp));
var p = _currentMeasurement.setPick(json.id, new Autodesk.Viewing.Extensions.Measure.SnapResult())
Object.assign(p, {
geomType:json.geomType,
fromTopology:false,
viewportIndex2d:json.viewportIndex2d,
geomVertex: new THREE.Vector3(json.geomVertex.x,json.geomVertex.y,json.geomVertex.z),
intersectPoint: new THREE.Vector3(json.intersectPoint.x,json.intersectPoint.y,json.intersectPoint.z),
radius:json.radius
});
}
this.addMeasurement = function(json) {
_currentMeasurement = _measurementsManager.createMeasurement(json.measurementType);
_currentMeasurement.MarkupID = json.id;
for (var key in json.picks) {
if (!json.picks[key])
delete(json.picks[key])
else
this.addPick(json.picks[key])
}
_currentMeasurement.closedArea = true;
_activePoint = Object.keys(json.picks).length+1;
//clean up non object arrays
_currentMeasurement.attachIndicator(_viewer, this, avem.MeasureToolIndicator);
this.onMeasurementChanged();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment