@@ -115,9 +115,14 @@ EditorPlugin::AfterGUIInput NavigationObstacle3DEditor::forward_3d_gui_input(Cam
115115 return EditorPlugin::AFTER_GUI_INPUT_PASS;
116116 }
117117
118- Transform3D gt = obstacle_node->get_global_transform ();
118+ // Use special transformation rules for NavigationObstacle3D: Only take global y-rotation into account and limit scaling to positive values.
119+ Transform3D gt;
120+ gt.origin = obstacle_node->get_global_position ();
121+ gt.scale_basis (obstacle_node->get_global_basis ().get_scale ().abs ().maxf (0.001 ));
122+ gt.rotate_basis (Vector3 (0.0 , 1.0 , 0.0 ), obstacle_node->get_global_rotation ().y );
119123 Transform3D gi = gt.affine_inverse ();
120124 Plane p (Vector3 (0.0 , 1.0 , 0.0 ), gt.origin );
125+ point_lines_meshinstance->set_transform (gt.translated (Vector3 (0.0 , 0.0 , 0.00001 )));
121126
122127 Ref<InputEventMouseButton> mb = p_event;
123128
@@ -374,9 +379,12 @@ void NavigationObstacle3DEditor::_polygon_draw() {
374379 point_handle_mesh->clear_surfaces ();
375380 point_lines_mesh->clear_surfaces ();
376381 point_lines_meshinstance->set_material_override (line_material);
377- point_lines_mesh->surface_begin (Mesh::PRIMITIVE_LINES);
378382
379- Rect2 rect;
383+ if (poly.is_empty ()) {
384+ return ;
385+ }
386+
387+ point_lines_mesh->surface_begin (Mesh::PRIMITIVE_LINES);
380388
381389 for (int i = 0 ; i < poly.size (); i++) {
382390 Vector2 p, p2;
@@ -392,12 +400,6 @@ void NavigationObstacle3DEditor::_polygon_draw() {
392400 p2 = poly[(i + 1 ) % poly.size ()];
393401 }
394402
395- if (i == 0 ) {
396- rect.position = p;
397- } else {
398- rect.expand_to (p);
399- }
400-
401403 Vector3 point = Vector3 (p.x , 0.0 , p.y );
402404 Vector3 next_point = Vector3 (p2.x , 0.0 , p2.y );
403405
@@ -411,58 +413,8 @@ void NavigationObstacle3DEditor::_polygon_draw() {
411413 // vpc->draw_texture(handle,point-handle->get_size()*0.5);
412414 }
413415
414- rect = rect.grow (1 );
415-
416- AABB r;
417- r.position .x = rect.position .x ;
418- r.position .y = 0.0 ;
419- r.position .z = rect.position .y ;
420- r.size .x = rect.size .x ;
421- r.size .y = 0 ;
422- r.size .z = rect.size .y ;
423-
424- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
425- point_lines_mesh->surface_add_vertex (r.position );
426- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
427- point_lines_mesh->surface_add_vertex (r.position + Vector3 (0.3 , 0 , 0 ));
428- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
429- point_lines_mesh->surface_add_vertex (r.position );
430- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
431- point_lines_mesh->surface_add_vertex (r.position + Vector3 (0.0 , 0.3 , 0 ));
432-
433- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
434- point_lines_mesh->surface_add_vertex (r.position + Vector3 (r.size .x , 0 , 0 ));
435- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
436- point_lines_mesh->surface_add_vertex (r.position + Vector3 (r.size .x , 0 , 0 ) - Vector3 (0.3 , 0 , 0 ));
437- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
438- point_lines_mesh->surface_add_vertex (r.position + Vector3 (r.size .x , 0 , 0 ));
439- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
440- point_lines_mesh->surface_add_vertex (r.position + Vector3 (r.size .x , 0 , 0 ) + Vector3 (0 , 0.3 , 0 ));
441-
442- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
443- point_lines_mesh->surface_add_vertex (r.position + Vector3 (0 , r.size .y , 0 ));
444- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
445- point_lines_mesh->surface_add_vertex (r.position + Vector3 (0 , r.size .y , 0 ) - Vector3 (0 , 0.3 , 0 ));
446- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
447- point_lines_mesh->surface_add_vertex (r.position + Vector3 (0 , r.size .y , 0 ));
448- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
449- point_lines_mesh->surface_add_vertex (r.position + Vector3 (0 , r.size .y , 0 ) + Vector3 (0.3 , 0 , 0 ));
450-
451- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
452- point_lines_mesh->surface_add_vertex (r.position + r.size );
453- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
454- point_lines_mesh->surface_add_vertex (r.position + r.size - Vector3 (0.3 , 0 , 0 ));
455- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
456- point_lines_mesh->surface_add_vertex (r.position + r.size );
457- point_lines_mesh->surface_set_color (Color (0.8 , 0.8 , 0.8 , 0.2 ));
458- point_lines_mesh->surface_add_vertex (r.position + r.size - Vector3 (0.0 , 0.3 , 0 ));
459-
460416 point_lines_mesh->surface_end ();
461417
462- if (poly.size () == 0 ) {
463- return ;
464- }
465-
466418 Array point_handle_mesh_array;
467419 point_handle_mesh_array.resize (Mesh::ARRAY_MAX);
468420 Vector<Vector3> point_handle_mesh_vertices;
@@ -541,6 +493,7 @@ NavigationObstacle3DEditor::NavigationObstacle3DEditor() {
541493 point_lines_mesh.instantiate ();
542494 point_lines_meshinstance->set_mesh (point_lines_mesh);
543495 point_lines_meshinstance->set_transform (Transform3D (Basis (), Vector3 (0 , 0 , 0.00001 )));
496+ point_lines_meshinstance->set_as_top_level (true );
544497
545498 line_material.instantiate ();
546499 line_material->set_shading_mode (StandardMaterial3D::SHADING_MODE_UNSHADED);
0 commit comments