1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| require(["bimsurfer/src/BimSurfer", "bimsurfer/src/BimServerModelLoader", "bimsurfer/src/StaticTreeRenderer", "bimsurfer/src/MetaDataRenderer", "bimsurfer/lib/domReady!"], function (BimSurfer, BimServerModelLoader, StaticTreeRenderer, MetaDataRenderer) {
function processBimSurferModel(bimSurferModel) {
bimSurferModel.getTree().then(function (tree) {
var domtree = new StaticTreeRenderer({ domNode: 'treeContainer' }); domtree.addModel({name: "", id: lastRevisionId, tree: tree}); domtree.build(); metadata = new MetaDataRenderer({ domNode: 'dataContainer' });
metadata.addModel({name: "", id: lastRevisionId, model: bimSurferModel});
bimSurfer.on("selection-changed", function (selected) { domtree.setSelected(selected, domtree.SELECT_EXCLUSIVE); metadata.setSelected(selected); });
domtree.on("click", function (oid, selected) { if (selected.length) { bimSurfer.viewFit({ ids: selected, animate: true }); } bimSurfer.setSelection({ ids: selected, clear: true, selected: true }); });
}); }
var bimSurfer = new BimSurfer({ domNode: "viewerContainer" }); window.bimSurfer = bimSurfer;
var bimServerClient = new BimServerClient(address, null); bimServerClient.init(function () {
bimServerClient.setToken(token, function () { var modelLoader = new BimServerModelLoader(bimServerClient, bimSurfer);
var models = {};
var nrProjects;
function loadModels(models, totalBounds) { var center = [ (totalBounds.min[0] + totalBounds.max[0]) / 2, (totalBounds.min[1] + totalBounds.max[1]) / 2, (totalBounds.min[2] + totalBounds.max[2]) / 2 ];
var globalTransformationMatrix = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -center[0], -center[1], -center[2], 1 ]; for (var roid in models) { var model = models[roid]; modelLoader.setGlobalTransformationMatrix(globalTransformationMatrix); modelLoader.loadFullModel(model).then(function (bimSurferModel) { processBimSurferModel(bimSurferModel); getModelOidAndName(bimSurferModel); }); } }
function getModelOidAndName(thisModel) { var modelObj = thisModel.apiModel.objects; Object.keys(modelObj).forEach(function (key) { if (modelObj[key].object.hasChildren === undefined) { var option = document.createElement("option"); $(option).val(key); if (modelObj[key].object.Name === undefined || modelObj[key].object.Name === "") { $(option).text(key); } else { $(option).text(modelObj[key].object.Name); } $('#select').append(option); } }); }
bimServerClient.call("ServiceInterface", "getAllRelatedProjects", {poid: poid}, function (projects) { nrProjects = projects.length; var totalBounds = { min: [Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE], max: [-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE] };
projects.forEach(function (project) {
if (project.lastRevisionId !== -1) { bimServerClient.getModel(project.oid, project.lastRevisionId, project.schema, false, function (model) { models[project.lastRevisionId] = model;
bimServerClient.call("ServiceInterface", "getModelMinBounds", {roid: project.lastRevisionId}, function (minBounds) { bimServerClient.call("ServiceInterface", "getModelMaxBounds", {roid: project.lastRevisionId}, function (maxBounds) { if (minBounds.x < totalBounds.min[0]) { totalBounds.min[0] = minBounds.x; } if (minBounds.y < totalBounds.min[1]) { totalBounds.min[1] = minBounds.y; } if (minBounds.z < totalBounds.min[2]) { totalBounds.min[2] = minBounds.z; } if (maxBounds.x > totalBounds.max[0]) { totalBounds.max[0] = maxBounds.x; } if (maxBounds.y > totalBounds.max[1]) { totalBounds.max[1] = maxBounds.y; } if (maxBounds.z > totalBounds.max[2]) { totalBounds.max[2] = maxBounds.z; } nrProjects--; if (nrProjects === 0) { loadModels(models, totalBounds); } }); }); }); } else { nrProjects--; if (nrProjects === 0) { loadModels(models, totalBounds); } } }); }); }); }); });
|