Skip to content

Commit

Permalink
Merge pull request #146 from K3D-tools/devel
Browse files Browse the repository at this point in the history
sandboxing THREE.js for K3D
  • Loading branch information
artur-trzesiok authored May 2, 2019
2 parents 50a42a9 + d62e893 commit d804c9f
Show file tree
Hide file tree
Showing 46 changed files with 3,459 additions and 784 deletions.
1 change: 0 additions & 1 deletion js/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"globals": {
"$": true,
"K3D": true,
"THREE": true,
"_": true,
"ImageData": true,
"jsonpatch": true,
Expand Down
5 changes: 2 additions & 3 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "k3d",
"version": "2.6.1",
"version": "2.6.2",
"description": "3D visualization library",
"author": "k3d team",
"main": "src/index.js",
Expand Down Expand Up @@ -81,7 +81,6 @@
"requirejs": "^2.3.6",
"screenfull": "^4.1.0",
"stats.js": "^0.17.0",
"three": "^0.102.1",
"three-octree": "^0.6.1"
"three": "^0.102.1"
}
}
10 changes: 1 addition & 9 deletions js/src/core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ function K3D(provider, targetDOMNode, parameters) {
if (!self.disabling) {
self.gui.domElement.parentNode.style['max-height'] = world.targetDOMNode.offsetHeight + 'px';
self.Provider.Helpers.resizeListener(world);
dispatch(self.events.RESIZED);
self.render();
}

dispatch(self.events.RESIZED);
};

world.overlayDOMNode = currentWindow.document.createElement('div');
Expand Down Expand Up @@ -772,13 +771,6 @@ function K3D(provider, targetDOMNode, parameters) {
GUI.info.__controllers[1].__input.readOnly = true;
}

if (self.parameters.specVersion) {
GUI.info.add({
version: self.parameters.specVersion.substr(1)
}, 'version').name('Spec version:');
GUI.info.__controllers[1].__input.readOnly = true;
}

self.setMenuVisibility(self.parameters.menuVisibility);
self.setTime(self.parameters.time);
self.setGridAutoFit(self.parameters.gridAutoFit);
Expand Down
2 changes: 2 additions & 0 deletions js/src/core/lib/clippingPlanesGUIProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var THREE = require('three');

