import * as THREE from 'three' ; import vertexShader from './shaders/unlit.vert' ; import fragmentShader from './shaders/unlit.frag' ; export interface VRMUnlitMaterialParameters extends THREE . ShaderMaterialParameters { cutoff ? : number ; map ? : THREE . Texture ; mainTex ? : THREE . Texture ; mainTex_ST ? : THREE . Vector4 ; renderType ? : VRMUnlitMaterialRenderType | number ; } export enum VRMUnlitMaterialRenderType { Opaque , Cutout , Transparent , TransparentWithZWrite } /**
 * This is a material that is an equivalent of "VRM/Unlit***" on VRM spec, those materials are already kinda deprecated though...
 */ export class VRMUnlitMaterial extends THREE . ShaderMaterial { /**
     * Readonly boolean that indicates this is a [[VRMUnlitMaterial]].
     */ public readonly isVRMUnlitMaterial : boolean = true ; public cutoff = 0.5 ; public map : THREE . Texture | null = null ; public mainTex_ST = new THREE . Vector4 ( 0.0 , 0.0 , 1.0 , 1.0 ) ; private _renderType = VRMUnlitMaterialRenderType . Opaque ; public shouldApplyUniforms = true ; constructor ( parameters ? ) { super ( ) ; if ( parameters === undefined ) { parameters = { } ; } parameters . fog = true ; parameters . clipping = true ; if ( parseInt ( THREE . REVISION , 10 ) < 129 ) { ( parameters as any ) . skinning = ( parameters as any ) . skinning || false ; } if ( parseInt ( THREE . REVISION , 10 ) < 131 ) { ( parameters as any ) . morphTargets = ( parameters as any ) . morphTargets || false ; ( parameters as any ) . morphNormals = ( parameters as any ) . morphNormals || false ; } parameters . uniforms = THREE . UniformsUtils . merge ( [ THREE . UniformsLib . common , THREE . UniformsLib . fog , { cutoff : { value : 0.5 } , mainTex_ST : { value : new THREE . Vector4 ( 0.0 , 0.0 , 1.0 , 1.0 ) } , } , ] ) ; this . setValues ( parameters ) ; this . _updateShaderCode ( ) ; this . _applyUniforms ( ) ; } get mainTex ( ) : THREE . Texture | null { return this . map ; } set mainTex ( t ) { this . map = t ; } get renderType ( ) : VRMUnlitMaterialRenderType { return this . _renderType ; } set renderType ( t ) { this . _renderType = t ; this . depthWrite = this . _renderType !== VRMUnlitMaterialRenderType . Transparent ; this . transparent = this . _renderType === VRMUnlitMaterialRenderType . Transparent || this . _renderType === VRMUnlitMaterialRenderType . TransparentWithZWrite ; this . _updateShaderCode ( ) ; } param delta public updateVRMMaterials ( delta ) { this . _applyUniforms ( ) ; } public copy ( source ) { super . copy ( source ) ; this . cutoff = source . cutoff ; this . map = source . map ; this . mainTex_ST . copy ( source . mainTex_ST ) ; this . renderType = source . renderType ; return this ; } /**
     * Apply updated uniform variables.
     */ private _applyUniforms ( ) { if ( ! this . shouldApplyUniforms ) { return ; } this . shouldApplyUniforms = false ; this . uniforms . cutoff . value = this . cutoff ; this . uniforms . map . value = this . map ; this . uniforms . mainTex_ST . value . copy ( this . mainTex_ST ) ; } private _updateShaderCode ( ) { this . defines = { RENDERTYPE_OPAQUE : this . _renderType === VRMUnlitMaterialRenderType . Opaque , RENDERTYPE_CUTOUT : this . _renderType === VRMUnlitMaterialRenderType . Cutout , RENDERTYPE_TRANSPARENT : this . _renderType === VRMUnlitMaterialRenderType . Transparent || this . _renderType === VRMUnlitMaterialRenderType . TransparentWithZWrite , } ; this . vertexShader = vertexShader ; this . fragmentShader = fragmentShader ; this . needsUpdate = true ; } }