Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Acoustic Texture Support for AkGeometry #123

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions addons/Wwise/native/src/core/wwise_gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ bool Wwise::set_object_obstruction_and_occlusion(
static_cast<AkGameObjectID>(listener->get_instance_id()), f_calculated_obs, f_calculated_occ));
}

bool Wwise::set_geometry(const Array vertices, const Array triangles, const Ref<Resource>& acoustic_texture,
bool Wwise::set_geometry(const Array vertices, const Array triangles, const Dictionary& acoustic_texture,
float transmission_loss_value, const Object* game_object, bool enable_diffraction,
bool enable_diffraction_on_boundary_edges)
{
Expand Down Expand Up @@ -931,22 +931,30 @@ bool Wwise::set_geometry(const Array vertices, const Array triangles, const Ref<

auto ak_triangles = std::make_unique<AkTriangle[]>(num_triangles);

AkAcousticSurface default_surface{};
AkAcousticSurface ak_surfaces[1] = { default_surface };
AkAcousticSurface surface{};
String texture_name = acoustic_texture.get("name", "");
AkUInt32 texture_id = acoustic_texture.get("id", AK_INVALID_SURFACE);

bool texture_valid = !texture_name.is_empty() && texture_id != AK_INVALID_SURFACE;
if (texture_valid)
{
surface.strName = texture_name.utf8().get_data();
surface.textureID = texture_id;
}
surface.transmissionLoss = transmission_loss_value;

AkAcousticSurface ak_surfaces[1] = { surface };
geometry.NumSurfaces = 1;
geometry.Surfaces = ak_surfaces;

// todo(alex): take care of AcousticTextures at a later stage

int triangleIdx = 0;

for (int i = 0; i < num_triangles; i++)
{
AkTriangle t{};
t.point0 = verts_remap[static_cast<unsigned int>(triangles[3 * i + 0])];
t.point1 = verts_remap[static_cast<unsigned int>(triangles[3 * i + 1])];
t.point2 = verts_remap[static_cast<unsigned int>(triangles[3 * i + 2])];
t.surface = acoustic_texture.is_valid() ? 0 : AK_INVALID_SURFACE;
t.surface = texture_valid ? 0 : AK_INVALID_SURFACE;

ak_triangles[triangleIdx] = t;

Expand Down
2 changes: 1 addition & 1 deletion addons/Wwise/native/src/core/wwise_gdextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Wwise : public Object
bool set_object_obstruction_and_occlusion(
const Object* game_object, const Object* listener, float f_calculated_obs, float f_calculated_occ);

bool set_geometry(const Array vertices, const Array triangles, const Ref<Resource>& acoustic_texture,
bool set_geometry(const Array vertices, const Array triangles, const Dictionary& acoustic_texture,
float transmission_loss_value, const Object* game_object, bool enable_diffraction,
bool enable_diffraction_on_boundary_edges);
bool remove_geometry(const Object* game_object);
Expand Down
14 changes: 13 additions & 1 deletion addons/Wwise/native/src/editor/ak_inspector_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ Dictionary AkInspectorTree::get_wwise_ids(const AkEditorUtils::AkType ak_type)
type_constant = "AUX_BUSSES";
break;
}
case AkEditorUtils::AkType::AKTYPE_ACOUSTIC_TEXTURE:
{
type_constant = "ACOUSTIC_TEXTURES";
break;
}
default:
break;
}
Expand Down Expand Up @@ -419,7 +424,7 @@ bool AkInspectorEditorInspectorPlugin::_can_handle(Object* object) const
return (object->get_class() == "AkBank" || object->get_class() == "AkState" || object->get_class() == "AkSwitch" ||
object->get_class() == "AkEvent2D" || object->get_class() == "AkEvent3D" ||
object->get_class() == "AkEnvironment" || object->get_class() == "AkRoom" ||
object->get_class() == "AkEarlyReflections");
object->get_class() == "AkEarlyReflections" || object->get_class() == "AkGeometry");
}

bool AkInspectorEditorInspectorPlugin::_parse_property(Object* object, Variant::Type type, const String& name,
Expand Down Expand Up @@ -483,6 +488,13 @@ bool AkInspectorEditorInspectorPlugin::_parse_property(Object* object, Variant::
add_property_editor(name, property);
return true;
}
else if (name == "acoustic_texture")
{
AkInspectorEditorProperty* property = memnew(AkInspectorEditorProperty);
property->init(AkEditorUtils::AkType::AKTYPE_ACOUSTIC_TEXTURE);
add_property_editor(name, property);
return true;
}
else
{
return false;
Expand Down
2 changes: 2 additions & 0 deletions addons/Wwise/native/src/editor/ak_inspector_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class AkInspectorEditorProperty : public EditorProperty
return AkInspectorEditorPropertyInfo{ "Select Bus...", "Search Busses..." };
case AkEditorUtils::AkType::AKTYPE_AUX_BUS:
return AkInspectorEditorPropertyInfo{ "Select Aux Bus...", "Search Aux Busses..." };
case AkEditorUtils::AkType::AKTYPE_ACOUSTIC_TEXTURE:
return AkInspectorEditorPropertyInfo{ "Select Acoustic Texture...", "Search Acoustic Textures..." };
default:
return AkInspectorEditorPropertyInfo{ "Default Select Label", "Default Search Label" };
}
Expand Down
8 changes: 7 additions & 1 deletion addons/Wwise/native/src/editor/ak_waapi_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ void AkWaapiPicker::generate_ids(const Array& data)
Array aux_bus_array;
Array audio_device_array;
Array external_src_array;
Array acoustic_texture_array;

for (int i = 0; i < data.size(); ++i)
{
Expand Down Expand Up @@ -437,6 +438,10 @@ void AkWaapiPicker::generate_ids(const Array& data)
{
external_src_array.append(data[i]);
}
else if (type == "AcousticTexture")
{
acoustic_texture_array.append(data[i]);
}
}

Dictionary init_soundbank;
Expand All @@ -458,6 +463,7 @@ void AkWaapiPicker::generate_ids(const Array& data)
create_class(aux_bus_array, "AUX_BUSSES");
create_class(audio_device_array, "AUDIO_DEVICES");
create_class(external_src_array, "EXTERNAL_SOURCES");
create_class(acoustic_texture_array, "ACOUSTIC_TEXTURES");
}

void AkWaapiPicker::create_class(const Array& data, const String& type)
Expand Down Expand Up @@ -812,7 +818,7 @@ void AkWaapiPicker::_on_file_dialog_file_selected(const String& path)
Dictionary args;
Dictionary of_type;
Array type_array = Array::make("Event", "StateGroup", "State", "SwitchGroup", "Switch", "GameParameter",
"Trigger", "SoundBank", "Bus", "AuxBus", "AudioDevice", "ExternalSource");
"Trigger", "SoundBank", "Bus", "AuxBus", "AudioDevice", "ExternalSource", "AcousticTexture");

