-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgeometry.cpp
114 lines (97 loc) · 3.42 KB
/
geometry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "geometry.hpp"
#include "geometry_common.hpp"
#include "godot_cpp/classes/collision_shape3d.hpp"
#include "godot_cpp/classes/engine.hpp"
#include "godot_cpp/classes/mesh_instance3d.hpp"
#include "godot_cpp/variant/array.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "phonon.h"
#include "server.hpp"
void SteamAudioGeometry::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_material"), &SteamAudioGeometry::get_material);
ClassDB::bind_method(D_METHOD("set_material", "p_material"), &SteamAudioGeometry::set_material);
ClassDB::bind_method(D_METHOD("is_disabled"), &SteamAudioGeometry::is_disabled);
ClassDB::bind_method(D_METHOD("set_disabled", "p_disabled"), &SteamAudioGeometry::set_disabled);
ClassDB::bind_method(D_METHOD("recalculate"), &SteamAudioGeometry::recalculate);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "SteamAudioMaterial"), "set_material", "get_material");
}
SteamAudioGeometry::SteamAudioGeometry() {}
SteamAudioGeometry::~SteamAudioGeometry() {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
unregister_geometry();
destroy_geometry();
}
void SteamAudioGeometry::ready_internal() {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
create_geometry();
register_geometry();
}
void SteamAudioGeometry::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
ready_internal();
break;
}
}
void SteamAudioGeometry::set_disabled(bool p_disabled) {
if (disabled == p_disabled) {
return;
}
if (p_disabled) {
unregister_geometry();
} else {
register_geometry();
}
disabled = p_disabled;
}
void SteamAudioGeometry::recalculate() {
unregister_geometry();
destroy_geometry();
create_geometry();
register_geometry();
}
void SteamAudioGeometry::create_geometry() {
// FIXME: we probably don't even have a global state yet
if (Object::cast_to<MeshInstance3D>(get_parent())) {
meshes = create_meshes_from_mesh_inst_3d(
Object::cast_to<MeshInstance3D>(get_parent()),
SteamAudioServer::get_singleton()->get_global_state()->scene, mat);
} else if (Object::cast_to<CollisionShape3D>(get_parent())) {
meshes = create_meshes_from_coll_inst_3d(
Object::cast_to<CollisionShape3D>(get_parent()),
SteamAudioServer::get_singleton()->get_global_state()->scene, mat);
} else {
UtilityFunctions::push_error("The parent of SteamAudioGeometry must be a MeshInstance3D or a CollisionShape3D.");
return;
}
}
void SteamAudioGeometry::destroy_geometry() {
for (auto mesh : meshes) {
iplStaticMeshRelease(&mesh);
}
meshes.clear();
}
void SteamAudioGeometry::register_geometry() {
for (auto mesh : meshes) {
SteamAudioServer::get_singleton()->add_static_mesh(mesh);
}
}
void SteamAudioGeometry::unregister_geometry() {
for (auto ipl_mesh : meshes) {
SteamAudioServer::get_singleton()->remove_static_mesh(ipl_mesh);
}
}
PackedStringArray SteamAudioGeometry::_get_configuration_warnings() const {
PackedStringArray res;
if (!Object::cast_to<MeshInstance3D>(get_parent()) && !Object::cast_to<CollisionShape3D>(get_parent())) {
res.push_back("The parent of SteamAudioGeometry must be a MeshInstance3D or a CollisionShape3D.");
}
return res;
}
Ref<SteamAudioMaterial> SteamAudioGeometry::get_material() { return mat; }
void SteamAudioGeometry::set_material(Ref<SteamAudioMaterial> p_material) { mat = p_material; }