@@ -19,23 +19,20 @@ import {assetPath, textureMatchesMeta, timePasses, waitForEvent} from '../helper
1919import { BasicSpecTemplate } from '../templates.js' ;
2020
2121const expect = chai . expect ;
22- const BG_IMAGE_URL = assetPath ( 'equirectangular.png ' ) ;
22+ const BG_IMAGE_URL = assetPath ( 'spruit_sunrise_2k.jpg ' ) ;
2323const MODEL_URL = assetPath ( 'reflective-sphere.gltf' ) ;
2424
25- const skysphereUsingMap =
25+ const backgroundHasMap =
2626 ( scene , url ) => {
27- const material = scene . skysphere . material ;
28- const color = material . color . getHexString ( ) ;
29- return textureMatchesMeta ( material . map , { url : url } ) && color === 'ffffff' ;
27+ return textureMatchesMeta ( scene . background . texture , { url : url } ) ;
3028 }
3129
32- const skysphereUsingColor =
30+ const backgroundHasColor =
3331 ( scene , hex ) => {
34- const { color, map} = scene . skysphere . material ;
35- // Invert gamma correct to match passed in hex
36- const gammaCorrectedColor = color . clone ( ) . convertLinearToGamma ( 2.2 ) ;
37-
38- return map == null && gammaCorrectedColor . getHexString ( ) === hex ;
32+ if ( ! scene . background || ! scene . background . isColor ) {
33+ return false ;
34+ }
35+ return scene . background . getHexString ( ) === hex ;
3936 }
4037
4138/**
@@ -47,7 +44,7 @@ const skysphereUsingColor =
4744 * @param {THREE.Scene } scene
4845 * @param {Object } meta
4946 */
50- const modelUsingEnvmap = ( scene , meta ) => {
47+ const modelUsingEnvMap = ( scene , meta ) => {
5148 let found = false ;
5249 scene . model . traverse ( object => {
5350 if ( ! object . material || ! object . material . envMap ) {
@@ -71,18 +68,22 @@ const modelUsingEnvmap = (scene, meta) => {
7168 * @param {Model } model
7269 * @param {Object } meta
7370 */
74- const waitForEnvmap = ( model , meta ) => waitForEvent (
75- model ,
76- 'envmap-change' ,
77- e => textureMatchesMeta ( e . value , { ... meta , type : 'EnvironmentMap' } ) ) ;
71+ const waitForEnvMap = ( model , meta ) =>
72+ waitForEvent ( model , 'envmap-change' , event => {
73+ return textureMatchesMeta ( event . value , { ... meta } ) ;
74+ } ) ;
7875
7976/**
8077 * Returns a promise that resolves when a given element is loaded
8178 * and has an environment map set that matches the passed in meta.
8279 * @see textureMatchesMeta
8380 */
84- const waitForLoadAndEnvmap = ( scene , element , meta ) => Promise . all (
85- [ waitForEvent ( element , 'load' ) , waitForEnvmap ( scene . model , meta ) ] ) ;
81+ const waitForLoadAndEnvMap =
82+ ( scene , element , meta ) => {
83+ const load = waitForEvent ( element , 'load' ) ;
84+ const envMap = waitForEnvMap ( scene . model , meta ) ;
85+ return Promise . all ( [ load , envMap ] ) ;
86+ }
8687
8788suite ( 'ModelViewerElementBase with EnvironmentMixin' , ( ) => {
8889 let nextId = 0 ;
@@ -109,34 +110,34 @@ suite('ModelViewerElementBase with EnvironmentMixin', () => {
109110 BasicSpecTemplate ( ( ) => ModelViewerElement , ( ) => tagName ) ;
110111
111112 test (
112- 'has default skysphere if no background-image or background-color' ,
113+ 'has default background if no background-image or background-color' ,
113114 ( ) => {
114- expect ( skysphereUsingColor ( scene , 'ffffff' ) ) . to . be . equal ( true ) ;
115+ expect ( backgroundHasColor ( scene , 'ffffff' ) ) . to . be . equal ( true ) ;
115116 } ) ;
116117
117118 test (
118- 'has default skysphere if no background-image or background-color when in DOM' ,
119+ 'has default background if no background-image or background-color when in DOM' ,
119120 async ( ) => {
120121 document . body . appendChild ( element ) ;
121122 await timePasses ( ) ;
122- expect ( skysphereUsingColor ( scene , 'ffffff' ) ) . to . be . equal ( true ) ;
123+ expect ( backgroundHasColor ( scene , 'ffffff' ) ) . to . be . equal ( true ) ;
123124 } ) ;
124125
125126 suite ( 'with a background-image property' , ( ) => {
126127 suite ( 'and a src property' , ( ) => {
127128 setup ( async ( ) => {
128- let onLoad = waitForLoadAndEnvmap ( scene , element , { url : BG_IMAGE_URL } ) ;
129+ let onLoad = waitForLoadAndEnvMap ( scene , element , { url : BG_IMAGE_URL } ) ;
129130 element . src = MODEL_URL ;
130131 element . backgroundImage = BG_IMAGE_URL ;
131132 await onLoad ;
132133 } ) ;
133134
134- test ( 'displays skysphere with the correct map' , async function ( ) {
135- expect ( skysphereUsingMap ( scene , element . backgroundImage ) ) . to . be . ok ;
135+ test ( 'displays background with the correct map' , async function ( ) {
136+ expect ( backgroundHasMap ( scene , element . backgroundImage ) ) . to . be . ok ;
136137 } ) ;
137138
138139 test ( 'applies the image as an environment map' , async function ( ) {
139- expect ( modelUsingEnvmap ( scene , {
140+ expect ( modelUsingEnvMap ( scene , {
140141 url : element . backgroundImage
141142 } ) ) . to . be . ok ;
142143 } ) ;
@@ -159,26 +160,30 @@ suite('ModelViewerElementBase with EnvironmentMixin', () => {
159160 suite ( 'with a background-color property' , ( ) => {
160161 suite ( 'and a src property' , ( ) => {
161162 setup ( async ( ) => {
162- let onLoad = waitForLoadAndEnvmap ( scene , element , { url : null } ) ;
163+ let onLoad = waitForLoadAndEnvMap ( scene , element , {
164+ url : null ,
165+ } ) ;
163166 element . src = MODEL_URL ;
164167 element . backgroundColor = '#ff0077' ;
165168 await onLoad ;
166169 } ) ;
167170
168- test ( 'displays skysphere with the correct color' , async function ( ) {
169- expect ( skysphereUsingColor ( scene , 'ff0077' ) ) . to . be . ok ;
171+ test ( 'displays background with the correct color' , async function ( ) {
172+ expect ( backgroundHasColor ( scene , 'ff0077' ) ) . to . be . ok ;
170173 } ) ;
171174
172175 test ( 'applies a generated environment map on model' , async function ( ) {
173- expect ( modelUsingEnvmap ( scene , { url : null } ) ) . to . be . ok ;
176+ expect ( modelUsingEnvMap ( scene , {
177+ url : null ,
178+ } ) ) . to . be . ok ;
174179 } ) ;
175180
176181 test (
177- 'displays skysphere with correct color after attaching to DOM' ,
182+ 'displays background with correct color after attaching to DOM' ,
178183 async function ( ) {
179184 document . body . appendChild ( element ) ;
180185 await timePasses ( ) ;
181- expect ( skysphereUsingColor ( scene , 'ff0077' ) ) . to . be . ok ;
186+ expect ( backgroundHasColor ( scene , 'ff0077' ) ) . to . be . ok ;
182187 } ) ;
183188 test ( 'the directional light is tinted' , ( ) => {
184189 const lightColor = scene . shadowLight . color . getHexString ( ) . toLowerCase ( ) ;
@@ -189,34 +194,34 @@ suite('ModelViewerElementBase with EnvironmentMixin', () => {
189194
190195 suite ( 'with background-color and background-image properties' , ( ) => {
191196 setup ( async ( ) => {
192- let onLoad = waitForLoadAndEnvmap ( scene , element , { url : BG_IMAGE_URL } ) ;
197+ let onLoad = waitForLoadAndEnvMap ( scene , element , { url : BG_IMAGE_URL } ) ;
193198 element . setAttribute ( 'src' , MODEL_URL ) ;
194199 element . setAttribute ( 'background-color' , '#ff0077' ) ;
195200 element . setAttribute ( 'background-image' , BG_IMAGE_URL ) ;
196201 await onLoad ;
197202 } ) ;
198203
199- test ( 'displays skysphere with background-image' , async function ( ) {
200- expect ( skysphereUsingMap ( scene , element . backgroundImage ) ) . to . be . ok ;
204+ test ( 'displays background with background-image' , async function ( ) {
205+ expect ( backgroundHasMap ( scene , element . backgroundImage ) ) . to . be . ok ;
201206 } ) ;
202207
203- test ( 'applies background-image envmap on model' , async function ( ) {
204- expect ( modelUsingEnvmap ( scene , { url : element . backgroundImage } ) ) . to . be . ok ;
208+ test ( 'applies background-image environment map on model' , async function ( ) {
209+ expect ( modelUsingEnvMap ( scene , { url : element . backgroundImage } ) ) . to . be . ok ;
205210 } ) ;
206211
207212 suite ( 'and background-image subsequently removed' , ( ) => {
208213 setup ( async ( ) => {
209- let envmapChanged = waitForEnvmap ( scene . model , { url : null } ) ;
214+ let envMapChanged = waitForEnvMap ( scene . model , { url : null } ) ;
210215 element . removeAttribute ( 'background-image' ) ;
211- await envmapChanged ;
216+ await envMapChanged ;
212217 } ) ;
213218
214- test ( 'displays skysphere with background-color' , async function ( ) {
215- expect ( skysphereUsingColor ( scene , 'ff0077' ) ) . to . be . ok ;
219+ test ( 'displays background with background-color' , async function ( ) {
220+ expect ( backgroundHasColor ( scene , 'ff0077' ) ) . to . be . ok ;
216221 } ) ;
217222
218- test ( 'reapplies generated envmap on model' , async function ( ) {
219- expect ( modelUsingEnvmap ( scene , { url : null } ) ) . to . be . ok ;
223+ test ( 'reapplies generated environment map on model' , async function ( ) {
224+ expect ( modelUsingEnvMap ( scene , { url : null } ) ) . to . be . ok ;
220225 } ) ;
221226 } ) ;
222227 } ) ;
0 commit comments