Skip to content

Scene and Acoustic Geometry

The acoustic scene contains the geometry that sound interacts with. Meshes in the scene are used for occlusion, transmission, and reflection simulation.

Static geometry never moves. It is the cheapest type of acoustic geometry and should be used for walls, floors, terrain, and other fixed objects.

import {
const createWorld: (options: WorldOptions) => Promise<World>
createWorld
,
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
} from 'three-steam-audio'
import {
class BufferGeometry<Attributes extends NormalOrGLBufferAttributes = NormalBufferAttributes, TEventMap extends BufferGeometryEventMap = BufferGeometryEventMap>

A representation of mesh, line, or point geometry Includes vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers, reducing the cost of passing all this data to the GPU.

@remarksTo read and edit data in BufferGeometry attributes, see THREE.BufferAttribute BufferAttribute documentation.

@example

const geometry = new THREE.BufferGeometry();
// create a simple square shape. We duplicate the top left and bottom right
// vertices because each vertex needs to appear once per triangle.
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
1.0, 1.0, 1.0, // v3
-1.0, 1.0, 1.0, // v4
-1.0, -1.0, 1.0 // v5
] );
// itemSize = 3 because there are 3 values (components) per vertex
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@example

const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
-1.0, 1.0, 1.0, // v3
] );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const indices = [
0, 1, 2,
2, 3, 0,
];
geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@seeExample : https://threejs.org/examples/#webgl_buffergeometry Mesh with non-indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_indexed Mesh with indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines_indexed Indexed Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_custom_attributes_particles Particles

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_rawshader Raw Shaders

@seehttps://threejs.org/docs/index.html#api/en/core/BufferGeometry Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/BufferGeometry.js Source

BufferGeometry
,
class Object3D<TEventMap extends Object3DEventMap = Object3DEventMap>
interface Object3D<TEventMap extends Object3DEventMap = Object3DEventMap>

This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D space.

@remarksNote that this can be used for grouping objects via the THREE.Object3D.add .add() method which adds the object as a child, however it is better to use THREE.Group Group for this.

@seehttps://threejs.org/docs/index.html#api/en/core/Object3D Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js Source

Object3D
} from 'three'
const
const world: World
world
= await
function createWorld(options: WorldOptions): Promise<World>
createWorld
({
WorldOptions.audioContext: AudioContext
audioContext
: new
var AudioContext: new (contextOptions?: AudioContextOptions) => AudioContext

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode.

MDN Reference

AudioContext
() })
const world: World
world
.
scene: AcousticSceneImpl
scene
.
AcousticSceneImpl.addStaticMesh(input: StaticMeshInput): AcousticMeshHandle
addStaticMesh
({
StaticMeshInput.geometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
geometry
:
const roomGeometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
roomGeometry
,
StaticMeshInput.material: AcousticMaterial | readonly AcousticMaterial[]
material
:
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
.
concrete: AcousticMaterial
concrete
,
StaticMeshInput.matrixWorld?: Matrix4 | undefined
matrixWorld
:
const room: Object3D<Object3DEventMap>
room
.
Object3D<Object3DEventMap>.matrixWorld: Matrix4

The global transform of the object.

@remarksIf the Object3D has no parent, then it's identical to the local transform THREE.Object3D.matrix .matrix.

@defaultValuenew THREE.Matrix4()

matrixWorld
,
})
const world: World
world
.
scene: AcousticSceneImpl
scene
.
AcousticSceneImpl.commit(): void
commit
()

Dynamic geometry can undergo rigid-body motion (translation and rotation). Scale is baked when the mesh is added, so non-uniform or animated scaling is not supported.

