forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
278 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<base href="../../../" /> | ||
<script src="list.js"></script> | ||
<script src="page.js"></script> | ||
<link type="text/css" rel="stylesheet" href="page.css" /> | ||
</head> | ||
<body> | ||
[page:Object3D] → | ||
|
||
<h1>[name]</h1> | ||
|
||
<p class="desc">This helper displays the directional cone of a [page:PositionalAudio].</p> | ||
|
||
<h2>Example</h2> | ||
|
||
<div>[example:webaudio_orientation webaudio / orientation ]</div> | ||
|
||
<h2>Code Example</h2> | ||
<code> | ||
var positionalAudio = new THREE.PositionalAudio( listener ); | ||
positionalAudio.setDirectionalCone( 180, 230, 0.1 ); | ||
|
||
var helper = new PositionalAudioHelper( positionalAudio ); | ||
positionalAudio.add( helper ); | ||
</code> | ||
|
||
|
||
<h2>Constructor</h2> | ||
|
||
<h3>[name]( [param:PositionalAudio audio], [param:Number range] )</h3> | ||
<p> | ||
[page:PositionalAudio audio] -- The [page:PositionalAudio] to be visualized. <br /><br/> | ||
|
||
[page:Number range] -- (optional) The range of the directional cone. <br /><br/> | ||
|
||
[page:Number divisionsInnerAngle] -- (optional) The amount of divisions of the inner part of the directional cone. <br /><br/> | ||
|
||
[page:Number divisionsOuterAngle] -- (optional) The amount of divisions of the outer part of the directional cone. <br /><br/> | ||
</p> | ||
|
||
|
||
<h2>Properties</h2> | ||
<p>See the base [page:Object3D] class for common properties.</p> | ||
|
||
<h3>[property:PositionalAudio audio]</h3> | ||
<p>[page:PositionalAudio] to be visualized.</p> | ||
|
||
<h3>[property:Number range]</h3> | ||
<p>The range of the directional cone.</p> | ||
|
||
<h3>[property:Number divisionsInnerAngle]</h3> | ||
<p>The amount of divisions of the inner part of the directional cone.</p> | ||
|
||
<h3>[property:Number divisionsOuterAngle]</h3> | ||
<p>The amount of divisions of the outer part of the directional cone.</p> | ||
|
||
<h2>Methods</h2> | ||
<p>See the base [page:Object3D] class for common methods.</p> | ||
|
||
<h3>[method:null dispose]()</h3> | ||
<p>Disposes of the helper.</p> | ||
|
||
<h3>[method:null update]()</h3> | ||
<p>Updates the helper.</p> | ||
|
||
<h2>Source</h2> | ||
|
||
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<base href="../../../" /> | ||
<script src="list.js"></script> | ||
<script src="page.js"></script> | ||
<link type="text/css" rel="stylesheet" href="page.css" /> | ||
</head> | ||
<body> | ||
[page:Object3D] → | ||
|
||
<h1>[name]</h1> | ||
|
||
<p class="desc">This helper displays the directional cone of a [page:PositionalAudio].</p> | ||
|
||
<h2>Example</h2> | ||
|
||
<div>[example:webaudio_orientation webaudio / orientation ]</div> | ||
|
||
<h2>Code Example</h2> | ||
<code> | ||
var positionalAudio = new THREE.PositionalAudio( listener ); | ||
positionalAudio.setDirectionalCone( 180, 230, 0.1 ); | ||
|
||
var helper = new PositionalAudioHelper( positionalAudio ); | ||
positionalAudio.add( helper ); | ||
</code> | ||
|
||
|
||
<h2>Constructor</h2> | ||
|
||
<h3>[name]( [param:PositionalAudio audio], [param:Number range] )</h3> | ||
<p> | ||
[page:PositionalAudio audio] -- The [page:PositionalAudio] to be visualized. <br /><br/> | ||
|
||
[page:Number range] -- (optional) The range of the directional cone. <br /><br/> | ||
|
||
[page:Number divisionsInnerAngle] -- (optional) The amount of divisions of the inner part of the directional cone. <br /><br/> | ||
|
||
[page:Number divisionsOuterAngle] -- (optional) The amount of divisions of the outer part of the directional cone. <br /><br/> | ||
</p> | ||
|
||
|
||
<h2>Properties</h2> | ||
<p>See the base [page:Object3D] class for common properties.</p> | ||
|
||
<h3>[property:PositionalAudio audio]</h3> | ||
<p>[page:PositionalAudio] to be visualized.</p> | ||
|
||
<h3>[property:Number range]</h3> | ||
<p>The range of the directional cone.</p> | ||
|
||
<h3>[property:Number divisionsInnerAngle]</h3> | ||
<p>The amount of divisions of the inner part of the directional cone.</p> | ||
|
||
<h3>[property:Number divisionsOuterAngle]</h3> | ||
<p>The amount of divisions of the outer part of the directional cone.</p> | ||
|
||
<h2>Methods</h2> | ||
<p>See the base [page:Object3D] class for common methods.</p> | ||
|
||
<h3>[method:null dispose]()</h3> | ||
<p>Disposes of the helper.</p> | ||
|
||
<h3>[method:null update]()</h3> | ||
<p>Updates the helper.</p> | ||
|
||
<h2>Source</h2> | ||
|
||
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { PositionalAudio } from './../audio/PositionalAudio'; | ||
import { Line } from './../objects/Line'; | ||
|
||
export class PositionalAudioHelper extends Line { | ||
constructor(audio: PositionalAudio, range?: number, divisionsInnerAngle?: number, divisionsOuterAngle?: number); | ||
|
||
audio: PositionalAudio; | ||
range: number; | ||
divisionsInnerAngle: number; | ||
divisionsOuterAngle: number; | ||
|
||
dispose(): void; | ||
update(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* @author Mugen87 / http://github.com/Mugen87 | ||
*/ | ||
|
||
import { BufferGeometry } from '../core/BufferGeometry.js'; | ||
import { BufferAttribute } from '../core/BufferAttribute.js'; | ||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js'; | ||
import { Line } from '../objects/Line.js'; | ||
import { _Math } from '../math/Math.js'; | ||
|
||
function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) { | ||
|
||
this.audio = audio; | ||
this.range = range || 1; | ||
this.divisionsInnerAngle = divisionsOuterAngle || 16; | ||
this.divisionsOuterAngle = divisionsOuterAngle || 2; | ||
|
||
var geometry = new BufferGeometry(); | ||
var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2; | ||
var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 ); | ||
geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) ); | ||
|
||
var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } ); | ||
var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } ); | ||
|
||
Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] ); | ||
|
||
this.update(); | ||
|
||
} | ||
|
||
PositionalAudioHelper.prototype = Object.create( Line.prototype ); | ||
PositionalAudioHelper.prototype.constructor = PositionalAudioHelper; | ||
|
||
PositionalAudioHelper.prototype.update = function () { | ||
|
||
var audio = this.audio; | ||
var range = this.range; | ||
var divisionsInnerAngle = this.divisionsInnerAngle; | ||
var divisionsOuterAngle = this.divisionsOuterAngle; | ||
|
||
var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle ); | ||
var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle ); | ||
|
||
var halfConeInnerAngle = coneInnerAngle / 2; | ||
var halfConeOuterAngle = coneOuterAngle / 2; | ||
|
||
var start = 0; | ||
var count = 0; | ||
var i, stride; | ||
|
||
var geometry = this.geometry; | ||
var positionAttribute = geometry.attributes.position; | ||
|
||
geometry.clearGroups(); | ||
|
||
// | ||
|
||
function generateSegment( from, to, divisions, materialIndex ) { | ||
|
||
var step = ( to - from ) / divisions; | ||
|
||
positionAttribute.setXYZ( start, 0, 0, 0 ); | ||
count ++; | ||
|
||
for ( i = from; i < to; i += step ) { | ||
|
||
stride = start + count; | ||
|
||
positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range ); | ||
positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range ); | ||
positionAttribute.setXYZ( stride + 2, 0, 0, 0 ); | ||
|
||
count += 3; | ||
|
||
} | ||
|
||
geometry.addGroup( start, count, materialIndex ); | ||
|
||
start += count; | ||
count = 0; | ||
|
||
} | ||
|
||
// | ||
|
||
generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 ); | ||
generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 ); | ||
generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 ); | ||
|
||
// | ||
|
||
positionAttribute.needsUpdate = true; | ||
|
||
if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false; | ||
|
||
}; | ||
|
||
PositionalAudioHelper.prototype.dispose = function () { | ||
|
||
this.geometry.dispose(); | ||
this.material[ 0 ].dispose(); | ||
this.material[ 1 ].dispose(); | ||
|
||
}; | ||
|
||
|
||
export { PositionalAudioHelper }; |