Polygons3DView.js
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import * as echarts from 'echarts/lib/echarts';
import Geo3DBuilder from '../../component/common/Geo3DBuilder';
import graphicGL from '../../util/graphicGL';
export default echarts.ChartView.extend({
type: 'polygons3D',
__ecgl__: true,
init: function (ecModel, api) {
this.groupGL = new graphicGL.Node();
this._geo3DBuilderList = [];
this._currentStep = 0;
},
render: function (seriesModel, ecModel, api) {
this.groupGL.removeAll();
var coordSys = seriesModel.coordinateSystem;
if (coordSys && coordSys.viewGL) {
coordSys.viewGL.add(this.groupGL);
}
var geo3DBuilder = this._geo3DBuilderList[0];
if (!geo3DBuilder) {
geo3DBuilder = new Geo3DBuilder(api);
geo3DBuilder.extrudeY = coordSys.type !== 'mapbox3D'
&& coordSys.type !== 'maptalks3D';
this._geo3DBuilderList[0] = geo3DBuilder;
}
this._updateShaderDefines(coordSys, geo3DBuilder);
geo3DBuilder.update(seriesModel, ecModel, api);
this._geo3DBuilderList.length = 1;
this.groupGL.add(geo3DBuilder.rootNode);
},
incrementalPrepareRender: function (seriesModel, ecModel, api) {
this.groupGL.removeAll();
var coordSys = seriesModel.coordinateSystem;
if (coordSys && coordSys.viewGL) {
coordSys.viewGL.add(this.groupGL);
}
this._currentStep = 0;
},
incrementalRender: function (params, seriesModel, ecModel, api) {
var geo3DBuilder = this._geo3DBuilderList[this._currentStep];
var coordSys = seriesModel.coordinateSystem;
if (!geo3DBuilder) {
geo3DBuilder = new Geo3DBuilder(api);
geo3DBuilder.extrudeY = coordSys.type !== 'mapbox3D'
&& coordSys.type !== 'maptalks3D';
this._geo3DBuilderList[this._currentStep] = geo3DBuilder;
}
geo3DBuilder.update(seriesModel, ecModel, api, params.start, params.end);
this.groupGL.add(geo3DBuilder.rootNode);
this._updateShaderDefines(coordSys, geo3DBuilder);
this._currentStep++;
},
_updateShaderDefines: function (coordSys, geo3DBuilder) {
var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
geo3DBuilder.rootNode.traverse(function (mesh) {
if (mesh.material) {
mesh.material[methodName]('fragment', 'SRGB_DECODE');
// FIXME
if (coordSys.type === 'mapbox3D' || coordSys.type === 'maptalks3D') {
mesh.material.define('fragment', 'NORMAL_UP_AXIS', 2);
mesh.material.define('fragment', 'NORMAL_FRONT_AXIS', 1);
}
}
});
},
remove: function () {
this.groupGL.removeAll();
},
dispose: function () {
this.groupGL.removeAll();
this._geo3DBuilderList.forEach(function (geo3DBuilder) {
geo3DBuilder.dispose();
})
}
});