import {
const createWorld: (options: WorldOptions) => Promise<World>
createWorld
,
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
} from 'three-steam-audio'
import {
class BufferGeometry<Attributes extends NormalOrGLBufferAttributes = NormalBufferAttributes, TEventMap extends BufferGeometryEventMap = BufferGeometryEventMap>

A representation of mesh, line, or point geometry Includes vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers, reducing the cost of passing all this data to the GPU.

@remarksTo read and edit data in BufferGeometry attributes, see THREE.BufferAttribute BufferAttribute documentation.

@example

const geometry = new THREE.BufferGeometry();
// create a simple square shape. We duplicate the top left and bottom right
// vertices because each vertex needs to appear once per triangle.
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
1.0, 1.0, 1.0, // v3
-1.0, 1.0, 1.0, // v4
-1.0, -1.0, 1.0 // v5
] );
// itemSize = 3 because there are 3 values (components) per vertex
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@example

const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
-1.0, 1.0, 1.0, // v3
] );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const indices = [
0, 1, 2,
2, 3, 0,
];
geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@seeExample : https://threejs.org/examples/#webgl_buffergeometry Mesh with non-indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_indexed Mesh with indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines_indexed Indexed Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_custom_attributes_particles Particles

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_rawshader Raw Shaders

@seehttps://threejs.org/docs/index.html#api/en/core/BufferGeometry Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/BufferGeometry.js Source

BufferGeometry
,
class Mesh<TGeometry extends BufferGeometry = BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>, TMaterial extends Material | Material[] = Material<...> | Material<...>[], TEventMap extends Object3DEventMap = Object3DEventMap>

Class representing triangular

https://en.wikipedia.org/wiki/Polygon_mesh polygon mesh

based objects.

@remarksAlso serves as a base for other classes such as THREE.SkinnedMesh SkinnedMesh, THREE.InstancedMesh InstancedMesh.

@example

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({
color: 0xffff00
});
const Mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

@seehttps://threejs.org/docs/index.html#api/en/objects/Mesh Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/objects/Mesh.js Source

Mesh
,
class Object3D<TEventMap extends Object3DEventMap = Object3DEventMap>
interface Object3D<TEventMap extends Object3DEventMap = Object3DEventMap>

This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D space.

@remarksNote that this can be used for grouping objects via the THREE.Object3D.add .add() method which adds the object as a child, however it is better to use THREE.Group Group for this.

@seehttps://threejs.org/docs/index.html#api/en/core/Object3D Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js Source

Object3D
} from 'three'
const
const world: World
world
= await
function createWorld(options: WorldOptions): Promise<World>
createWorld
({
WorldOptions.audioContext: AudioContext
audioContext
: new
var AudioContext: new (contextOptions?: AudioContextOptions) => AudioContext

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode.

MDN Reference

AudioContext
() })
const
const handle: DynamicAcousticMeshHandle
handle
=
const world: World
world
.
scene: AcousticSceneImpl
scene
.
AcousticSceneImpl.addDynamicMesh(input: DynamicMeshInput): DynamicAcousticMeshHandle
addDynamicMesh
({
StaticMeshInput.geometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
geometry
:
const doorGeometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
doorGeometry
,
StaticMeshInput.material: AcousticMaterial | readonly AcousticMaterial[]
material
:
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
.
wood: AcousticMaterial
wood
,
DynamicMeshInput.matrixWorld: Matrix4
matrixWorld
:
const door: Object3D<Object3DEventMap> & {
position: Mesh["position"];
}
door
.
Object3D<Object3DEventMap>.matrixWorld: Matrix4

The global transform of the object.

@remarksIf the Object3D has no parent, then it's identical to the local transform THREE.Object3D.matrix .matrix.

@defaultValuenew THREE.Matrix4()

matrixWorld
,
})
const world: World
world
.
scene: AcousticSceneImpl
scene
.
AcousticSceneImpl.commit(): void
commit
()
const
const animate: () => void
animate
= () => {
function requestAnimationFrame(callback: FrameRequestCallback): number
requestAnimationFrame
(
const animate: () => void
animate
)
// Update the door transform.
const door: Object3D<Object3DEventMap> & {
position: Mesh["position"];
}
door
.
position: Vector3

Object's local position.

@defaultValuenew THREE.Vector3() - that is (0, 0, 0).

position
.
Vector3.x: number

@default0

x
+= 0.01
const door: Object3D<Object3DEventMap> & {
position: Mesh["position"];
}
door
.
Object3D<Object3DEventMap>.updateMatrixWorld(force?: boolean): void

Updates the global transform of the object. And will update the object descendants if

matrixWorldNeedsUpdate .matrixWorldNeedsUpdate

is set to true or if the

force

parameter is set to true.

@paramforce A boolean that can be used to bypass matrixWorldAutoUpdate.matrixWorldAutoUpdate, to recalculate the world matrix of the object and descendants on the current frame. Useful if you cannot wait for the renderer to update it on the next frame, assuming matrixWorldAutoUpdate.matrixWorldAutoUpdate set to true.

updateMatrixWorld
()
const handle: DynamicAcousticMeshHandle
handle
.
DynamicAcousticMeshHandle.setTransform: (matrixWorld: Matrix4) => void
setTransform
(
const door: Object3D<Object3DEventMap> & {
position: Mesh["position"];
}
door
.
Object3D<Object3DEventMap>.matrixWorld: Matrix4

The global transform of the object.

@remarksIf the Object3D has no parent, then it's identical to the local transform THREE.Object3D.matrix .matrix.

@defaultValuenew THREE.Matrix4()

matrixWorld
)
}
const animate: () => void
animate
()

