@@ -15,7 +15,7 @@ class Viewer {
15
15
const { offsetWidth, offsetHeight } = this . HTMLContainer ;
16
16
this . scene = new THREE . Scene ( ) ;
17
17
this . camera = new THREE . PerspectiveCamera ( 70 , offsetWidth / offsetHeight , 0.1 , 1000 ) ;
18
- this . camera . position . set ( 0 , 1 , DEADLINE + 2 ) ;
18
+ this . camera . position . set ( 0 , 1 , DEADLINE + 5 ) ;
19
19
this . camera . lookAt ( 0 , 2.5 , 0 ) ;
20
20
this . renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
21
21
this . renderer . setSize ( offsetWidth , offsetHeight ) ;
@@ -65,49 +65,49 @@ class Viewer {
65
65
66
66
/**
67
67
* @method drawObject
68
- * @param obj - {object with params like: type: 'text', content: 'text', }
68
+ * @param config - {object with params like: type: 'text', content: 'text', }
69
69
*/
70
- drawObject ( obj ) {
71
- const enemy = this . _makeEmojiSprite ( obj . look , .3 ) ;
70
+ drawObject ( config ) {
71
+ const obj = this . _makeEmojiSprite ( config . look ) ;
72
72
73
- enemy . position . set ( this . getRandomIntInclusive ( - RANGE_X , RANGE_X ) , 0.5 , - DEADLINE ) ;
74
- this . _objContainer . add ( enemy ) ;
73
+ obj . position . set (
74
+ this . getRandomInt ( - RANGE_X , RANGE_X ) ,
75
+ this . getRandomFloat ( 0 , RANGE_Y ) ,
76
+ - DEADLINE
77
+ ) ;
78
+
79
+ this . _objContainer . add ( obj ) ;
75
80
76
- return enemy . uuid ;
81
+ return obj . uuid ;
77
82
}
78
83
79
- _makeEmojiSprite ( message , emojiSize = 2.5 ) {
80
- let url = window . location . search . substring ( 1 ) ;
81
- let emojiwidth = new URLSearchParams ( url ) . get ( "emojiWidth" )
82
- ? new URLSearchParams ( url ) . get ( "emojiWidth" )
83
- : 80 ;
84
- let fontface = "Arial" ;
85
- let fontsize = emojiwidth * 0.75 ;
86
-
87
- let canvas = document . createElement ( "canvas" ) ;
88
- canvas . width = emojiwidth ;
89
- canvas . height = emojiwidth ;
90
- let context = canvas . getContext ( "2d" ) ;
91
- context . font = `Bold ${ fontsize } px ${ fontface } ` ;
92
- context . font = `Bold ${ fontsize } px ${ fontface } ` ;
84
+ _makeEmojiSprite ( look , emojiTextureSize = 100 ) {
85
+ const emojiCanvas = document . createElement ( 'canvas' ) ;
86
+
87
+ emojiCanvas . width = emojiTextureSize ;
88
+ emojiCanvas . height = emojiTextureSize ;
89
+
90
+ const fontFace = 'Arial' ;
91
+ const fontSize = emojiTextureSize * 0.75 ;
92
+
93
+ const context = emojiCanvas . getContext ( "2d" ) ;
94
+ context . font = `Bold ${ fontSize } px ${ fontFace } ` ;
93
95
context . lineWidth = 1 ;
94
- context . fillText ( message , - 2 , fontsize - 3 ) ;
96
+ context . fillText ( look , - 2 , fontSize - 3 ) ;
95
97
96
- let texture = new THREE . Texture ( canvas ) ;
97
- texture . needsUpdate = true ;
98
+ const emojiTexture = new THREE . Texture ( emojiCanvas ) ;
99
+ emojiTexture . needsUpdate = true ;
98
100
99
- let spriteMaterial = new THREE . SpriteMaterial ( {
100
- map : texture ,
101
+ const spriteMaterial = new THREE . SpriteMaterial ( {
102
+ map : emojiTexture ,
101
103
transparent : false ,
102
104
alphaTest : 0.5
103
105
} ) ;
104
106
105
107
let sprite = new THREE . Sprite ( spriteMaterial ) ;
106
- sprite . scale . set (
107
- emojiSize * 0.5 * fontsize ,
108
- emojiSize * 0.45 * fontsize ,
109
- 0.25 * fontsize
110
- ) ;
108
+
109
+ sprite . scale . set ( 3 , 3 , 3 ) ;
110
+
111
111
return sprite ;
112
112
}
113
113
@@ -122,9 +122,13 @@ class Viewer {
122
122
}
123
123
}
124
124
125
- getRandomIntInclusive ( min , max ) {
125
+ getRandomInt ( min , max ) {
126
126
min = Math . ceil ( min ) ;
127
127
max = Math . floor ( max ) ;
128
128
return Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ;
129
129
}
130
+
131
+ getRandomFloat ( min , max ) {
132
+ return Math . random ( ) * ( max - min ) + min ;
133
+ }
130
134
}
0 commit comments