mirror of
https://github.com/Relintai/pandemonium_engine_minimal.git
synced 2024-12-21 16:56:50 +01:00
Removed the instancing api.
This commit is contained in:
parent
f796007990
commit
8d5eb28de5
@ -361,44 +361,9 @@ public:
|
||||
|
||||
BIND2(scenario_set_debug, RID, ScenarioDebugMode)
|
||||
|
||||
/* INSTANCING API */
|
||||
|
||||
BIND0R(RID, instance_create)
|
||||
|
||||
BIND2(instance_set_base, RID, RID)
|
||||
BIND2(instance_set_scenario, RID, RID)
|
||||
BIND2(instance_set_layer_mask, RID, uint32_t)
|
||||
BIND3(instance_set_pivot_data, RID, float, bool)
|
||||
BIND2(instance_set_transform, RID, const Transform &)
|
||||
BIND2(instance_set_interpolated, RID, bool)
|
||||
BIND1(instance_reset_physics_interpolation, RID)
|
||||
BIND2(instance_attach_object_instance_id, RID, ObjectID)
|
||||
BIND3(instance_set_blend_shape_weight, RID, int, float)
|
||||
BIND3(instance_set_surface_material, RID, int, RID)
|
||||
BIND2(instance_set_visible, RID, bool)
|
||||
|
||||
BIND2(instance_set_custom_aabb, RID, AABB)
|
||||
|
||||
BIND2(instance_attach_skeleton, RID, RID)
|
||||
BIND2(instance_set_exterior, RID, bool)
|
||||
|
||||
BIND2(instance_set_extra_visibility_margin, RID, real_t)
|
||||
|
||||
// Callbacks
|
||||
BIND1(callbacks_register, RenderingServerCallbacks *)
|
||||
|
||||
// don't use these in a game!
|
||||
BIND2RC(Vector<ObjectID>, instances_cull_aabb, const AABB &, RID)
|
||||
BIND3RC(Vector<ObjectID>, instances_cull_ray, const Vector3 &, const Vector3 &, RID)
|
||||
BIND2RC(Vector<ObjectID>, instances_cull_convex, const Vector<Plane> &, RID)
|
||||
|
||||
BIND3(instance_geometry_set_flag, RID, InstanceFlags, bool)
|
||||
BIND2(instance_geometry_set_material_override, RID, RID)
|
||||
BIND2(instance_geometry_set_material_overlay, RID, RID)
|
||||
|
||||
BIND5(instance_geometry_set_draw_range, RID, float, float, float, float)
|
||||
BIND2(instance_geometry_set_as_instance_lod, RID, RID)
|
||||
|
||||
#undef BINDBASE
|
||||
//from now on, calls forwarded to this singleton
|
||||
#define BINDBASE RSG::canvas
|
||||
|
@ -373,227 +373,6 @@ void RenderingServerScene::_instance_queue_update(Instance *p_instance, bool p_u
|
||||
_instance_update_list.add(&p_instance->update_item);
|
||||
}
|
||||
|
||||
RID RenderingServerScene::instance_create() {
|
||||
Instance *instance = memnew(Instance);
|
||||
ERR_FAIL_COND_V(!instance, RID());
|
||||
|
||||
RID instance_rid = instance_owner.make_rid(instance);
|
||||
instance->self = instance_rid;
|
||||
|
||||
return instance_rid;
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_base(RID p_instance, RID p_base) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
Scenario *scenario = instance->scenario;
|
||||
|
||||
if (instance->base_type != RS::INSTANCE_NONE) {
|
||||
//free anything related to that base
|
||||
|
||||
RSG::storage->instance_remove_dependency(instance->base, instance);
|
||||
|
||||
if (scenario && instance->spatial_partition_id) {
|
||||
scenario->sps->erase(instance->spatial_partition_id);
|
||||
instance->spatial_partition_id = 0;
|
||||
}
|
||||
|
||||
if (instance->base_data) {
|
||||
memdelete(instance->base_data);
|
||||
instance->base_data = nullptr;
|
||||
}
|
||||
|
||||
instance->blend_values = PoolRealArray();
|
||||
|
||||
for (int i = 0; i < instance->materials.size(); i++) {
|
||||
if (instance->materials[i].is_valid()) {
|
||||
RSG::storage->material_remove_instance_owner(instance->materials[i], instance);
|
||||
}
|
||||
}
|
||||
instance->materials.clear();
|
||||
}
|
||||
|
||||
instance->base_type = RS::INSTANCE_NONE;
|
||||
instance->base = RID();
|
||||
|
||||
if (p_base.is_valid()) {
|
||||
instance->base_type = RSG::storage->get_base_type(p_base);
|
||||
ERR_FAIL_COND(instance->base_type == RS::INSTANCE_NONE);
|
||||
|
||||
switch (instance->base_type) {
|
||||
case RS::INSTANCE_MESH:
|
||||
case RS::INSTANCE_MULTIMESH: {
|
||||
InstanceGeometryData *geom = memnew(InstanceGeometryData);
|
||||
instance->base_data = geom;
|
||||
if (instance->base_type == RS::INSTANCE_MESH) {
|
||||
instance->blend_values.resize(RSG::storage->mesh_get_blend_shape_count(p_base));
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
}
|
||||
}
|
||||
|
||||
RSG::storage->instance_add_dependency(p_base, instance);
|
||||
|
||||
instance->base = p_base;
|
||||
|
||||
if (scenario) {
|
||||
_instance_queue_update(instance, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
void RenderingServerScene::instance_set_scenario(RID p_instance, RID p_scenario) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->scenario) {
|
||||
instance->scenario->instances.remove(&instance->scenario_item);
|
||||
|
||||
if (instance->spatial_partition_id) {
|
||||
instance->scenario->sps->erase(instance->spatial_partition_id);
|
||||
instance->spatial_partition_id = 0;
|
||||
}
|
||||
|
||||
// remove any interpolation data associated with the instance in this scenario
|
||||
_interpolation_data.notify_free_instance(p_instance, *instance);
|
||||
|
||||
instance->scenario = nullptr;
|
||||
}
|
||||
|
||||
if (p_scenario.is_valid()) {
|
||||
Scenario *scenario = scenario_owner.get(p_scenario);
|
||||
ERR_FAIL_COND(!scenario);
|
||||
|
||||
instance->scenario = scenario;
|
||||
|
||||
scenario->instances.add(&instance->scenario_item);
|
||||
|
||||
_instance_queue_update(instance, true, true);
|
||||
}
|
||||
}
|
||||
void RenderingServerScene::instance_set_layer_mask(RID p_instance, uint32_t p_mask) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->layer_mask == p_mask) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance->layer_mask = p_mask;
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_pivot_data(RID p_instance, float p_sorting_offset, bool p_use_aabb_center) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
instance->sorting_offset = p_sorting_offset;
|
||||
instance->use_aabb_center = p_use_aabb_center;
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_reset_physics_interpolation(RID p_instance) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (_interpolation_data.interpolation_enabled && instance->interpolated) {
|
||||
_interpolation_data.instance_teleport_list.push_back(p_instance);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_interpolated(RID p_instance, bool p_interpolated) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
instance->interpolated = p_interpolated;
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_transform(RID p_instance, const Transform &p_transform) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (!(_interpolation_data.interpolation_enabled && instance->interpolated) || !instance->scenario) {
|
||||
if (instance->transform == p_transform) {
|
||||
return; //must be checked to avoid worst evil
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const Vector3 &v = i < 3 ? p_transform.basis.rows[i] : p_transform.origin;
|
||||
ERR_FAIL_COND(Math::is_inf(v.x));
|
||||
ERR_FAIL_COND(Math::is_nan(v.x));
|
||||
ERR_FAIL_COND(Math::is_inf(v.y));
|
||||
ERR_FAIL_COND(Math::is_nan(v.y));
|
||||
ERR_FAIL_COND(Math::is_inf(v.z));
|
||||
ERR_FAIL_COND(Math::is_nan(v.z));
|
||||
}
|
||||
|
||||
#endif
|
||||
instance->transform = p_transform;
|
||||
_instance_queue_update(instance, true);
|
||||
return;
|
||||
}
|
||||
|
||||
float new_checksum = TransformInterpolator::checksum_transform(p_transform);
|
||||
bool checksums_match = (instance->transform_checksum_curr == new_checksum) && (instance->transform_checksum_prev == new_checksum);
|
||||
|
||||
// we can't entirely reject no changes because we need the interpolation
|
||||
// system to keep on stewing
|
||||
|
||||
// Optimized check. First checks the checksums. If they pass it does the slow check at the end.
|
||||
// Alternatively we can do this non-optimized and ignore the checksum...
|
||||
// if no change
|
||||
if (checksums_match && (instance->transform_curr == p_transform) && (instance->transform_prev == p_transform)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const Vector3 &v = i < 3 ? p_transform.basis.rows[i] : p_transform.origin;
|
||||
ERR_FAIL_COND(Math::is_inf(v.x));
|
||||
ERR_FAIL_COND(Math::is_nan(v.x));
|
||||
ERR_FAIL_COND(Math::is_inf(v.y));
|
||||
ERR_FAIL_COND(Math::is_nan(v.y));
|
||||
ERR_FAIL_COND(Math::is_inf(v.z));
|
||||
ERR_FAIL_COND(Math::is_nan(v.z));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
instance->transform_curr = p_transform;
|
||||
|
||||
// keep checksums up to date
|
||||
instance->transform_checksum_curr = new_checksum;
|
||||
|
||||
if (!instance->on_interpolate_transform_list) {
|
||||
_interpolation_data.instance_transform_update_list_curr->push_back(p_instance);
|
||||
instance->on_interpolate_transform_list = true;
|
||||
} else {
|
||||
DEV_ASSERT(_interpolation_data.instance_transform_update_list_curr->size());
|
||||
}
|
||||
|
||||
// If the instance is invisible, then we are simply updating the data flow, there is no need to calculate the interpolated
|
||||
// transform or anything else.
|
||||
// Ideally we would not even call the RenderingServer::set_transform() when invisible but that would entail having logic
|
||||
// to keep track of the previous transform on the SceneTree side. The "early out" below is less efficient but a lot cleaner codewise.
|
||||
if (!instance->visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
// decide on the interpolation method .. slerp if possible
|
||||
instance->interpolation_method = TransformInterpolator::find_method(instance->transform_prev.basis, instance->transform_curr.basis);
|
||||
|
||||
if (!instance->on_interpolate_list) {
|
||||
_interpolation_data.instance_interpolate_update_list.push_back(p_instance);
|
||||
instance->on_interpolate_list = true;
|
||||
} else {
|
||||
DEV_ASSERT(_interpolation_data.instance_interpolate_update_list.size());
|
||||
}
|
||||
|
||||
_instance_queue_update(instance, true);
|
||||
}
|
||||
|
||||
void RenderingServerScene::InterpolationData::notify_free_camera(RID p_rid, Camera &r_camera) {
|
||||
r_camera.on_interpolate_transform_list = false;
|
||||
|
||||
@ -753,283 +532,11 @@ void RenderingServerScene::update_interpolation_frame(bool p_process) {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_attach_object_instance_id(RID p_instance, ObjectID p_id) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
instance->object_id = p_id;
|
||||
}
|
||||
void RenderingServerScene::instance_set_blend_shape_weight(RID p_instance, int p_shape, float p_weight) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->update_item.in_list()) {
|
||||
_update_dirty_instance(instance);
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX(p_shape, instance->blend_values.size());
|
||||
instance->blend_values.write().ptr()[p_shape] = p_weight;
|
||||
RSG::storage->mesh_set_blend_shape_values(instance->base, instance->blend_values);
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_surface_material(RID p_instance, int p_surface, RID p_material) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->base_type == RS::INSTANCE_MESH) {
|
||||
//may not have been updated yet
|
||||
instance->materials.resize(RSG::storage->mesh_get_surface_count(instance->base));
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX(p_surface, instance->materials.size());
|
||||
|
||||
if (instance->materials[p_surface].is_valid()) {
|
||||
RSG::storage->material_remove_instance_owner(instance->materials[p_surface], instance);
|
||||
}
|
||||
instance->materials.write[p_surface] = p_material;
|
||||
instance->base_changed(false, true);
|
||||
|
||||
if (instance->materials[p_surface].is_valid()) {
|
||||
RSG::storage->material_add_instance_owner(instance->materials[p_surface], instance);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_visible(RID p_instance, bool p_visible) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->visible == p_visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance->visible = p_visible;
|
||||
|
||||
// Special case for physics interpolation, we want to ensure the interpolated data is up to date
|
||||
if (_interpolation_data.interpolation_enabled && p_visible && instance->interpolated && instance->scenario && !instance->on_interpolate_list) {
|
||||
// Do all the extra work we normally do on instance_set_transform(), because this is optimized out for hidden instances.
|
||||
// This prevents a glitch of stale interpolation transform data when unhiding before the next physics tick.
|
||||
instance->interpolation_method = TransformInterpolator::find_method(instance->transform_prev.basis, instance->transform_curr.basis);
|
||||
_interpolation_data.instance_interpolate_update_list.push_back(p_instance);
|
||||
instance->on_interpolate_list = true;
|
||||
_instance_queue_update(instance, true);
|
||||
|
||||
// We must also place on the transform update list for a tick, so the system
|
||||
// can auto-detect if the instance is no longer moving, and remove from the interpolate lists again.
|
||||
// If this step is ignored, an unmoving instance could remain on the interpolate lists indefinitely
|
||||
// (or rather until the object is deleted) and cause unnecessary updates and drawcalls.
|
||||
if (!instance->on_interpolate_transform_list) {
|
||||
_interpolation_data.instance_transform_update_list_curr->push_back(p_instance);
|
||||
instance->on_interpolate_transform_list = true;
|
||||
}
|
||||
}
|
||||
|
||||
// give the opportunity for the spatial partitioning scene to use a special implementation of visibility
|
||||
// for efficiency (supported in BVH but not octree)
|
||||
|
||||
// slightly bug prone optimization here - we want to avoid doing a collision check twice
|
||||
// once when activating, and once when calling set_pairable. We do this by deferring the collision check.
|
||||
// However, in some cases (notably meshes), set_pairable never gets called. So we want to catch this case
|
||||
// and force a collision check (see later in this function).
|
||||
// This is only done in two stages to maintain compatibility with the octree.
|
||||
if (instance->spatial_partition_id && instance->scenario) {
|
||||
if (p_visible) {
|
||||
instance->scenario->sps->activate(instance->spatial_partition_id, instance->transformed_aabb);
|
||||
} else {
|
||||
instance->scenario->sps->deactivate(instance->spatial_partition_id);
|
||||
}
|
||||
}
|
||||
|
||||
switch (instance->base_type) {
|
||||
default: {
|
||||
// if we haven't called set_pairable, we STILL need to do a collision check
|
||||
// for activated items because we deferred it earlier in the call to activate.
|
||||
if (instance->spatial_partition_id && instance->scenario && p_visible) {
|
||||
instance->scenario->sps->force_collision_check(instance->spatial_partition_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
inline bool is_geometry_instance(RenderingServer::InstanceType p_type) {
|
||||
return p_type == RS::INSTANCE_MESH || p_type == RS::INSTANCE_MULTIMESH;
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
ERR_FAIL_COND(!is_geometry_instance(instance->base_type));
|
||||
|
||||
if (p_aabb != AABB()) {
|
||||
// Set custom AABB
|
||||
if (instance->custom_aabb == nullptr) {
|
||||
instance->custom_aabb = memnew(AABB);
|
||||
}
|
||||
*instance->custom_aabb = p_aabb;
|
||||
|
||||
} else {
|
||||
// Clear custom AABB
|
||||
if (instance->custom_aabb != nullptr) {
|
||||
memdelete(instance->custom_aabb);
|
||||
instance->custom_aabb = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance->scenario) {
|
||||
_instance_queue_update(instance, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_attach_skeleton(RID p_instance, RID p_skeleton) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->skeleton == p_skeleton) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (instance->skeleton.is_valid()) {
|
||||
RSG::storage->instance_remove_skeleton(instance->skeleton, instance);
|
||||
}
|
||||
|
||||
instance->skeleton = p_skeleton;
|
||||
|
||||
if (instance->skeleton.is_valid()) {
|
||||
RSG::storage->instance_add_skeleton(instance->skeleton, instance);
|
||||
}
|
||||
|
||||
_instance_queue_update(instance, true);
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_exterior(RID p_instance, bool p_enabled) {
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
instance->extra_margin = p_margin;
|
||||
_instance_queue_update(instance, true, false);
|
||||
}
|
||||
|
||||
// Rooms
|
||||
void RenderingServerScene::callbacks_register(RenderingServerCallbacks *p_callbacks) {
|
||||
_rendering_server_callbacks = p_callbacks;
|
||||
}
|
||||
|
||||
Vector<ObjectID> RenderingServerScene::instances_cull_aabb(const AABB &p_aabb, RID p_scenario) const {
|
||||
Vector<ObjectID> instances;
|
||||
Scenario *scenario = scenario_owner.get(p_scenario);
|
||||
ERR_FAIL_COND_V(!scenario, instances);
|
||||
|
||||
const_cast<RenderingServerScene *>(this)->update_dirty_instances(); // check dirty instances before culling
|
||||
|
||||
int culled = 0;
|
||||
Instance *cull[1024];
|
||||
culled = scenario->sps->cull_aabb(p_aabb, cull, 1024);
|
||||
|
||||
for (int i = 0; i < culled; i++) {
|
||||
Instance *instance = cull[i];
|
||||
ERR_CONTINUE(!instance);
|
||||
if (instance->object_id == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
instances.push_back(instance->object_id);
|
||||
}
|
||||
|
||||
return instances;
|
||||
}
|
||||
Vector<ObjectID> RenderingServerScene::instances_cull_ray(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const {
|
||||
Vector<ObjectID> instances;
|
||||
Scenario *scenario = scenario_owner.get(p_scenario);
|
||||
ERR_FAIL_COND_V(!scenario, instances);
|
||||
const_cast<RenderingServerScene *>(this)->update_dirty_instances(); // check dirty instances before culling
|
||||
|
||||
int culled = 0;
|
||||
Instance *cull[1024];
|
||||
culled = scenario->sps->cull_segment(p_from, p_from + p_to * 10000, cull, 1024);
|
||||
|
||||
for (int i = 0; i < culled; i++) {
|
||||
Instance *instance = cull[i];
|
||||
ERR_CONTINUE(!instance);
|
||||
if (instance->object_id == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
instances.push_back(instance->object_id);
|
||||
}
|
||||
|
||||
return instances;
|
||||
}
|
||||
Vector<ObjectID> RenderingServerScene::instances_cull_convex(const Vector<Plane> &p_convex, RID p_scenario) const {
|
||||
Vector<ObjectID> instances;
|
||||
Scenario *scenario = scenario_owner.get(p_scenario);
|
||||
ERR_FAIL_COND_V(!scenario, instances);
|
||||
const_cast<RenderingServerScene *>(this)->update_dirty_instances(); // check dirty instances before culling
|
||||
|
||||
int culled = 0;
|
||||
Instance *cull[1024];
|
||||
|
||||
culled = scenario->sps->cull_convex(p_convex, cull, 1024);
|
||||
|
||||
for (int i = 0; i < culled; i++) {
|
||||
Instance *instance = cull[i];
|
||||
ERR_CONTINUE(!instance);
|
||||
if (instance->object_id == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
instances.push_back(instance->object_id);
|
||||
}
|
||||
|
||||
return instances;
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_geometry_set_flag(RID p_instance, RS::InstanceFlags p_flags, bool p_enabled) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
switch (p_flags) {
|
||||
case RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE: {
|
||||
instance->redraw_if_visible = p_enabled;
|
||||
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
void RenderingServerScene::instance_geometry_set_material_override(RID p_instance, RID p_material) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->material_override.is_valid()) {
|
||||
RSG::storage->material_remove_instance_owner(instance->material_override, instance);
|
||||
}
|
||||
instance->material_override = p_material;
|
||||
instance->base_changed(false, true);
|
||||
|
||||
if (instance->material_override.is_valid()) {
|
||||
RSG::storage->material_add_instance_owner(instance->material_override, instance);
|
||||
}
|
||||
}
|
||||
void RenderingServerScene::instance_geometry_set_material_overlay(RID p_instance, RID p_material) {
|
||||
Instance *instance = instance_owner.get(p_instance);
|
||||
ERR_FAIL_COND(!instance);
|
||||
|
||||
if (instance->material_overlay.is_valid()) {
|
||||
RSG::storage->material_remove_instance_owner(instance->material_overlay, instance);
|
||||
}
|
||||
instance->material_overlay = p_material;
|
||||
instance->base_changed(false, true);
|
||||
|
||||
if (instance->material_overlay.is_valid()) {
|
||||
RSG::storage->material_add_instance_owner(instance->material_overlay, instance);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingServerScene::instance_geometry_set_draw_range(RID p_instance, float p_min, float p_max, float p_min_margin, float p_max_margin) {
|
||||
}
|
||||
void RenderingServerScene::instance_geometry_set_as_instance_lod(RID p_instance, RID p_as_lod_of_instance) {
|
||||
}
|
||||
|
||||
void RenderingServerScene::_update_instance(Instance *p_instance) {
|
||||
p_instance->version++;
|
||||
@ -1381,9 +888,6 @@ bool RenderingServerScene::free(RID p_rid) {
|
||||
} else if (scenario_owner.owns(p_rid)) {
|
||||
Scenario *scenario = scenario_owner.get(p_rid);
|
||||
|
||||
while (scenario->instances.first()) {
|
||||
instance_set_scenario(scenario->instances.first()->self()->self, RID());
|
||||
}
|
||||
|
||||
scenario_owner.free(p_rid);
|
||||
memdelete(scenario);
|
||||
@ -1397,12 +901,6 @@ bool RenderingServerScene::free(RID p_rid) {
|
||||
|
||||
_interpolation_data.notify_free_instance(p_rid, *instance);
|
||||
|
||||
instance_set_scenario(p_rid, RID());
|
||||
instance_set_base(p_rid, RID());
|
||||
instance_geometry_set_material_override(p_rid, RID());
|
||||
instance_geometry_set_material_overlay(p_rid, RID());
|
||||
instance_attach_skeleton(p_rid, RID());
|
||||
|
||||
update_dirty_instances(); //in case something changed this
|
||||
|
||||
instance_owner.free(p_rid);
|
||||
|
@ -332,7 +332,6 @@ public:
|
||||
InstanceBaseData *base_data;
|
||||
|
||||
virtual void base_removed() {
|
||||
singleton->instance_set_base(self, RID());
|
||||
}
|
||||
|
||||
virtual void base_changed(bool p_aabb, bool p_materials) {
|
||||
@ -421,45 +420,12 @@ public:
|
||||
|
||||
RID_Owner<Instance> instance_owner;
|
||||
|
||||
virtual RID instance_create();
|
||||
|
||||
virtual void instance_set_base(RID p_instance, RID p_base);
|
||||
virtual void instance_set_scenario(RID p_instance, RID p_scenario);
|
||||
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask);
|
||||
virtual void instance_set_pivot_data(RID p_instance, float p_sorting_offset, bool p_use_aabb_center);
|
||||
virtual void instance_set_transform(RID p_instance, const Transform &p_transform);
|
||||
virtual void instance_set_interpolated(RID p_instance, bool p_interpolated);
|
||||
virtual void instance_reset_physics_interpolation(RID p_instance);
|
||||
virtual void instance_attach_object_instance_id(RID p_instance, ObjectID p_id);
|
||||
virtual void instance_set_blend_shape_weight(RID p_instance, int p_shape, float p_weight);
|
||||
virtual void instance_set_surface_material(RID p_instance, int p_surface, RID p_material);
|
||||
virtual void instance_set_visible(RID p_instance, bool p_visible);
|
||||
|
||||
virtual void instance_set_custom_aabb(RID p_instance, AABB p_aabb);
|
||||
|
||||
virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton);
|
||||
virtual void instance_set_exterior(RID p_instance, bool p_enabled);
|
||||
|
||||
virtual void instance_set_extra_visibility_margin(RID p_instance, real_t p_margin);
|
||||
|
||||
public:
|
||||
virtual void callbacks_register(RenderingServerCallbacks *p_callbacks);
|
||||
RenderingServerCallbacks *get_callbacks() const {
|
||||
return _rendering_server_callbacks;
|
||||
}
|
||||
|
||||
// don't use these in a game!
|
||||
virtual Vector<ObjectID> instances_cull_aabb(const AABB &p_aabb, RID p_scenario = RID()) const;
|
||||
virtual Vector<ObjectID> instances_cull_ray(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario = RID()) const;
|
||||
virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane> &p_convex, RID p_scenario = RID()) const;
|
||||
|
||||
virtual void instance_geometry_set_flag(RID p_instance, RS::InstanceFlags p_flags, bool p_enabled);
|
||||
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material);
|
||||
virtual void instance_geometry_set_material_overlay(RID p_instance, RID p_material);
|
||||
|
||||
virtual void instance_geometry_set_draw_range(RID p_instance, float p_min, float p_max, float p_min_margin, float p_max_margin);
|
||||
virtual void instance_geometry_set_as_instance_lod(RID p_instance, RID p_as_lod_of_instance);
|
||||
|
||||
_FORCE_INLINE_ void _update_instance(Instance *p_instance);
|
||||
_FORCE_INLINE_ void _update_instance_aabb(Instance *p_instance);
|
||||
_FORCE_INLINE_ void _update_dirty_instance(Instance *p_instance);
|
||||
|
@ -148,7 +148,6 @@ void RenderingServerWrapMT::finish() {
|
||||
camera_free_cached_ids();
|
||||
viewport_free_cached_ids();
|
||||
scenario_free_cached_ids();
|
||||
instance_free_cached_ids();
|
||||
canvas_free_cached_ids();
|
||||
canvas_item_free_cached_ids();
|
||||
}
|
||||
|
@ -279,43 +279,9 @@ public:
|
||||
|
||||
FUNC2(scenario_set_debug, RID, ScenarioDebugMode)
|
||||
|
||||
/* INSTANCING API */
|
||||
FUNCRID(instance)
|
||||
|
||||
FUNC2(instance_set_base, RID, RID)
|
||||
FUNC2(instance_set_scenario, RID, RID)
|
||||
FUNC2(instance_set_layer_mask, RID, uint32_t)
|
||||
FUNC3(instance_set_pivot_data, RID, float, bool)
|
||||
FUNC2(instance_set_transform, RID, const Transform &)
|
||||
FUNC2(instance_set_interpolated, RID, bool)
|
||||
FUNC1(instance_reset_physics_interpolation, RID)
|
||||
FUNC2(instance_attach_object_instance_id, RID, ObjectID)
|
||||
FUNC3(instance_set_blend_shape_weight, RID, int, float)
|
||||
FUNC3(instance_set_surface_material, RID, int, RID)
|
||||
FUNC2(instance_set_visible, RID, bool)
|
||||
|
||||
FUNC2(instance_set_custom_aabb, RID, AABB)
|
||||
|
||||
FUNC2(instance_attach_skeleton, RID, RID)
|
||||
FUNC2(instance_set_exterior, RID, bool)
|
||||
|
||||
FUNC2(instance_set_extra_visibility_margin, RID, real_t)
|
||||
|
||||
// Callbacks
|
||||
FUNC1(callbacks_register, RenderingServerCallbacks *)
|
||||
|
||||
// don't use these in a game!
|
||||
FUNC2RC(Vector<ObjectID>, instances_cull_aabb, const AABB &, RID)
|
||||
FUNC3RC(Vector<ObjectID>, instances_cull_ray, const Vector3 &, const Vector3 &, RID)
|
||||
FUNC2RC(Vector<ObjectID>, instances_cull_convex, const Vector<Plane> &, RID)
|
||||
|
||||
FUNC3(instance_geometry_set_flag, RID, InstanceFlags, bool)
|
||||
FUNC2(instance_geometry_set_material_override, RID, RID)
|
||||
FUNC2(instance_geometry_set_material_overlay, RID, RID)
|
||||
|
||||
FUNC5(instance_geometry_set_draw_range, RID, float, float, float, float)
|
||||
FUNC2(instance_geometry_set_as_instance_lod, RID, RID)
|
||||
|
||||
/* CANVAS (2D) */
|
||||
|
||||
FUNCRID(canvas)
|
||||
|
@ -86,37 +86,6 @@ Array RenderingServer::_shader_get_param_list_bind(RID p_shader) const {
|
||||
return convert_property_list(&l);
|
||||
}
|
||||
|
||||
static Array to_array(const Vector<ObjectID> &ids) {
|
||||
Array a;
|
||||
a.resize(ids.size());
|
||||
for (int i = 0; i < ids.size(); ++i) {
|
||||
a[i] = ids[i];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
Array RenderingServer::_instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario) const {
|
||||
Vector<ObjectID> ids = instances_cull_aabb(p_aabb, p_scenario);
|
||||
return to_array(ids);
|
||||
}
|
||||
|
||||
Array RenderingServer::_instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const {
|
||||
Vector<ObjectID> ids = instances_cull_ray(p_from, p_to, p_scenario);
|
||||
return to_array(ids);
|
||||
}
|
||||
|
||||
Array RenderingServer::_instances_cull_convex_bind(const Array &p_convex, RID p_scenario) const {
|
||||
Vector<Plane> planes;
|
||||
for (int i = 0; i < p_convex.size(); ++i) {
|
||||
Variant v = p_convex[i];
|
||||
ERR_FAIL_COND_V(v.get_type() != Variant::PLANE, Array());
|
||||
planes.push_back(v);
|
||||
}
|
||||
|
||||
Vector<ObjectID> ids = instances_cull_convex(planes, p_scenario);
|
||||
return to_array(ids);
|
||||
}
|
||||
|
||||
RID RenderingServer::get_test_texture() {
|
||||
if (test_texture.is_valid()) {
|
||||
return test_texture;
|
||||
@ -1967,34 +1936,6 @@ void RenderingServer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("scenario_create"), &RenderingServer::scenario_create);
|
||||
ClassDB::bind_method(D_METHOD("scenario_set_debug", "scenario", "debug_mode"), &RenderingServer::scenario_set_debug);
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &RenderingServer::instance_create2);
|
||||
ClassDB::bind_method(D_METHOD("instance_create"), &RenderingServer::instance_create);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &RenderingServer::instance_set_base);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &RenderingServer::instance_set_scenario);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &RenderingServer::instance_set_layer_mask);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &RenderingServer::instance_set_transform);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_interpolated", "instance", "interpolated"), &RenderingServer::instance_set_interpolated);
|
||||
ClassDB::bind_method(D_METHOD("instance_reset_physics_interpolation", "instance"), &RenderingServer::instance_reset_physics_interpolation);
|
||||
ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &RenderingServer::instance_attach_object_instance_id);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &RenderingServer::instance_set_blend_shape_weight);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &RenderingServer::instance_set_surface_material);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &RenderingServer::instance_set_visible);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &RenderingServer::instance_set_custom_aabb);
|
||||
ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &RenderingServer::instance_attach_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_exterior", "instance", "enabled"), &RenderingServer::instance_set_exterior);
|
||||
ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &RenderingServer::instance_set_extra_visibility_margin);
|
||||
ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &RenderingServer::instance_geometry_set_flag);
|
||||
ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &RenderingServer::instance_geometry_set_material_override);
|
||||
ClassDB::bind_method(D_METHOD("instance_geometry_set_material_overlay", "instance", "material"), &RenderingServer::instance_geometry_set_material_overlay);
|
||||
ClassDB::bind_method(D_METHOD("instance_geometry_set_draw_range", "instance", "min", "max", "min_margin", "max_margin"), &RenderingServer::instance_geometry_set_draw_range);
|
||||
ClassDB::bind_method(D_METHOD("instance_geometry_set_as_instance_lod", "instance", "as_lod_of_instance"), &RenderingServer::instance_geometry_set_as_instance_lod);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &RenderingServer::_instances_cull_aabb_bind, DEFVAL(RID()));
|
||||
ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &RenderingServer::_instances_cull_ray_bind, DEFVAL(RID()));
|
||||
ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &RenderingServer::_instances_cull_convex_bind, DEFVAL(RID()));
|
||||
#endif
|
||||
ClassDB::bind_method(D_METHOD("canvas_create"), &RenderingServer::canvas_create);
|
||||
ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &RenderingServer::canvas_set_item_mirroring);
|
||||
ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &RenderingServer::canvas_set_modulate);
|
||||
@ -2281,14 +2222,6 @@ void RenderingServer::mesh_add_surface_from_planes(RID p_mesh, const PoolVector<
|
||||
mesh_add_surface_from_mesh_data(p_mesh, mdata);
|
||||
}
|
||||
|
||||
RID RenderingServer::instance_create2(RID p_base, RID p_scenario) {
|
||||
RID instance = instance_create();
|
||||
instance_set_base(instance, p_base);
|
||||
instance_set_scenario(instance, p_scenario);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool RenderingServer::is_render_loop_enabled() const {
|
||||
return render_loop_enabled;
|
||||
}
|
||||
|
@ -538,53 +538,14 @@ public:
|
||||
INSTANCE_GEOMETRY_MASK = (1 << INSTANCE_MESH) | (1 << INSTANCE_MULTIMESH)
|
||||
};
|
||||
|
||||
virtual RID instance_create2(RID p_base, RID p_scenario);
|
||||
|
||||
virtual RID instance_create() = 0;
|
||||
|
||||
virtual void instance_set_base(RID p_instance, RID p_base) = 0;
|
||||
virtual void instance_set_scenario(RID p_instance, RID p_scenario) = 0;
|
||||
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask) = 0;
|
||||
virtual void instance_set_pivot_data(RID p_instance, float p_sorting_offset, bool p_use_aabb_center) = 0;
|
||||
virtual void instance_set_transform(RID p_instance, const Transform &p_transform) = 0;
|
||||
virtual void instance_set_interpolated(RID p_instance, bool p_interpolated) = 0;
|
||||
virtual void instance_reset_physics_interpolation(RID p_instance) = 0;
|
||||
virtual void instance_attach_object_instance_id(RID p_instance, ObjectID p_id) = 0;
|
||||
virtual void instance_set_blend_shape_weight(RID p_instance, int p_shape, float p_weight) = 0;
|
||||
virtual void instance_set_surface_material(RID p_instance, int p_surface, RID p_material) = 0;
|
||||
virtual void instance_set_visible(RID p_instance, bool p_visible) = 0;
|
||||
|
||||
virtual void instance_set_custom_aabb(RID p_instance, AABB aabb) = 0;
|
||||
|
||||
virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton) = 0;
|
||||
virtual void instance_set_exterior(RID p_instance, bool p_enabled) = 0;
|
||||
|
||||
virtual void instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) = 0;
|
||||
|
||||
// callbacks are used to send messages back from the visual server to scene tree in thread friendly manner
|
||||
virtual void callbacks_register(RenderingServerCallbacks *p_callbacks) = 0;
|
||||
|
||||
// don't use these in a game!
|
||||
virtual Vector<ObjectID> instances_cull_aabb(const AABB &p_aabb, RID p_scenario = RID()) const = 0;
|
||||
virtual Vector<ObjectID> instances_cull_ray(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario = RID()) const = 0;
|
||||
virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane> &p_convex, RID p_scenario = RID()) const = 0;
|
||||
|
||||
Array _instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario = RID()) const;
|
||||
Array _instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario = RID()) const;
|
||||
Array _instances_cull_convex_bind(const Array &p_convex, RID p_scenario = RID()) const;
|
||||
|
||||
enum InstanceFlags {
|
||||
INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE,
|
||||
INSTANCE_FLAG_MAX
|
||||
};
|
||||
|
||||
virtual void instance_geometry_set_flag(RID p_instance, InstanceFlags p_flags, bool p_enabled) = 0;
|
||||
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material) = 0;
|
||||
virtual void instance_geometry_set_material_overlay(RID p_instance, RID p_material) = 0;
|
||||
|
||||
virtual void instance_geometry_set_draw_range(RID p_instance, float p_min, float p_max, float p_min_margin, float p_max_margin) = 0;
|
||||
virtual void instance_geometry_set_as_instance_lod(RID p_instance, RID p_as_lod_of_instance) = 0;
|
||||
|
||||
/* CANVAS (2D) */
|
||||
|
||||
virtual RID canvas_create() = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user