<AcousticMesh> does not support SkinnedMesh or meshes with morph targets. It also does not support animated non-rigid deformations.

A material describes how sound interacts with a surface. It contains absorption coefficients, a scattering value, and optional transmission coefficients.

const
const material: {
absorption: number[];
scattering: number;
transmission: number[];
}
material
= {
absorption: number[]
absorption
: [0.10, 0.05, 0.02], // low, mid, high
scattering: number
scattering
: 0.05,
transmission: number[]
transmission
: [0.06, 0.03, 0.02], // optional
}

Three Steam Audio ships with a small set of frozen presets. See Materials for the full list.

You can assign different materials to different triangles in a mesh by passing an array of materials and material indices.

import {
const createWorld: (options: WorldOptions) => Promise<World>
createWorld
,
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
} from 'three-steam-audio'
import {
class BufferGeometry<Attributes extends NormalOrGLBufferAttributes = NormalBufferAttributes, TEventMap extends BufferGeometryEventMap = BufferGeometryEventMap>

A representation of mesh, line, or point geometry Includes vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers, reducing the cost of passing all this data to the GPU.

@remarksTo read and edit data in BufferGeometry attributes, see THREE.BufferAttribute BufferAttribute documentation.

@example

const geometry = new THREE.BufferGeometry();
// create a simple square shape. We duplicate the top left and bottom right
// vertices because each vertex needs to appear once per triangle.
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
1.0, 1.0, 1.0, // v3
-1.0, 1.0, 1.0, // v4
-1.0, -1.0, 1.0 // v5
] );
// itemSize = 3 because there are 3 values (components) per vertex
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@example

const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
-1.0, 1.0, 1.0, // v3
] );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const indices = [
0, 1, 2,
2, 3, 0,
];
geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@seeExample : https://threejs.org/examples/#webgl_buffergeometry Mesh with non-indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_indexed Mesh with indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines_indexed Indexed Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_custom_attributes_particles Particles

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_rawshader Raw Shaders

@seehttps://threejs.org/docs/index.html#api/en/core/BufferGeometry Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/BufferGeometry.js Source

BufferGeometry
,
class Object3D<TEventMap extends Object3DEventMap = Object3DEventMap>
interface Object3D<TEventMap extends Object3DEventMap = Object3DEventMap>

This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D space.

@remarksNote that this can be used for grouping objects via the THREE.Object3D.add .add() method which adds the object as a child, however it is better to use THREE.Group Group for this.

