diff --git a/demos/goat.mp3 b/demos/goat.mp3 new file mode 100644 index 0000000..806871a Binary files /dev/null and b/demos/goat.mp3 differ diff --git a/demos/missing-goat.html b/demos/missing-goat.html new file mode 100644 index 0000000..c258b7b --- /dev/null +++ b/demos/missing-goat.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + +
+ + + + diff --git a/demos/setup.js b/demos/setup.js index d28e8d8..a4dabf6 100644 --- a/demos/setup.js +++ b/demos/setup.js @@ -17,6 +17,7 @@ export async function createViewer(container) { homeButton: false, fullscreenButton: false, scene3DOnly: true, + requestRenderMode: true, baseLayer: new Cesium.ImageryLayer( new Cesium.UrlTemplateImageryProvider({ url: "https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.swissimage/default/current/3857/{z}/{x}/{y}.jpeg", @@ -37,9 +38,9 @@ export async function createViewer(container) { viewer.scene.fog.minimumBrightness = 0.03 * 10; viewer.camera.flyTo({ - destination: Cesium.Cartesian3.fromDegrees(7.863775, 46.686447, 1200), + destination: Cesium.Cartesian3.fromDegrees(7.863775, 46.686447, 1000), orientation: { - heading: Cesium.Math.toRadians(25.0), + heading: Math.PI, pitch: 0.0, }, duration: 0, diff --git a/packages/cesium-audio/LICENSE b/packages/cesium-audio/LICENSE new file mode 100644 index 0000000..1d3bc0e --- /dev/null +++ b/packages/cesium-audio/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2020-present, camptocamp SA +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/cesium-audio/cesium-audio.js b/packages/cesium-audio/cesium-audio.js new file mode 100644 index 0000000..7916d6b --- /dev/null +++ b/packages/cesium-audio/cesium-audio.js @@ -0,0 +1,27 @@ +import { Cartesian2, Cartesian3} from "cesium"; + +export default class CesiumSound { + constructor(viewer, position, panner) { + this.scene = viewer.scene; + this.position = position; + this.panner = panner; + + this.setPan(); + + viewer.scene.postRender.addEventListener(() => this.setPan()); + } + + setPan() { + const camera = this.scene.camera; + const cameraDirection = Cartesian2.fromCartesian3(camera.direction); + // vector from camera to sound + const toPosition = Cartesian2.fromCartesian3(Cartesian3.subtract(this.position, camera.position, new Cartesian3())); + + // angle between camera direction and sound + const angle = Cartesian2.angleBetween(cameraDirection, toPosition); + const rightSide = Cartesian2.cross(cameraDirection, toPosition) > 0; + + this.panner.pan.value = rightSide ? -Math.sin(angle) : Math.sin(angle); + console.log(angle, this.panner.pan.value); + } +} diff --git a/packages/cesium-audio/package.json b/packages/cesium-audio/package.json new file mode 100644 index 0000000..66b2863 --- /dev/null +++ b/packages/cesium-audio/package.json @@ -0,0 +1,14 @@ +{ + "name": "@geoblocks/cesium-audio", + "version": "0.0.0", + "license": "BSD-3-Clause", + "repository": "github:geoblocks/cesium-helpers", + "main": "cesium-audio.js", + "module": "cesium-audio.js", + "publishConfig": { + "access": "public" + }, + "peerDependencies": { + "cesium": "1.x" + } +}