@@ -46944,13 +46944,100 @@ MathBox.ViewportPolar.prototype = _.extend(new MathBox.ViewportCartesian(null),
4694446944
4694546945 validatePolar: function (polar) {
4694646946 return Math.max(0, Math.min(1, +polar || 0));
46947- }//,
46947+ },
46948+
46949+ validateFold: function (fold) {
46950+ return +fold || 0;
46951+ },
46952+
46953+ validatePower: function (power) {
46954+ return +power || 0;
46955+ },
46956+
46957+ validateHelix: function (helix) {
46958+ return +helix || 0;
46959+ },
4694846960
4694946961});
4695046962
4695146963MathBox.Attributes.mixin(MathBox.Viewport);
4695246964
4695346965MathBox.Viewport.types.polar = MathBox.ViewportPolar;
46966+ /**
46967+ * Projective viewport, i.e. with a 4x4 projective transform applied
46968+ */
46969+ MathBox.ViewportProjective = function (options) {
46970+ var _super = MathBox.ViewportCartesian;
46971+ _super.call(this, options);
46972+ this.super = _super.prototype;
46973+
46974+ // Prepare uniforms
46975+ _.extend(this._uniforms, {
46976+ projectiveTransform: new THREE.Matrix4(),//,
46977+ });
46978+ };
46979+
46980+ MathBox.ViewportProjective.prototype = _.extend(new MathBox.ViewportCartesian(null), {
46981+
46982+ defaults: function () {
46983+ return {
46984+ type: 'projective',
46985+ range: [[-1, 1], [-1, 1], [-1, 1]],
46986+ scale: [1, 1, 1],
46987+ rotation: [0, 0, 0],
46988+ position: [0, 0, 0],
46989+ projective: [[1, 0, 0, 0],
46990+ [0, 1, 0, 0],
46991+ [0, 0, 1, 0],
46992+ [0, 0, 0, 1]],
46993+ };
46994+ },
46995+
46996+ to: function (vector) {
46997+ // Apply projective transform
46998+ this._uniforms.projectiveTransform.multiplyVector3(vector);
46999+
47000+ // Apply viewport
47001+ this.transform.multiplyVector3(vector);
47002+ },
47003+
47004+ from: function (vector) {
47005+ // Apply inverse viewport
47006+ this.inverse.multiplyVector3(vector);
47007+ },
47008+
47009+ update: function (stage) {
47010+ var t = this._uniforms.projectiveTransform;
47011+ var m = this.get('projective');
47012+ console.log(m, m[0].concat(m[1], m[2], m[3]));
47013+ // t.set.apply(t, m[0].concat(m[1], m[2], m[3]));
47014+
47015+ MathBox.ViewportCartesian.prototype.update.call(this, stage);
47016+ },
47017+
47018+ shader: function (factory) {
47019+ factory
47020+ .snippet('projectiveTransform')
47021+ .snippet('mathToWorld');
47022+ },
47023+
47024+ // Attribute validators
47025+
47026+ validateProjective: function (m) {
47027+ if (m.constructor == Array) {
47028+ for (var j = 0; j < 3; ++j) {
47029+ m[j] = (m[j] && m.constructor == Array && m[j]) || [];
47030+ m[j] = m[j].concat([0, 0, 0, 0]).slice(0, 4);
47031+ }
47032+ return m;
47033+ }
47034+ },
47035+
47036+ });
47037+
47038+ MathBox.Attributes.mixin(MathBox.Viewport);
47039+
47040+ MathBox.Viewport.types.projective = MathBox.ViewportProjective;
4695447041/**
4695547042 * Cartesian to spherical viewport transform.
4695647043 *
0 commit comments