@seehttps://threejs.org/docs/index.html#api/en/core/Object3D Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js Source

Object3D
} from 'three'
const
const world: World
world
= await
function createWorld(options: WorldOptions): Promise<World>
createWorld
({
WorldOptions.audioContext: AudioContext
audioContext
: new
var AudioContext: new (contextOptions?: AudioContextOptions) => AudioContext

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode.

MDN Reference

AudioContext
() })
const world: World
world
.
scene: AcousticSceneImpl
scene
.
AcousticSceneImpl.addStaticMesh(input: StaticMeshInput): AcousticMeshHandle
addStaticMesh
({
StaticMeshInput.geometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
geometry
:
const roomGeometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
roomGeometry
,
StaticMeshInput.material: AcousticMaterial | readonly AcousticMaterial[]
material
: [
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
.
concrete: AcousticMaterial
concrete
,
const Materials: Readonly<{
concrete: AcousticMaterial;
generic: AcousticMaterial;
glass: AcousticMaterial;
metal: AcousticMaterial;
wood: AcousticMaterial;
}>
Materials
.
glass: AcousticMaterial
glass
],
StaticMeshInput.matrixWorld?: Matrix4 | undefined
matrixWorld
:
const room: Object3D<Object3DEventMap>
room
.
Object3D<Object3DEventMap>.matrixWorld: Matrix4

The global transform of the object.

@remarksIf the Object3D has no parent, then it's identical to the local transform THREE.Object3D.matrix .matrix.

@defaultValuenew THREE.Matrix4()

matrixWorld
,
})

In Three.js, material indices are read from the geometry’s materialIndex attribute or the standard groups. In React, you can also pass a function that receives each Mesh and returns a material.

import {
const createWorld: (options: WorldOptions) => Promise<World>
createWorld
} from 'three-steam-audio'
import {
class BufferGeometry<Attributes extends NormalOrGLBufferAttributes = NormalBufferAttributes, TEventMap extends BufferGeometryEventMap = BufferGeometryEventMap>

A representation of mesh, line, or point geometry Includes vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers, reducing the cost of passing all this data to the GPU.

@remarksTo read and edit data in BufferGeometry attributes, see THREE.BufferAttribute BufferAttribute documentation.

@example

const geometry = new THREE.BufferGeometry();
// create a simple square shape. We duplicate the top left and bottom right
// vertices because each vertex needs to appear once per triangle.
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
1.0, 1.0, 1.0, // v3
-1.0, 1.0, 1.0, // v4
-1.0, -1.0, 1.0 // v5
] );
// itemSize = 3 because there are 3 values (components) per vertex
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@example

const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
-1.0, 1.0, 1.0, // v3
] );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const indices = [
0, 1, 2,
2, 3, 0,
];
geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

@seeExample : https://threejs.org/examples/#webgl_buffergeometry Mesh with non-indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_indexed Mesh with indexed faces

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_lines_indexed Indexed Lines

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_custom_attributes_particles Particles

@seeExample : https://threejs.org/examples/#webgl_buffergeometry_rawshader Raw Shaders

@seehttps://threejs.org/docs/index.html#api/en/core/BufferGeometry Official Documentation

@seehttps://github.com/mrdoob/three.js/blob/master/src/core/BufferGeometry.js Source

BufferGeometry
} from 'three'
const
const world: World
world
= await
function createWorld(options: WorldOptions): Promise<World>
createWorld
({
WorldOptions.audioContext: AudioContext
audioContext
: new
var AudioContext: new (contextOptions?: AudioContextOptions) => AudioContext

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode.

MDN Reference

AudioContext
() })
const handle: AcousticMeshHandle
handle
.
AcousticMeshHandle.dispose: () => void
dispose
()
const world: World
world
.
scene: AcousticSceneImpl
scene
.
AcousticSceneImpl.commit(): void
commit
()