(function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; if (ELA.Views == null) { ELA.Views = {}; } ELA.Views.ThreeGraph = (function(superClass) { extend(ThreeGraph, superClass); function ThreeGraph() { this.render = bind(this.render, this); this.resetCanvas = bind(this.resetCanvas, this); this.pinchend = bind(this.pinchend, this); this.pinch = bind(this.pinch, this); this.pinchstart = bind(this.pinchstart, this); this.mousewheel = bind(this.mousewheel, this); return ThreeGraph.__super__.constructor.apply(this, arguments); } ThreeGraph.Params = (function(superClass1) { extend(Params, superClass1); function Params() { return Params.__super__.constructor.apply(this, arguments); } Params.prototype.serializedAttributes = ['zoom']; Params.prototype.serialize = function() { return _.pick(this.attributes, this.serializedAttributes); }; Params.prototype.deserialize = function(attributes) { return this.set(attributes); }; return Params; })(Backbone.Model); ThreeGraph.prototype.start = {}; ThreeGraph.prototype.events = { 'pinchstart': 'pinchstart', 'pinch': 'pinch', 'pinchend': 'pinchend', 'mousewheel': 'mousewheel', 'DOMMouseScroll': 'mousewheel', 'doubletap': 'resetCanvas' }; ThreeGraph.prototype.defaults = { zoom: 1 }; ThreeGraph.prototype.initialize = function() { var fog; if (Modernizr.webgl) { this.renderer = new THREE.WebGLRenderer({ canvas: this.$el[0] }); } else { _.defer(function() { return alert(t('messages.noWebGL')); }); this.renderer = new THREE.CanvasRenderer({ canvas: this.$el[0] }); } this.renderer.setClearColor(0xffffff); this.camera = new THREE.PerspectiveCamera(45, null, 100, 1000); this.camera.position.z = 500; this.scene = new THREE.Scene(); fog = new THREE.Fog(0xffffff, ELA.settings.laminateDeformation.graph.fogMinimumDistance, ELA.settings.laminateDeformation.graph.fogMaximumDistance); this.scene.fog = fog; ThreeGraph.__super__.initialize.apply(this, arguments); this.params.on('change:zoom', this.requestRepaint); return new THREE.FontLoader().load('ela/fonts/droid_sans_regular.typeface.svg', (function(_this) { return function(font) { _this._droidSansRegularFont = font; return _this.trigger('threeJsFontLoaded'); }; })(this)); }; ThreeGraph.prototype.setCanvasResolution = function() { var height, width; this.renderer.setPixelRatio((window.devicePixelRatio || 1) * 2); width = this.params.get('width'); height = this.params.get('height'); this.renderer.setSize(width, height); this.camera.aspect = width / height; return this.requestRepaint(); }; ThreeGraph.prototype.mousewheel = function(e) { var zoom; e.preventDefault(); zoom = this.params.get('zoom'); if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) { return this.params.set({ zoom: zoom + 0.06 }); } else { if (zoom <= 0.06) { return; } return this.params.set({ zoom: zoom - 0.06 }); } }; ThreeGraph.prototype.pinchstart = function(e) { return this.start.zoom = this.params.get('zoom'); }; ThreeGraph.prototype.pinch = function(e) { if (this.params.get('zoom') > 0.01 || scale > 1) { return this.params.set({ zoom: this.start.zoom * e.gesture.scale }); } }; ThreeGraph.prototype.pinchend = function(e) { return this.hammer.stop(); }; ThreeGraph.prototype.resetCanvas = function() { return this.params.set({ zoom: this.defaults.zoom }); }; ThreeGraph.prototype.render = function() { this.camera.zoom = this.params.get('zoom'); this.camera.updateProjectionMatrix(); this.renderer.render(this.scene, this.camera); return this; }; return ThreeGraph; })(ELA.Views.Canvas); }).call(this);