2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_instance.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "visual_instance.h"
|
|
|
|
|
|
|
|
#include "scene/scene_string_names.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "servers/visual_server.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "skeleton.h"
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB VisualInstance::get_transformed_aabb() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
return get_global_transform().xform(get_aabb());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 10:43:08 +00:00
|
|
|
void VisualInstance::_refresh_portal_mode() {
|
|
|
|
VisualServer::get_singleton()->instance_set_portal_mode(instance, (VisualServer::InstancePortalMode)get_portal_mode());
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
void VisualInstance::_update_visibility() {
|
2021-01-30 15:17:58 +00:00
|
|
|
if (!is_inside_tree()) {
|
2017-01-04 04:16:14 +00:00
|
|
|
return;
|
2021-01-30 15:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool visible = is_visible_in_tree();
|
|
|
|
|
|
|
|
// keep a quick flag available in each node.
|
|
|
|
// no need to call is_visible_in_tree all over the place,
|
|
|
|
// providing it is propagated with a notification.
|
2021-09-15 11:30:45 +00:00
|
|
|
bool already_visible = _is_vi_visible();
|
|
|
|
_set_vi_visible(visible);
|
2021-01-30 15:17:58 +00:00
|
|
|
|
|
|
|
// if making visible, make sure the visual server is up to date with the transform
|
|
|
|
if (visible && (!already_visible)) {
|
2021-09-15 11:30:45 +00:00
|
|
|
if (!_is_using_identity_transform()) {
|
|
|
|
Transform gt = get_global_transform();
|
|
|
|
VisualServer::get_singleton()->instance_set_transform(instance, gt);
|
|
|
|
}
|
2021-01-30 15:17:58 +00:00
|
|
|
}
|
2017-01-04 04:16:14 +00:00
|
|
|
|
|
|
|
_change_notify("visible");
|
2021-01-30 15:17:58 +00:00
|
|
|
VS::get_singleton()->instance_set_visible(get_instance(), visible);
|
2017-01-04 04:16:14 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 11:30:45 +00:00
|
|
|
void VisualInstance::set_instance_use_identity_transform(bool p_enable) {
|
|
|
|
// prevent sending instance transforms when using global coords
|
|
|
|
_set_use_identity_transform(p_enable);
|
|
|
|
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
if (p_enable) {
|
|
|
|
// want to make sure instance is using identity transform
|
|
|
|
VisualServer::get_singleton()->instance_set_transform(instance, get_global_transform());
|
|
|
|
} else {
|
|
|
|
// want to make sure instance is up to date
|
|
|
|
VisualServer::get_singleton()->instance_set_transform(instance, Transform());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void VisualInstance::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case NOTIFICATION_ENTER_WORLD: {
|
2014-05-13 05:24:26 +00:00
|
|
|
// CHECK SKELETON => moving skeleton attaching logic to MeshInstance
|
|
|
|
/*
|
2017-08-24 20:58:51 +00:00
|
|
|
Skeleton *skeleton=Object::cast_to<Skeleton>(get_parent());
|
2014-02-10 01:10:30 +00:00
|
|
|
if (skeleton)
|
|
|
|
VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
|
2014-05-13 05:24:26 +00:00
|
|
|
*/
|
2019-06-22 12:52:51 +00:00
|
|
|
ERR_FAIL_COND(get_world().is_null());
|
2017-03-05 15:44:50 +00:00
|
|
|
VisualServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario());
|
2017-01-04 04:16:14 +00:00
|
|
|
_update_visibility();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
2022-04-28 11:15:14 +00:00
|
|
|
if (_is_vi_visible() || is_physics_interpolated_and_enabled()) {
|
2021-09-15 11:30:45 +00:00
|
|
|
if (!_is_using_identity_transform()) {
|
|
|
|
Transform gt = get_global_transform();
|
|
|
|
VisualServer::get_singleton()->instance_set_transform(instance, gt);
|
2022-05-06 11:09:06 +00:00
|
|
|
|
|
|
|
// For instance when first adding to the tree, when the previous transform is
|
|
|
|
// unset, to prevent streaking from the origin.
|
|
|
|
if (_is_physics_interpolation_reset_requested()) {
|
|
|
|
if (_is_vi_visible()) {
|
|
|
|
_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
|
|
|
|
}
|
|
|
|
_set_physics_interpolation_reset_requested(false);
|
|
|
|
}
|
2021-09-15 11:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
|
2022-04-28 11:15:14 +00:00
|
|
|
if (_is_vi_visible() && is_physics_interpolated()) {
|
|
|
|
VisualServer::get_singleton()->instance_reset_physics_interpolation(instance);
|
2021-01-30 15:17:58 +00:00
|
|
|
}
|
2022-05-10 09:56:54 +00:00
|
|
|
#if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
|
|
|
|
else if (GLOBAL_GET("debug/settings/physics_interpolation/enable_warnings")) {
|
|
|
|
String node_name = is_inside_tree() ? String(get_path()) : String(get_name());
|
|
|
|
if (!_is_vi_visible()) {
|
|
|
|
WARN_PRINT("[Physics interpolation] NOTIFICATION_RESET_PHYSICS_INTERPOLATION only works with unhidden nodes: \"" + node_name + "\".");
|
|
|
|
}
|
|
|
|
if (!is_physics_interpolated()) {
|
|
|
|
WARN_PRINT("[Physics interpolation] NOTIFICATION_RESET_PHYSICS_INTERPOLATION only works with interpolated nodes: \"" + node_name + "\".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_WORLD: {
|
2017-03-05 15:44:50 +00:00
|
|
|
VisualServer::get_singleton()->instance_set_scenario(instance, RID());
|
|
|
|
VisualServer::get_singleton()->instance_attach_skeleton(instance, RID());
|
2017-01-14 11:26:56 +00:00
|
|
|
//VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-01-30 15:17:58 +00:00
|
|
|
// the vi visible flag is always set to invisible when outside the tree,
|
|
|
|
// so it can detect re-entering the tree and becoming visible, and send
|
|
|
|
// the transform to the visual server
|
2021-09-15 11:30:45 +00:00
|
|
|
_set_vi_visible(false);
|
2017-01-04 04:16:14 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
_update_visibility();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-15 11:30:45 +00:00
|
|
|
void VisualInstance::_physics_interpolated_changed() {
|
|
|
|
VisualServer::get_singleton()->instance_set_interpolated(instance, is_physics_interpolated());
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
RID VisualInstance::get_instance() const {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualInstance::_get_visual_instance_rid() const {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualInstance::set_layer_mask(uint32_t p_mask) {
|
2017-03-05 15:44:50 +00:00
|
|
|
layers = p_mask;
|
|
|
|
VisualServer::get_singleton()->instance_set_layer_mask(instance, p_mask);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t VisualInstance::get_layer_mask() const {
|
|
|
|
return layers;
|
|
|
|
}
|
|
|
|
|
2018-07-29 23:05:16 +00:00
|
|
|
void VisualInstance::set_layer_mask_bit(int p_layer, bool p_enable) {
|
|
|
|
ERR_FAIL_INDEX(p_layer, 32);
|
|
|
|
if (p_enable) {
|
|
|
|
set_layer_mask(layers | (1 << p_layer));
|
|
|
|
} else {
|
|
|
|
set_layer_mask(layers & (~(1 << p_layer)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualInstance::get_layer_mask_bit(int p_layer) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_layer, 32, false);
|
|
|
|
return (layers & (1 << p_layer));
|
|
|
|
}
|
|
|
|
|
2022-07-13 18:06:25 +00:00
|
|
|
void VisualInstance::set_sorting_offset(float p_offset) {
|
|
|
|
sorting_offset = p_offset;
|
|
|
|
VisualServer::get_singleton()->instance_set_pivot_data(instance, sorting_offset, sorting_use_aabb_center);
|
|
|
|
}
|
|
|
|
|
|
|
|
float VisualInstance::get_sorting_offset() {
|
|
|
|
return sorting_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualInstance::set_sorting_use_aabb_center(bool p_enabled) {
|
|
|
|
sorting_use_aabb_center = p_enabled;
|
|
|
|
VisualServer::get_singleton()->instance_set_pivot_data(instance, sorting_offset, sorting_use_aabb_center);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualInstance::is_sorting_use_aabb_center() {
|
|
|
|
return sorting_use_aabb_center;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void VisualInstance::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance::_get_visual_instance_rid);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance::set_base);
|
2019-04-22 22:27:30 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance::get_base);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance::get_instance);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &VisualInstance::set_layer_mask);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance::get_layer_mask);
|
2018-07-29 23:05:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "layer", "enabled"), &VisualInstance::set_layer_mask_bit);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "layer"), &VisualInstance::get_layer_mask_bit);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transformed_aabb"), &VisualInstance::get_transformed_aabb);
|
2022-07-13 18:06:25 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_sorting_offset", "offset"), &VisualInstance::set_sorting_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_sorting_offset"), &VisualInstance::get_sorting_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_sorting_use_aabb_center", "enabled"), &VisualInstance::set_sorting_use_aabb_center);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_sorting_use_aabb_center"), &VisualInstance::is_sorting_use_aabb_center);
|
2016-09-22 21:01:44 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask");
|
2022-07-13 18:06:25 +00:00
|
|
|
|
|
|
|
ADD_GROUP("Sorting", "sorting_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "sorting_offset"), "set_sorting_offset", "get_sorting_offset");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sorting_use_aabb_center"), "set_sorting_use_aabb_center", "is_sorting_use_aabb_center");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualInstance::set_base(const RID &p_base) {
|
|
|
|
VisualServer::get_singleton()->instance_set_base(instance, p_base);
|
2019-04-22 22:27:30 +00:00
|
|
|
base = p_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualInstance::get_base() const {
|
|
|
|
return base;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VisualInstance::VisualInstance() {
|
2021-11-09 12:00:07 +00:00
|
|
|
instance = RID_PRIME(VisualServer::get_singleton()->instance_create());
|
2017-08-07 10:17:31 +00:00
|
|
|
VisualServer::get_singleton()->instance_attach_object_instance_id(instance, get_instance_id());
|
2017-03-05 15:44:50 +00:00
|
|
|
layers = 1;
|
2022-07-13 18:06:25 +00:00
|
|
|
sorting_offset = 0.0f;
|
|
|
|
sorting_use_aabb_center = true;
|
2017-01-12 23:35:46 +00:00
|
|
|
set_notify_transform(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualInstance::~VisualInstance() {
|
|
|
|
VisualServer::get_singleton()->free(instance);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GeometryInstance::set_material_override(const Ref<Material> &p_material) {
|
|
|
|
material_override = p_material;
|
|
|
|
VS::get_singleton()->instance_geometry_set_material_override(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Material> GeometryInstance::get_material_override() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return material_override;
|
|
|
|
}
|
|
|
|
|
2021-07-24 20:45:51 +00:00
|
|
|
void GeometryInstance::set_material_overlay(const Ref<Material> &p_material) {
|
|
|
|
material_overlay = p_material;
|
|
|
|
VS::get_singleton()->instance_geometry_set_material_overlay(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID());
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Material> GeometryInstance::get_material_overlay() const {
|
|
|
|
return material_overlay;
|
|
|
|
}
|
|
|
|
|
2020-12-19 17:17:22 +00:00
|
|
|
void GeometryInstance::set_generate_lightmap(bool p_enabled) {
|
|
|
|
generate_lightmap = p_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GeometryInstance::get_generate_lightmap() {
|
|
|
|
return generate_lightmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeometryInstance::set_lightmap_scale(LightmapScale p_scale) {
|
|
|
|
ERR_FAIL_INDEX(p_scale, LIGHTMAP_SCALE_MAX);
|
|
|
|
lightmap_scale = p_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeometryInstance::LightmapScale GeometryInstance::get_lightmap_scale() const {
|
|
|
|
return lightmap_scale;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GeometryInstance::set_lod_min_distance(float p_dist) {
|
|
|
|
lod_min_distance = p_dist;
|
|
|
|
VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float GeometryInstance::get_lod_min_distance() const {
|
2016-10-03 19:33:42 +00:00
|
|
|
return lod_min_distance;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
void GeometryInstance::set_lod_max_distance(float p_dist) {
|
2017-03-05 15:44:50 +00:00
|
|
|
lod_max_distance = p_dist;
|
|
|
|
VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
float GeometryInstance::get_lod_max_distance() const {
|
|
|
|
return lod_max_distance;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GeometryInstance::set_lod_min_hysteresis(float p_dist) {
|
|
|
|
lod_min_hysteresis = p_dist;
|
|
|
|
VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float GeometryInstance::get_lod_min_hysteresis() const {
|
2016-10-03 19:33:42 +00:00
|
|
|
return lod_min_hysteresis;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
void GeometryInstance::set_lod_max_hysteresis(float p_dist) {
|
2017-03-05 15:44:50 +00:00
|
|
|
lod_max_hysteresis = p_dist;
|
|
|
|
VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
float GeometryInstance::get_lod_max_hysteresis() const {
|
|
|
|
return lod_max_hysteresis;
|
|
|
|
}
|
2014-06-11 13:41:03 +00:00
|
|
|
|
|
|
|
void GeometryInstance::_notification(int p_what) {
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GeometryInstance::set_flag(Flags p_flag, bool p_value) {
|
|
|
|
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (flags[p_flag] == p_value) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
flags[p_flag] = p_value;
|
|
|
|
VS::get_singleton()->instance_geometry_set_flag(get_instance(), (VS::InstanceFlags)p_flag, p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GeometryInstance::get_flag(Flags p_flag) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
|
2016-03-07 23:00:55 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return flags[p_flag];
|
|
|
|
}
|
|
|
|
|
2016-03-07 23:00:55 +00:00
|
|
|
void GeometryInstance::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) {
|
|
|
|
shadow_casting_setting = p_shadow_casting_setting;
|
|
|
|
|
|
|
|
VS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), (VS::ShadowCastingSetting)p_shadow_casting_setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeometryInstance::ShadowCastingSetting GeometryInstance::get_cast_shadows_setting() const {
|
|
|
|
return shadow_casting_setting;
|
|
|
|
}
|
|
|
|
|
2015-03-02 03:54:10 +00:00
|
|
|
void GeometryInstance::set_extra_cull_margin(float p_margin) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_margin < 0);
|
|
|
|
extra_cull_margin = p_margin;
|
|
|
|
VS::get_singleton()->instance_set_extra_visibility_margin(get_instance(), extra_cull_margin);
|
2015-03-02 03:54:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float GeometryInstance::get_extra_cull_margin() const {
|
2015-03-02 03:54:10 +00:00
|
|
|
return extra_cull_margin;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-31 16:54:00 +00:00
|
|
|
void GeometryInstance::set_custom_aabb(AABB aabb) {
|
|
|
|
VS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void GeometryInstance::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance::set_material_override);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance::get_material_override);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-07-24 20:45:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_material_overlay", "material"), &GeometryInstance::set_material_overlay);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_material_overlay"), &GeometryInstance::get_material_overlay);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance::set_flag);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance::get_flag);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance::set_cast_shadows_setting);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance::get_cast_shadows_setting);
|
2016-03-07 23:00:55 +00:00
|
|
|
|
2020-12-19 17:17:22 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_generate_lightmap", "enabled"), &GeometryInstance::set_generate_lightmap);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_generate_lightmap"), &GeometryInstance::get_generate_lightmap);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_lightmap_scale", "scale"), &GeometryInstance::set_lightmap_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_lightmap_scale"), &GeometryInstance::get_lightmap_scale);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance::set_lod_max_hysteresis);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance::get_lod_max_hysteresis);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance::set_lod_max_distance);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance::get_lod_max_distance);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance::set_lod_min_hysteresis);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance::get_lod_min_hysteresis);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_lod_min_distance", "mode"), &GeometryInstance::set_lod_min_distance);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_lod_min_distance"), &GeometryInstance::get_lod_min_distance);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance::set_extra_cull_margin);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance::get_extra_cull_margin);
|
2015-03-02 03:54:10 +00:00
|
|
|
|
2019-01-31 16:54:00 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance::set_custom_aabb);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance::get_aabb);
|
2016-09-22 21:01:44 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Geometry", "");
|
2017-06-22 12:17:06 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,SpatialMaterial"), "set_material_override", "get_material_override");
|
2021-07-24 20:45:51 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_overlay", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,SpatialMaterial"), "set_material_overlay", "get_material_overlay");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting");
|
2018-09-23 11:58:58 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0.01"), "set_extra_cull_margin", "get_extra_cull_margin");
|
2020-12-19 17:17:22 +00:00
|
|
|
|
|
|
|
ADD_GROUP("Baked Light", "");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_in_baked_light"), "set_flag", "get_flag", FLAG_USE_BAKED_LIGHT);
|
2020-12-19 17:17:22 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_lightmap"), "set_generate_lightmap", "get_generate_lightmap");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "lightmap_scale", PROPERTY_HINT_ENUM, "1x,2x,4x,8x"), "set_lightmap_scale", "get_lightmap_scale");
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
ADD_GROUP("LOD", "lod_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_distance", "get_lod_min_distance");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_hysteresis", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_hysteresis", "get_lod_min_hysteresis");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_max_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_max_distance", "get_lod_max_distance");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_max_hysteresis", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_max_hysteresis", "get_lod_max_hysteresis");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//ADD_SIGNAL( MethodInfo("visibility_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-12-19 17:17:22 +00:00
|
|
|
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_1X);
|
|
|
|
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_2X);
|
|
|
|
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_4X);
|
|
|
|
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_8X);
|
|
|
|
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_MAX);
|
|
|
|
|
2017-09-12 19:09:06 +00:00
|
|
|
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_OFF);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_ON);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-12 19:09:06 +00:00
|
|
|
BIND_ENUM_CONSTANT(FLAG_USE_BAKED_LIGHT);
|
2019-06-27 09:10:53 +00:00
|
|
|
BIND_ENUM_CONSTANT(FLAG_DRAW_NEXT_FRAME_IF_VISIBLE);
|
2017-09-12 19:09:06 +00:00
|
|
|
BIND_ENUM_CONSTANT(FLAG_MAX);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GeometryInstance::GeometryInstance() {
|
2017-03-05 15:44:50 +00:00
|
|
|
lod_min_distance = 0;
|
|
|
|
lod_max_distance = 0;
|
|
|
|
lod_min_hysteresis = 0;
|
|
|
|
lod_max_hysteresis = 0;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < FLAG_MAX; i++) {
|
|
|
|
flags[i] = false;
|
2014-12-07 05:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_casting_setting = SHADOW_CASTING_SETTING_ON;
|
|
|
|
extra_cull_margin = 0;
|
2020-12-19 17:17:22 +00:00
|
|
|
generate_lightmap = true;
|
|
|
|
lightmap_scale = LightmapScale::LIGHTMAP_SCALE_1X;
|
2017-01-14 11:26:56 +00:00
|
|
|
//VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|