@xeokit/xeokit-sdk 2.4.0-alpha-42 → 2.4.0-alpha-44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16550,9 +16550,18 @@ class RenderBuffer {
16550
16550
  const canvas = imageDataCache.canvas;
16551
16551
  const imageData = imageDataCache.imageData;
16552
16552
  const context = imageDataCache.context;
16553
- gl.readPixels(0, 0, this.buffer.width, this.buffer.height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
16553
+ const { width, height } = this.buffer;
16554
+ gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
16554
16555
  imageData.data.set(pixelData);
16555
16556
  context.putImageData(imageData, 0, 0);
16557
+
16558
+ // flip Y
16559
+ context.save();
16560
+ context.globalCompositeOperation = 'copy';
16561
+ context.scale(1, -1);
16562
+ context.drawImage(canvas, 0, -height, width, height);
16563
+ context.restore();
16564
+
16556
16565
  let format = params.format || "png";
16557
16566
  if (format !== "jpeg" && format !== "png" && format !== "bmp") {
16558
16567
  console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");
@@ -103273,7 +103282,7 @@ class PropertySet {
103273
103282
  /**
103274
103283
  * @private
103275
103284
  */
103276
- constructor(id, originalSystemId, name, type, properties) {
103285
+ constructor(params) {
103277
103286
 
103278
103287
  /**
103279
103288
  * Globally-unique ID for this PropertySet.
@@ -103283,7 +103292,7 @@ class PropertySet {
103283
103292
  * @property id
103284
103293
  * @type {String}
103285
103294
  */
103286
- this.id = id;
103295
+ this.id = params.id;
103287
103296
 
103288
103297
  /**
103289
103298
  * ID of the corresponding object within the originating system, if any.
@@ -103291,7 +103300,7 @@ class PropertySet {
103291
103300
  * @type {String}
103292
103301
  * @abstract
103293
103302
  */
103294
- this.originalSystemId = originalSystemId;
103303
+ this.originalSystemId = params.originalSystemId;
103295
103304
 
103296
103305
  /**
103297
103306
  * The MetaModels that share this PropertySet.
@@ -103305,7 +103314,7 @@ class PropertySet {
103305
103314
  * @property name
103306
103315
  * @type {String}
103307
103316
  */
103308
- this.name = name;
103317
+ this.name = params.name;
103309
103318
 
103310
103319
  /**
103311
103320
  * Type of this PropertySet.
@@ -103313,7 +103322,7 @@ class PropertySet {
103313
103322
  * @property type
103314
103323
  * @type {String}
103315
103324
  */
103316
- this.type = type;
103325
+ this.type = params.type;
103317
103326
 
103318
103327
  /**
103319
103328
  * Properties within this PropertySet.
@@ -103323,7 +103332,8 @@ class PropertySet {
103323
103332
  */
103324
103333
  this.properties = [];
103325
103334
 
103326
- if (properties) {
103335
+ if (params.properties) {
103336
+ const properties = params.properties;
103327
103337
  for (let i = 0, len = properties.length; i < len; i++) {
103328
103338
  const property = properties[i];
103329
103339
  this.properties.push(new Property(property.name, property.value, property.type, property.valueType, property.description));
@@ -16546,9 +16546,18 @@ class RenderBuffer {
16546
16546
  const canvas = imageDataCache.canvas;
16547
16547
  const imageData = imageDataCache.imageData;
16548
16548
  const context = imageDataCache.context;
16549
- gl.readPixels(0, 0, this.buffer.width, this.buffer.height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
16549
+ const { width, height } = this.buffer;
16550
+ gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
16550
16551
  imageData.data.set(pixelData);
16551
16552
  context.putImageData(imageData, 0, 0);
16553
+
16554
+ // flip Y
16555
+ context.save();
16556
+ context.globalCompositeOperation = 'copy';
16557
+ context.scale(1, -1);
16558
+ context.drawImage(canvas, 0, -height, width, height);
16559
+ context.restore();
16560
+
16552
16561
  let format = params.format || "png";
16553
16562
  if (format !== "jpeg" && format !== "png" && format !== "bmp") {
16554
16563
  console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");
@@ -103269,7 +103278,7 @@ class PropertySet {
103269
103278
  /**
103270
103279
  * @private
103271
103280
  */
103272
- constructor(id, originalSystemId, name, type, properties) {
103281
+ constructor(params) {
103273
103282
 
103274
103283
  /**
103275
103284
  * Globally-unique ID for this PropertySet.
@@ -103279,7 +103288,7 @@ class PropertySet {
103279
103288
  * @property id
103280
103289
  * @type {String}
103281
103290
  */
103282
- this.id = id;
103291
+ this.id = params.id;
103283
103292
 
103284
103293
  /**
103285
103294
  * ID of the corresponding object within the originating system, if any.
@@ -103287,7 +103296,7 @@ class PropertySet {
103287
103296
  * @type {String}
103288
103297
  * @abstract
103289
103298
  */
103290
- this.originalSystemId = originalSystemId;
103299
+ this.originalSystemId = params.originalSystemId;
103291
103300
 
103292
103301
  /**
103293
103302
  * The MetaModels that share this PropertySet.
@@ -103301,7 +103310,7 @@ class PropertySet {
103301
103310
  * @property name
103302
103311
  * @type {String}
103303
103312
  */
103304
- this.name = name;
103313
+ this.name = params.name;
103305
103314
 
103306
103315
  /**
103307
103316
  * Type of this PropertySet.
@@ -103309,7 +103318,7 @@ class PropertySet {
103309
103318
  * @property type
103310
103319
  * @type {String}
103311
103320
  */
103312
- this.type = type;
103321
+ this.type = params.type;
103313
103322
 
103314
103323
  /**
103315
103324
  * Properties within this PropertySet.
@@ -103319,7 +103328,8 @@ class PropertySet {
103319
103328
  */
103320
103329
  this.properties = [];
103321
103330
 
103322
- if (properties) {
103331
+ if (params.properties) {
103332
+ const properties = params.properties;
103323
103333
  for (let i = 0, len = properties.length; i < len; i++) {
103324
103334
  const property = properties[i];
103325
103335
  this.properties.push(new Property(property.name, property.value, property.type, property.valueType, property.description));
@@ -4383,7 +4383,8 @@ gl.bindFramebuffer(gl.FRAMEBUFFER,framebuf);if(!gl.isFramebuffer(framebuf)){thro
4383
4383
  *
4384
4384
  * @returns {HTMLCanvasElement}
4385
4385
  */},{key:"readImageAsCanvas",value:function readImageAsCanvas(){var gl=this.gl;var imageDataCache=this._getImageDataCache();var pixelData=imageDataCache.pixelData;var canvas=imageDataCache.canvas;var imageData=imageDataCache.imageData;var context=imageDataCache.context;gl.readPixels(0,0,this.buffer.width,this.buffer.height,gl.RGBA,gl.UNSIGNED_BYTE,pixelData);var width=this.buffer.width;var height=this.buffer.height;var halfHeight=height/2|0;// the | 0 keeps the result an int
4386
- var bytesPerRow=width*4;var temp=new Uint8Array(width*4);for(var y=0;y<halfHeight;++y){var topOffset=y*bytesPerRow;var bottomOffset=(height-y-1)*bytesPerRow;temp.set(pixelData.subarray(topOffset,topOffset+bytesPerRow));pixelData.copyWithin(topOffset,bottomOffset,bottomOffset+bytesPerRow);pixelData.set(temp,bottomOffset);}imageData.data.set(pixelData);context.putImageData(imageData,0,0);return canvas;}},{key:"readImage",value:function readImage(params){var gl=this.gl;var imageDataCache=this._getImageDataCache();var pixelData=imageDataCache.pixelData;var canvas=imageDataCache.canvas;var imageData=imageDataCache.imageData;var context=imageDataCache.context;gl.readPixels(0,0,this.buffer.width,this.buffer.height,gl.RGBA,gl.UNSIGNED_BYTE,pixelData);imageData.data.set(pixelData);context.putImageData(imageData,0,0);var format=params.format||"png";if(format!=="jpeg"&&format!=="png"&&format!=="bmp"){console.error("Unsupported image format: '"+format+"' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");format="png";}return canvas.toDataURL("image/".concat(format));}},{key:"_getImageDataCache",value:function _getImageDataCache(){var type=arguments.length>0&&arguments[0]!==undefined?arguments[0]:Uint8Array;var multiplier=arguments.length>1&&arguments[1]!==undefined?arguments[1]:4;var bufferWidth=this.buffer.width;var bufferHeight=this.buffer.height;var imageDataCache=this._imageDataCache;if(imageDataCache){if(imageDataCache.width!==bufferWidth||imageDataCache.height!==bufferHeight){this._imageDataCache=null;imageDataCache=null;}}if(!imageDataCache){var _canvas=document.createElement('canvas');var context=_canvas.getContext('2d');_canvas.width=bufferWidth;_canvas.height=bufferHeight;imageDataCache={pixelData:new type(bufferWidth*bufferHeight*multiplier),canvas:_canvas,context:context,imageData:context.createImageData(bufferWidth,bufferHeight),width:bufferWidth,height:bufferHeight};this._imageDataCache=imageDataCache;}imageDataCache.context.resetTransform();// Prevents strange scale-accumulation effect with html2canvas
4386
+ var bytesPerRow=width*4;var temp=new Uint8Array(width*4);for(var y=0;y<halfHeight;++y){var topOffset=y*bytesPerRow;var bottomOffset=(height-y-1)*bytesPerRow;temp.set(pixelData.subarray(topOffset,topOffset+bytesPerRow));pixelData.copyWithin(topOffset,bottomOffset,bottomOffset+bytesPerRow);pixelData.set(temp,bottomOffset);}imageData.data.set(pixelData);context.putImageData(imageData,0,0);return canvas;}},{key:"readImage",value:function readImage(params){var gl=this.gl;var imageDataCache=this._getImageDataCache();var pixelData=imageDataCache.pixelData;var canvas=imageDataCache.canvas;var imageData=imageDataCache.imageData;var context=imageDataCache.context;var _this$buffer=this.buffer,width=_this$buffer.width,height=_this$buffer.height;gl.readPixels(0,0,width,height,gl.RGBA,gl.UNSIGNED_BYTE,pixelData);imageData.data.set(pixelData);context.putImageData(imageData,0,0);// flip Y
4387
+ context.save();context.globalCompositeOperation='copy';context.scale(1,-1);context.drawImage(canvas,0,-height,width,height);context.restore();var format=params.format||"png";if(format!=="jpeg"&&format!=="png"&&format!=="bmp"){console.error("Unsupported image format: '"+format+"' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");format="png";}return canvas.toDataURL("image/".concat(format));}},{key:"_getImageDataCache",value:function _getImageDataCache(){var type=arguments.length>0&&arguments[0]!==undefined?arguments[0]:Uint8Array;var multiplier=arguments.length>1&&arguments[1]!==undefined?arguments[1]:4;var bufferWidth=this.buffer.width;var bufferHeight=this.buffer.height;var imageDataCache=this._imageDataCache;if(imageDataCache){if(imageDataCache.width!==bufferWidth||imageDataCache.height!==bufferHeight){this._imageDataCache=null;imageDataCache=null;}}if(!imageDataCache){var _canvas=document.createElement('canvas');var context=_canvas.getContext('2d');_canvas.width=bufferWidth;_canvas.height=bufferHeight;imageDataCache={pixelData:new type(bufferWidth*bufferHeight*multiplier),canvas:_canvas,context:context,imageData:context.createImageData(bufferWidth,bufferHeight),width:bufferWidth,height:bufferHeight};this._imageDataCache=imageDataCache;}imageDataCache.context.resetTransform();// Prevents strange scale-accumulation effect with html2canvas
4387
4388
  return imageDataCache;}},{key:"unbind",value:function unbind(){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,null);this.bound=false;}},{key:"getTexture",value:function getTexture(){var self=this;return this._texture||(this._texture={renderBuffer:this,bind:function bind(unit){if(self.buffer&&self.buffer.texture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,self.buffer.texture);return true;}return false;},unbind:function unbind(unit){if(self.buffer&&self.buffer.texture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,null);}}});}},{key:"hasDepthTexture",value:function hasDepthTexture(){return this._hasDepthTexture;}},{key:"getDepthTexture",value:function getDepthTexture(){if(!this._hasDepthTexture){return null;}var self=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function bind(unit){if(self.buffer&&self.buffer.depthTexture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,self.buffer.depthTexture);return true;}return false;},unbind:function unbind(unit){if(self.buffer&&self.buffer.depthTexture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,null);}}});}},{key:"destroy",value:function destroy(){if(this.allocated){var _gl2=this.gl;_gl2.deleteTexture(this.buffer.texture);_gl2.deleteTexture(this.buffer.depthTexture);_gl2.deleteFramebuffer(this.buffer.framebuf);_gl2.deleteRenderbuffer(this.buffer.renderbuf);this.allocated=false;this.buffer=null;this.bound=false;}this._imageDataCache=null;this._texture=null;this._depthTexture=null;}}]);return RenderBuffer;}();/**
4388
4389
  * @private
4389
4390
  */var RenderBufferManager=/*#__PURE__*/function(){function RenderBufferManager(scene){_classCallCheck(this,RenderBufferManager);this.scene=scene;this._renderBuffersBasic={};this._renderBuffersScaled={};}_createClass(RenderBufferManager,[{key:"getRenderBuffer",value:function getRenderBuffer(id,options){var renderBuffers=this.scene.canvas.resolutionScale===1.0?this._renderBuffersBasic:this._renderBuffersScaled;var renderBuffer=renderBuffers[id];if(!renderBuffer){renderBuffer=new RenderBuffer(this.scene.canvas.canvas,this.scene.canvas.gl,options);renderBuffers[id]=renderBuffer;}return renderBuffer;}},{key:"destroy",value:function destroy(){for(var id in this._renderBuffersBasic){this._renderBuffersBasic[id].destroy();}for(var _id in this._renderBuffersScaled){this._renderBuffersScaled[_id].destroy();}}}]);return RenderBufferManager;}();/**
@@ -23344,19 +23345,19 @@ value=value||"qwerty";if(value!=="qwerty"&&value!=="azerty"){this.error("Unsuppo
23344
23345
  * @class PropertySet
23345
23346
  */var PropertySet=/*#__PURE__*/_createClass(/**
23346
23347
  * @private
23347
- */function PropertySet(id,originalSystemId,name,type,properties){_classCallCheck(this,PropertySet);/**
23348
+ */function PropertySet(params){_classCallCheck(this,PropertySet);/**
23348
23349
  * Globally-unique ID for this PropertySet.
23349
23350
  *
23350
23351
  * PropertySet instances are registered by this ID in {@link MetaScene#propertySets} and {@link MetaModel#propertySets}.
23351
23352
  *
23352
23353
  * @property id
23353
23354
  * @type {String}
23354
- */this.id=id;/**
23355
+ */this.id=params.id;/**
23355
23356
  * ID of the corresponding object within the originating system, if any.
23356
23357
  *
23357
23358
  * @type {String}
23358
23359
  * @abstract
23359
- */this.originalSystemId=originalSystemId;/**
23360
+ */this.originalSystemId=params.originalSystemId;/**
23360
23361
  * The MetaModels that share this PropertySet.
23361
23362
  * @type {MetaModel[]}
23362
23363
  */this.metaModels=[];/**
@@ -23364,17 +23365,17 @@ value=value||"qwerty";if(value!=="qwerty"&&value!=="azerty"){this.error("Unsuppo
23364
23365
  *
23365
23366
  * @property name
23366
23367
  * @type {String}
23367
- */this.name=name;/**
23368
+ */this.name=params.name;/**
23368
23369
  * Type of this PropertySet.
23369
23370
  *
23370
23371
  * @property type
23371
23372
  * @type {String}
23372
- */this.type=type;/**
23373
+ */this.type=params.type;/**
23373
23374
  * Properties within this PropertySet.
23374
23375
  *
23375
23376
  * @property properties
23376
23377
  * @type {Property[]}
23377
- */this.properties=[];if(properties){for(var _i540=0,len=properties.length;_i540<len;_i540++){var property=properties[_i540];this.properties.push(new Property(property.name,property.value,property.type,property.valueType,property.description));}}});/**
23378
+ */this.properties=[];if(params.properties){var properties=params.properties;for(var _i540=0,len=properties.length;_i540<len;_i540++){var property=properties[_i540];this.properties.push(new Property(property.name,property.value,property.type,property.valueType,property.description));}}});/**
23378
23379
  * @desc Metadata corresponding to a {@link Scene}.
23379
23380
  *
23380
23381
  * * Located in {@link Viewer#metaScene}.