@@ -35,18 +35,19 @@ import { pxlPrincipledVert, pxlPrincipledFrag } from "./shaders/objects/PxlPrinc
3535import { COLLIDER_TYPE } from "./core/Enums.js" ;
3636
3737class RoomEnvironment {
38- constructor ( roomName = 'CampfireEnvironment' , assetPath = null , pxlFile = null , pxlAnim = null , pxlUtils = null , pxlDevice = null , pxlEnv = null , msRunner = null , camera = null , scene = null , cloud3dTexture = null ) {
38+ constructor ( roomName = 'CampfireEnvironment' , assetPath = null , msRunner = null , camera = null , scene = null , cloud3dTexture = null ) {
3939 this . roomName = roomName ;
40- this . pxlFile = pxlFile ;
41- this . pxlUtils = pxlUtils ;
42- this . pxlAnim = pxlAnim ;
43- this . pxlDevice = pxlDevice ;
44- this . pxlEnv = pxlEnv ;
40+ this . pxlFile = null ;
41+ this . pxlUtils = null ;
42+ this . pxlAnim = null ;
43+ this . pxlColliders = null ;
44+ this . pxlDevice = null ;
45+ this . pxlEnv = null ;
4546 this . booted = false ;
4647 this . initScene = true ;
4748 this . active = true ;
4849 this . assetPath = assetPath + "Assets/" ;
49- this . mobile = pxlDevice . mobile ;
50+ this . mobile = false ;
5051
5152 this . sceneFile = this . assetPath + "CampfireEnvironment.fbx" ;
5253 this . animFile = this . assetPath + "Campfire_RabbitDruidA_anim.fbx" ;
@@ -68,7 +69,7 @@ class RoomEnvironment{
6869 this . camHoldWarpPos = true ;
6970 this . camLocation = { } ;
7071
71- this . pxlCamFOV = ( this . mobile ? 80 :60 ) ;
72+ this . pxlCamFOV = { 'PC' :60 , 'MOBILE' : 80 } ;
7273 this . pxlCamZoom = 1 ;
7374 this . pxlCamAspect = 1 ;
7475 this . pxlCamNearClipping = 5 ;
@@ -110,6 +111,7 @@ class RoomEnvironment{
110111 this . hasHoverables = false ;
111112 this . hoverableList = [ ] ;
112113 this . hoverableObj = null ;
114+
113115 this . hasClickables = false ;
114116 this . clickableList = [ ] ;
115117 this . clickableObj = null ;
@@ -141,11 +143,26 @@ class RoomEnvironment{
141143 this . cloud3dTexture = null ;
142144 this . smoothNoiseTexture = null ;
143145
146+ // Helper objects for debug visualizations
147+ this . hasHelpers = false ;
148+ this . helperObjects = { } ;
149+
144150 //%=
145151 this . currentShader = null ;
146152 //%
147153 }
148154
155+ // Set pxlNav dependencies
156+ setDependencies ( pxlNav ) {
157+ this . pxlEnv = pxlNav ;
158+ this . pxlFile = pxlNav . pxlFile ;
159+ this . pxlAnim = pxlNav . pxlAnim ;
160+ this . pxlUtils = pxlNav . pxlUtils ;
161+ this . pxlDevice = pxlNav . pxlDevice ;
162+ this . pxlColliders = pxlNav . pxlColliders ;
163+ this . mobile = pxlNav . mobile ;
164+ }
165+
149166// Run after all needed pxlNav services are loaded/built
150167// So it's safe to access global assets at this point
151168 init ( ) {
@@ -172,6 +189,9 @@ class RoomEnvironment{
172189// Per-Frame Render updates
173190 step ( ) {
174191 this . runTime . x = this . msRunner . x ;
192+
193+ // Update helper objects, if they exist
194+ this . stepColliderHelper ( COLLIDER_TYPE . FLOOR ) ;
175195
176196 //this.pxlEnv.engine.setClearColor(this.pxlEnv.fogColor, 0);
177197
@@ -193,6 +213,8 @@ class RoomEnvironment{
193213 //this.pxlEnv.roomBloomPass.enabled=this.bloomPreState;
194214 }
195215
216+ // -- -- --
217+
196218// Runs on window resize
197219 resize ( sW , sH ) {
198220 /*if(this.worldPosRenderTarget){
@@ -204,7 +226,7 @@ class RoomEnvironment{
204226 }
205227
206228 setUserHeight ( toHeight = 1 ) {
207- this . pxlEnv . pxlCamera . userScale = toHeight ;
229+ this . pxlEnv . pxlCamera . setUserHeight ( toHeight ) ;
208230 }
209231
210232 resetCamera ( ) {
@@ -352,6 +374,39 @@ class RoomEnvironment{
352374
353375 // -- -- --
354376
377+ hitColliders ( colliderList = [ ] , colliderType = COLLIDER_TYPE . FLOOR ) {
378+ if ( colliderList . length == 0 ) {
379+ return ;
380+ }
381+ // Implement custom-event logic in this function to handle collisions in your room
382+ /* switch( colliderType ){
383+ case COLLIDER_TYPE.FLOOR:
384+ break;
385+ case COLLIDER_TYPE.WALL:
386+ break;
387+ case COLLIDER_TYPE.WALL_TOP:
388+ break;
389+ case COLLIDER_TYPE.CEILING:
390+ break;
391+ case COLLIDER_TYPE.PORTAL_WARP:
392+ break;
393+ case COLLIDER_TYPE.ROOM_WARP:
394+ break;
395+ case COLLIDER_TYPE.ITEM:
396+ break;
397+ case COLLIDER_TYPE.SCRIPTED:
398+ break;
399+ case COLLIDER_TYPE.HOVERABLE:
400+ break;
401+ case COLLIDER_TYPE.CLICKABLE:
402+ break;
403+ default:
404+ break;
405+ } */
406+ }
407+
408+ // -- -- --
409+
355410 hasColliders ( ) {
356411 return this . collidersExist
357412 }
@@ -476,6 +531,44 @@ class RoomEnvironment{
476531 //forHashing = this.colliderHashMap;
477532 return forHashing ;
478533 }
534+
535+ // -- -- --
536+
537+ // Collider helper functions
538+ addColliderHelper ( colliderType = COLLIDER_TYPE . FLOOR ) {
539+ if ( ! this . hasColliders ( ) ) {
540+ return ;
541+ }
542+ if ( ! this . helperObjects . hasOwnProperty ( 'colliders' ) ) {
543+ this . helperObjects [ 'colliders' ] = { } ;
544+ this . helperObjects [ 'colliders' ] [ colliderType ] = null ;
545+ } else if ( ! this . helperObjects [ 'colliders' ] . hasOwnProperty ( colliderType ) ) {
546+ this . helperObjects [ 'colliders' ] [ colliderType ] = null ;
547+ }
548+
549+ // This is only used to easierly reveal the helper objects to the pxlRoom
550+ // This is only for debugging purposes
551+ this . helperObjects [ 'colliders' ] [ colliderType ] = this . pxlColliders . buildHelper ( this , colliderType ) ;
552+
553+ if ( this . helperObjects [ 'colliders' ] [ colliderType ] ) {
554+ this . scene . add ( this . helperObjects [ 'colliders' ] [ colliderType ] ) ;
555+ this . hasHelpers = true ;
556+ }
557+ }
558+
559+ stepColliderHelper ( colliderType = COLLIDER_TYPE . FLOOR ) {
560+ if ( ! this . hasHelpers ||
561+ ! this . hasColliders ( ) ||
562+ ! this . helperObjects . hasOwnProperty ( 'colliders' ) ||
563+ ! this . helperObjects [ 'colliders' ] . hasOwnProperty ( colliderType ) ) {
564+ return ;
565+ }
566+
567+ this . helperObjects [ 'colliders' ] [ colliderType ] . stepHelper ( this , colliderType ) ;
568+ }
569+
570+
571+ // -- -- --
479572
480573 toCameraPos ( positionName ) {
481574 if ( this . cameraBooted && this . camLocation . hasOwnProperty ( positionName ) ) {
0 commit comments