Skip to content

A room from OBJ files

A room and a table read from OBJ files, one acoustic object per OBJ group, the table as a free-standing obstacle, simulated with image sources and ray tracing and analysed.

"""A room from OBJ files.

A room and a table read from OBJ files, one acoustic object per OBJ group, the table as a free-standing
obstacle, simulated with image sources and ray tracing and analysed.
"""

import os
import compas_acoustics as ca


########### create a source and receivers
source = ca.Source(x=1.5, y=3.0, z=1.5, name="source_1")
receiver_1 = ca.Receiver(x=2.0, y=2.0, z=1.0, name="receiver_1")
# receiver_2 = ca.Receiver(x=6.0, y=4.0, z=1.0, name="receiver_2")


########### create a scene
scene = ca.Scene(name="Demo Scene", description="This is a demo scene.")


########### add the source and receiver to the scene
scene.add_source(source)
scene.add_receiver(receiver_1)
# scene.add_receiver(receiver_2)


########### what are the scene's surface groups?
# scene.print_scene_materials()


########### create acoustic materials
concrete = ca.AcousticMaterial(name='concrete', absorption_coefficients=[0.01, 0.01, 0.02, 0.02, 0.02, 0.05, 0.05], scattering_coefficients=[0.01, 0.01, 0.03, 0.05, 0.1, 0.1, 0.1])
plasterboard = ca.AcousticMaterial(name='plasterboard', absorption_coefficients=[0.15, 0.1, 0.06, 0.04, 0.04, 0.05, 0.05], scattering_coefficients=[0.01, 0.01, 0.03, 0.05, 0.2, 0.1, 0.1])
acoustic_plaster = ca.AcousticMaterial(name='acoustic_plaster', absorption_coefficients=[0.17, 0.36, 0.66, 0.65, 0.62, 0.68, 0.80], scattering_coefficients=0.2)
glass = ca.AcousticMaterial(name='glass', absorption_coefficients=[0.1, 0.07, 0.05, 0.03, 0.02, 0.02, 0.02], scattering_coefficients=0.05)
plywood = ca.AcousticMaterial(name='plywood', absorption_coefficients=[0.18, 0.12, 0.1, 0.09, 0.08, 0.07, 0.07], scattering_coefficients=[0.05, 0.3, 0.03, 0.5, 0.6, 0.7, 0.7])


########### read the room and the table from OBJ files, one acoustic object per OBJ group (Rhino layer)
room_obj_path = os.path.join(os.path.dirname(__file__), 'sample_room.obj')
room = ca.AcousticObject.from_obj(room_obj_path, materials={
    'floor': concrete,
    'plasterboard': plasterboard,
    'glass': glass,
    'ceiling': concrete,
}, name="sample_room")

# The table stands free in the room: an obstacle, reflecting from both sides
table_obj_path = os.path.join(os.path.dirname(__file__), 'sample_table.obj')
table = ca.AcousticObject.from_obj(table_obj_path, materials=plywood, name="sample_table")
ca.AcousticObject.assign_roles_by_group(table, {"wood": "obstacle"})

scene.add_acoustic_objects(room)
scene.add_acoustic_objects(table)


########### run a ray tracing simulation
rirs = scene.simulate(ca.Mono(ray_tracing=True, n_rays=10000, air_absorption=True))


########### analyze the RIR
analyser = ca.Analyser(next(iter(rirs.values())))
results = analyser.analyse()


########### print the results
analyser.print_table()


########## plot results
# analyser.plot_rir()
# analyser.plot_frequency_response(smooth=3)
analyser.plot('T30')

Output

                   125     250     500    1000    2000    4000    8000
----------------------------------------------------------------------
EDT               3.80    4.50    4.06    3.64    3.35    1.81    0.93
T20               4.53    5.73    4.10    4.22    3.72    2.06    1.11
T30               4.98    5.79    4.25    4.34    3.84    2.28    1.16
C50              -3.35   -4.66   -3.25   -3.92   -4.00   -0.15    3.66
C80              -2.72   -2.12   -2.03   -1.92   -2.10    2.33    6.07
D50              31.64   25.48   32.11   28.87   28.46   49.12   69.91
DRR             -10.25   -9.09   -9.64  -11.26  -10.73   -8.03   -5.73
Ts                0.22    0.27    0.23    0.23    0.22    0.10    0.05
STI               0.40    0.36    0.40    0.39    0.39    0.53    0.67
G                27.09   28.28   29.03   30.32   29.62   27.19   25.30
SPL             127.09  128.28  129.03  130.32  129.62  127.19  125.30
LF                 nan     nan     nan     nan     nan     nan     nan
LFC                nan     nan     nan     nan     nan     nan     nan