@@ -59,6 +59,7 @@ class View extends Component {
5959 let el = document . getElementById ( "rig" ) ;
6060 el . components [ "movement-controls" ] . velocity = new THREE . Vector3 ( 0 , 0 , 0 ) ;
6161 }
62+
6263 }
6364
6465 componentWillUnmount ( ) {
@@ -110,16 +111,87 @@ class View extends Component {
110111 </ a-entity >
111112 ) ;
112113 }
114+ if ( ent . light ) {
115+ delete flattened . light ;
116+ let target = null , indicator = null ;
117+ if ( ent . light . target ) {
118+ //Since the target will override the rotation, we want to delete the rotation attribute so it won't have an effect on the rotation of indicator.
119+ delete flattened . rotation ;
120+ ent . light . state += "target: #lighttarget;" ;
121+ let target_position = `${ ent . light . target . x || 0 } ${ ent . light . target . y || 0 } ${ ent . light . target . z || 0 } ` ;
122+ target = < a-entity id = "lighttarget" position = { target_position } > </ a-entity > ;
123+ }
124+ if ( this . props . sceneConfig . settings . lightIndicator ) {
125+ indicator = this . lightIndicatorHelper ( ent ) ;
126+ }
127+ if ( this . props . sceneConfig . settings . castShadow ) {
128+ ent . light . state += this . lightShadowHelper ( ent . light ) ;
129+ }
130+ return [ < a-entity key = { ent . id } id = { ent . id } light = { ent . light . state } { ...flattened } > { indicator } </ a-entity > , target ] ;
131+ }
132+ let shadow ;
133+ if ( this . props . sceneConfig . settings . castShadow ) {
134+ shadow = "cast:true; receive:true;" ;
135+ } else {
136+ shadow = "cast:false; receive:false;" ;
137+ }
138+
113139 if ( ent . text ) {
114140 delete flattened . text ; // this takes care of a warning, may not be necessary
115141 return < a-text key = { ent . id } { ...flattened } > </ a-text > ;
116142 }
117143 if ( ent . tube ) {
118- return < a-tube path = { ent . path } radius = { ent . radius } material = { ent . material } > </ a-tube > ;
144+ return < a-tube path = { ent . path } radius = { ent . radius } material = { ent . material } shadow = { shadow } shadowcustomsetting > </ a-tube > ;
119145 }
120- return < a-entity key = { ent . id } { ...flattened } > </ a-entity > ;
146+ return < a-entity key = { ent . id } { ...flattened } shadow = { shadow } shadowcustomsetting > </ a-entity > ;
121147 }
122148 }
149+ //return elements that contains necessary configuration for light indicator based on light's type and properties
150+ lightIndicatorHelper = ( ent ) => {
151+
152+ //this is a position for passing in to indicatorroation to determine the rotation of the light that use position as vector.
153+ let position = `position:${ ent . position . x || 0 } ${ ent . position . y || 0 } ${ ent . position . z || 0 } ;` ;
154+ if ( ent . light . target ) {
155+ position += `target:${ ent . light . target . x || 0 } ${ ent . light . target . y || 0 } ${ ent . light . target . z || 0 } ;` ;
156+ }
157+
158+ //ambient light doesn't have an indicator
159+ switch ( ent . light . type ) {
160+ case "point" :
161+ return < a-entity id = { ent . id + "Ind" } key = { ent . id + "Ind" } pointlightindicator = { `color: ${ ent . color } ;` } > </ a-entity > ;
162+ case "spot" :
163+ let target = true ;
164+ if ( ! ent . light . target ) {
165+ position = "" ;
166+ target = false ;
167+ }
168+ return < a-entity id = { ent . id + "Ind" } key = { ent . id + "Ind" } spotlightindicator = { `color: ${ ent . color } ; target:${ target } ` } indicatorrotation = { position } > </ a-entity > ;
169+ case "directional" :
170+ return < a-entity id = { ent . id + "Ind" } key = { ent . id + "Ind" } directionallightindicator = { `color: ${ ent . color } ;` } indicatorrotation = { position } > </ a-entity > ;
171+ case "hemisphere" :
172+ return < a-entity id = { ent . id + "Ind" } key = { ent . id + "Ind" } hemispherelightindicator = { `color: ${ ent . color } ; secondColor: ${ ent . light . secondColor } ` } > </ a-entity > ;
173+ default :
174+ return null ;
175+ }
176+ }
177+ //return string that contains necessary configuration for shadow based on light's type
178+ lightShadowHelper = ( light ) => {
179+ let newState = "" ;
180+ //ambient and hemisphere light doesn't cast shadow
181+ if ( light . type !== "ambient" && light . type !== "hemisphere" ) {
182+ newState += "castShadow:true; shadowMapHeight:2000; shadowMapWidth:2000;" ;
183+ if ( light . type === "spot" ) {
184+ newState += "shadowBias: -0.02; shadowCameraNear: 7;" ;
185+ } else if ( light . type === "directional" ) {
186+ newState += "shadowCameraNear: -40; shadowBias: -0.002; shadowCameraTop: 40; shadowCameraBottom: -40; shadowCameraLeft: -40; shadowCameraRight: 40;" ;
187+ } else if ( light . type === "point" ) {
188+ newState += "shadowCameraFar: 25; shadowBias: -0.02;" ;
189+ }
190+ } else {
191+ newState += "castShadow: false;" ;
192+ }
193+ return newState ;
194+ }
123195
124196 assetsHelper = ( asset ) => {
125197 return (
@@ -180,30 +252,32 @@ class View extends Component {
180252 if ( this . props . sceneConfig . settings . showCoordHelper ) {
181253 return (
182254 < Fragment >
183- < a-grid height = "53.33" width = "53.33" position = "-0.5 -0.26 -0.5" scale = "1.5 1.5 1.5" />
184- < a-tube path = "-35 -0.2 0, 35 -0.2 0" radius = "0.05" material = "color: red" > </ a-tube >
185- < a-tube path = "0 -0.2 -35, 0 -0.2 35" radius = "0.05" material = "color: blue" > </ a-tube >
255+ < a-grid height = "53.33" width = "53.33" position = "-0.5 -0.26 -0.5" scale = "1.5 1.5 1.5" layer = "type:mesh;layer:1;" />
256+ < a-tube path = "-35 -0.2 0, 35 -0.2 0" radius = "0.05" material = "color: red" layer = "type:mesh;layer:1;" > </ a-tube >
257+ < a-tube path = "0 -0.2 -35, 0 -0.2 35" radius = "0.05" material = "color: blue" layer = "type:mesh;layer:1;" > </ a-tube >
186258 < a-text
187259 color = "#555"
188260 rotation = "0 0 0"
189261 position = "-0.0005 .1 0"
190262 side = "double"
191263 align = "center"
192- value = "- X X +" > </ a-text >
264+ value = "- X X +"
265+ layer = "type:text;layer:1;" > </ a-text >
193266 < a-text
194267 color = "#555"
195268 rotation = "0 90 0"
196269 position = "0 .1 -0.01"
197270 side = "double"
198271 align = "center"
199- value = "+ Z Z -" >
200- </ a-text >
272+ value = "+ Z Z -"
273+ layer = "type:text;layer:1;" > </ a-text >
201274 < a-text
202275 color = "#555"
203276 rotation = "0 90 90"
204277 position = "0 .1 0"
205278 side = "double"
206- value = " Y + " > </ a-text >
279+ value = " Y + "
280+ layer = "type:text;layer:1;" > </ a-text >
207281 </ Fragment >
208282 ) ;
209283 } else {
@@ -214,12 +288,15 @@ class View extends Component {
214288 makeFloor = ( ) => {
215289 if ( this . props . sceneConfig . settings . showFloor ) {
216290 return (
217- < a-entity id = "floor"
291+ < a-plane
292+ id = "floor"
218293 geometry = "primitive: box;"
219- material = { "color: " + this . props . sceneConfig . settings . floorColor }
294+ color = { this . props . sceneConfig . settings . floorColor }
295+ material = "side: double;"
220296 static-body = "shape: box"
221297 scale = "80 .01 80"
222298 position = "0 -0.5 0"
299+ shadow = { `cast: false; receive: ${ this . props . sceneConfig . settings . castShadow } ` }
223300 />
224301 ) ;
225302 } else {
@@ -231,7 +308,7 @@ class View extends Component {
231308 /* eslint-disable */
232309 return (
233310 ! this . state . welcomeOpen ?
234- < a-scene physics = "debug: false; friction: 3; restitution: .3;" embedded debug = "false" >
311+ < a-scene scenelayer shadow = "type:pcf;" physics = "debug: false; friction: 3; restitution: .3;" embedded debug = "false" >
235312 < a-assets >
236313 < a-mixin id = "checkpoint" > </ a-mixin >
237314 < a-mixin id = "checkpoint-hovered" color = "#6CEEB5" > </ a-mixin >
@@ -242,11 +319,25 @@ class View extends Component {
242319 < a-sky color = { this . props . sceneConfig . settings . skyColor } />
243320 < this . coordinateHelper />
244321 < this . makeFloor />
322+ { this . props . sceneConfig . settings . defaultLight ?
323+ < a-entity id = "DefaultLight" >
324+ < a-entity id = "AmbientLight" light = "type: ambient; color: #BBB" > </ a-entity >
325+ < a-entity id = "DirectionalLight" light = { "type: directional; color: #FFF; intensity: 0.6; " + this . lightShadowHelper ( { state : "" , type : "directional" } ) } position = "-3 3 1" > </ a-entity >
326+ </ a-entity >
327+ : null
328+ }
329+ { this . props . sceneConfig . settings . lightIndicator || this . props . sceneConfig . settings . showCoordHelper ?
330+ < a-entity id = "AltLayerLight" >
331+ < a-entity id = "AmbientLight" light = "type: ambient; color: #BBB" layer = "type:light;layer:1;" > </ a-entity >
332+ < a-entity id = "DirectionalLight" light = { "type: directional; color: #FFF; intensity: 0.6; " + this . lightShadowHelper ( { state : "" , type : "directional" } ) } position = "-3 3 1" layer = "type:light;layer:1;" > </ a-entity >
333+ </ a-entity >
334+ : null }
245335 { // create the entities
246336 Object . keys ( this . props . objects ) . map ( it => {
247337 return this . helper ( this . props . objects [ it ] ) ;
248338 } )
249339 }
340+
250341
251342 { this . props . sceneConfig . settings . camConfig === 1 ?
252343 < a-entity position = "0 0 0" >
0 commit comments