lume
Version:
42 lines (35 loc) • 1.15 kB
text/typescript
import 'element-behaviors'
import {stringAttribute} from '@lume/element'
import {MeshBasicMaterial} from 'three/src/materials/MeshBasicMaterial.js'
import {behavior} from '../../Behavior.js'
import {receiver} from '../../PropReceiver.js'
import {MaterialBehavior, type MaterialBehaviorAttributes} from './MaterialBehavior.js'
export type BasicMaterialBehaviorAttributes = MaterialBehaviorAttributes | 'texture' | 'specularMap'
export
class BasicMaterialBehavior extends MaterialBehavior {
texture = ''
specularMap = ''
override _createComponent() {
return new MeshBasicMaterial()
}
override connectedCallback() {
super.connectedCallback()
this._handleTexture(
() => this.texture, // map
(mat, tex) => (mat.map = tex),
mat => !!mat.map,
() => {},
true,
)
this._handleTexture(
() => this.specularMap,
(mat, tex) => (mat.specularMap = tex),
mat => !!mat.specularMap,
() => {},
true,
)
}
}
if (globalThis.window?.document && !elementBehaviors.has('basic-material'))
elementBehaviors.define('basic-material', BasicMaterialBehavior)