11import * as THREE from "../../js/libs/three/three.module.js" ;
2- import { campfireLogVert , campfireLogFrag ,
2+ import { rabbitDruidVert , rabbitDruidFrag ,
3+ campfireLogVert , campfireLogFrag ,
34 campfireVert , campfireFrag ,
45 envGroundVert , envGroundFrag } from "./Shaders.js" ;
56import RoomEnvironment from "../../js/pxlNav/RoomClass.js" ;
@@ -54,6 +55,13 @@ export class CampfireEnvironment extends RoomEnvironment{
5455 this . fog = new THREE . FogExp2 ( this . fogColor , this . fogExp ) ;
5556
5657 this . perspectiveInstances = 160 ;
58+
59+ this . eyeBlinkInf = new THREE . Vector2 ( 0 , 0 ) ;
60+ this . eyeBlinkMinMaxDelay = [ 1.0 , 8.0 ] ;
61+ this . eyeBlinkMinMaxRate = [ .035 , 0.06 ] ;
62+ this . eyeBlinkNext = 0 ;
63+ this . eyeBlinkAnim = 0 ;
64+ this . eyeBlinkRate = 0 ;
5765 }
5866 init ( ) {
5967 super . init ( ) ;
@@ -95,11 +103,34 @@ export class CampfireEnvironment extends RoomEnvironment{
95103 // Cycle changes occur here as well.
96104 if ( this . animMixer ) {
97105 this . pxlAnim . step ( this . animRigName ) ;
106+ this . checkEyeBlink ( ) ;
98107 }
99108
100109 //this.pxlEnv.pxlCamera.setStats( this.pxlCamFOV, this.pxlCamZoom, this.pxlCamAspect, this.pxlCamNearClipping );
101110 }
102111
112+ checkEyeBlink ( ) {
113+ if ( this . eyeBlinkAnim > 0 ) {
114+ // Decrease the eye blink animation 1 to 0
115+ this . eyeBlinkAnim -= this . eyeBlinkRate ;
116+ // Map 0-1 to 0-1-0
117+ let sawAnim = ( Math . min ( .5 , this . eyeBlinkAnim ) - Math . max ( 0 , this . eyeBlinkAnim - .5 ) ) * 2 ;
118+ this . eyeBlinkInf . x = sawAnim ;
119+ if ( this . eyeBlinkAnim <= 0 ) {
120+ // Add a random time until the next eye blink
121+ this . eyeBlinkNext = this . msRunner . x + this . pxlUtils . randomFloat ( this . eyeBlinkMinMaxDelay [ 0 ] , this . eyeBlinkMinMaxDelay [ 1 ] ) ;
122+ }
123+ } else {
124+ this . eyeBlinkInf . x = 0 ;
125+ if ( this . msRunner . x > this . eyeBlinkNext ) {
126+ // Set the next blink rate, how quickly the animation goes from 1 to 0
127+ this . eyeBlinkRate = this . pxlUtils . randomFloat ( this . eyeBlinkMinMaxRate [ 0 ] , this . eyeBlinkMinMaxRate [ 1 ] ) ;
128+ this . eyeBlinkAnim = 1 ;
129+ }
130+ }
131+ this . textureList [ "RabbitDruidA" ] . uniforms . eyeBlink . value = this . eyeBlinkInf ;
132+ }
133+
103134 // -- -- --
104135
105136
@@ -207,9 +238,6 @@ export class CampfireEnvironment extends RoomEnvironment{
207238 this . textureList [ "CampfireLogs" ] = logMat ;
208239 }
209240
210- // Asign Campfire Log material
211- //console.log(x)
212- //console.log(x.material)
213241 this . geoList [ 'InstancesObjects' ] [ x ] . material = logMat ;
214242 }
215243 }
@@ -219,7 +247,6 @@ export class CampfireEnvironment extends RoomEnvironment{
219247 this . setUserHeight ( this . camInitPos . y ) ;
220248
221249
222- //console.log(this.geoList);
223250
224251 this . booted = true ;
225252 }
@@ -238,7 +265,6 @@ export class CampfireEnvironment extends RoomEnvironment{
238265 this . animInitCycle = fallback ;
239266 this . log ( "No animation cycle '" + this . animInitCycle + "' found; Using '" + fallback + "' instead" ) ;
240267 }
241-
242268
243269 // To view the skeleton of Mr. Rabbit Druid
244270 // Uncomment the following 2 lines --
@@ -249,11 +275,47 @@ export class CampfireEnvironment extends RoomEnvironment{
249275 let curMesh = this . pxlAnim . getMesh ( animKey ) ;
250276 if ( curMesh ) {
251277 let curMtl = curMesh . material ;
278+ curMtl . side = THREE . DoubleSide ;
279+ let vert = curMtl . vertexShader ;
280+ let frag = curMtl . fragmentShader ;
281+ let newSkinnedMtl = this . setSkinnedMaterial ( curMesh , rabbitDruidVert ( ) , rabbitDruidFrag ( ) ) ;
282+ this . textureList [ "RabbitDruidA" ] = newSkinnedMtl ;
252283 }
253284
254-
285+ if ( this . geoList [ "Scripted" ] . hasOwnProperty ( "pokinStick_geo" ) ) {
286+ let stickMtl = this . geoList [ "Scripted" ] [ "pokinStick_geo" ] . material ;
287+ stickMtl . shininess = 0 ;
288+ }
289+ }
290+
291+ setSkinnedMaterial ( bindObj , vertShader = null , fragShader = null ) {
292+
293+ let skinnedMtlUniforms = THREE . UniformsUtils . merge (
294+ [
295+ THREE . UniformsLib [ 'common' ] ,
296+ THREE . UniformsLib [ 'lights' ] ,
297+ {
298+ 'diffuseTexture' : { type :'t' , value : null } ,
299+ 'areTexture' : { type :'t' , value : null } ,
300+ 'noiseTexture' : { type :'t' , value : null } ,
301+ 'eyeBlink' : { type :'v2' , value : this . eyeBlinkInf } ,
302+ 'mult' : { type :'f' , value :1 } ,
303+ }
304+ ]
305+ ) ;
306+
307+ skinnedMtlUniforms . diffuseTexture . value = bindObj . material . map ;
308+ skinnedMtlUniforms . areTexture . value = this . pxlUtils . loadTexture ( this . assetPath + "RabbitDruidA/RabbitDruidA_lowRes_ARE.jpg" ) ;
309+ skinnedMtlUniforms . noiseTexture . value = this . cloud3dTexture ;
310+
311+ let skinnedMaterial = this . pxlFile . pxlShaderBuilder ( skinnedMtlUniforms , vertShader , fragShader ) ;
312+ skinnedMaterial . skinning = true ;
313+ skinnedMaterial . side = THREE . DoubleSide ;
314+ skinnedMaterial . lights = true ;
315+
316+ bindObj . material = skinnedMaterial ;
317+ return skinnedMaterial ;
255318 }
256-
257319
258320 // -- -- -- -- -- -- -- -- -- -- -- -- -- //
259321
@@ -333,8 +395,6 @@ export class CampfireEnvironment extends RoomEnvironment{
333395 this . textureList [ "CampfireFlame_geo" ] = campfireMtl ;
334396
335397
336-
337-
338398 //
339399 // -- -- --
340400
@@ -344,5 +404,4 @@ export class CampfireEnvironment extends RoomEnvironment{
344404
345405 }
346406
347-
348407}
0 commit comments