zincjs 1.19.3 → 1.20.0
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.
- package/build/zinc.frontend.js +1 -1
- package/build/zinc.js +5 -5
- package/build/zinc.js.map +1 -1
- package/package.json +1 -1
- package/src/loaders/niftiReader.js +80 -193
- package/src/primitives/textureSlides.js +43 -22
- package/src/primitives/textureVolume.js +5 -0
- package/src/shaders/textureSlide.js +23 -8
- package/src/three/GLTFExporter.js +2 -2
package/build/zinc.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = require("url-polyfill");
|
|
|
32
32
|
/***/ ((module) => {
|
|
33
33
|
|
|
34
34
|
"use strict";
|
|
35
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"zincjs","version":"1.
|
|
35
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"zincjs","version":"1.20.0","description":"ZincJS (Web-based-Zinc-Visualisation)","main":"build/zinc.js","directories":{"doc":"docs"},"files":["package.json","LICENSE","README.md","src/*","build/zinc.js","build/zinc.frontend.js","build/zinc.js.map","webpack.config.js"],"scripts":{"build-bundle":"webpack --config webpack.frontend.js; webpack --config webpack.backend.js","build-backend":"webpack --config webpack.backend.js","test":"npm --prefix ./test install && npm --prefix ./test run test-ci","changelog":"auto-changelog -p --output CHANGELOG.md --template keepachangelog","jsdoc":"jsdoc -c jsdoc_conf.json","version":"npm run build-bundle;npm run jsdoc;npm run changelog; git add CHANGELOG.md docs","release:beta":"npm version prerelease --preid=beta; npm publish --tag beta","release:minor":"npm version minor; npm publish","release:patch":"npm version patch; npm publish"},"repository":{"type":"git","url":"git+https://github.com/alan-wu/ZincJS.git"},"keywords":["library","webgl","3d","zincjs"],"author":"Alan Wu <alan.wu@auckland.ac.nz>","license":"MIT","bugs":{"url":"https://github.com/alan-wu/ZincJS/issues"},"homepage":"http://alan-wu.github.io/ZincJS/","devDependencies":{"@babel/core":"^7.23.9","@babel/preset-env":"^7.23.9","auto-changelog":"^2.4.0","babel-loader":"^9.1.3","babel-preset-minify":"^0.5.1","file-loader":"^6.2.0","jsdoc":"^4.0.2","raw-loader":"^4.0.2","webpack":"^5.90.3","webpack-cli":"^5.1.4","webpack-node-externals":"^3.0.0"},"dependencies":{"css-element-queries":"^1.2.2","lodash":"^4.17.19","nifti-reader-js":"^0.8.0","promise-polyfill":"^8.1.3","three":"^0.130.1","three-spritetext":"1.6.2","url-loader":"^4.1.1","url-polyfill":"^1.1.7","webworkify-webpack":"^2.1.5"}}');
|
|
36
36
|
|
|
37
37
|
/***/ }),
|
|
38
38
|
/* 3 */
|
|
@@ -1026,7 +1026,7 @@ function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value}catch(n){
|
|
|
1026
1026
|
/* 27 */
|
|
1027
1027
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1028
1028
|
|
|
1029
|
-
function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var t,r=1;r<arguments.length;r++)t=null==arguments[r]?{}:arguments[r],r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))});return e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==typeof i?i:i+""}function _toPrimitive(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var THREE=__webpack_require__(4),shader=__webpack_require__(28),TextureSlides=function(textureIn){(__webpack_require__(29).TexturePrimitive).call(this,textureIn),this.isTextureSlides=!0;var textureSettings=[],idTextureMap={};this.morph=new THREE.Group,this.group=this.morph,this.morph.userData=this;var edgesLine=void 0,flipY=!0,brightness=0,contrast=1,discardAlpha=!0,lt0=0,lt1=0,prevTime=-.1;/**
|
|
1029
|
+
function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var t,r=1;r<arguments.length;r++)t=null==arguments[r]?{}:arguments[r],r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))});return e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==typeof i?i:i+""}function _toPrimitive(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var THREE=__webpack_require__(4),shader=__webpack_require__(28),TextureSlides=function(textureIn){(__webpack_require__(29).TexturePrimitive).call(this,textureIn),this.isTextureSlides=!0;var textureSettings=[],idTextureMap={};this.morph=new THREE.Group,this.group=this.morph,this.morph.userData=this;var edgesLine=void 0,flipY=!0,flipZ=!1,brightness=0,contrast=1,nChannels=1,maskTexture=void 0,discardAlpha=!0,lt0=0,lt1=0,prevTime=-.1;/**
|
|
1030
1030
|
@typedef SLIDE_SETTINGS
|
|
1031
1031
|
@type {Set}
|
|
1032
1032
|
@property {String} direction - the value must be x, y or z, specify the
|
|
@@ -1050,7 +1050,7 @@ function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var
|
|
|
1050
1050
|
* Modify the mesh based on a setting
|
|
1051
1051
|
*
|
|
1052
1052
|
* @param {SLIDE_SETTINGS} settings - s.
|
|
1053
|
-
*/this.modifySlideSettings=settings=>{settings&&settings.id&&settings.id in idTextureMap&&idTextureMap[settings.id]&&setUniformSlideSettingsOfMesh(idTextureMap[settings.id],settings)},this.createSlide=settings=>{if(this.texture&&this.texture.isTextureArray&&this.texture.isReady()&&settings&&settings.direction&&void 0!==settings.value){var geometry=new THREE.PlaneGeometry(1,1);geometry.translate(.5,.5,0);var uniforms=shader.getUniforms();uniforms.brightness.value=brightness,uniforms.contrast.value=contrast,uniforms.diffuse0.value=this.texture.impl,uniforms.diffuse1.value=this.texture.impl,uniforms.discardAlpha.value=discardAlpha,uniforms.depth.value=this.texture.size.depth,uniforms.flipY.value=flipY;var options={fs:shader.fs,vs:shader.vs,uniforms:uniforms,glslVersion:shader.glslVersion,side:THREE.DoubleSide,transparent:!1},material=this.texture.getMaterial(options);material.needsUpdate=!0;var mesh=new THREE.Mesh(geometry,material);mesh.name=this.groupName,mesh.userData=this;var slideSettings={value:settings.value,direction:settings.direction,id:mesh.id};return textureSettings.push(slideSettings),setUniformSlideSettingsOfMesh(mesh,slideSettings),idTextureMap[mesh.id]=mesh,this.morph.add(mesh),this.boundingBoxUpdateRequired=!0,this.updateTimeTexture(),slideSettings;}},this.getTextureSettings=()=>[...textureSettings],this.getTextureSettingsWithId=id=>{for(var i=0;i<textureSettings.length;i++)if(id===textureSettings[i].id)return _objectSpread({},textureSettings[i]);},this.getSlides=()=>this.morph?[...this.morph.children]:[],this.removeSlide=slide=>{slide&&this.removeSlideWithId(slide.id)},this.removeSlideWithId=id=>{if(this.morph&&id in idTextureMap&&idTextureMap[id]){if(this.morph.getObjectById(id)){var slide=idTextureMap[id];this.morph.remove(slide),slide.clear(),slide.geometry&&slide.geometry.dispose(),slide.material&&slide.material.dispose(),this.boundingBoxUpdateRequired=!0}var index=textureSettings.findIndex(item=>item.id===id);-1<index&&textureSettings.splice(index,1)}},this.dispose=()=>{this.morph.children.forEach(slide=>{slide.geometry&&slide.geometry.dispose(),slide.material&&slide.material.dispose()}),(__webpack_require__(29).TexturePrimitive).prototype.dispose.call(this),this.boundingBoxUpdateRequired=!0};//Expand the boundingbox with slide settings
|
|
1053
|
+
*/this.modifySlideSettings=settings=>{settings&&settings.id&&settings.id in idTextureMap&&idTextureMap[settings.id]&&setUniformSlideSettingsOfMesh(idTextureMap[settings.id],settings)},this.createSlide=settings=>{if(this.texture&&this.texture.isTextureArray&&this.texture.isReady()&&settings&&settings.direction&&void 0!==settings.value){var geometry=new THREE.PlaneGeometry(1,1);geometry.translate(.5,.5,0);var uniforms=shader.getUniforms();uniforms.brightness.value=brightness,uniforms.contrast.value=contrast,uniforms.diffuse0.value=this.texture.impl,uniforms.diffuse1.value=this.texture.impl,uniforms.discardAlpha.value=discardAlpha,uniforms.depth.value=this.texture.size.depth,uniforms.flipY.value=flipY,uniforms.flipZ.value=flipZ,uniforms.mask.value=maskTexture,uniforms.maskEnabled.value=!1,uniforms.nChannels.value=nChannels;var options={fs:shader.fs,vs:shader.vs,uniforms:uniforms,glslVersion:shader.glslVersion,side:THREE.DoubleSide,transparent:!1},material=this.texture.getMaterial(options);material.needsUpdate=!0;var mesh=new THREE.Mesh(geometry,material);mesh.name=this.groupName,mesh.userData=this;var slideSettings={value:settings.value,direction:settings.direction,id:mesh.id};return textureSettings.push(slideSettings),setUniformSlideSettingsOfMesh(mesh,slideSettings),idTextureMap[mesh.id]=mesh,this.morph.add(mesh),this.boundingBoxUpdateRequired=!0,this.updateTimeTexture(),slideSettings;}},this.getTextureSettings=()=>[...textureSettings],this.getTextureSettingsWithId=id=>{for(var i=0;i<textureSettings.length;i++)if(id===textureSettings[i].id)return _objectSpread({},textureSettings[i]);},this.getSlides=()=>this.morph?[...this.morph.children]:[],this.removeSlide=slide=>{slide&&this.removeSlideWithId(slide.id)},this.removeSlideWithId=id=>{if(this.morph&&id in idTextureMap&&idTextureMap[id]){if(this.morph.getObjectById(id)){var slide=idTextureMap[id];this.morph.remove(slide),slide.clear(),slide.geometry&&slide.geometry.dispose(),slide.material&&slide.material.dispose(),this.boundingBoxUpdateRequired=!0}var index=textureSettings.findIndex(item=>item.id===id);-1<index&&textureSettings.splice(index,1)}},this.dispose=()=>{this.morph.children.forEach(slide=>{slide.geometry&&slide.geometry.dispose(),slide.material&&slide.material.dispose()}),(__webpack_require__(29).TexturePrimitive).prototype.dispose.call(this),this.boundingBoxUpdateRequired=!0};//Expand the boundingbox with slide settings
|
|
1054
1054
|
var expandBoxWithSettings=(box,settings,vector)=>{if(settings)switch(settings.direction.value){case 1:vector.copy(settings.slide.value),box.expandByPoint(vector),vector.setY(1),vector.setZ(1),box.expandByPoint(vector);break;case 2:vector.copy(settings.slide.value),box.expandByPoint(vector),vector.setX(1),vector.setZ(1),box.expandByPoint(vector);break;case 3:vector.copy(settings.slide.value),box.expandByPoint(vector),vector.setX(1),vector.setY(1),box.expandByPoint(vector);break;default:}};/**
|
|
1055
1055
|
* Get the bounding box of this slides.
|
|
1056
1056
|
* It uses the max and min of the slides position and the
|
|
@@ -1062,7 +1062,7 @@ var expandBoxWithSettings=(box,settings,vector)=>{if(settings)switch(settings.di
|
|
|
1062
1062
|
*//**
|
|
1063
1063
|
* Update the glyphsets if required the render.
|
|
1064
1064
|
*/this.getBoundingBox=()=>{if(this.morph&&this.morph.children&&this.morph.visible&&this.boundingBoxUpdateRequired){this.cachedBoundingBox.makeEmpty();var vector=new THREE.Vector3(0,0,0);this.morph.children.forEach(slide=>{expandBoxWithSettings(this.cachedBoundingBox,slide.material.uniforms,vector)}),this.morph.updateMatrixWorld(!0,!0),this.cachedBoundingBox.applyMatrix4(this.morph.matrixWorld),this.boundingBoxUpdateRequired=!1}return this.cachedBoundingBox;},this.applyTransformation=(rotation,position,scale)=>{var matrix=new THREE.Matrix4;matrix.set(rotation[0],rotation[1],rotation[2],0,rotation[3],rotation[4],rotation[5],0,rotation[6],rotation[7],rotation[8],0,0,0,0,0);var quaternion=new THREE.Quaternion().setFromRotationMatrix(matrix);this.morph.position.set(...position),this.morph.quaternion.copy(quaternion),this.morph.scale.set(...scale),this.morph.updateMatrix(),this.boundingBoxUpdateRequired=!0},this.setRenderOrder=order=>{//multiilayers
|
|
1065
|
-
this.morph.renderOrder=order},this.initialise=(textureData,finishCallback)=>{if(textureData){var locations=textureData.locations;locations&&0<locations.length&&(this.applyTransformation(locations[0].orientation,locations[0].position,locations[0].scale),"flipY"in locations[0]&&(flipY=locations[0].flipY)),this.createSlides(textureData.settings.slides),finishCallback!=null&&"function"==typeof finishCallback&&finishCallback(this)}},this.showEdges=color=>{if(!edgesLine){var geometry=new THREE.BoxGeometry(1,1,1);geometry.translate(.5,.5,.5);var edges=new THREE.EdgesGeometry(geometry);edgesLine=new THREE.LineSegments(edges,new THREE.LineBasicMaterial({color})),this.group.add(edgesLine)}else edgesLine.material.color=color;edgesLine.visible=!0},this.
|
|
1065
|
+
this.morph.renderOrder=order},this.initialise=(textureData,finishCallback)=>{if(textureData){var locations=textureData.locations;locations&&0<locations.length&&(this.applyTransformation(locations[0].orientation,locations[0].position,locations[0].scale),"flipY"in locations[0]&&(flipY=locations[0].flipY),"flipZ"in locations[0]&&(flipZ=locations[0].flipZ)),this.createSlides(textureData.settings.slides),finishCallback!=null&&"function"==typeof finishCallback&&finishCallback(this)}},this.showEdges=color=>{if(!edgesLine){var geometry=new THREE.BoxGeometry(1,1,1);geometry.translate(.5,.5,.5);var edges=new THREE.EdgesGeometry(geometry);edgesLine=new THREE.LineSegments(edges,new THREE.LineBasicMaterial({color})),this.group.add(edgesLine)}else edgesLine.material.color=color;edgesLine.visible=!0},this.setUniformsValue=(name,val)=>{this.morph.children.forEach(mesh=>{var material=mesh.material;if("ShaderMaterial"===material.type){var uniforms=material.uniforms;uniforms[name].value=val,material.needsUpdate=!0}})},this.isAlphaPixelDiscarded=()=>discardAlpha,this.discardAlphaPixel=flag=>{discardAlpha=flag,this.setUniformsValue("discardAlpha",discardAlpha)},this.getBrightness=()=>brightness,this.setBrightness=brightnessIn=>{brightness=brightnessIn,this.setUniformsValue("brightness",brightness)},this.getContrast=()=>contrast,this.setContrast=contrastIn=>{0<=contrast&&(contrast=contrastIn,this.setUniformsValue("contrast",contrast))},this.getNumberOfChannels=()=>nChannels,this.setNumberOfChannels=numbersIn=>{nChannels=numbersIn,this.setUniformsValue("nChannels",nChannels)},this.getMask=()=>maskTexture,this.setMask=maskTextureIn=>{maskTexture=maskTextureIn,this.setUniformsValue("mask",maskTexture),this.setUniformsValue("maskEnabled",!!maskTexture)},this.hideEdges=()=>{edgesLine&&(edgesLine.visible=!1)},this.updateTimeTexture=()=>{var maxIndex=this.textureList.length-1,normalisedTime=this.inbuildTime/this.duration;if(this.timeEnabled&&0<maxIndex&&prevTime!==normalisedTime){var iTime=normalisedTime*maxIndex,t0=Math.floor(iTime),t1=Math.ceil(iTime);this.morph.children.forEach(mesh=>{var material=mesh.material;if("ShaderMaterial"===material.type){var uniforms=material.uniforms;lt0!==t0&&(uniforms.diffuse0.value=this.textureList[t0].impl),lt1!==t1&&(uniforms.diffuse1.value=this.textureList[t1].impl),uniforms.time.value=iTime-t0,material.needsUpdate=!0}}),lt0=t0,lt1=t1,prevTime=normalisedTime}},this.setMorphTime=time=>{var newTime=time;newTime=time>this.duration?this.duration:0>time?0:time,newTime!=this.inbuildTime&&(this.inbuildTime=newTime,this.updateTimeTexture())},this.render=(delta,playAnimation)=>{//console.log("render", delta, playAnimation, this.textureList)
|
|
1066
1066
|
if(!0==playAnimation&&this.timeEnabled&&1<this.textureList.length){var targetTime=this.inbuildTime+delta;targetTime>this.duration&&(targetTime-=this.duration),this.inbuildTime=targetTime,this.updateTimeTexture()}}};/**
|
|
1067
1067
|
* Provides a class which create a texture stacks in a block
|
|
1068
1068
|
* with shaders allowing slices of texture to be displayed.
|
|
@@ -1079,7 +1079,7 @@ if(!0==playAnimation&&this.timeEnabled&&1<this.textureList.length){var targetTim
|
|
|
1079
1079
|
/* 28 */
|
|
1080
1080
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1081
1081
|
|
|
1082
|
-
var THREE=__webpack_require__(4),glslVersion=THREE.GLSL3,fs="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2DArray;\n\nuniform sampler2DArray diffuse0;\nuniform sampler2DArray diffuse1;\nuniform bool discardAlpha;\nuniform float brightness;\nuniform float contrast;\nuniform float time;\nin vec3 vUw;\n\nout vec4 outColor;\n\nvoid main() {\n\n
|
|
1082
|
+
var THREE=__webpack_require__(4),glslVersion=THREE.GLSL3,fs="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2DArray;\n\nuniform sampler2DArray diffuse0;\nuniform sampler2DArray diffuse1;\nuniform sampler2DArray mask;\nuniform bool discardAlpha;\nuniform bool maskEnabled;\nuniform float brightness;\nuniform float contrast;\nuniform float time;\nuniform int nChannels;\nin vec3 vUw;\n\nout vec4 outColor;\n\nvoid main() {\n\n float color0 = texture( diffuse0, vUw ).r;\n float color1 = texture( diffuse1, vUw ).r;\n float color = mix(color0, color1, time);\n // discard if alpha is zero\n if (maskEnabled && discardAlpha) {\n float mask = texture(mask, vUw).r;\n if (mask == 0.0) discard;\n }\n\n // discard if alpha is zero\n //if (discardAlpha && color.a == 0.0) discard;\n // Apply brightness\n vec3 brightenedColor = vec3(color) + vec3(brightness);\n // Apply contrast\n vec3 contrastedColor = (brightenedColor - vec3(0.5)) * contrast + vec3(0.5);\n outColor = vec4(contrastedColor, 1.0);\n}\n",vs="\nout vec3 vUw;\nuniform float depth;\nuniform vec3 slide;\nuniform int direction;\nuniform bool flipY;\nuniform bool flipZ;\n\nvoid main() {\n\n vec3 slidePos = position.xyz;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position.xyz, 1.0 );\n\n if (direction == 1)\n slidePos = vec3(slide.x, position.y, position.x);\n if (direction == 2)\n slidePos = vec3(position.x, slide.y, position.y);\n if (direction == 3)\n slidePos = vec3(position.x, position.y, slide.z);\n\n if (flipY)\n slidePos.y = 1.0 - slidePos.y;\n if (flipZ)\n slidePos.z = 1.0 - slidePos.z;\n\n vUw.xyz = vec3(slidePos.x, slidePos.y, slidePos.z * depth);\n\n}\n",getUniforms=function(){return{brightness:{value:0},contrast:{value:1},depth:{value:1},discardAlpha:{value:!0},diffuse0:{value:void 0},diffuse1:{value:void 0},direction:{value:1},flipY:{value:!0},flipZ:{value:!1},nChannels:{value:1},mask:{value:void 0},maskEnabled:{value:!1},slide:{value:new THREE.Vector3(0,0,1)},time:{value:0}};};exports.fs=fs,exports.vs=vs,exports.glslVersion=glslVersion,exports.getUniforms=getUniforms;
|
|
1083
1083
|
|
|
1084
1084
|
/***/ }),
|
|
1085
1085
|
/* 29 */
|