of_type["ofType"] = type_array;
args["from"] = of_type;
Expand Down
18 changes: 11 additions & 7 deletions addons/Wwise/native/src/scene/ak_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ void AkGeometry::_bind_methods()
"get_enable_diffraction");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_diffraction_on_boundary_edges", PROPERTY_HINT_NONE),
"set_enable_diffraction_on_boundary_edges", "get_enable_diffraction_on_boundary_edges");
// todo(alex): Add proper hint for acoustic texture
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "acoustic_texture", PROPERTY_HINT_NONE), "set_acoustic_texture",
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "acoustic_texture", PROPERTY_HINT_NONE), "set_acoustic_texture",
"get_acoustic_texture");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "transmission_loss_value", PROPERTY_HINT_NONE),
"set_transmission_loss_value", "get_transmission_loss_value");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "associated_room", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AkRoom"),
"set_associated_room", "get_associated_room");
}
Expand Down Expand Up @@ -62,6 +63,12 @@ void AkGeometry::add_indices(int a, int b, int c, int d)
indices.append(c);
}

AkGeometry::AkGeometry()
{
acoustic_texture["name"] = "";
acoustic_texture["id"] = 0;
}

void AkGeometry::_enter_tree()
{
RETURN_IF_EDITOR;
Expand Down Expand Up @@ -169,12 +176,9 @@ void AkGeometry::set_enable_diffraction_on_boundary_edges(bool enable_diffractio

bool AkGeometry::get_enable_diffraction_on_boundary_edges() const { return enable_diffraction_on_boundary_edges; }

void AkGeometry::set_acoustic_texture(const Ref<Resource>& acoustic_texture)
{
this->acoustic_texture = acoustic_texture;
}
void AkGeometry::set_acoustic_texture(const Dictionary& acoustic_texture) { this->acoustic_texture = acoustic_texture; }

Ref<Resource> AkGeometry::get_acoustic_texture() const { return acoustic_texture; }
Dictionary AkGeometry::get_acoustic_texture() const { return acoustic_texture; }

void AkGeometry::set_transmission_loss_value(float transmission_loss_value)
{
Expand Down
7 changes: 4 additions & 3 deletions addons/Wwise/native/src/scene/ak_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AkGeometry : public Node3D
bool is_static{ true };
bool enable_diffraction{};
bool enable_diffraction_on_boundary_edges{};
Ref<Resource> acoustic_texture{};
Dictionary acoustic_texture{};
float transmission_loss_value{ 1.0f };
NodePath associated_room{};

Expand All @@ -41,6 +41,7 @@ class AkGeometry : public Node3D
void add_indices(int a, int b, int c, int d);

public:
AkGeometry();
virtual void _enter_tree() override;
virtual void _exit_tree() override;
bool set_geometry(const MeshInstance3D* mesh_instance);
Expand All @@ -55,8 +56,8 @@ class AkGeometry : public Node3D
void set_enable_diffraction_on_boundary_edges(bool enable_diffraction_on_boundary_edges);
bool get_enable_diffraction_on_boundary_edges() const;

void set_acoustic_texture(const Ref<Resource>& acoustic_texture);
Ref<Resource> get_acoustic_texture() const;
void set_acoustic_texture(const Dictionary& acoustic_texture);
Dictionary get_acoustic_texture() const;

void set_transmission_loss_value(float transmission_loss_value);
float get_transmission_loss_value() const;
Expand Down
4 changes: 4 additions & 0 deletions addons/Wwise/tools/wwise_ids.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ class AUX_BUSSES:
}

class AUDIO_DEVICES:
const _dict = {
}

class ACOUSTIC_TEXTURES:
const _dict = {
}
Loading