diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/audio_stream_sample.cpp | 8 | ||||
-rw-r--r-- | scene/resources/curve.cpp | 125 | ||||
-rw-r--r-- | scene/resources/curve.h | 6 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 5 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 7 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 4 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.cpp | 2 | ||||
-rw-r--r-- | scene/resources/style_box.cpp | 9 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 11 | ||||
-rw-r--r-- | scene/resources/texture.h | 2 | ||||
-rw-r--r-- | scene/resources/tile_set.cpp | 3 | ||||
-rw-r--r-- | scene/resources/tile_set.h | 1 |
12 files changed, 168 insertions, 15 deletions
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index b77143cd9d..02a9e4d69b 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -524,6 +524,9 @@ String AudioStreamSample::get_stream_name() const { void AudioStreamSample::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamSample::set_data); + ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamSample::get_data); + ClassDB::bind_method(D_METHOD("set_format", "format"), &AudioStreamSample::set_format); ClassDB::bind_method(D_METHOD("get_format"), &AudioStreamSample::get_format); @@ -542,16 +545,13 @@ void AudioStreamSample::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stereo", "stereo"), &AudioStreamSample::set_stereo); ClassDB::bind_method(D_METHOD("is_stereo"), &AudioStreamSample::is_stereo); - ClassDB::bind_method(D_METHOD("_set_data", "data"), &AudioStreamSample::set_data); - ClassDB::bind_method(D_METHOD("_get_data"), &AudioStreamSample::get_data); - + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data"); ADD_PROPERTY(PropertyInfo(Variant::INT, "format", PROPERTY_HINT_ENUM, "8-Bit,16-Bit,IMA-ADPCM"), "set_format", "get_format"); ADD_PROPERTY(PropertyInfo(Variant::INT, "loop_mode", PROPERTY_HINT_ENUM, "Disabled,Forward,Ping-Pong"), "set_loop_mode", "get_loop_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "loop_begin"), "set_loop_begin", "get_loop_begin"); ADD_PROPERTY(PropertyInfo(Variant::INT, "loop_end"), "set_loop_end", "get_loop_end"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_rate"), "set_mix_rate", "get_mix_rate"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stereo"), "set_stereo", "is_stereo"); - ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); BIND_ENUM_CONSTANT(FORMAT_8_BITS); BIND_ENUM_CONSTANT(FORMAT_16_BITS); diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 4ec1e8973d..7f902fc982 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -1169,6 +1169,7 @@ void Curve3D::_bake() const { if (points.size() == 0) { baked_point_cache.resize(0); baked_tilt_cache.resize(0); + baked_up_vector_cache.resize(0); return; } @@ -1178,6 +1179,14 @@ void Curve3D::_bake() const { baked_point_cache.set(0, points[0].pos); baked_tilt_cache.resize(1); baked_tilt_cache.set(0, points[0].tilt); + + if (up_vector_enabled) { + + baked_up_vector_cache.resize(1); + baked_up_vector_cache.set(0, Vector3(0, 1, 0)); + } else + baked_up_vector_cache.resize(0); + return; } @@ -1247,10 +1256,51 @@ void Curve3D::_bake() const { baked_tilt_cache.resize(pointlist.size()); PoolRealArray::Write wt = baked_tilt_cache.write(); + baked_up_vector_cache.resize(up_vector_enabled ? pointlist.size() : 0); + PoolVector3Array::Write up_write = baked_up_vector_cache.write(); + + Vector3 sideways; + Vector3 up; + Vector3 forward; + + Vector3 prev_sideways = Vector3(1, 0, 0); + Vector3 prev_up = Vector3(0, 1, 0); + Vector3 prev_forward = Vector3(0, 0, 1); + for (List<Plane>::Element *E = pointlist.front(); E; E = E->next()) { w[idx] = E->get().normal; wt[idx] = E->get().d; + + if (!up_vector_enabled) { + idx++; + continue; + } + + forward = idx > 0 ? (w[idx] - w[idx - 1]).normalized() : prev_forward; + + float y_dot = prev_up.dot(forward); + + if (y_dot > (1.0f - CMP_EPSILON)) { + sideways = prev_sideways; + up = -prev_forward; + } else if (y_dot < -(1.0f - CMP_EPSILON)) { + sideways = prev_sideways; + up = prev_forward; + } else { + sideways = prev_up.cross(forward).normalized(); + up = forward.cross(sideways).normalized(); + } + + if (idx == 1) + up_write[0] = up; + + up_write[idx] = up; + + prev_sideways = sideways; + prev_up = up; + prev_forward = forward; + idx++; } } @@ -1343,6 +1393,53 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { return Math::lerp(r[idx], r[idx + 1], frac); } +Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) const { + + if (baked_cache_dirty) + _bake(); + + //validate// + // curve may not have baked up vectors + int count = baked_up_vector_cache.size(); + if (count == 0) { + ERR_EXPLAIN("No up vectors in Curve3D"); + ERR_FAIL_COND_V(count == 0, Vector3(0, 1, 0)); + } + + if (count == 1) + return baked_up_vector_cache.get(0); + + PoolVector3Array::Read r = baked_up_vector_cache.read(); + PoolVector3Array::Read rp = baked_point_cache.read(); + PoolRealArray::Read rt = baked_tilt_cache.read(); + + float offset = CLAMP(p_offset, 0.0f, baked_max_ofs); + + int idx = Math::floor((double)offset / (double)bake_interval); + float frac = Math::fmod(offset, bake_interval) / bake_interval; + + if (idx == count - 1) + return p_apply_tilt ? r[idx].rotated((rp[idx] - rp[idx - 1]).normalized(), rt[idx]) : r[idx]; + + Vector3 forward = (rp[idx + 1] - rp[idx]).normalized(); + Vector3 up = r[idx]; + Vector3 up1 = r[idx + 1]; + + if (p_apply_tilt) { + up.rotate(forward, rt[idx]); + up1.rotate(idx + 2 >= count ? forward : (rp[idx + 2] - rp[idx + 1]).normalized(), rt[idx + 1]); + } + + Vector3 axis = up.cross(up1); + + if (axis.length_squared() < CMP_EPSILON2) + axis = forward; + else + axis.normalize(); + + return up.rotated(axis, up.angle_to(up1) * frac); +} + PoolVector3Array Curve3D::get_baked_points() const { if (baked_cache_dirty) @@ -1359,6 +1456,14 @@ PoolRealArray Curve3D::get_baked_tilts() const { return baked_tilt_cache; } +PoolVector3Array Curve3D::get_baked_up_vectors() const { + + if (baked_cache_dirty) + _bake(); + + return baked_up_vector_cache; +} + Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { // Brute force method @@ -1452,6 +1557,18 @@ float Curve3D::get_bake_interval() const { return bake_interval; } +void Curve3D::set_up_vector_enabled(bool p_enable) { + + up_vector_enabled = p_enable; + baked_cache_dirty = true; + emit_signal(CoreStringNames::get_singleton()->changed); +} + +bool Curve3D::is_up_vector_enabled() const { + + return up_vector_enabled; +} + Dictionary Curve3D::_get_data() const { Dictionary dc; @@ -1563,11 +1680,15 @@ void Curve3D::_bind_methods() { //ClassDB::bind_method(D_METHOD("bake","subdivs"),&Curve3D::bake,DEFVAL(10)); ClassDB::bind_method(D_METHOD("set_bake_interval", "distance"), &Curve3D::set_bake_interval); ClassDB::bind_method(D_METHOD("get_bake_interval"), &Curve3D::get_bake_interval); + ClassDB::bind_method(D_METHOD("set_up_vector_enabled", "enable"), &Curve3D::set_up_vector_enabled); + ClassDB::bind_method(D_METHOD("is_up_vector_enabled"), &Curve3D::is_up_vector_enabled); ClassDB::bind_method(D_METHOD("get_baked_length"), &Curve3D::get_baked_length); ClassDB::bind_method(D_METHOD("interpolate_baked", "offset", "cubic"), &Curve3D::interpolate_baked, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("interpolate_baked_up_vector", "offset", "apply_tilt"), &Curve3D::interpolate_baked_up_vector, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_baked_points"), &Curve3D::get_baked_points); ClassDB::bind_method(D_METHOD("get_baked_tilts"), &Curve3D::get_baked_tilts); + ClassDB::bind_method(D_METHOD("get_baked_up_vectors"), &Curve3D::get_baked_up_vectors); ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Curve3D::get_closest_point); ClassDB::bind_method(D_METHOD("get_closest_offset", "to_point"), &Curve3D::get_closest_offset); ClassDB::bind_method(D_METHOD("tessellate", "max_stages", "tolerance_degrees"), &Curve3D::tessellate, DEFVAL(5), DEFVAL(4)); @@ -1577,6 +1698,9 @@ void Curve3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval"); ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); + + ADD_GROUP("Up Vector", "up_vector_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "up_vector_enabled"), "set_up_vector_enabled", "is_up_vector_enabled"); } Curve3D::Curve3D() { @@ -1586,4 +1710,5 @@ Curve3D::Curve3D() { add_point(Vector3(0,2,0)); add_point(Vector3(0,3,5));*/ bake_interval = 0.2; + up_vector_enabled = true; } diff --git a/scene/resources/curve.h b/scene/resources/curve.h index 492eb05d1e..9cb12a4345 100644 --- a/scene/resources/curve.h +++ b/scene/resources/curve.h @@ -232,11 +232,13 @@ class Curve3D : public Resource { mutable bool baked_cache_dirty; mutable PoolVector3Array baked_point_cache; mutable PoolRealArray baked_tilt_cache; + mutable PoolVector3Array baked_up_vector_cache; mutable float baked_max_ofs; void _bake() const; float bake_interval; + bool up_vector_enabled; void _bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, float p_tol) const; Dictionary _get_data() const; @@ -264,12 +266,16 @@ public: void set_bake_interval(float p_tolerance); float get_bake_interval() const; + void set_up_vector_enabled(bool p_enable); + bool is_up_vector_enabled() const; float get_baked_length() const; Vector3 interpolate_baked(float p_offset, bool p_cubic = false) const; float interpolate_baked_tilt(float p_offset) const; + Vector3 interpolate_baked_up_vector(float p_offset, bool p_apply_tilt = false) const; PoolVector3Array get_baked_points() const; //useful for going through PoolRealArray get_baked_tilts() const; //useful for going through + PoolVector3Array get_baked_up_vectors() const; Vector3 get_closest_point(const Vector3 &p_to_point) const; float get_closest_offset(const Vector3 &p_to_point) const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 5ac9344f31..3ea856541e 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -544,6 +544,11 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("updown", "SpinBox", make_icon(spinbox_updown_png)); + //scroll container + Ref<StyleBoxEmpty> empty; + empty.instance(); + theme->set_stylebox("bg", "ScrollContainer", empty); + // WindowDialog theme->set_stylebox("panel", "WindowDialog", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6)); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index f41a26a680..05493d5777 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -307,8 +307,6 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V } ret.x += _get_kerning_advance(font, p_char, p_next); - // ensures oversampled glyphs will have enough space when this value is used by clipping/wrapping algorithms - ret.x = Math::ceil(ret.x); return ret; } @@ -1080,6 +1078,11 @@ void DynamicFont::update_oversampling() { if (E->self()->data_at_size.is_valid()) { E->self()->data_at_size->update_oversampling(); + + if (E->self()->outline_data_at_size.is_valid()) { + E->self()->outline_data_at_size->update_oversampling(); + } + changed.push_back(Ref<DynamicFont>(E->self())); } E = E->next(); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index d87644381c..b0620d3363 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -222,7 +222,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { continue; Array a = surface_get_arrays(i); - int vcount = 0; if (i == 0) { arrays = a; @@ -230,6 +229,7 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { index_accum += v.size(); } else { + int vcount = 0; for (int j = 0; j < arrays.size(); j++) { if (arrays[j].get_type() == Variant::NIL || a[j].get_type() == Variant::NIL) { @@ -1194,8 +1194,6 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe for (int j = 0; j < 3; j++) { - int vertex_idx = gen_vertices[gen_indices[i + j]]; - SurfaceTool::Vertex v = surfaces[surface].vertices[uv_index[gen_vertices[gen_indices[i + j]]].second]; if (surfaces[surface].format & ARRAY_FORMAT_COLOR) { diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index e0562d9e4a..5b600623b9 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -676,7 +676,7 @@ void CubeMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_subdivide_depth", "divisions"), &CubeMesh::set_subdivide_depth); ClassDB::bind_method(D_METHOD("get_subdivide_depth"), &CubeMesh::get_subdivide_depth); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_width", PROPERTY_HINT_RANGE, "0,100,1"), "set_subdivide_width", "get_subdivide_width"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_height", PROPERTY_HINT_RANGE, "0,100,1"), "set_subdivide_height", "get_subdivide_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_depth", PROPERTY_HINT_RANGE, "0,100,1"), "set_subdivide_depth", "get_subdivide_depth"); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 7da65ac984..ebad00b068 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -136,8 +136,17 @@ Ref<Texture> StyleBoxTexture::get_normal_map() const { void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) { + ERR_FAIL_INDEX(p_margin, 4); + margin[p_margin] = p_size; emit_changed(); + static const char *margin_prop[4] = { + "content_margin_left", + "content_margin_top", + "content_margin_right", + "content_margin_bottom", + }; + _change_notify(margin_prop[p_margin]); } float StyleBoxTexture::get_margin_size(Margin p_margin) const { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index c0f6756fd1..54f5aea160 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -76,7 +76,9 @@ void Texture::_bind_methods() { ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map", "clip_uv"), &Texture::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_data"), &Texture::get_data); + ADD_GROUP("Flags", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "flags", PROPERTY_HINT_FLAGS, "Mipmaps,Repeat,Filter,Anisotropic Linear,Convert to Linear,Mirrored Repeat,Video Surface"), "set_flags", "get_flags"); + ADD_GROUP("", ""); BIND_ENUM_CONSTANT(FLAGS_DEFAULT); BIND_ENUM_CONSTANT(FLAG_MIPMAPS); @@ -220,12 +222,15 @@ Image::Format ImageTexture::get_format() const { return format; } -void ImageTexture::load(const String &p_path) { +Error ImageTexture::load(const String &p_path) { Ref<Image> img; img.instance(); - img->load(p_path); - create_from_image(img); + Error err = img->load(p_path); + if (err == OK) { + create_from_image(img); + } + return err; } void ImageTexture::set_data(const Ref<Image> &p_image) { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 93d7ec4ef9..d81fd3b19b 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -124,7 +124,7 @@ public: void set_flags(uint32_t p_flags); uint32_t get_flags() const; Image::Format get_format() const; - void load(const String &p_path); + Error load(const String &p_path); void set_data(const Ref<Image> &p_image); Ref<Image> get_data() const; diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 42d64376f5..58057cda0c 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -264,7 +264,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::RECT2, pre + "region")); p_list->push_back(PropertyInfo(Variant::INT, pre + "tile_mode", PROPERTY_HINT_ENUM, "SINGLE_TILE,AUTO_TILE")); if (tile_get_tile_mode(id) == AUTO_TILE) { - p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/bitmask_mode", PROPERTY_HINT_ENUM, "2X2,3X3", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); + p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/bitmask_mode", PROPERTY_HINT_ENUM, "2X2,3X3 (minimal),3X3", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/bitmask_flags", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); @@ -960,6 +960,7 @@ void TileSet::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_forward_subtile_selection", PropertyInfo(Variant::INT, "autotile_id"), PropertyInfo(Variant::INT, "bitmask"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "TileMap"), PropertyInfo(Variant::VECTOR2, "tile_location"))); BIND_ENUM_CONSTANT(BITMASK_2X2); + BIND_ENUM_CONSTANT(BITMASK_3X3_MINIMAL); BIND_ENUM_CONSTANT(BITMASK_3X3); BIND_ENUM_CONSTANT(BIND_TOPLEFT); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index d5704ac9a0..ec635ee5cc 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -56,6 +56,7 @@ public: enum BitmaskMode { BITMASK_2X2, + BITMASK_3X3_MINIMAL, BITMASK_3X3 }; |