1 | import {cube} from './primitiveShapes/cube';
|
2 | import {gridPlane} from './primitiveShapes/gridPlane';
|
3 | import {lineStrip} from './primitiveShapes/lineStrip';
|
4 | import {line} from './primitiveShapes/line';
|
5 | import {plane} from './primitiveShapes/plane';
|
6 | import {point} from './primitiveShapes/point';
|
7 | import {triangle} from './primitiveShapes/triangle';
|
8 |
|
9 | import {drawLineStrip} from './draw/drawLineStrip';
|
10 | import {drawPlane} from './draw/drawPlane';
|
11 | import {drawTriangle} from './draw/drawTriangle';
|
12 |
|
13 | import {orthographic} from './projection-orthographic';
|
14 |
|
15 | import {x as px, y as py, z as pz } from './point';
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export default function() {
|
21 |
|
22 | var origin = [0, 0],
|
23 | scale = 1,
|
24 | projection = orthographic,
|
25 | angleX = 0,
|
26 | angleY = 0,
|
27 | angleZ = 0,
|
28 | rotateCenter = [0,0,0],
|
29 | x = px,
|
30 | y = py,
|
31 | z = pz,
|
32 | row = undefined,
|
33 | shape = 'POINT',
|
34 | processData = {
|
35 | 'CUBE' : cube,
|
36 | 'GRID' : gridPlane,
|
37 | 'LINE' : line,
|
38 | 'LINE_STRIP' : lineStrip,
|
39 | 'PLANE' : plane,
|
40 | 'POINT' : point,
|
41 | 'SURFACE' : gridPlane,
|
42 | 'TRIANGLE' : triangle,
|
43 | },
|
44 | draw = {
|
45 | 'CUBE' : drawPlane,
|
46 | 'GRID' : drawPlane,
|
47 | 'LINE_STRIP' : drawLineStrip,
|
48 | 'PLANE' : drawPlane,
|
49 | 'SURFACE' : drawPlane,
|
50 | 'TRIANGLE' : drawTriangle,
|
51 | };
|
52 |
|
53 | function _3d(data){
|
54 | return processData[shape](
|
55 | data,
|
56 | { scale: scale, origin: origin, project: projection, row: row },
|
57 | { x: x, y: y, z: z },
|
58 | { x: angleX, y: angleY, z: angleZ, rotateCenter: rotateCenter }
|
59 | );
|
60 | }
|
61 |
|
62 | _3d.origin = function(_){
|
63 | return arguments.length ? (origin = _, _3d) : origin;
|
64 | };
|
65 |
|
66 | _3d.scale = function(_){
|
67 | return arguments.length ? (scale = _, _3d) : scale;
|
68 | };
|
69 |
|
70 | _3d.rotateX = function(_){
|
71 | return arguments.length ? (angleX = _, _3d) : angleX;
|
72 | };
|
73 |
|
74 | _3d.rotateY = function(_){
|
75 | return arguments.length ? (angleY = _, _3d) : angleY;
|
76 | };
|
77 |
|
78 | _3d.rotateZ = function(_){
|
79 | return arguments.length ? (angleZ = _, _3d) : angleZ;
|
80 | };
|
81 |
|
82 | _3d.shape = function(_, r){
|
83 | return arguments.length ? (shape = _, row = r, _3d) : shape;
|
84 | };
|
85 |
|
86 | _3d.rotateCenter = function(_){
|
87 | return arguments.length ? (rotateCenter = _, _3d) : rotateCenter;
|
88 | };
|
89 |
|
90 | _3d.x = function(_){
|
91 | return arguments.length ? (x = typeof _ === 'function' ? _ : +_, _3d) : x;
|
92 | };
|
93 |
|
94 | _3d.y = function(_){
|
95 | return arguments.length ? (y = typeof _ === 'function' ? _ : +_, _3d) : y;
|
96 | };
|
97 |
|
98 | _3d.z = function(_){
|
99 | return arguments.length ? (z = typeof _ === 'function' ? _ : +_, _3d) : z;
|
100 | };
|
101 |
|
102 | _3d.sort = function(a, b){
|
103 | var _a = a.centroid.z, _b = b.centroid.z;
|
104 | return _a < _b ? -1 : _a > _b ? 1 : _a >= _b ? 0 : NaN;
|
105 | };
|
106 |
|
107 | _3d.draw = function(d){
|
108 | if(!((shape === 'POINT') || (shape === 'LINE'))){
|
109 | return draw[shape](d);
|
110 | }
|
111 | };
|
112 |
|
113 | return _3d;
|
114 | }
|