Exemplo n.º 1
0
void SoftBody::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_WORLD: {

			if (Engine::get_singleton()->is_editor_hint())
				add_change_receptor(this);

			RID space = get_world()->get_space();
			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, space);
			PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());
			update_physics_server();
		} break;
		case NOTIFICATION_READY: {
			if (!parent_collision_ignore.is_empty())
				add_collision_exception_with(get_node(parent_collision_ignore));

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (!simulation_started) {
				PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());

				_update_cache_pin_points_datas();
				// Submit bone attachment
				const int pinned_points_indices_size = pinned_points_indices.size();
				PoolVector<PinnedPoint>::Read r = pinned_points_indices.read();
				for (int i = 0; i < pinned_points_indices_size; ++i) {
					if (!r[i].spatial_attachment) {
						// Use soft body position to update the point position
						PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, (get_global_transform() * r[i].vertex_offset_transform).origin);
					} else {
						PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, (r[i].spatial_attachment->get_global_transform() * r[i].vertex_offset_transform).origin);
					}
				}
			}
		} break;
		case NOTIFICATION_VISIBILITY_CHANGED: {

			_update_pickable();

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, RID());

		} break;
	}

#ifdef TOOLS_ENABLED

	if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
		if (Engine::get_singleton()->is_editor_hint()) {
			update_configuration_warning();
		}
	}

#endif
}
Exemplo n.º 2
0
void SoftBody::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_WORLD: {

			if (Engine::get_singleton()->is_editor_hint()) {

				add_change_receptor(this);
			}

			RID space = get_world()->get_space();
			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, space);
			update_physics_server();
		} break;
		case NOTIFICATION_READY: {
			if (!parent_collision_ignore.is_empty())
				add_collision_exception_with(get_node(parent_collision_ignore));

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (Engine::get_singleton()->is_editor_hint()) {
				_reset_points_offsets();
				return;
			}

			PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());

			set_notify_transform(false);
			// Required to be top level with Transform at center of world in order to modify VisualServer only to support custom Transform
			set_as_toplevel(true);
			set_transform(Transform());
			set_notify_transform(true);

		} break;
		case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {

			if (!simulation_started)
				return;

			_update_cache_pin_points_datas();
			// Submit bone attachment
			const int pinned_points_indices_size = pinned_points.size();
			PoolVector<PinnedPoint>::Read r = pinned_points.read();
			for (int i = 0; i < pinned_points_indices_size; ++i) {
				if (r[i].spatial_attachment) {
					PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, r[i].spatial_attachment->get_global_transform().xform(r[i].offset));
				}
			}
		} break;
		case NOTIFICATION_VISIBILITY_CHANGED: {

			_update_pickable();

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, RID());

		} break;
	}

#ifdef TOOLS_ENABLED

	if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
		if (Engine::get_singleton()->is_editor_hint()) {
			update_configuration_warning();
		}
	}

#endif
}