1
1
import * as THREE from 'three' ;
2
2
import * as CANNON from 'cannon' ;
3
3
4
- import { Object3D } from 'three' ;
5
4
import { Utilities as Utils } from '../sketchbook/Utilities' ;
6
5
7
- import * as Springs from '../simulation/SpringSimulation' ;
8
- import * as Controls from '../sketchbook/Controls' ;
9
- import * as CharacterAI from './CharacterAI' ;
10
- import * as CharacterStates from './CharacterStates' ;
6
+ import * as Springs from '../simulation/SpringExports' ;
7
+ import { FBXLoader } from '../lib/utils/FBXLoader' ;
8
+ import { Controls } from '../sketchbook/Controls' ;
9
+ import { CharacterAI } from './CharacterAI' ;
10
+ import { CharacterStates } from './CharacterStates' ;
11
+ import { GameModes } from '../sketchbook/GameModes' ;
11
12
12
13
//Character class
13
- export class Character extends Object3D {
14
+ export class Character extends THREE . Object3D {
14
15
15
16
constructor ( world ) {
16
17
@@ -26,7 +27,7 @@ export class Character extends Object3D {
26
27
this . modelOffset = new THREE . Vector3 ( ) ;
27
28
28
29
// Default model
29
- const loader = new THREE . FBXLoader ( ) ;
30
+ const loader = new FBXLoader ( ) ;
30
31
loader . load ( 'resources/models/game_man/game_man.fbx' , function ( object ) {
31
32
32
33
object . traverse ( function ( child ) {
@@ -65,7 +66,7 @@ export class Character extends Object3D {
65
66
66
67
// scope.player.setModel(object);
67
68
scope . setModelOffset ( new THREE . Vector3 ( 0 , - 0.1 , 0 ) ) ;
68
- scope . setState ( CharacterStates . CharacterState_Idle ) ;
69
+ scope . setState ( CharacterStates . Idle ) ;
69
70
} ) ;
70
71
71
72
// Movement
@@ -88,23 +89,23 @@ export class Character extends Object3D {
88
89
this . rotationSimulator = new Springs . RelativeSpringSimulator ( 60 , this . defaultRotationSimulatorMass , this . defaultRotationSimulatorDamping ) ;
89
90
90
91
// States
91
- this . setState ( CharacterStates . CharacterState_DefaultState ) ;
92
+ this . setState ( CharacterStates . DefaultState ) ;
92
93
this . viewVector = new THREE . Vector3 ( ) ;
93
94
94
95
// Controls
95
- this . behaviour = new CharacterAI . CharacterAI_Default ( this ) ;
96
+ this . behaviour = new CharacterAI . Default ( this ) ;
96
97
this . controls = {
97
- up : new Controls . Control_EventControl ( ) ,
98
- down : new Controls . Control_EventControl ( ) ,
99
- left : new Controls . Control_EventControl ( ) ,
100
- right : new Controls . Control_EventControl ( ) ,
101
- run : new Controls . Control_EventControl ( ) ,
102
- jump : new Controls . Control_EventControl ( ) ,
103
- use : new Controls . Control_EventControl ( ) ,
104
- primary : new Controls . Control_EventControl ( ) ,
105
- secondary : new Controls . Control_EventControl ( ) ,
106
- tertiary : new Controls . Control_EventControl ( ) ,
107
- lastControl : new Controls . Control_EventControl ( )
98
+ up : new Controls . EventControl ( ) ,
99
+ down : new Controls . EventControl ( ) ,
100
+ left : new Controls . EventControl ( ) ,
101
+ right : new Controls . EventControl ( ) ,
102
+ run : new Controls . EventControl ( ) ,
103
+ jump : new Controls . EventControl ( ) ,
104
+ use : new Controls . EventControl ( ) ,
105
+ primary : new Controls . EventControl ( ) ,
106
+ secondary : new Controls . EventControl ( ) ,
107
+ tertiary : new Controls . EventControl ( ) ,
108
+ lastControl : new Controls . EventControl ( )
108
109
} ;
109
110
110
111
// Physics
@@ -113,10 +114,18 @@ export class Character extends Object3D {
113
114
const initPosition = new CANNON . Vec3 ( 0 , 0 , 0 ) ;
114
115
const characterHeight = 0.5 ;
115
116
const characterRadius = 0.25 ;
116
- const characterSegments = 12 ;
117
+ const characterSegments = 8 ;
117
118
const characterFriction = 0 ;
118
119
const characterCollisionGroup = 2 ;
119
- this . characterCapsule = world . createCharacterCapsule ( characterMass , initPosition , characterHeight , characterRadius , characterSegments , characterFriction ) ;
120
+ this . characterCapsule = world . createCapsulePrimitive ( {
121
+ mass : characterMass ,
122
+ position : initPosition ,
123
+ height : characterHeight ,
124
+ radius : characterRadius ,
125
+ segments : characterSegments ,
126
+ friction : characterFriction ,
127
+ visible : false
128
+ } ) ;
120
129
this . characterCapsule . visual . visible = false ;
121
130
122
131
// Pass reference to character for callbacks
@@ -266,6 +275,10 @@ export class Character extends Object3D {
266
275
action . justReleased = false ;
267
276
}
268
277
278
+ Control ( ) {
279
+ this . world . gameMode = new GameModes . CharacterControls ( this . world , this ) ;
280
+ }
281
+
269
282
resetControls ( ) {
270
283
this . setControl ( 'up' , false ) ;
271
284
this . setControl ( 'down' , false ) ;
0 commit comments