Godot Engine – Multi-platform 2D and 3D game engine
Fix trail wrongly scaling points
Qbieshay73663112d511
diff --git a/scene/3d/trail_3d.cpp b/scene/3d/trail_3d.cppindex 9cc332a3242..3ebff83938c 100644--- a/scene/3d/trail_3d.cpp+++ b/scene/3d/trail_3d.cpp@@ -539,7 +539,7 @@ void Trail3D::_do_rebuild() {*(uint16_t *)&index_write_buffer[(j + 11) * 2] = idx;}- Transform3D inv_global_tf = get_global_transform_interpolated().inverse();+ Transform3D inv_global_tf = get_global_transform_interpolated().affine_inverse();real_t length = _calc_current_length();@@ -588,22 +588,26 @@ void Trail3D::_do_rebuild() {}Vector3 tangent = tangents[i];+ Vector3 normal = normals[i];+ Vector3 curve_binormal = normal.cross(tangent);+ curve_binormal *= half_width;+ curve_binormal = inv_global_tf.basis.xform(curve_binormal);+ real_t curve_width = curve_binormal.length();p = inv_global_tf.xform(p);tangent = inv_global_tf.basis.xform(tangent);+ normal = inv_global_tf.basis.xform(normal);+min_bounds = min_bounds.min(p - width_bounds);max_bounds = max_bounds.max(p + width_bounds);- Vector3 normal = normals[i];- normal = inv_global_tf.basis.xform(normal);uint32_t vnormal = _encode_normal(normal);- Vector3 curve_binormal = normal.cross(tangent);// we don't actually add the side offset if we're billboardingreal_t is_billboard = alignment == MESH_ALIGNMENT_BILLBOARD ? 0.0 : 1.0;- _encode_vertex(p + half_width * curve_binormal * is_billboard, j2, write_vert);+ _encode_vertex(p + curve_binormal * is_billboard, j2, write_vert);_encode_vertex(p, j1, write_vert);- _encode_vertex(p - half_width * curve_binormal * is_billboard, j0, write_vert);+ _encode_vertex(p - curve_binormal * is_billboard, j0, write_vert);_write_normal(vnormal, j2, write_vert);_write_normal(vnormal, j1, write_vert);@@ -619,11 +623,11 @@ void Trail3D::_do_rebuild() {custom.y = tangent.y;custom.z = tangent.z;- custom.w = -half_width;+ custom.w = -curve_width;_write_custom(custom, j2, write_attrib);custom.w = 0.;_write_custom(custom, j1, write_attrib);- custom.w = half_width;+ custom.w = curve_width;_write_custom(custom, j0, write_attrib);}@@ -661,8 +665,18 @@ void Trail3D::_process_trail() {return;}- Transform3D tf = get_global_transform_interpolated();+ Transform3D tf;+ if (is_visible_in_tree()) {+ // TODO+ // Think about culling rebuild calls for trails when they're offscreen+ // And instead calculate a rough AABB during process trail, otherwise trail might get wrongly not updated.+ // Possibly include different culling modes? Though ideally it should just work.+ tf = get_global_transform_interpolated();+ } else {+ tf = get_global_transform();+ }Vector3 pos = tf.origin;+ tf.orthonormalize();if (!_transform_changed && points.size() == 2 && pos.distance_squared_to(points[1]) <= CMP_EPSILON2) {// When the two last points are close enough, we manually stack them, so their distance will always be less@@ -670,8 +684,12 @@ void Trail3D::_process_trail() {return;}- Vector3 up = tf.basis.get_column(1);- Vector3 fw = tf.basis.get_column(2);+ // We currently do not support having different scale at different emission times, since width is a+ // Property of the whole trail and not of a certain point.+ // We could support it if instead of storing tangents and normals we stored also binormals with their associated+ // scale, but this should be first proven with a usecase. Most of "wobbly edges" can be achieved via shader.+ Vector3 up = tf.basis.get_column(1).normalized();+ Vector3 fw = tf.basis.get_column(2).normalized();real_t delta = get_process_delta_time();_time += delta;real_t head_velocity = (get_global_position() - _previous_position).length() / MAX(delta, CMP_EPSILON);