@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 14.3 kB
JavaScript
import{a as t,_ as n,b as e}from"./webAudioBaseSubGraph-Ww7puCo8.esm.min.js";import{aD as o,V as i,M as a}from"./index-BPURObVq.esm.min.js";import{e as s,d as r,f as h}from"./spatialWebAudioUpdaterComponent-LOlF6N8J.esm.min.js";const u={coneInnerAngle:6.28318530718,coneOuterAngle:6.28318530718,coneOuterVolume:0,distanceModel:"linear",maxDistance:1e4,minDistance:1,orientation:i.Right(),panningEnabled:!0,panningModel:"equalpower",position:i.Zero(),rolloffFactor:1,rotation:i.Zero(),rotationQuaternion:new o};function d(t){return t.spatialEnabled||void 0!==t.spatialAutoUpdate||void 0!==t.spatialConeInnerAngle||void 0!==t.spatialConeOuterAngle||void 0!==t.spatialConeOuterVolume||void 0!==t.spatialDistanceModel||void 0!==t.spatialMaxDistance||void 0!==t.spatialMinDistance||void 0!==t.spatialMinUpdateTime||void 0!==t.spatialOrientation||void 0!==t.spatialPanningEnabled||void 0!==t.spatialPanningModel||void 0!==t.spatialPosition||void 0!==t.spatialRolloffFactor||void 0!==t.spatialRotation||void 0!==t.spatialRotationQuaternion}class c{}const l=0;class p{}class _ extends t{constructor(t){super("Stereo",t)}setOptions(t){this.pan=t.stereoPan??l}}function g(t){return t.getSubNode("Stereo")}class m extends p{constructor(t){super(),this._pan=l,this._subGraph=t}get pan(){return this._pan}set pan(t){this._pan=t,function(t,n,e){t.callOnSubNode("Stereo",t=>{t[n]=e})}(this._subGraph,"pan",t)}}class b extends t{constructor(t){super("Spatial",t),this._attacherComponent=null}get isAttached(){return null!==this._attacherComponent&&this._attacherComponent.isAttached}get attachedNode(){return this._attacherComponent?.sceneNode??null}get useBoundingBox(){return this._attacherComponent?.useBoundingBox??!1}get attachmentType(){return this._attacherComponent?.attachmentType??3}attach(t,n,e){this.detach(),this._attacherComponent||(this._attacherComponent=new s(this)),this._attacherComponent.attach(t,n,e)}detach(){this._attacherComponent?.detach()}dispose(){super.dispose(),this._attacherComponent?.dispose(),this._attacherComponent=null}setOptions(t){this.coneInnerAngle=t.spatialConeInnerAngle??u.coneInnerAngle,this.coneOuterAngle=t.spatialConeOuterAngle??u.coneOuterAngle,this.coneOuterVolume=t.spatialConeOuterVolume??u.coneOuterVolume,this.distanceModel=t.spatialDistanceModel??u.distanceModel,this.maxDistance=t.spatialMaxDistance??u.maxDistance,this.minDistance=t.spatialMinDistance??u.minDistance,this.orientation=t.spatialOrientation??u.orientation,this.panningEnabled=t.spatialPanningEnabled??u.panningEnabled,this.panningModel=t.spatialPanningModel??u.panningModel,this.rolloffFactor=t.spatialRolloffFactor??u.rolloffFactor,t.spatialPosition&&(this.position=t.spatialPosition.clone()),t.spatialRotationQuaternion?this.rotationQuaternion=t.spatialRotationQuaternion.clone():t.spatialRotation?this.rotation=t.spatialRotation.clone():this.rotationQuaternion=u.rotationQuaternion.clone(),this.update()}update(){this.isAttached?this._attacherComponent?.update():(this._updatePosition(),this._updateRotation())}}function N(t){return t.getSubNode("Spatial")}function A(t,n,e){t.callOnSubNode("Spatial",t=>{t[n]=e})}const f=a.Zero(),x=new o;function M(t){return t*Math.PI/180}function O(t){return 180*t/Math.PI}class S extends b{constructor(t){super(t),this._lastOrientation=i.Zero(),this._lastPosition=i.Zero(),this._lastRotation=i.Zero(),this._lastRotationQuaternion=new o,this._panningEnabled=u.panningEnabled,this.orientation=u.orientation.clone(),this.position=u.position.clone(),this.rotation=u.rotation.clone(),this.rotationQuaternion=u.rotationQuaternion.clone(),this._inputNode=new GainNode(t._audioContext),this._attenuationNode=new GainNode(t._audioContext),this._attenuation=new r(t,this._attenuationNode.gain),this.node=new PannerNode(t._audioContext),this._orientationX=new r(t,this.node.orientationX),this._orientationY=new r(t,this.node.orientationY),this._orientationZ=new r(t,this.node.orientationZ),this._positionX=new r(t,this.node.positionX),this._positionY=new r(t,this.node.positionY),this._positionZ=new r(t,this.node.positionZ),this._connectActiveInput()}dispose(){super.dispose(),this._attenuation.dispose(),this._orientationX.dispose(),this._orientationY.dispose(),this._orientationZ.dispose(),this._positionX.dispose(),this._positionY.dispose(),this._positionZ.dispose(),this._inputNode.disconnect(),this._attenuationNode.disconnect(),this.node.disconnect()}get coneInnerAngle(){return M(this.node.coneInnerAngle)}set coneInnerAngle(t){this.node.coneInnerAngle=O(t)}get coneOuterAngle(){return M(this.node.coneOuterAngle)}set coneOuterAngle(t){this.node.coneOuterAngle=O(t)}get coneOuterVolume(){return this.node.coneOuterGain}set coneOuterVolume(t){this.node.coneOuterGain=t}get distanceModel(){return this.node.distanceModel}set distanceModel(t){this.node.distanceModel=t;const n=this.node.maxDistance;this.node.maxDistance=n+.001,this.node.maxDistance=n,this._updateAttenuation()}get minDistance(){return this.node.refDistance}set minDistance(t){this.node.refDistance=t,this._updateAttenuation()}get maxDistance(){return this.node.maxDistance}set maxDistance(t){this.node.maxDistance=t,this._updateAttenuation()}get panningEnabled(){return this._panningEnabled}set panningEnabled(t){this._panningEnabled!==t&&(this._panningEnabled=t,this._connectActiveInput(),this._updateAttenuation())}get panningModel(){return this.node.panningModel}set panningModel(t){this.node.panningModel=t}get rolloffFactor(){return this.node.rolloffFactor}set rolloffFactor(t){this.node.rolloffFactor=t,this._updateAttenuation()}get _inNode(){return this._inputNode}get _outNode(){return this._panningEnabled?this.node:this._attenuationNode}_updatePosition(){this._lastPosition.equalsWithEpsilon(this.position)||(this._positionX.targetValue=this.position.x,this._positionY.targetValue=this.position.y,this._positionZ.targetValue=this.position.z,this._lastPosition.copyFrom(this.position)),this._updateAttenuation()}_updateRotation(){let t=!1;if(this._lastRotationQuaternion.equalsWithEpsilon(this.rotationQuaternion))if(this._lastRotation.equalsWithEpsilon(this.rotation)){if(this._lastOrientation.equalsWithEpsilon(this.orientation))return}else o.FromEulerAnglesToRef(this.rotation.x,this.rotation.y,this.rotation.z,x),this._lastRotation.copyFrom(this.rotation),t=!0;else x.copyFrom(this.rotationQuaternion),this._lastRotationQuaternion.copyFrom(this.rotationQuaternion),t=!0;t&&(a.FromQuaternionToRef(x,f),i.TransformNormalToRef(i.RightReadOnly,f,this.orientation)),this._orientationX.targetValue=this.orientation.x,this._orientationY.targetValue=this.orientation.y,this._orientationZ.targetValue=this.orientation.z}_connect(t){return!!super._connect(t)&&(t._inNode&&(this.node.connect(t._inNode),this._attenuationNode.connect(t._inNode)),!0)}_disconnect(t){return!!super._disconnect(t)&&(t._inNode&&(this.node.disconnect(t._inNode),this._attenuationNode.disconnect(t._inNode)),!0)}getClassName(){return"_SpatialWebAudioSubNode"}_connectActiveInput(){this._inputNode.disconnect(),this._panningEnabled?this._inputNode.connect(this.node):this._inputNode.connect(this._attenuationNode)}_updateAttenuation(){if(this._panningEnabled)return void(this._attenuation.targetValue=1);const t=this.engine.listener.position,n=this.position.x-t.x,e=this.position.y-t.y,o=this.position.z-t.z,i=Math.sqrt(n*n+e*e+o*o),a=Math.max(this.minDistance,0);let s=1;switch(this.distanceModel){case"linear":{const t=Math.max(this.maxDistance,a),n=Math.min(Math.max(i,a),t);s=t===a?i<=a?1:0:1-this.rolloffFactor*(n-a)/(t-a)}break;case"inverse":if(0===a){s=0;break}s=a/(a+this.rolloffFactor*(Math.max(i,a)-a));break;case"exponential":if(0===a){s=0;break}s=Math.pow(Math.max(i,a)/a,-this.rolloffFactor)}this._attenuation.targetValue=Math.min(Math.max(s,0),1)}}class w extends _{constructor(t){super(t),this.node=new StereoPannerNode(t._audioContext),this._pan=new r(t,this.node.pan)}dispose(){super.dispose(),this._pan.dispose()}get pan(){return this._pan.targetValue}set pan(t){this._pan.targetValue=t}get _inNode(){return this.node}get _outNode(){return this.node}getClassName(){return"_StereoWebAudioSubNode"}_connect(t){return!!super._connect(t)&&(t._inNode&&this.node.connect(t._inNode),!0)}_disconnect(t){return!!super._disconnect(t)&&(t._inNode&&this.node.disconnect(t._inNode),!0)}}class D extends n{constructor(){super(...arguments),this._rootNode=null,this._inputNode=null}async initAsync(t){let n,e;await super.initAsync(t),(n=d(t))&&await this.createAndAddSubNodeAsync("Spatial"),(e=function(t){return t.stereoEnabled||void 0!==t.stereoPan}(t))&&await this.createAndAddSubNodeAsync("Stereo"),await this._createSubNodePromisesResolvedAsync(),n&&N(this)?.setOptions(t),e&&g(this)?.setOptions(t)}get _inNode(){return this._inputNode}_createSubNode(t){try{return super._createSubNode(t)}catch(t){}switch(t){case"Spatial":return async function(t){return new S(t)}(this._owner.engine);case"Stereo":return async function(t){return new w(t)}(this._owner.engine);default:throw new Error(`Unknown subnode name: ${t}`)}}_onSubNodesChanged(){super._onSubNodesChanged();const t=N(this),n=g(this),o=e(this);if(t&&"_SpatialWebAudioSubNode"!==t.getClassName())throw new Error("Not a WebAudio subnode.");if(n&&"_StereoWebAudioSubNode"!==n.getClassName())throw new Error("Not a WebAudio subnode.");if(o&&"_VolumeWebAudioSubNode"!==o.getClassName())throw new Error("Not a WebAudio subnode.");t&&(t.disconnectAll(),o&&t.connect(o)),n&&(n.disconnectAll(),o&&n.connect(o)),t&&n?(this._rootNode=new GainNode(this._owner.engine._audioContext),this._rootNode.connect(t._inNode),this._rootNode.connect(n._inNode)):(this._rootNode?.disconnect(),this._rootNode=null);let i,a=null;if(this._rootNode?i=this._rootNode:(t?a=t:n?a=n:o&&(a=o),i=a?._inNode??null),this._inputNode!==i){if(this._inputNode&&this._upstreamNodes){const t=this._upstreamNodes.values();for(let n=t.next();!n.done;n=t.next())n.value._outNode?.disconnect(this._inputNode)}if(this._inputNode=i,i&&this._upstreamNodes){const t=this._upstreamNodes.values();for(let n=t.next();!n.done;n=t.next())n.value._outNode?.connect(i)}}}}class E extends c{constructor(t){super(),this._coneInnerAngle=u.coneInnerAngle,this._coneOuterAngle=u.coneOuterAngle,this._coneOuterVolume=u.coneOuterVolume,this._distanceModel=u.distanceModel,this._maxDistance=u.maxDistance,this._minDistance=u.minDistance,this._panningEnabled=u.panningEnabled,this._panningModel=u.panningModel,this._rolloffFactor=u.rolloffFactor;const n=N(t);n?(this._orientation=n.orientation.clone(),this._panningEnabled=n.panningEnabled,this._position=n.position.clone(),this._rotation=n.rotation.clone(),this._rotationQuaternion=n.rotationQuaternion.clone()):(this._orientation=u.orientation.clone(),this._position=u.position.clone(),this._rotation=u.rotation.clone(),this._rotationQuaternion=u.rotationQuaternion.clone(),t.createAndAddSubNodeAsync("Spatial")),this._subGraph=t}dispose(){this._subGraph.removeSubNodeAsync(N(this._subGraph))}get coneInnerAngle(){return this._coneInnerAngle}set coneInnerAngle(t){this._coneInnerAngle=t,A(this._subGraph,"coneInnerAngle",t)}get coneOuterAngle(){return this._coneOuterAngle}set coneOuterAngle(t){this._coneOuterAngle=t,A(this._subGraph,"coneOuterAngle",t)}get coneOuterVolume(){return this._coneOuterVolume}set coneOuterVolume(t){this._coneOuterVolume=t,A(this._subGraph,"coneOuterVolume",t)}get distanceModel(){return this._distanceModel}set distanceModel(t){this._distanceModel=t,A(this._subGraph,"distanceModel",t)}get isAttached(){return this._subGraph.getSubNode("Spatial")?.isAttached??!1}get attachedNode(){return this._subGraph.getSubNode("Spatial")?.attachedNode??null}get useBoundingBox(){return this._subGraph.getSubNode("Spatial")?.useBoundingBox??!1}get attachmentType(){return this._subGraph.getSubNode("Spatial")?.attachmentType??3}get maxDistance(){return this._maxDistance}set maxDistance(t){t<=0&&(t=1e-6),this._maxDistance=t,A(this._subGraph,"maxDistance",t)}get minDistance(){return this._minDistance}set minDistance(t){this._minDistance=t,A(this._subGraph,"minDistance",t)}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this._updateRotation()}get panningEnabled(){return this._panningEnabled}set panningEnabled(t){this._panningEnabled=t,A(this._subGraph,"panningEnabled",t)}get panningModel(){return this._panningModel}set panningModel(t){this._panningModel=t,A(this._subGraph,"panningModel",t)}get position(){return this._position}set position(t){this._position=t,this._updatePosition()}get rolloffFactor(){return this._rolloffFactor}set rolloffFactor(t){this._rolloffFactor=t,A(this._subGraph,"rolloffFactor",t)}get rotation(){return this._rotation}set rotation(t){this._rotation=t,this._updateRotation()}get rotationQuaternion(){return this._rotationQuaternion}set rotationQuaternion(t){this._rotationQuaternion=t,this._updateRotation()}attach(t,n=!1,e=3){N(this._subGraph)?.attach(t,n,e)}detach(){N(this._subGraph)?.detach()}update(){const t=N(this._subGraph);t&&(t.isAttached?t.update():(this._updatePosition(t),this._updateRotation(t)))}_updatePosition(t=null){if(!t&&!(t=N(this._subGraph)))return;t.position.equalsWithEpsilon(this._position)?t.panningEnabled||t._updatePosition():(t.position.copyFrom(this._position),t._updatePosition())}_updateRotation(t=null){(t||(t=N(this._subGraph)))&&(t.rotationQuaternion.equalsWithEpsilon(this._rotationQuaternion)?t.rotation.equalsWithEpsilon(this._rotation)?t.orientation.equalsWithEpsilon(this._orientation)||(t.orientation.copyFrom(this._orientation),t._updateRotation(),this._rotation.copyFrom(t.rotation),this._rotationQuaternion.copyFrom(t.rotationQuaternion)):(t.rotation.copyFrom(this._rotation),t._updateRotation(),this._orientation.copyFrom(t.orientation),this._rotationQuaternion.copyFrom(t.rotationQuaternion)):(t.rotationQuaternion.copyFrom(this._rotationQuaternion),t._updateRotation(),this._orientation.copyFrom(t.orientation),this._rotation.copyFrom(t.rotation)))}}class C extends E{constructor(t,n,e){super(t),this._updaterComponent=new h(this,n,e)}get minUpdateTime(){return this._updaterComponent.minUpdateTime}set minUpdateTime(t){this._updaterComponent.minUpdateTime=t}dispose(){super.dispose(),this._updaterComponent.dispose(),this._updaterComponent=null}}export{d as _,m as a,C as b,D as c,u as d};
//# sourceMappingURL=spatialWebAudio-Cxs0XdBX.esm.min.js.map