function clippingPlanesGUIProvider(K3D, clippingPlanesGUI) {

function dispatch() {
Expand Down
30 changes: 24 additions & 6 deletions js/src/core/lib/colorMapLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = function getColorLegend(K3D, object) {
intervalOffset,
intervalCount = 0,
strokeWidth = 0.5,
resizeListenerId = null,
i, y;

if (K3D.colorMapNode) {
Expand Down Expand Up @@ -152,13 +153,30 @@ module.exports = function getColorLegend(K3D, object) {

K3D.getWorld().targetDOMNode.appendChild(svg);

maxTextWidth = texts.reduce(function (max, text) {
return Math.max(max, text.getBBox().width);
}, 0);
function tryPosLabels() {
if (K3D.getWorld().width < 10 || K3D.getWorld().height < 10) {
if (resizeListenerId === null) {
resizeListenerId = K3D.on(K3D.events.RESIZED, function () {
tryPosLabels();
});
}
} else {
if (resizeListenerId !== null) {
K3D.off(K3D.events.RESIZED, resizeListenerId);
resizeListenerId = null;
}

maxTextWidth = texts.reduce(function (max, text) {
return Math.max(max, text.getBBox().width);
}, 0);

texts.forEach(function (text) {
text.setAttribute('x', (maxTextWidth + 20).toString(10));
});
}
}

texts.forEach(function (text) {
text.setAttribute('x', (maxTextWidth + 20).toString(10));
});
tryPosLabels();

K3D.colorMapNode = svg;
};
4 changes: 2 additions & 2 deletions js/src/k3d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
//jshint maxstatements:false

var widgets = require('@jupyter-widgets/base'),
K3D = require('./core/Core'),
Expand All @@ -9,7 +10,7 @@ var widgets = require('@jupyter-widgets/base'),
ChunkModel,
ObjectModel,
ObjectView,
semverRange = require('./version').EXTENSION_SPEC_VERSION,
semverRange = require('./version').version,
objectsList = {},
chunkList = {},
plotsList = [];
Expand Down Expand Up @@ -212,7 +213,6 @@ PlotView = widgets.DOMWidgetView.extend({
try {
this.K3DInstance = new K3D(ThreeJsProvider, this.container, {
antialias: this.model.get('antialias'),
specVersion: this.model.get('_view_module_version'),
backendVersion: this.model.get('_backend_version'),
screenshotScale: this.model.get('screenshot_scale'),
menuVisibility: this.model.get('menu_visibility'),
Expand Down
4 changes: 2 additions & 2 deletions js/src/labplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require('./deps');

var k3d = require('./index'),
EXTENSION_SPEC_VERSION = require('./version').EXTENSION_SPEC_VERSION,
version = require('./version').version,
base = require('@jupyter-widgets/base');

module.exports = {
Expand All @@ -14,7 +14,7 @@ module.exports = {
activate: function (app, widgets) {
widgets.registerWidget({
name: 'k3d',
version: EXTENSION_SPEC_VERSION,
version: version,
exports: k3d
});
},
Expand Down
3 changes: 2 additions & 1 deletion js/src/providers/threejs/helpers/Fn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var lut = require('./../../../core/lib/helpers/lut'),
var THREE = require('three'),
lut = require('./../../../core/lib/helpers/lut'),
Float16Array = require('./../../../core/lib/helpers/float16Array');

function getSpaceDimensionsFromTargetElement(world) {
Expand Down
63 changes: 32 additions & 31 deletions js/src/providers/threejs/helpers/SSAAChunkedRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,38 @@
//
// Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

var JitterVectors = [
[
[0, 0]
],
[
[4, 4], [-4, -4]
],
[
[-2, -6], [6, -2], [-6, 2], [2, 6]
],
[
[1, -3], [-1, 3], [5, 1], [-3, -5],
[-5, 5], [-7, -1], [3, 7], [7, -7]
],
[
[1, 1], [-1, -3], [-3, 2], [4, -1],
[-5, -2], [2, 5], [5, 3], [3, -5],
[-2, 6], [0, -7], [-4, -6], [-6, 4],
[-8, 0], [7, -4], [6, 7], [-7, -8]
],
[
[-4, -7], [-7, -5], [-3, -5], [-5, -4],
[-1, -4], [-2, -2], [-6, -1], [-4, 0],
[-7, 1], [-1, 2], [-6, 3], [-3, 3],
[-7, 6], [-3, 6], [-5, 7], [-1, 7],
[5, -7], [1, -6], [6, -5], [4, -4],
[2, -3], [7, -2], [1, -1], [4, -1],
[2, 1], [6, 2], [0, 4], [4, 4],
[2, 5], [7, 5], [5, 6], [3, 7]
]
];
var THREE = require('three'),
JitterVectors = [
[
[0, 0]
],
[
[4, 4], [-4, -4]
],
[
[-2, -6], [6, -2], [-6, 2], [2, 6]
],
[
[1, -3], [-1, 3], [5, 1], [-3, -5],
[-5, 5], [-7, -1], [3, 7], [7, -7]
],
[
[1, 1], [-1, -3], [-3, 2], [4, -1],
[-5, -2], [2, 5], [5, 3], [3, -5],
[-2, 6], [0, -7], [-4, -6], [-6, 4],
[-8, 0], [7, -4], [6, 7], [-7, -8]
],
[
[-4, -7], [-7, -5], [-3, -5], [-5, -4],
[-1, -4], [-2, -2], [-6, -1], [-4, 0],
[-7, 1], [-1, 2], [-6, 3], [-3, 3],
[-7, 6], [-3, 6], [-5, 7], [-1, 7],
[5, -7], [1, -6], [6, -5], [4, -4],
[2, -3], [7, -2], [1, -1], [4, -1],
[2, 1], [6, 2], [0, 4], [4, 4],
[2, 5], [7, 5], [5, 6], [3, 7]
]
];

function getArrayFromRenderTarget(renderer, rt) {
var array = new Uint8Array(rt.width * rt.height * 4);
Expand Down
2 changes: 2 additions & 0 deletions js/src/providers/threejs/helpers/Streamline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
//jshint maxstatements:false

var THREE = require('three');

module.exports = function (points, attributes, radius, radialSegments, color, verticesColors, colorRange) {

var geometry = new THREE.BufferGeometry(),
Expand Down
53 changes: 53 additions & 0 deletions js/src/providers/threejs/helpers/THREE.CopyShader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
// jshint ignore: start
// jscs:disable

module.exports = function (THREE) {
/**
* @author alteredq / http://alteredqualia.com/
*
* Full-screen textured quad shader
*/

THREE.CopyShader = {

uniforms: {

"tDiffuse": { value: null },
"opacity": { value: 1.0 }

},

vertexShader: [

"varying vec2 vUv;",

"void main() {",

"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",

"}"

].join( "\n" ),

fragmentShader: [

"uniform float opacity;",

"uniform sampler2D tDiffuse;",

"varying vec2 vUv;",

"void main() {",

"vec4 texel = texture2D( tDiffuse, vUv );",
"gl_FragColor = opacity * texel;",

"}"

].join( "\n" )

};

};
32 changes: 9 additions & 23 deletions js/src/providers/threejs/helpers/THREE.MeshLine.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
//jshint maxstatements:false, maxcomplexity:false, maxdepth:false

;(function () {
'use strict';

var root = this,
has_require = typeof require !== 'undefined',
THREE = root.THREE || has_require && require('three');

if (!THREE) {
throw new Error('MeshLine requires three.js');
}
'use strict';
//jshint ignore: start
//jscs:disable

module.exports = function (THREE) {
function MeshLine() {
this.positions = [];
this.previous = [];
Expand Down Expand Up @@ -393,14 +385,8 @@
return this;
};

if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = {MeshLine: MeshLine, MeshLineMaterial: MeshLineMaterial};
}
exports.MeshLine = MeshLine;
exports.MeshLineMaterial = MeshLineMaterial;
} else {
root.MeshLine = MeshLine;
root.MeshLineMaterial = MeshLineMaterial;
}
}).call(this);
return {
MeshLine: MeshLine,
MeshLineMaterial: MeshLineMaterial
};
};
Loading

0 comments on commit d804c9f

Please sign in to comment.