Skip to content

Commit 44fb7d0

Browse files
committed
Collider advancements & Camera updates
_Collider system still a bit weird, but implemented a debugger system to display the collision mesh in the scene. _Reduced how many checks are ran for colliders; Ground and Interactables __Was running checks on every frame step, bit excessive. Since collisions are not correct yet, jumping has broke.
1 parent f596b0b commit 44fb7d0

File tree

17 files changed

+1049
-311
lines changed

17 files changed

+1049
-311
lines changed

Source/js/pxlNav.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ class pxlNav{
193193
"device-keydown" : "Returns an [int]; The just pressed key.",
194194
"device-keyup" : "Returns an [int]; The just released key.",
195195
"device-resize" : "Returns an [{height:#,width:#}]; Height Width object of the new window size.",
196+
"camera-move" : "Returns a {'pos':vec3(),'dist':float}; Emitted when the camera moves.",
197+
"camera-rotate" : "Returns a [quaternion]; Emitted when the camera rotates.",
198+
"camera-jump" : "Returns a [bool]; Emitted when the camera jumps to a new position.",
199+
"camera-fall" : "Returns a [bool]; Emitted when the camera starts to free-fall / gravity.",
200+
"camera-landed" : "Returns a [bool]; Emitted when the camera lands from a jump / fall.",
201+
"camera-collision" : "Returns a [bool]; Emitted when the camera collides with an object.",
196202
"pxlNavEventNameHere" : "Never emitted; You did some copy'pasta.",
197203
"" : "** NOTE : callbacks get an event object shaped - **",
198204
"" : "** { 'type' : *eventName*, 'value' : *data* } **",
@@ -497,9 +503,11 @@ class pxlNav{
497503
this.pxlEnv.warpZoneRenderTarget.texture.magFilter=LinearFilter;
498504
this.pxlEnv.warpZoneRenderTarget.texture.generateMipmaps=false;*/
499505

500-
var aspectRatio=this.pxlGuiDraws.pxlNavCanvas.width/this.pxlGuiDraws.pxlNavCanvas.height;
506+
// TODO : Aspect Ratio is a bit off, need to fix this
507+
//var aspectRatio=this.pxlGuiDraws.pxlNavCanvas.width/this.pxlGuiDraws.pxlNavCanvas.height;
501508
// To change the near and far, see Environment .init()
502-
this.pxlCamera.camera=new PerspectiveCamera( this.pxlEnv.pxlCamFOV, 1, this.pxlEnv.camNear, this.pxlEnv.camFar);
509+
let curFOV=this.pxlEnv.pxlCamFOV[ this.pxlDevice.mobile ? 'MOBILE' : 'PC' ];
510+
this.pxlCamera.camera=new PerspectiveCamera( curFOV, 1, this.pxlEnv.camNear, this.pxlEnv.camFar);
503511
this.pxlAutoCam.camera=this.pxlCamera.camera;
504512

505513
//this.pxlEnv.listener = new AudioListener();
@@ -1021,6 +1029,36 @@ class pxlNav{
10211029
let eventSplit = eventType.split("-");
10221030
if( eventSplit[0] == "device" ){
10231031
this.pxlDevice.subscribe( eventSplit[1], callbackFunc );
1032+
}else if( eventSplit[0] == "camera" ){
1033+
let camEventType = pxlEnums.CAMERA_EVENT.MOVE;
1034+
1035+
// Find the camera event type
1036+
switch( eventSplit[1] ){
1037+
case "move":
1038+
camEventType = pxlEnums.CAMERA_EVENT.MOVE;
1039+
break;
1040+
case "rotate":
1041+
camEventType = pxlEnums.CAMERA_EVENT.ROTATE;
1042+
break;
1043+
case "jump":
1044+
camEventType = pxlEnums.CAMERA_EVENT.JUMP;
1045+
break;
1046+
case "fall":
1047+
camEventType = pxlEnums.CAMERA_EVENT.FALL;
1048+
break;
1049+
case "landed":
1050+
camEventType = pxlEnums.CAMERA_EVENT.LANDED;
1051+
break;
1052+
case "collision":
1053+
camEventType = pxlEnums.CAMERA_EVENT.COLLISION;
1054+
break;
1055+
default:
1056+
console.warn("Warning : `pxlNav.subscribe( 'camera-"+eventSplit[1]+"', ... )` was used; use 'help' for a list of valid events.");
1057+
break;
1058+
}
1059+
1060+
this.pxlCamera.subscribe( camEventType, callbackFunc );
1061+
10241062
}else{
10251063
this.callbacks[eventType] = callbackFunc;
10261064
}

Source/js/pxlNav/Environment.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class Environment{
160160
this.camReturnLookAt=new Vector3(0,0,0);
161161
this.camLobbyPos=new Vector3(0, 15, 0);
162162
this.camLobbyLookAt=new Vector3(0, 15, -100);
163-
this.pxlCamFOV=mobile?80:60;
163+
this.pxlCamFOV={ 'PC':60, 'MOBILE':80 };
164164
this.pxlCamZoom=1;
165165
this.pxlCamAspect=1;
166166
this.pxlCamNearClipping = this.camNear;
@@ -416,7 +416,8 @@ export class Environment{
416416
/* webpackIgnore: true */
417417
import( curImportPath )
418418
.then((module)=>{
419-
let roomObj=new module[roomName]( roomName, `${this.pxlRoomLclRoot}/${roomName}/`, this.pxlFile, this.pxlAnim, this.pxlUtils, this.pxlDevice, this, this.pxlTimer.msRunner, null, null, this.cloud3dTexture);
419+
let roomObj=new module[roomName]( roomName, `${this.pxlRoomLclRoot}/${roomName}/`, this.pxlTimer.msRunner, null, null, this.cloud3dTexture);
420+
roomObj.setDependencies( this );
420421

421422
roomObj.camera=this.pxlCamera.camera;
422423
roomObj.scene=new Scene();
@@ -477,7 +478,7 @@ export class Environment{
477478
}
478479

479480
newSubRoom( roomObject ){
480-
this.roomSubList[ roomObject.roomName ]=roomObject;
481+
this.roomSubList[ roomObject.getName() ]=roomObject;
481482
}
482483
addToRooms( obj ){
483484
let roomObjDict={};

Source/js/pxlNav/RoomClass.js

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ import { pxlPrincipledVert, pxlPrincipledFrag } from "./shaders/objects/PxlPrinc
3535
import { COLLIDER_TYPE } from "./core/Enums.js";
3636

3737
class 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

Comments
 (0)