Merge pull request #50979 from lawnjelly/portals_autoplace_priority_setting

This commit is contained in:
Rémi Verschelde 2021-07-29 15:46:01 +02:00 committed by GitHub
commit 7a35eec705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 8 deletions

View File

@ -15,6 +15,11 @@
<methods>
</methods>
<members>
<member name="autoplace_priority" type="int" setter="set_portal_autoplace_priority" getter="get_portal_autoplace_priority" default="0">
When set to [code]0[/code], [CullInstance]s will be autoplaced in the [Room] with the highest priority.
When set to a value other than [code]0[/code], the system will attempt to autoplace in a [Room] with the [code]autoplace_priority[/code], if it is present.
This can be used to control autoplacement of building exteriors in an outer [RoomGroup].
</member>
<member name="include_in_bound" type="bool" setter="set_include_in_bound" getter="get_include_in_bound" default="true">
When a manual bound has not been explicitly specified for a [Room], the convex hull bound will be estimated from the geometry of the objects within the room. This setting determines whether the geometry of an object is included in this estimate of the room bound.
[b]Note:[/b] This setting is only relevant when the object is set to [code]PORTAL_MODE_STATIC[/code] or [code]PORTAL_MODE_DYNAMIC[/code], and for [Portal]s.

View File

@ -48,6 +48,9 @@ void CullInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_include_in_bound"), &CullInstance::set_include_in_bound);
ClassDB::bind_method(D_METHOD("get_include_in_bound"), &CullInstance::get_include_in_bound);
ClassDB::bind_method(D_METHOD("set_portal_autoplace_priority", "priority"), &CullInstance::set_portal_autoplace_priority);
ClassDB::bind_method(D_METHOD("get_portal_autoplace_priority"), &CullInstance::get_portal_autoplace_priority);
ADD_GROUP("Portals", "");
BIND_ENUM_CONSTANT(PORTAL_MODE_STATIC);
@ -58,9 +61,11 @@ void CullInstance::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "portal_mode", PROPERTY_HINT_ENUM, "Static,Dynamic,Roaming,Global,Ignore"), "set_portal_mode", "get_portal_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "include_in_bound"), "set_include_in_bound", "get_include_in_bound");
ADD_PROPERTY(PropertyInfo(Variant::INT, "autoplace_priority", PROPERTY_HINT_RANGE, "-16,16,1", PROPERTY_USAGE_DEFAULT), "set_portal_autoplace_priority", "get_portal_autoplace_priority");
}
CullInstance::CullInstance() {
_portal_mode = PORTAL_MODE_STATIC;
_include_in_bound = true;
_portal_autoplace_priority = 0;
}

View File

@ -51,6 +51,9 @@ public:
void set_include_in_bound(bool p_enable) { _include_in_bound = p_enable; }
bool get_include_in_bound() const { return _include_in_bound; }
void set_portal_autoplace_priority(int p_priority) { _portal_autoplace_priority = p_priority; }
int get_portal_autoplace_priority() const { return _portal_autoplace_priority; }
CullInstance();
protected:
@ -61,6 +64,14 @@ protected:
private:
PortalMode _portal_mode;
bool _include_in_bound;
// Allows instances to prefer to be autoplaced
// in specific RoomGroups. This allows building exteriors
// to be autoplaced in outside RoomGroups, allowing a complete
// exterior / interior of building in one reusable Scene.
// The default value 0 gives no preference (chooses the highest priority).
// All other values will autoplace in the selected RoomGroup priority by preference.
int _portal_autoplace_priority;
};
#endif

View File

