resolves #21
This commit is contained in:
+15
-16
@@ -1,6 +1,6 @@
|
||||
import { AnimationMixer, Vector3, Clock } from 'three';
|
||||
import { PointerControls } from './PointerControls';
|
||||
import { getBoundingBox, getBoundingBoxCenterPoint, getBoundingBoxSize } from './MeshUtils';
|
||||
import { getBoundingBox, getBoundingBoxCenterPoint, getBoundingBoxSize, centerOrigin } from './MeshUtils';
|
||||
import { QueryFilterFlags } from '@dimforge/rapier3d';
|
||||
|
||||
class Hero{
|
||||
@@ -21,12 +21,14 @@ class Hero{
|
||||
fadeDuration = 0.2
|
||||
runVelocity = 11
|
||||
walkVelocity = 7
|
||||
characterGapOffset = 0.1;
|
||||
|
||||
lerp = (x, y, a) => x * (1 - a) + y * a;
|
||||
|
||||
constructor(object, data){
|
||||
this.object = object;
|
||||
constructor(io, data){
|
||||
this.source = io.source;
|
||||
this.model = io.object
|
||||
this.data = data;
|
||||
this.model = object.scene
|
||||
}
|
||||
|
||||
init(gameEngine){
|
||||
@@ -36,31 +38,25 @@ class Hero{
|
||||
gameEngine.mixers.push( this.mixer );
|
||||
|
||||
this.animationsMap = {};
|
||||
this.object.animations.forEach(a=>{
|
||||
this.source.animations.forEach(a=>{
|
||||
this.animationsMap[a.name] = this.mixer.clipAction(a);
|
||||
})
|
||||
|
||||
this.pointerControls = new PointerControls(gameEngine.camera, this.model, gameEngine.renderer.domElement);
|
||||
gameEngine.hero = this;
|
||||
|
||||
let bb = getBoundingBox(this.model);
|
||||
let bb = this.model.userData.bbox;
|
||||
let size = getBoundingBoxSize(bb);
|
||||
let center = getBoundingBoxCenterPoint(bb, this.model.position)
|
||||
let center = getBoundingBoxCenterPoint(bb, this.model.userData.object.position)
|
||||
|
||||
this.po = gameEngine.physics.add(this.model, 'kinematicPositionBased', false, undefined, 'capsule', { radius: size.x/2, halfHeight: size.y/2})
|
||||
this.po.collider.setTranslationWrtParent({x: center.x, y: center.y + size.y/2, z: center.z});
|
||||
this.po.collider.setTranslationWrtParent({x: center.x, y: center.y + size.y/2 + this.characterGapOffset, z: center.z});
|
||||
|
||||
|
||||
this.initCharacterControls();
|
||||
|
||||
this.clock = new Clock()
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
initCharacterControls(){
|
||||
this.currentAction = 'idle';
|
||||
this.animationsMap[this.currentAction].play()
|
||||
|
||||
this.characterController = this.gameEngine.physics.world.createCharacterController(0.1);
|
||||
this.characterController = this.gameEngine.physics.world.createCharacterController(this.characterGapOffset);
|
||||
this.characterController.setUp({x:0, y:1, z:0});
|
||||
this.po.rigidBody.setTranslation(this.model.position)
|
||||
this.po.characterController = this.characterController;
|
||||
@@ -81,6 +77,9 @@ class Hero{
|
||||
this.actionStart = 0;
|
||||
this.cameraDelta = 0;
|
||||
this.cameraIdleDelta = 0;
|
||||
|
||||
this.clock = new Clock()
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
lockControls(){
|
||||
|
||||
@@ -72,7 +72,13 @@ function centerOrigin(object){
|
||||
return group;
|
||||
}
|
||||
|
||||
function bottomOrigin(object){
|
||||
let group = centerOrigin(object);
|
||||
group.userData.object.position.y += (group.userData.bbox.max.y - group.userData.bbox.min.y)/2
|
||||
return group;
|
||||
}
|
||||
|
||||
export {
|
||||
assignParams, assignMaterial, autoScale, centerOrigin, wrapInGroup,
|
||||
assignParams, assignMaterial, autoScale, centerOrigin, wrapInGroup, bottomOrigin,
|
||||
getBoundingBox, getBoundingBoxSize, getBoundingBoxMaxLength, getBoundingBoxCenterPoint
|
||||
}
|
||||
Reference in New Issue
Block a user