@hology/core 0.0.171 → 0.0.172
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Behaviour as o,Emitter as t}from"@hology/nebula";import{RayTestResult as i}from"../../gameplay/services/physics/physics-system.js";import{Color as
|
|
1
|
+
import{Behaviour as o,Emitter as t}from"@hology/nebula";import{RayTestResult as i}from"../../gameplay/services/physics/physics-system.js";import{Color as l,Vector3 as e}from"three";export class WorldCollisionBehaviour extends o{constructor(o,t=0,i=0,l=0){super(),this.physics=o,this.bounce=t,this.friction=i,this.lifeLoss=l}initialize(o){null==o.old.rayFrom?o.old.rayFrom=new e:o.old.rayFrom.set(0,0,0),o.old.rayLength=-1,null==o.old.hitNormal?o.old.hitNormal=new e:o.old.hitNormal.set(0,0,0),o.old.hitDistance=-1}mutate(o,i,l){if(0===o.velocity.length())return;const e=r(),c=.5*o.scale*.5;a.copy(o.velocity).normalize(),s.copy(o.velocity).multiplyScalar(i);const d=h.copy(o.old.velocity).normalize(),m=o.old.rayFrom,p=o.old.hitDistance,u=o.old.hitNormal,f=o.old.rayLength;if(d.dot(a)>.99&&o.position.distanceTo(m)+c<f)p>0?(e.hasHit=!0,e.distance=p-m.distanceTo(o.position),e.hitNormal.copy(u)):e.hasHit=!1;else{const t=15;n.copy(o.position).addScaledVector(o.velocity,i*t).addScaledVector(a,c),this.physics.rayTest(o.position,n,e),o.old.rayFrom.copy(o.position),o.old.hitDistance=e.hasHit?e.distance:-1,o.old.hitNormal.copy(e.hitNormal),o.old.rayLength=o.position.distanceTo(n)}var v,w,N;e.hasHit&&s.length()+c>e.distance&&(o.acceleration.set(0,0,0),this.bounce>0?(v=o.velocity,w=e.hitNormal,N=this.bounce,o.velocity.copy(v).sub(y.copy(w).multiplyScalar(2*v.dot(w))).multiplyScalar(N)):function(o,t,i=.95,l){const e=y.copy(t).multiplyScalar(o.dot(t)),s=l.sub(e).multiplyScalar(1-i)}(o.velocity,e.hitNormal,this.friction,o.velocity),o.old.hitDistance=-1,o.parent instanceof t&&o.parent.dispatch("PARTICLE_COLLISION",o),this.lifeLoss>0&&setTimeout(()=>{o.life-=this.lifeLoss+30},30))}}const s=new e,a=new e,n=new e;let c=null;function r(){return null===c&&(c=new i),c}new e;const h=new e,y=new e;(new l).setRGB(Math.random(),Math.random(),Math.random());/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|