@@ -279,6 +279,64 @@ test("Change light shader", 4, function() {
279279
280280} ) ;
281281
282+ test ( "Change light transformation" , function ( ) {
283+ stop ( ) ;
284+ var frameLoaded = Q . fcall ( promiseIFrameLoaded , "scenes/webgl-rendering03.html" ) ;
285+
286+ var test = frameLoaded . then ( function ( doc ) {
287+ var s = doc . querySelector ( "#xml3DElem" ) ;
288+ doc . getElementById ( "pointlight" ) . style . display = 'inherit' ;
289+ doc . getElementById ( "dirlight" ) . style . display = 'none' ;
290+ doc . getElementById ( "phongShadedGroup" ) . style . display = 'inherit' ;
291+
292+ return s ;
293+ } ) . then ( promiseSceneRendered ) . then ( function ( s ) {
294+ var actual = XML3DUnit . getPixelValue ( getContextForXml3DElement ( s ) , 90 , 90 ) ;
295+ deepEqual ( actual , [ 255 , 0 , 0 , 255 ] , "Phong object is lit by red point light shader" ) ;
296+
297+ var light = s . ownerDocument . querySelector ( "#pointlightLight" ) ;
298+ QUnit . closeMatrix ( light . getLocalMatrix ( ) , new XML3D . Mat4 ( ) , EPSILON , "Light has a local transform matrix that is identity" ) ;
299+
300+ light . setAttribute ( "style" , "transform: translate3d(0, 0, -10px)" ) ;
301+
302+ return s ;
303+ } ) . then ( promiseSceneRendered ) . then ( function ( s ) {
304+ var light = s . ownerDocument . querySelector ( "#pointlightLight" ) ;
305+ QUnit . closeMatrix ( light . getLocalMatrix ( ) , new XML3D . Mat4 ( ) . translate ( new XML3D . Vec3 ( 0 , 0 , - 10 ) ) , EPSILON , "Light's local matrix was updated with new style transform" ) ;
306+ var parentWorld = light . parentElement . getWorldMatrix ( ) ;
307+ QUnit . closeMatrix ( light . getWorldMatrix ( ) , parentWorld . translate ( new XML3D . Vec3 ( 0 , 0 , - 10 ) ) , EPSILON , "Light's world matrix matches parent * local" ) ;
308+
309+ var actual = XML3DUnit . getPixelValue ( getContextForXml3DElement ( s ) , 90 , 90 ) ;
310+ deepEqual ( actual , [ 0 , 0 , 0 , 255 ] , "Light is properly positioned behind the square" ) ;
311+
312+ light . removeAttribute ( "style" ) ;
313+
314+ return s ;
315+ } ) . then ( promiseSceneRendered ) . then ( function ( s ) {
316+ var actual = XML3DUnit . getPixelValue ( getContextForXml3DElement ( s ) , 90 , 90 ) ;
317+ deepEqual ( actual , [ 255 , 0 , 0 , 255 ] , "Light position was reset once local transform was removed" ) ;
318+
319+ var transform = s . ownerDocument . createElement ( "transform" ) ;
320+ transform . setAttribute ( "id" , "test_light_transform" ) ;
321+ transform . setAttribute ( "translation" , "0 0 -10" ) ;
322+ s . appendChild ( transform ) ;
323+
324+ s . ownerDocument . querySelector ( "#pointlightLight" ) . setAttribute ( "transform" , "#test_light_transform" ) ;
325+ return s ;
326+ } ) . then ( promiseSceneRendered ) . then ( function ( s ) {
327+ var light = s . ownerDocument . querySelector ( "#pointlightLight" ) ;
328+ QUnit . closeMatrix ( light . getLocalMatrix ( ) , new XML3D . Mat4 ( ) . translate ( new XML3D . Vec3 ( 0 , 0 , - 10 ) ) , EPSILON , "Light's local matrix was updated with new transform element" ) ;
329+ var parentWorld = light . parentElement . getWorldMatrix ( ) ;
330+ QUnit . closeMatrix ( light . getWorldMatrix ( ) , parentWorld . translate ( new XML3D . Vec3 ( 0 , 0 , - 10 ) ) , EPSILON , "Light's world matrix matches parent * local" ) ;
331+
332+ var actual = XML3DUnit . getPixelValue ( getContextForXml3DElement ( s ) , 90 , 90 ) ;
333+ deepEqual ( actual , [ 0 , 0 , 0 , 255 ] , "Light is properly positioned behind the square" ) ;
334+ } ) ;
335+
336+ test . fin ( QUnit . start ) . done ( ) ;
337+
338+ } ) ;
339+
282340
283341module ( "Lights" , {
284342 setup : function ( ) {
0 commit comments