@ -1121,14 +1121,26 @@ bool RoomManager::_autoplace_object(VisualInstance *p_vi) {
int best_priority = -INT32_MAX;
Room *best_room = nullptr;
// if not set to zero (no preference) this can override a preference
// for a certain RoomGroup priority to ensure the instance gets placed in the correct
// RoomGroup (e.g. outside, for building exteriors)
int preferred_priority = p_vi->get_portal_autoplace_priority();
for (int n = 0; n < _rooms.size(); n++) {
Room *room = _rooms[n];
if (room->contains_point(centre)) {
// the standard routine autoplaces in the highest priority room
if (room->_room_priority > best_priority) {
best_priority = room->_room_priority;
best_room = room;
}
// if we override the preferred priority we always choose this
if (preferred_priority && (room->_room_priority == preferred_priority)) {
best_room = room;
break;
}
}
}

View File

@ -240,12 +240,13 @@ void PortalRenderer::portal_destroy(PortalHandle p_portal) {
_portal_pool.free(p_portal);
}
void PortalRenderer::portal_set_geometry(PortalHandle p_portal, const Vector<Vector3> &p_points) {
void PortalRenderer::portal_set_geometry(PortalHandle p_portal, const Vector<Vector3> &p_points, real_t p_margin) {
ERR_FAIL_COND(!p_portal);
p_portal--; // plus 1 based
VSPortal &portal = _portal_pool[p_portal];
portal._pts_world = p_points;
portal._margin = p_margin;
if (portal._pts_world.size() < 3) {
WARN_PRINT("Portal must have at least 3 vertices");

View File

@ -132,7 +132,7 @@ public:
PortalHandle portal_create();
void portal_destroy(PortalHandle p_portal);
void portal_set_geometry(PortalHandle p_portal, const Vector<Vector3> &p_points);
void portal_set_geometry(PortalHandle p_portal, const Vector<Vector3> &p_points, real_t p_margin);
void portal_link(PortalHandle p_portal, RoomHandle p_room_from, RoomHandle p_room_to, bool p_two_way);
void portal_set_active(PortalHandle p_portal, bool p_active);

View File

@ -567,7 +567,7 @@ public:
BIND0R(RID, portal_create)
BIND2(portal_set_scenario, RID, RID)
BIND3(portal_set_geometry, RID, const Vector<Vector3> &, float)
BIND3(portal_set_geometry, RID, const Vector<Vector3> &, real_t)
BIND4(portal_link, RID, RID, RID, bool)
BIND2(portal_set_active, RID, bool)

View File

@ -1006,11 +1006,11 @@ void VisualServerScene::portal_set_scenario(RID p_portal, RID p_scenario) {
}
}
void VisualServerScene::portal_set_geometry(RID p_portal, const Vector<Vector3> &p_points, float p_margin) {
void VisualServerScene::portal_set_geometry(RID p_portal, const Vector<Vector3> &p_points, real_t p_margin) {
Portal *portal = portal_owner.getornull(p_portal);
ERR_FAIL_COND(!portal);
ERR_FAIL_COND(!portal->scenario);
portal->scenario->_portal_renderer.portal_set_geometry(portal->scenario_portal_id, p_points);
portal->scenario->_portal_renderer.portal_set_geometry(portal->scenario_portal_id, p_points, p_margin);
}
void VisualServerScene::portal_link(RID p_portal, RID p_room_from, RID p_room_to, bool p_two_way) {

View File

@ -593,7 +593,7 @@ public:
virtual RID portal_create();
virtual void portal_set_scenario(RID p_portal, RID p_scenario);
virtual void portal_set_geometry(RID p_portal, const Vector<Vector3> &p_points, float p_margin);
virtual void portal_set_geometry(RID p_portal, const Vector<Vector3> &p_points, real_t p_margin);
virtual void portal_link(RID p_portal, RID p_room_from, RID p_room_to, bool p_two_way);
virtual void portal_set_active(RID p_portal, bool p_active);

View File

@ -490,7 +490,7 @@ public:
FUNCRID(portal)
FUNC2(portal_set_scenario, RID, RID)
FUNC3(portal_set_geometry, RID, const Vector<Vector3> &, float)
FUNC3(portal_set_geometry, RID, const Vector<Vector3> &, real_t)
FUNC4(portal_link, RID, RID, RID, bool)
FUNC2(portal_set_active, RID, bool)

View File

@ -874,7 +874,7 @@ public:
virtual RID portal_create() = 0;
virtual void portal_set_scenario(RID p_portal, RID p_scenario) = 0;
virtual void portal_set_geometry(RID p_portal, const Vector<Vector3> &p_points, float p_margin) = 0;
virtual void portal_set_geometry(RID p_portal, const Vector<Vector3> &p_points, real_t p_margin) = 0;
virtual void portal_link(RID p_portal, RID p_room_from, RID p_room_to, bool p_two_way) = 0;
virtual void portal_set_active(RID p_portal, bool p_active) = 0;