allow generic objects animation filtering
This commit is contained in:
@@ -2,6 +2,7 @@ import { EventManager } from '@/lib/EventManager';
|
|||||||
|
|
||||||
class GenericObject extends EventManager{
|
class GenericObject extends EventManager{
|
||||||
emits = ['finish', 'interaction']
|
emits = ['finish', 'interaction']
|
||||||
|
#actions = [];
|
||||||
constructor(engine, data){
|
constructor(engine, data){
|
||||||
super();
|
super();
|
||||||
return new Promise(async(resolve, reject)=>{
|
return new Promise(async(resolve, reject)=>{
|
||||||
@@ -17,14 +18,25 @@ class GenericObject extends EventManager{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.source?.animations?.length){
|
||||||
|
let mix = this.source.animations.filter(a=>a.name.match(/\.mix/));
|
||||||
|
if (!mix.length) mix = [this.source.animations[0]];
|
||||||
|
mix.forEach(m=>{
|
||||||
|
this.#actions.push(engine.playAnimation(this.object, m));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (!data.exclude){
|
if (!data.exclude){
|
||||||
engine.clickable.add(this.object, async e=>{
|
engine.clickable.add(this.object, async e=>{
|
||||||
this.object.__onhud = !this.object.__onhud;
|
this.object.__onhud = !this.object.__onhud;
|
||||||
if (engine.dashboard){
|
if (engine.dashboard){
|
||||||
if (data.hud){
|
if (data.hud){
|
||||||
|
const filterNoHud = a=>a.getClip().name.match(/\.nohud/)
|
||||||
if (this.object._hud ){
|
if (this.object._hud ){
|
||||||
|
this.#actions.filter(filterNoHud).forEach(a=>a.play());
|
||||||
engine.dashboard.detach(this.object);
|
engine.dashboard.detach(this.object);
|
||||||
}else{
|
}else{
|
||||||
|
this.#actions.filter(filterNoHud).forEach(a=>a.stop());
|
||||||
let bb = engine.meshUtils.getBoundingBox(this.object);
|
let bb = engine.meshUtils.getBoundingBox(this.object);
|
||||||
let scale = 0.5 * engine.dashboard.height/engine.meshUtils.getBoundingBoxMaxLength(bb);
|
let scale = 0.5 * engine.dashboard.height/engine.meshUtils.getBoundingBoxMaxLength(bb);
|
||||||
let position = engine.meshUtils.getBoundingBoxCenterPoint(bb, this.object.position).multiplyScalar(scale).negate()
|
let position = engine.meshUtils.getBoundingBoxCenterPoint(bb, this.object.position).multiplyScalar(scale).negate()
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class GameEngine extends EventManager{
|
|||||||
|
|
||||||
if (this.opts.gizmo) {
|
if (this.opts.gizmo) {
|
||||||
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
|
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
|
||||||
this.orbitControls.enableZoom = false;
|
//this.orbitControls.enableZoom = false;
|
||||||
const gizmo = new ViewportGizmo(this.camera, this.renderer, {
|
const gizmo = new ViewportGizmo(this.camera, this.renderer, {
|
||||||
container: '.renderer-gizmo',
|
container: '.renderer-gizmo',
|
||||||
//type:'cube'
|
//type:'cube'
|
||||||
@@ -501,8 +501,8 @@ class GameEngine extends EventManager{
|
|||||||
|
|
||||||
playAnimation(object, clip, play = true) {
|
playAnimation(object, clip, play = true) {
|
||||||
let action = this.mixers[0].clipAction(clip, object);
|
let action = this.mixers[0].clipAction(clip, object);
|
||||||
if (play) action.play();
|
action[play ? 'play' : 'stop']();
|
||||||
else action.stop();
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ class GameManager extends EventManager{
|
|||||||
if (i.data.$go?.type == 'player3d'){
|
if (i.data.$go?.type == 'player3d'){
|
||||||
let hero = new Hero(engine, io);
|
let hero = new Hero(engine, io);
|
||||||
}else{
|
}else{
|
||||||
if (io.source?.animations?.length){
|
|
||||||
engine.playAnimation(engine.scene, io.source.animations[0]);
|
|
||||||
}
|
|
||||||
if (i.data.collisionType == 'basic'){
|
if (i.data.collisionType == 'basic'){
|
||||||
let bb = engine.meshUtils.getBoundingBox(io.object);
|
let bb = engine.meshUtils.getBoundingBox(io.object);
|
||||||
let bbs = engine.meshUtils.getBoundingBoxSize(bb);
|
let bbs = engine.meshUtils.getBoundingBoxSize(bb);
|
||||||
|
|||||||
Reference in New Issue
Block a user