diff --git a/bimsurfer/src/BimServerGeometryLoader.js b/bimsurfer/src/BimServerGeometryLoader.js index 5682251..2ddb4a4 100644 --- a/bimsurfer/src/BimServerGeometryLoader.js +++ b/bimsurfer/src/BimServerGeometryLoader.js @@ -11,13 +11,13 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { o.objectAddedListeners = []; o.prepareReceived = false; o.todo = []; - o.geometryIds = {}; - o.dataToInfo = {}; - - o.model = model; - o.roid = roid; - - console.log(globalTransformationMatrix); + o.geometryIds = {}; + o.dataToInfo = {}; + + o.model = model; + o.roid = roid; + + console.log(globalTransformationMatrix); this.addProgressListener = function (progressListener) { o.progressListeners.push(progressListener); @@ -37,10 +37,10 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { if (messageType == 0) { o._readStart(stream); - } else if (messageType == 6) { - o._readEnd(stream); - } else { - o._readObject(stream, messageType); + } else if (messageType == 6) { + o._readEnd(stream); + } else { + o._readObject(stream, messageType); } data = o.todo.shift(); @@ -77,48 +77,48 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { }); } else { - var obj = []; + var obj = []; o.groupId = o.roid; o.infoToOid = o.options.oids; - for (var k in o.infoToOid) { - var oid = parseInt(o.infoToOid[k]); - o.model.apiModel.get(oid, function(object){ - if (object.object._rgeometry != null) { - if (object.model.objects[object.object._rgeometry] != null) { - // Only if this data is preloaded, otherwise just don't include any gi - object.getGeometry(function(geometryInfo){ - obj.push({gid: object.object._rgeometry, oid: object.oid, object: object, info: geometryInfo.object}); - }); - } else { - obj.push({gid: object.object._rgeometry, oid: object.oid, object: object}); - } - } - }); - } - obj.sort(function(a, b){ - if (a.info != null && b.info != null) { - var topa = (a.info._emaxBounds.z + a.info._eminBounds.z) / 2; - var topb = (b.info._emaxBounds.z + b.info._eminBounds.z) / 2; - return topa - topb; - } else { - // Resort back to type - // TODO this is dodgy when some objects do have info, and others don't - return a.object.getType().localeCompare(b.object.getType()); - } - }); + for (var k in o.infoToOid) { + var oid = parseInt(o.infoToOid[k]); + o.model.apiModel.get(oid, function(object){ + if (object.object._rgeometry != null) { + if (object.model.objects[object.object._rgeometry] != null) { + // Only if this data is preloaded, otherwise just don't include any gi + object.getGeometry(function(geometryInfo){ + obj.push({gid: object.object._rgeometry, oid: object.oid, object: object, info: geometryInfo.object}); + }); + } else { + obj.push({gid: object.object._rgeometry, oid: object.oid, object: object}); + } + } + }); + } + obj.sort(function(a, b){ + if (a.info != null && b.info != null) { + var topa = (a.info._emaxBounds.z + a.info._eminBounds.z) / 2; + var topb = (b.info._emaxBounds.z + b.info._eminBounds.z) / 2; + return topa - topb; + } else { + // Resort back to type + // TODO this is dodgy when some objects do have info, and others don't + return a.object.getType().localeCompare(b.object.getType()); + } + }); var oids = []; obj.forEach(function(wrapper){ - oids.push(wrapper.object.object._rgeometry._i); + oids.push(wrapper.object.object._rgeometry._i); }); var query = { type: "GeometryInfo", oids: oids, include: { - type: "GeometryInfo", + type: "GeometryInfo", field: "data" } }; @@ -179,10 +179,10 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { }; this._readEnd = function (data) { - o.progressListeners.forEach(function(progressListener){ - progressListener("done", o.state.nrObjectsRead, o.state.nrObjectsRead); - }); - o.bimServerApi.call("ServiceInterface", "cleanupLongAction", {topicId: o.topicId}, function(){}); + o.progressListeners.forEach(function(progressListener){ + progressListener("done", o.state.nrObjectsRead, o.state.nrObjectsRead); + }); + o.bimServerApi.call("ServiceInterface", "cleanupLongAction", {topicId: o.topicId}, function(){}); }; this._readStart = function (data) { @@ -197,15 +197,15 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { console.log(o.protocolVersion); if (BIMSERVER_VERSION == "1.4") { - if (version != 4 && version != 5 && version != 6) { - console.error("Unimplemented version"); - return false; - } + if (version != 4 && version != 5 && version != 6) { + console.error("Unimplemented version"); + return false; + } } else { - if (o.protocolVersion != 10 && o.protocolVersion != 11 && o.protocolVersion != 12) { - console.error("Unimplemented version"); - return false; - } + if (o.protocolVersion != 10 && o.protocolVersion != 11 && o.protocolVersion != 12) { + console.error("Unimplemented version"); + return false; + } } data.align8(); @@ -220,12 +220,12 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { o.state.mode = 1; if (BIMSERVER_VERSION == "1.4") { - o.state.nrObjects = data.readInt(); + o.state.nrObjects = data.readInt(); } - o.progressListeners.forEach(function(progressListener){ - progressListener("start", o.state.nrObjectsRead, o.state.nrObjectsRead); - }); + o.progressListeners.forEach(function(progressListener){ + progressListener("start", o.state.nrObjectsRead, o.state.nrObjectsRead); + }); //o._updateProgress(); }; @@ -260,12 +260,20 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { scale * ((ymax + ymin) / 2), scale * ((zmax + zmin) / 2) ]; - + + var scaledGlobalTransformationMatrix = globalTransformationMatrix.slice(); + scaledGlobalTransformationMatrix[12] = globalTransformationMatrix[12] * scale; + scaledGlobalTransformationMatrix[13] = globalTransformationMatrix[13] * scale; + scaledGlobalTransformationMatrix[14] = globalTransformationMatrix[14] * scale; + + var transformedCenter = xeogl.math.mulMat4v4(scaledGlobalTransformationMatrix, new xeogl.math.vec4([center[0], center[1], center[2], 1])); + var finalCenter = [transformedCenter[0], transformedCenter[1], transformedCenter[2]]; + this.viewer.setCamera({ type: "persp", - target: center, + target: finalCenter, up: [0, 0, 1], - eye: [center[0] - scale * diagonal, center[1] - scale * diagonal, center[2] + scale * diagonal], + eye: [finalCenter[0] - scale * diagonal, finalCenter[1] - scale * diagonal, finalCenter[2] + scale * diagonal], far: 5000, near: 0.1, fovy: 35.8493 @@ -298,9 +306,9 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { }; this._readObject = function (stream, geometryType) { - if (BIMSERVER_VERSION != "1.4") { - stream.align8(); - } + if (BIMSERVER_VERSION != "1.4") { + stream.align8(); + } // var type = stream.readUTF8(); // var roid = stream.readLong(); // TODO: Needed? @@ -323,21 +331,21 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { var i; if (geometryType == 1) { - if (o.protocolVersion == 12) { - var hasTransparency = stream.readLong() == 1; - } + if (o.protocolVersion == 12) { + var hasTransparency = stream.readLong() == 1; + } geometryId = stream.readLong(); numIndices = stream.readInt(); if (BIMSERVER_VERSION == "1.4") { - indices = stream.readIntArray(numIndices); + indices = stream.readIntArray(numIndices); } else { - indices = stream.readShortArray(numIndices); + indices = stream.readShortArray(numIndices); } if (o.protocolVersion >= 11) { - var b = stream.readInt(); - if (b == 1) { - var color = {r: stream.readFloat(), g: stream.readFloat(), b: stream.readFloat(), a: stream.readFloat()}; - } + var b = stream.readInt(); + if (b == 1) { + var color = {r: stream.readFloat(), g: stream.readFloat(), b: stream.readFloat(), a: stream.readFloat()}; + } } stream.align4(); numPositions = stream.readInt(); @@ -346,57 +354,57 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { normals = stream.readFloatArray(numNormals); numColors = stream.readInt(); if (numColors > 0) { - colors = stream.readFloatArray(numColors); + colors = stream.readFloatArray(numColors); } else if (color != null) { - // Creating vertex colors here anyways (not transmitted over the line is a plus), should find a way to do this with scenejs without vertex-colors - colors = new Array(numPositions * 4); - for (var i=0; i= 11) { - var b = stream.readInt(); - if (b == 1) { - var color = {r: stream.readFloat(), g: stream.readFloat(), b: stream.readFloat(), a: stream.readFloat()}; - } + var b = stream.readInt(); + if (b == 1) { + var color = {r: stream.readFloat(), g: stream.readFloat(), b: stream.readFloat(), a: stream.readFloat()}; + } } - stream.align4(); + stream.align4(); numPositions = stream.readInt(); positions = stream.readFloatArray(numPositions); @@ -404,65 +412,65 @@ define(["./DataInputStreamReader"], function (DataInputStreamReader) { normals = stream.readFloatArray(numNormals); numColors = stream.readInt(); if (numColors > 0) { - colors = stream.readFloatArray(numColors); + colors = stream.readFloatArray(numColors); } else if (color != null) { - // Creating vertex colors here anyways (not transmitted over the line is a plus), should find a way to do this with scenejs without vertex-colors - colors = new Array(numPositions * 4); - for (var i=0; i