1
1
import React , { Component } from "react" ;
2
2
import * as THREE from "three" ;
3
+ import { CircleGeometry , LineLoop , LineBasicMaterial } from "three" ;
3
4
4
5
window . THREE = THREE ;
5
6
@@ -30,7 +31,7 @@ class ThreeView extends Component {
30
31
this . scene . add ( dirLight ) ;
31
32
32
33
this . camera . position . y = 1 ;
33
- this . camera . position . z = 3 ;
34
+ this . camera . position . z = 3.5 ;
34
35
this . camera . lookAt ( new THREE . Vector3 ( 0 , 0 , 0 ) ) ;
35
36
this . objectGroup = new THREE . Group ( ) ;
36
37
@@ -68,6 +69,23 @@ class ThreeView extends Component {
68
69
this . clouds . visible = true ;
69
70
}
70
71
72
+ const geometry = new CircleGeometry ( 1.1 , 32 ) ;
73
+ geometry . vertices . shift ( ) ;
74
+ const mat1 = new LineBasicMaterial ( {
75
+ color : 0xfac79e ,
76
+ } ) ;
77
+ const mat2 = new LineBasicMaterial ( {
78
+ color : 0xfafa9a ,
79
+ } ) ;
80
+
81
+ this . scannerLine1 = new LineLoop ( geometry , mat1 ) ;
82
+ this . scannerLine1 . scale . set ( 1.1 , 1.1 , 1.1 ) ;
83
+ this . objectGroup . add ( this . scannerLine1 ) ;
84
+
85
+ this . scannerLine2 = new LineLoop ( geometry , mat2 ) ;
86
+ this . scannerLine2 . scale . set ( 1.15 , 1.15 , 1.15 ) ;
87
+ this . objectGroup . add ( this . scannerLine2 ) ;
88
+
71
89
this . threeMount . current . appendChild ( this . renderer . domElement ) ;
72
90
this . animating = true ;
73
91
this . animate ( ) ;
@@ -108,6 +126,16 @@ class ThreeView extends Component {
108
126
this . clouds . visible = true ;
109
127
}
110
128
}
129
+ shouldComponentUpdate ( nextProps ) {
130
+ if (
131
+ nextProps . wireframe !== this . props . wireframe ||
132
+ nextProps . color !== this . props . color ||
133
+ nextProps . planet !== this . props . planet ||
134
+ nextProps . clouds !== this . props . clouds
135
+ )
136
+ return true ;
137
+ return false ;
138
+ }
111
139
componentWillUnmount ( ) {
112
140
this . animating = false ;
113
141
cancelAnimationFrame ( this . frame ) ;
@@ -130,6 +158,13 @@ class ThreeView extends Component {
130
158
this . cloudRotation += 0.03 ;
131
159
this . objectGroup . rotation . setFromVector3 ( rot ) ;
132
160
this . clouds . rotation . setFromVector3 ( cloudRot ) ;
161
+
162
+ this . scannerLine1 . rotation . x += 0.01 ;
163
+ this . scannerLine1 . rotateY ( 0.02 ) ;
164
+
165
+ this . scannerLine2 . rotation . x += 0.005 ;
166
+ this . scannerLine2 . rotateY ( 0.03 ) ;
167
+
133
168
this . renderer . render ( this . scene , this . camera ) ;
134
169
this . frame = requestAnimationFrame ( this . animate ) ;
135
170
} ;
0 commit comments