javascript - Confused with Viewer API vs example, passing options to extensions -
i confused examples on how use viewer don't seem match documentation of api, functions not in docs or signature different.
base on examples code, how pass options extensions instantiate? pass extension callback.
thanks!
we need fix doc not rely anymore on undocumented a360 viewer additional code, supposed internal. sorry incovenience, asap...
for time being, can use code viewer boilerplate sample:
function initializeviewer(containerid, urn) { autodesk.viewing.document.load(urn, function (model) { var rootitem = model.getrootitem(); // grab 3d items var geometryitems3d = autodesk.viewing.document.getsubitemswithproperties( rootitem, { 'type': 'geometry', 'role': '3d' }, true); // grab 2d items var geometryitems2d = autodesk.viewing.document.getsubitemswithproperties( rootitem, { 'type': 'geometry', 'role': '2d' }, true); var domcontainer = document.getelementbyid(containerid); //ui-less version: viewer without autodesk buttons , commands //viewer = new autodesk.viewing.viewer3d(domcontainer); //gui version: viewer controls viewer = new autodesk.viewing.private.guiviewer3d(domcontainer); viewer.initialize(); viewer.setlightpreset(8); //button events - 2 buttons load/unload sample extension // irrelevant viewer code var loadbtn = document.getelementbyid('loadbtn'); loadbtn.addeventlistener("click", function(){ loadextension(viewer); }); var unloadbtn = document.getelementbyid('unloadbtn'); unloadbtn.addeventlistener("click", function(){ unloadextension(viewer); }); // illustrates how listen events // geometry loaded fired once model loaded // safe perform operation involving model structure @ point viewer.addeventlistener( autodesk.viewing.geometry_loaded_event, ongeometryloaded); //optional var options = { globaloffset: { x: 0, y: 0, z: 0 } } // pick first 3d item ortherwise first 2d item var viewablepath = (geometryitems3d.length ? geometryitems3d[0] : geometryitems2d[0]); viewer.loadmodel( model.getviewablepath(viewablepath), options); }, function(err) { logerror(err); }); }
once viewer initialized, can load independently each extension , pass callback follow:
var options = { oncustomeventfiredbymyextension: function() { console.log('lmv rulez!') } } viewer.loadextension('myextensionid', options)
but think more elegant approach fire events extension itself, may this:
viewer.loadextension('myextensionid') var myextension = viewer.getextension('myextensionid') myextension.on('customevent', function () { console.log('lmv still rulez!') })
see micro-events super simple event library.
Comments
Post a Comment