Skip to content

Commit 8c6b243

Browse files
committed
fix(function_3d): enable var in
Closes #542
1 parent bbb1309 commit 8c6b243

File tree

1 file changed

+41
-36
lines changed
  • src/modules/types/chart/advanced/plot_function

1 file changed

+41
-36
lines changed

src/modules/types/chart/advanced/plot_function/view.js

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
/*global Parser*/
3-
define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], function (require, Default, Util, THREE) {
2+
define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs', 'src/util/debug', 'lib/parser/Parser', 'lib/threejs/TrackballControls'], function (require, Default, Util, THREE, Debug) {
43

54
function View() {
65
}
@@ -36,37 +35,10 @@ define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], f
3635
this.yRange = this.yMax - this.yMin;
3736

3837

39-
if (this.scene) {
40-
// this.scene.remove
41-
42-
this.scene.remove(this.graphGeometry);
43-
this.scene.remove(this.graphMesh);
44-
this.scene.remove(this.floor);
45-
delete this.graphGeometry;
46-
delete this.graphMesh;
47-
delete this.floor;
48-
}
49-
50-
require(['./TrackballControls', 'lib/parser/Parser'], function () {
51-
52-
that.createGraph();
38+
this.clearScene();
5339

54-
55-
that.scene = new THREE.Scene();
56-
if (!that.renderer) {
57-
if (that.webgl) {
58-
that.renderer = new THREE.WebGLRenderer({antialias: true});
59-
} else {
60-
that.renderer = new THREE.CanvasRenderer();
61-
}
62-
that.renderer.setClearColor(0xEEEEEE, 1);
63-
}
64-
65-
that.dom.append(that.renderer.domElement);
66-
67-
that.addFloor(that.scene);
68-
that.resolveReady();
69-
});
40+
this.createGraph();
41+
this.resolveReady();
7042

7143
// This should reduce CPU if the mouse if not over and we can not move the object
7244
// this is only valid for non animated graph
@@ -82,14 +54,30 @@ define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], f
8254

8355
},
8456

57+
clearScene: function () {
58+
if (this.scene) {
59+
// this.scene.remove
60+
61+
this.scene.remove(this.graphGeometry);
62+
this.scene.remove(this.graphMesh);
63+
this.scene.remove(this.floor);
64+
delete this.graphGeometry;
65+
delete this.graphMesh;
66+
delete this.floor;
67+
}
68+
},
69+
8570

8671
blank: function () {
87-
this.dom.empty();
72+
this.clearScene();
8873
},
8974

9075
onResize: function () {
9176

92-
if (!this.webgl) return;
77+
if (!this.webgl) {
78+
Debug.warn('webgl context does not exist');
79+
return;
80+
}
9381
var that = this;
9482
this.module.viewReady.then(function () {
9583
var cfg = $.proxy(that.module.getConfiguration, that.module);
@@ -140,7 +128,7 @@ define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], f
140128
wireframe: true,
141129
side: THREE.DoubleSide
142130
});
143-
var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
131+
var floorGeometry = new THREE.PlaneBufferGeometry(1000, 1000, 10, 10);
144132
this.floor = new THREE.Mesh(floorGeometry, wireframeMaterial);
145133
//floor.position.z = 0; // required, otherwise from time to time it is NaN !!!???
146134
// floor.rotation.x = Math.PI / 2;
@@ -150,7 +138,9 @@ define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], f
150138

151139
update: {
152140
'function': function (data) {
153-
141+
this.zFunctionText = data.get();
142+
this.createGraph();
143+
this.onResize();
154144
}
155145
},
156146

@@ -179,6 +169,7 @@ define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], f
179169
},
180170

181171
createGraph: function () {
172+
console.log('create graph');
182173
var that = this;
183174
var cfg = $.proxy(that.module.getConfiguration, that.module);
184175
var segments = cfg('segments');
@@ -229,6 +220,20 @@ define(['require', 'modules/default/defaultview', 'src/util/util', 'threejs'], f
229220
}
230221
that.graphGeometry = graphGeometry;
231222

223+
that.scene = new THREE.Scene();
224+
if (!that.renderer) {
225+
if (that.webgl) {
226+
that.renderer = new THREE.WebGLRenderer({antialias: true});
227+
} else {
228+
that.renderer = new THREE.CanvasRenderer();
229+
}
230+
that.renderer.setClearColor(0xEEEEEE, 1);
231+
}
232+
233+
that.dom.append(that.renderer.domElement);
234+
235+
that.addFloor(that.scene);
236+
232237
}
233238

234239
});

0 commit comments

Comments
 (0)