@hology/core 0.0.86 → 0.0.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as r}from"../../services/render.js";import{DecimalInput as h,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new h(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}async onInit(){this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)})))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0||null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=y;let s=!1,o=this.distance;const a=new m,r=this.camera.getWorldPosition(g);for(let t=-1;t<=1;t++){const n=k.subVectors(r,e);i.copy(r).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,a,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),a.hasHit&&a.distance<this.distance&&(o=Math.min(a.distance,o),s||=a.hasHit)}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=v;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(this.actor.object.updateWorldMatrix(!0,!1),this.camera.position.set(this.offset.x,this.offset.y,this.offset.z),this.camera.rotation.set(0,0,0),this.camera.scale.set(1,1,1),this.camera.applyMatrix4(this.actor.object.matrix)):this.camera.position.copy(this.actor.position).add(this.offset);const t=this.getLookAtPosition();this.camera.lookAt(t)}};t([l(),e("design:type",Number)],w.prototype,"near",void 0),t([l(),e("design:type",Number)],w.prototype,"far",void 0),t([l(),e("design:type",Number)],w.prototype,"viewAngle",void 0),w=t([s(),e("design:paramtypes",[r,d])],w);export{w as ThirdPersonCameraComponent};const v=new o,y=new o,k=(new o,new o),g=new o;export class ThirdPartyCameraComponent extends w{}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -1,6 +1,6 @@
1
1
  export { CameraActor } from './builtin/camera-actor.js';
2
2
  export { CameraComponent } from './camera/camera-component.js';
3
- export { ThirdPersonCameraComponent, ThirdPartyCameraComponent } from './camera/third-party-camera-component.js';
3
+ export { ThirdPersonCameraComponent, ThirdPartyCameraComponent } from './camera/third-person-camera-component.js';
4
4
  export { SpawnPoint } from './builtin/spawn-point.js';
5
5
  export { TriggerVolume, TriggerVolumeComponent } from './builtin/trigger-volume.js';
6
6
  export { PositionalAudioActor, PositionalAudioComponent } from './builtin/positional-audio-actor.js';
@@ -1,4 +1,4 @@
1
- export{CameraActor}from"./builtin/camera-actor.js";export{CameraComponent}from"./camera/camera-component.js";export{ThirdPersonCameraComponent,ThirdPartyCameraComponent}from"./camera/third-party-camera-component.js";export{SpawnPoint}from"./builtin/spawn-point.js";export{TriggerVolume,TriggerVolumeComponent}from"./builtin/trigger-volume.js";export{PositionalAudioActor,PositionalAudioComponent}from"./builtin/positional-audio-actor.js";export*from"./builtin/components/mesh-component.js";export*from"./builtin/components/character/character-movement.js";export*from"./builtin/components/character/modes.js";export*from"./builtin/components/character/character-animation.js";
1
+ export{CameraActor}from"./builtin/camera-actor.js";export{CameraComponent}from"./camera/camera-component.js";export{ThirdPersonCameraComponent,ThirdPartyCameraComponent}from"./camera/third-person-camera-component.js";export{SpawnPoint}from"./builtin/spawn-point.js";export{TriggerVolume,TriggerVolumeComponent}from"./builtin/trigger-volume.js";export{PositionalAudioActor,PositionalAudioComponent}from"./builtin/positional-audio-actor.js";export*from"./builtin/components/mesh-component.js";export*from"./builtin/components/character/character-movement.js";export*from"./builtin/components/character/modes.js";export*from"./builtin/components/character/character-animation.js";
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.86",
3
+ "version": "0.0.87",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",