@easyv/react-component-builder 0.19.3 → 0.19.5-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,122 +1,122 @@
1
- import React, { Component } from "react";
2
- import * as THREE from "three";
3
- import { isEqual } from "lodash";
4
- import { EasyVComponent3d } from "./utils/Component";
5
- import { reduceConfig } from "./utils/reduce-config";
6
-
7
- export default class MyComponent extends Component {
8
- constructor(props) {
9
- super(props);
10
-
11
- this.component = new EasyVComponent3d(props);
12
- this.initStage();
13
- }
14
-
15
- initStage = () => {
16
- let { width, height } = this.component.getDimension(),
17
- { cameraConfig } = this.component.config.chart.visionConfig,
18
- camera = new THREE.PerspectiveCamera(
19
- cameraConfig.fov,
20
- width / height,
21
- 0.01,
22
- 10000
23
- ),
24
- renderer = new THREE.WebGLRenderer({
25
- antialias: true,
26
- alpha: true,
27
- logarithmicDepthBuffer: true,
28
- }),
29
- scene = new THREE.Scene();
30
-
31
- scene.add(new THREE.AmbientLight(0xffffff, 1));
32
-
33
- // 测试几何体
34
- const geo = new THREE.BoxGeometry(20, 20, 20);
35
- const mat = new THREE.MeshNormalMaterial();
36
- const box = new THREE.Mesh(geo, mat);
37
- scene.add(box);
38
- // :测试几何体
39
-
40
- this.component.init({ camera, renderer, scene });
41
- this.component.initOrbitControls();
42
- this.updateCamera();
43
- this.animate();
44
- };
45
-
46
- updateCamera = () => {
47
- let { cameraConfig } = this.component.config.chart.visionConfig,
48
- { fov, position, target } = cameraConfig;
49
-
50
- this.component.setCameraFov(fov);
51
- this.component.setCameraPosition(position.x, position.y, position.z);
52
- this.component.setOrbitControlsPosition(target.x, target.y, target.z);
53
- this.component.updateCamera();
54
- };
55
-
56
- // ========================== 3d渲染 ==========================
57
- animate = () => {
58
- this.component.render();
59
- this.timer = requestAnimationFrame(this.animate);
60
- };
61
-
62
- // ========================== 组件生命周期 ==========================
63
- componentDidMount() {
64
- this.component.appendCanvasToDom(this.container);
65
- }
66
-
67
- componentWillReceiveProps(nextProps) {
68
- if (!isEqual(this.props.configuration, nextProps.configuration)) {
69
- let { config } = this.component,
70
- { chart } = config,
71
- { visionConfig } = chart,
72
- { cameraConfig } = visionConfig;
73
-
74
- this.component.setConfig(nextProps.configuration);
75
-
76
- let { config: nextConfig } = this.component,
77
- { chart: nextChart } = nextConfig,
78
- { visionConfig: nextVisionConfig } = nextChart,
79
- { cameraConfig: nextCameraConfig } = nextVisionConfig;
80
-
81
- if (!isEqual(cameraConfig, nextCameraConfig)) {
82
- this.updateCamera();
83
- }
84
- }
85
- }
86
-
87
- componentWillUnmount() {
88
- this.timer && cancelAnimationFrame(this.timer);
89
- this.timer = null;
90
- }
91
-
92
- render() {
93
- const { configuration, id } = this.props;
94
- const { chart } = reduceConfig(configuration);
95
- const { dimension } = chart;
96
-
97
- const styles = {
98
- position: "absolute",
99
- ...dimension.chartPosition,
100
- ...dimension.chartDimension,
101
- };
102
-
103
- const containerStyle = {
104
- position: "relative",
105
- width: "100%",
106
- height: "100%",
107
- overflow: "hidden",
108
- };
109
-
110
- /**
111
- * 固定格式: 返回的div必须有className/id属性
112
- */
113
- return (
114
- <div className="__easyv-component" style={styles} id={id}>
115
- <div
116
- ref={(elment) => (this.container = elment)}
117
- style={containerStyle}
118
- />
119
- </div>
120
- );
121
- }
122
- }
1
+ import React, { Component } from "react";
2
+ import * as THREE from "three";
3
+ import { isEqual } from "lodash";
4
+ import { EasyVComponent3d } from "./utils/Component";
5
+ import { reduceConfig } from "./utils/reduce-config";
6
+
7
+ export default class MyComponent extends Component {
8
+ constructor(props) {
9
+ super(props);
10
+
11
+ this.component = new EasyVComponent3d(props);
12
+ this.initStage();
13
+ }
14
+
15
+ initStage = () => {
16
+ let { width, height } = this.component.getDimension(),
17
+ { cameraConfig } = this.component.config.chart.visionConfig,
18
+ camera = new THREE.PerspectiveCamera(
19
+ cameraConfig.fov,
20
+ width / height,
21
+ 0.01,
22
+ 10000
23
+ ),
24
+ renderer = new THREE.WebGLRenderer({
25
+ antialias: true,
26
+ alpha: true,
27
+ logarithmicDepthBuffer: true,
28
+ }),
29
+ scene = new THREE.Scene();
30
+
31
+ scene.add(new THREE.AmbientLight(0xffffff, 1));
32
+
33
+ // 测试几何体
34
+ const geo = new THREE.BoxGeometry(20, 20, 20);
35
+ const mat = new THREE.MeshNormalMaterial();
36
+ const box = new THREE.Mesh(geo, mat);
37
+ scene.add(box);
38
+ // :测试几何体
39
+
40
+ this.component.init({ camera, renderer, scene });
41
+ this.component.initOrbitControls();
42
+ this.updateCamera();
43
+ this.animate();
44
+ };
45
+
46
+ updateCamera = () => {
47
+ let { cameraConfig } = this.component.config.chart.visionConfig,
48
+ { fov, position, target } = cameraConfig;
49
+
50
+ this.component.setCameraFov(fov);
51
+ this.component.setCameraPosition(position.x, position.y, position.z);
52
+ this.component.setOrbitControlsPosition(target.x, target.y, target.z);
53
+ this.component.updateCamera();
54
+ };
55
+
56
+ // ========================== 3d渲染 ==========================
57
+ animate = () => {
58
+ this.component.render();
59
+ this.timer = requestAnimationFrame(this.animate);
60
+ };
61
+
62
+ // ========================== 组件生命周期 ==========================
63
+ componentDidMount() {
64
+ this.component.appendCanvasToDom(this.container);
65
+ }
66
+
67
+ componentWillReceiveProps(nextProps) {
68
+ if (!isEqual(this.props.configuration, nextProps.configuration)) {
69
+ let { config } = this.component,
70
+ { chart } = config,
71
+ { visionConfig } = chart,
72
+ { cameraConfig } = visionConfig;
73
+
74
+ this.component.setConfig(nextProps.configuration);
75
+
76
+ let { config: nextConfig } = this.component,
77
+ { chart: nextChart } = nextConfig,
78
+ { visionConfig: nextVisionConfig } = nextChart,
79
+ { cameraConfig: nextCameraConfig } = nextVisionConfig;
80
+
81
+ if (!isEqual(cameraConfig, nextCameraConfig)) {
82
+ this.updateCamera();
83
+ }
84
+ }
85
+ }
86
+
87
+ componentWillUnmount() {
88
+ this.timer && cancelAnimationFrame(this.timer);
89
+ this.timer = null;
90
+ }
91
+
92
+ render() {
93
+ const { configuration, id } = this.props;
94
+ const { chart } = reduceConfig(configuration);
95
+ const { dimension } = chart;
96
+
97
+ const styles = {
98
+ position: "absolute",
99
+ ...dimension.chartPosition,
100
+ ...dimension.chartDimension,
101
+ };
102
+
103
+ const containerStyle = {
104
+ position: "relative",
105
+ width: "100%",
106
+ height: "100%",
107
+ overflow: "hidden",
108
+ };
109
+
110
+ /**
111
+ * 固定格式: 返回的div必须有className/id属性
112
+ */
113
+ return (
114
+ <div className="__easyv-component" style={styles} id={id}>
115
+ <div
116
+ ref={(elment) => (this.container = elment)}
117
+ style={containerStyle}
118
+ />
119
+ </div>
120
+ );
121
+ }
122
+ }