@@ -43,6 +43,7 @@ import {CheckboxElement} from '../shared/checkbox/checkbox.js';
43
43
import { ColorPicker } from '../shared/color_picker/color_picker.js' ;
44
44
import { Dropdown } from '../shared/dropdown/dropdown.js' ;
45
45
import { SliderWithInputElement } from '../shared/slider_with_input/slider_with_input.js' ;
46
+ import { TabbedPanel } from '../shared/tabs/tabs.js' ;
46
47
import { FileDetails , TexturePicker } from '../shared/texture_picker/texture_picker.js' ;
47
48
import { ALPHA_BLEND_MODES } from '../utils/gltf_constants.js' ;
48
49
import { checkFinite } from '../utils/reducer_utils.js' ;
@@ -172,6 +173,8 @@ export class MaterialPanel extends ConnectedLitElement {
172
173
let start = - 1 ;
173
174
const DURATION = 1600 ; // in milliseconds
174
175
176
+ const material = this . getMaterial ( ) ;
177
+
175
178
const interpolateStep = ( timestamp : number ) => {
176
179
// New model is loaded mid interpolation
177
180
if ( start === - 1 ) {
@@ -180,11 +183,10 @@ export class MaterialPanel extends ConnectedLitElement {
180
183
181
184
const baseColorFactor = this . getInterpolatedColor (
182
185
originalBaseColor , timestamp - start , DURATION ) ;
183
- this . getMaterial ( ) . pbrMetallicRoughness . setBaseColorFactor (
184
- baseColorFactor ) ;
186
+ material . pbrMetallicRoughness . setBaseColorFactor ( baseColorFactor ) ;
185
187
const emissiveFactor = this . getInterpolatedEmissive (
186
188
originalEmissiveFactor , timestamp - start , DURATION ) ;
187
- this . getMaterial ( ) . setEmissiveFactor ( emissiveFactor ) ;
189
+ material . setEmissiveFactor ( emissiveFactor ) ;
188
190
189
191
if ( timestamp - start <= DURATION ) {
190
192
requestAnimationFrame ( interpolateStep ) ;
@@ -272,6 +274,28 @@ export class MaterialPanel extends ConnectedLitElement {
272
274
this . onSelectMaterial ( ) ;
273
275
}
274
276
277
+ firstUpdated ( ) {
278
+ getModelViewer ( ) . addEventListener ( 'click' , this . onClick ) ;
279
+ }
280
+
281
+ onClick = ( event ) => {
282
+ if ( ! ( this . parentElement as TabbedPanel ) . selected ) {
283
+ return ;
284
+ }
285
+ const modelviewer = getModelViewer ( ) ;
286
+ const pickedMaterial =
287
+ modelviewer . materialFromPoint ( event . layerX , event . layerY ) ;
288
+ if ( pickedMaterial == null ) {
289
+ return ;
290
+ }
291
+ for ( const [ index , material ] of modelviewer . model ! . materials ! . entries ( ) ) {
292
+ if ( material === pickedMaterial ) {
293
+ this . selectedMaterialIndex = index ;
294
+ return ;
295
+ }
296
+ }
297
+ } ;
298
+
275
299
get selectedBaseColor ( ) : RGBA {
276
300
const alphaFactor =
277
301
this . getMaterial ( ) . pbrMetallicRoughness . baseColorFactor [ 3 ] ;
0 commit comments