Repository: godotengine/godot
File: editor/scene/3d/path_3d_editor_plugin.cpp (C++)

Code before:

void Path3DGizmo::set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
	Ref<Curve3D> c = path->get_curve();
	if (c.is_null()) {
		return;
	}

	const Transform3D gt = path->get_global_transform();
	const Transform3D gi = gt.affine_inverse();
	const Vector3 ray_from = p_camera->project_ray_origin(p_point);
	const Vector3 ray_dir = p_camera->project_ray_normal(p_point);
	const Plane p = Plane(p_camera->get_transform().basis.get_column(2), gt.xform(original));

	// Primary handles: position.
	if (!p_secondary) {
		Vector3 inters;
		// Special case for primary handle, the handle id equals control point id.
		const int idx = p_id;
		if (!Path3DEditorPlugin::singleton->_edit.waiting_handle_physics || !Path3DEditorPlugin::singleton->_edit.in_physics_frame) {
			Path3DEditorPlugin::singleton->_edit.waiting_handle_physics = true;
			Path3DEditorPlugin::singleton->_edit.gizmo_handle = p_id;
			Path3DEditorPlugin::singleton->_edit.gizmo_handle_secondary = p_secondary;
			Path3DEditorPlugin::singleton->_edit.gizmo_camera = p_camera;
			Path3DEditorPlugin::singleton->_edit.mouse_pos = p_point;
			return;
			// Only advances this code if inside physics frame and waiting for physics
		}
		if (Path3DEditorPlugin::singleton->snap_to_collider) {
			PhysicsDirectSpaceState3D *ss = p_camera->get_world_3d()->get_direct_space_state();

			PhysicsDirectSpaceState3D::RayParameters ray_params;
			ray_params.from = ray_from;
			ray_params.to = ray_from + ray_dir * p_camera->get_far();
			PhysicsDirectSpaceState3D::RayResult result;
			if (ss->intersect_ray(ray_params, result)) {
				Vector3 local = gi.xform(result.position);
				c->set_point_position(idx, local);
				return;
			}
			// Will continue and do the plane intersect_ray if doesn't hit anything.
		}
		if (p.intersects_ray(ray_from, ray_dir, &inters)) {
			if (Node3DEditor::get_singleton()->is_snap_enabled()) {
				float snap = Node3DEditor::get_singleton()->get_translate_snap();
				inters.snapf(snap);
			}

			Vector3 local = gi.xform(inters);
			c->set_point_position(idx, local);
		}


Review comment (suggestion):
```suggestion
			// Only continue if inside physics frame and waiting for physics.
```

Code after:

void Path3DGizmo::set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
	Ref<Curve3D> c = path->get_curve();
	if (c.is_null()) {
		return;
	}

	const Transform3D gt = path->get_global_transform();
	const Transform3D gi = gt.affine_inverse();
	const Vector3 ray_from = p_camera->project_ray_origin(p_point);
	const Vector3 ray_dir = p_camera->project_ray_normal(p_point);
	const Plane p = Plane(p_camera->get_transform().basis.get_column(2), gt.xform(original));

	// Primary handles: position.
	if (!p_secondary) {
		Vector3 inters;
		// Special case for primary handle, the handle id equals control point id.
		const int idx = p_id;
		if (!Path3DEditorPlugin::singleton->_edit.waiting_handle_physics || !Path3DEditorPlugin::singleton->_edit.in_physics_frame) {
			Path3DEditorPlugin::singleton->_edit.waiting_handle_physics = true;
			Path3DEditorPlugin::singleton->_edit.gizmo_handle = p_id;
			Path3DEditorPlugin::singleton->_edit.gizmo_handle_secondary = p_secondary;
			Path3DEditorPlugin::singleton->_edit.gizmo_camera = p_camera;
			Path3DEditorPlugin::singleton->_edit.mouse_pos = p_point;
			return;
			// Only continue if inside physics frame and waiting for physics.
		}
		if (Path3DEditorPlugin::singleton->snap_to_collider) {
			PhysicsDirectSpaceState3D *ss = p_camera->get_world_3d()->get_direct_space_state();

			PhysicsDirectSpaceState3D::RayParameters ray_params;
			ray_params.from = ray_from;
			ray_params.to = ray_from + ray_dir * p_camera->get_far();
			PhysicsDirectSpaceState3D::RayResult result;
			if (ss->intersect_ray(ray_params, result)) {
				Vector3 local = gi.xform(result.position);
				c->set_point_position(idx, local);
				return;
			}
			// Will continue and do the plane intersect_ray if doesn't hit anything.
		}
		if (p.intersects_ray(ray_from, ray_dir, &inters)) {
			if (Node3DEditor::get_singleton()->is_snap_enabled()) {
				float snap = Node3DEditor::get_singleton()->get_translate_snap();
				inters.snapf(snap);
			}

			Vector3 local = gi.xform(inters);
			c->set_point_position(idx, local);
		}