diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/immediate_mesh.cpp | 2 | ||||
-rw-r--r-- | scene/resources/immediate_mesh.h | 2 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 66 | ||||
-rw-r--r-- | scene/resources/mesh.h | 12 | ||||
-rw-r--r-- | scene/resources/navigation_mesh.cpp | 4 | ||||
-rw-r--r-- | scene/resources/particle_process_material.cpp | 4 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.cpp | 2 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.h | 2 | ||||
-rw-r--r-- | scene/resources/resource_format_text.cpp | 91 | ||||
-rw-r--r-- | scene/resources/resource_format_text.h | 3 | ||||
-rw-r--r-- | scene/resources/visual_shader.cpp | 8 | ||||
-rw-r--r-- | scene/resources/visual_shader_particle_nodes.cpp | 90 | ||||
-rw-r--r-- | scene/resources/visual_shader_particle_nodes.h | 3 |
13 files changed, 185 insertions, 104 deletions
diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp index 2254c19327..247927163b 100644 --- a/scene/resources/immediate_mesh.cpp +++ b/scene/resources/immediate_mesh.cpp @@ -346,7 +346,7 @@ TypedArray<Array> ImmediateMesh::surface_get_blend_shape_arrays(int p_surface) c Dictionary ImmediateMesh::surface_get_lods(int p_surface) const { return Dictionary(); } -uint32_t ImmediateMesh::surface_get_format(int p_idx) const { +BitField<Mesh::ArrayFormat> ImmediateMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), 0); return surfaces[p_idx].format; } diff --git a/scene/resources/immediate_mesh.h b/scene/resources/immediate_mesh.h index 9407ecd98c..bf07c82a0c 100644 --- a/scene/resources/immediate_mesh.h +++ b/scene/resources/immediate_mesh.h @@ -99,7 +99,7 @@ public: virtual Array surface_get_arrays(int p_surface) const override; virtual TypedArray<Array> surface_get_blend_shape_arrays(int p_surface) const override; virtual Dictionary surface_get_lods(int p_surface) const override; - virtual uint32_t surface_get_format(int p_idx) const override; + virtual BitField<ArrayFormat> surface_get_format(int p_idx) const override; virtual PrimitiveType surface_get_primitive_type(int p_idx) const override; virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override; virtual Ref<Material> surface_get_material(int p_idx) const override; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 07baa0ad96..5e18b5df37 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -75,7 +75,7 @@ Dictionary Mesh::surface_get_lods(int p_surface) const { return ret; } -uint32_t Mesh::surface_get_format(int p_idx) const { +BitField<Mesh::ArrayFormat> Mesh::surface_get_format(int p_idx) const { uint32_t ret = 0; GDVIRTUAL_REQUIRED_CALL(_surface_get_format, p_idx, ret); return ret; @@ -658,35 +658,35 @@ void Mesh::_bind_methods() { BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_FLOAT); BIND_ENUM_CONSTANT(ARRAY_CUSTOM_MAX); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM0); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM1); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM2); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM3); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX); - - BIND_ENUM_CONSTANT(ARRAY_FORMAT_BLEND_SHAPE_MASK); - - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_BASE); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_BITS); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM0_SHIFT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM1_SHIFT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM2_SHIFT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM3_SHIFT); - - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_MASK); - BIND_ENUM_CONSTANT(ARRAY_COMPRESS_FLAGS_BASE); - - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES); - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_DYNAMIC_UPDATE); - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_8_BONE_WEIGHTS); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_VERTEX); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_NORMAL); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_TANGENT); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_COLOR); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_TEX_UV); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_TEX_UV2); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM0); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM1); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM2); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM3); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_BONES); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_WEIGHTS); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_INDEX); + + BIND_BITFIELD_FLAG(ARRAY_FORMAT_BLEND_SHAPE_MASK); + + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_BASE); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_BITS); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM0_SHIFT); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM1_SHIFT); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM2_SHIFT); + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM3_SHIFT); + + BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_MASK); + BIND_BITFIELD_FLAG(ARRAY_COMPRESS_FLAGS_BASE); + + BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_2D_VERTICES); + BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_DYNAMIC_UPDATE); + BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_8_BONE_WEIGHTS); BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED); BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE); @@ -1554,7 +1554,7 @@ void ArrayMesh::_recompute_aabb() { } // TODO: Need to add binding to add_surface using future MeshSurfaceData object. -void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, const Vector<uint8_t> &p_attribute_array, const Vector<uint8_t> &p_skin_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<uint8_t> &p_blend_shape_data, const Vector<AABB> &p_bone_aabbs, const Vector<RS::SurfaceData::LOD> &p_lods) { +void ArrayMesh::add_surface(BitField<ArrayFormat> p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, const Vector<uint8_t> &p_attribute_array, const Vector<uint8_t> &p_skin_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<uint8_t> &p_blend_shape_data, const Vector<AABB> &p_bone_aabbs, const Vector<RS::SurfaceData::LOD> &p_lods) { _create_if_empty(); Surface s; @@ -1589,7 +1589,7 @@ void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const emit_changed(); } -void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const TypedArray<Array> &p_blend_shapes, const Dictionary &p_lods, uint32_t p_flags) { +void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const TypedArray<Array> &p_blend_shapes, const Dictionary &p_lods, BitField<ArrayFormat> p_flags) { ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX); RS::SurfaceData surface; @@ -1705,7 +1705,7 @@ int ArrayMesh::surface_get_array_index_len(int p_idx) const { return surfaces[p_idx].index_array_length; } -uint32_t ArrayMesh::surface_get_format(int p_idx) const { +BitField<Mesh::ArrayFormat> ArrayMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), 0); return surfaces[p_idx].format; } diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index f62f060682..1baa466312 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -156,7 +156,7 @@ public: virtual Array surface_get_arrays(int p_surface) const; virtual TypedArray<Array> surface_get_blend_shape_arrays(int p_surface) const; virtual Dictionary surface_get_lods(int p_surface) const; - virtual uint32_t surface_get_format(int p_idx) const; + virtual BitField<ArrayFormat> surface_get_format(int p_idx) const; virtual PrimitiveType surface_get_primitive_type(int p_idx) const; virtual void surface_set_material(int p_idx, const Ref<Material> &p_material); virtual Ref<Material> surface_get_material(int p_idx) const; @@ -269,9 +269,9 @@ protected: static void _bind_methods(); public: - void add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const TypedArray<Array> &p_blend_shapes = TypedArray<Array>(), const Dictionary &p_lods = Dictionary(), uint32_t p_flags = 0); + void add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const TypedArray<Array> &p_blend_shapes = TypedArray<Array>(), const Dictionary &p_lods = Dictionary(), BitField<ArrayFormat> p_flags = 0); - void add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, const Vector<uint8_t> &p_attribute_array, const Vector<uint8_t> &p_skin_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<uint8_t> &p_blend_shape_data = Vector<uint8_t>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>(), const Vector<RS::SurfaceData::LOD> &p_lods = Vector<RS::SurfaceData::LOD>()); + void add_surface(BitField<ArrayFormat> p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, const Vector<uint8_t> &p_attribute_array, const Vector<uint8_t> &p_skin_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<uint8_t> &p_blend_shape_data = Vector<uint8_t>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>(), const Vector<RS::SurfaceData::LOD> &p_lods = Vector<RS::SurfaceData::LOD>()); Array surface_get_arrays(int p_surface) const override; TypedArray<Array> surface_get_blend_shape_arrays(int p_surface) const override; @@ -298,7 +298,7 @@ public: int surface_get_array_len(int p_idx) const override; int surface_get_array_index_len(int p_idx) const override; - uint32_t surface_get_format(int p_idx) const override; + BitField<ArrayFormat> surface_get_format(int p_idx) const override; PrimitiveType surface_get_primitive_type(int p_idx) const override; virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override; @@ -330,7 +330,7 @@ public: }; VARIANT_ENUM_CAST(Mesh::ArrayType); -VARIANT_ENUM_CAST(Mesh::ArrayFormat); +VARIANT_BITFIELD_CAST(Mesh::ArrayFormat); VARIANT_ENUM_CAST(Mesh::ArrayCustomFormat); VARIANT_ENUM_CAST(Mesh::PrimitiveType); VARIANT_ENUM_CAST(Mesh::BlendShapeMode); @@ -351,7 +351,7 @@ public: virtual Array surface_get_arrays(int p_surface) const override { return Array(); } virtual TypedArray<Array> surface_get_blend_shape_arrays(int p_surface) const override { return TypedArray<Array>(); } virtual Dictionary surface_get_lods(int p_surface) const override { return Dictionary(); } - virtual uint32_t surface_get_format(int p_idx) const override { return 0; } + virtual BitField<ArrayFormat> surface_get_format(int p_idx) const override { return 0; } virtual PrimitiveType surface_get_primitive_type(int p_idx) const override { return PRIMITIVE_TRIANGLES; } virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override {} virtual Ref<Material> surface_get_material(int p_idx) const override { return Ref<Material>(); } diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 287597de32..7e1b42c80b 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -401,7 +401,7 @@ Ref<ArrayMesh> NavigationMesh::get_debug_mesh() { } debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, face_mesh_array); - Ref<StandardMaterial3D> debug_geometry_face_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_geometry_face_material(); + Ref<StandardMaterial3D> debug_geometry_face_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_material(); debug_mesh->surface_set_material(0, debug_geometry_face_material); // if enabled build geometry edge line surface @@ -426,7 +426,7 @@ Ref<ArrayMesh> NavigationMesh::get_debug_mesh() { line_mesh_array.resize(Mesh::ARRAY_MAX); line_mesh_array[Mesh::ARRAY_VERTEX] = line_vertex_array; debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, line_mesh_array); - Ref<StandardMaterial3D> debug_geometry_edge_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_geometry_edge_material(); + Ref<StandardMaterial3D> debug_geometry_edge_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_edge_material(); debug_mesh->surface_set_material(1, debug_geometry_edge_material); } diff --git a/scene/resources/particle_process_material.cpp b/scene/resources/particle_process_material.cpp index a7f48b92fe..7ae154ea1d 100644 --- a/scene/resources/particle_process_material.cpp +++ b/scene/resources/particle_process_material.cpp @@ -1756,8 +1756,8 @@ void ParticleProcessMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_min", PROPERTY_HINT_RANGE, "0,16,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_ANIM_SPEED); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_max", PROPERTY_HINT_RANGE, "0,16,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_ANIM_SPEED); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_speed_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANIM_SPEED); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_min", PROPERTY_HINT_RANGE, "0,16,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_ANIM_OFFSET); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_max", PROPERTY_HINT_RANGE, "0,16,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_ANIM_OFFSET); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_min", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_param_min", "get_param_min", PARAM_ANIM_OFFSET); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_max", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_param_max", "get_param_max", PARAM_ANIM_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANIM_OFFSET); ADD_GROUP("Sub Emitter", "sub_emitter_"); diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index b6e953dd56..5ef66a22b6 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -180,7 +180,7 @@ TypedArray<Array> PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) c return TypedArray<Array>(); //not really supported } -uint32_t PrimitiveMesh::surface_get_format(int p_idx) const { +BitField<Mesh::ArrayFormat> PrimitiveMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, 0); uint32_t mesh_format = RS::ARRAY_FORMAT_VERTEX | RS::ARRAY_FORMAT_NORMAL | RS::ARRAY_FORMAT_TANGENT | RS::ARRAY_FORMAT_TEX_UV | RS::ARRAY_FORMAT_INDEX; diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index c1c51b350b..22cd12b004 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -84,7 +84,7 @@ public: virtual Array surface_get_arrays(int p_surface) const override; virtual TypedArray<Array> surface_get_blend_shape_arrays(int p_surface) const override; virtual Dictionary surface_get_lods(int p_surface) const override; - virtual uint32_t surface_get_format(int p_idx) const override; + virtual BitField<ArrayFormat> surface_get_format(int p_idx) const override; virtual Mesh::PrimitiveType surface_get_primitive_type(int p_idx) const override; virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override; virtual Ref<Material> surface_get_material(int p_idx) const override; diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index ade8875935..80b9ff3f38 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -449,10 +449,10 @@ Error ResourceLoaderText::load() { #ifdef TOOLS_ENABLED // Silence a warning that can happen during the initial filesystem scan due to cache being regenerated. if (ResourceLoader::get_resource_uid(path) != uid) { - WARN_PRINT(String(res_path + ":" + itos(lines) + " - ext_resource, invalid UUID: " + uidt + " - using text path instead: " + path).utf8().get_data()); + WARN_PRINT(String(res_path + ":" + itos(lines) + " - ext_resource, invalid UID: " + uidt + " - using text path instead: " + path).utf8().get_data()); } #else - WARN_PRINT(String(res_path + ":" + itos(lines) + " - ext_resource, invalid UUID: " + uidt + " - using text path instead: " + path).utf8().get_data()); + WARN_PRINT(String(res_path + ":" + itos(lines) + " - ext_resource, invalid UID: " + uidt + " - using text path instead: " + path).utf8().get_data()); #endif } } @@ -601,14 +601,14 @@ Error ResourceLoaderText::load() { resource_current++; + if (progress && resources_total > 0) { + *progress = resource_current / float(resources_total); + } + int_resources[id] = res; //always assign int resources - if (do_assign) { - if (cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE) { - res->set_path(path); - } else { - res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); - res->set_scene_unique_id(id); - } + if (do_assign && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { + res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); + res->set_scene_unique_id(id); } Dictionary missing_resource_properties; @@ -663,10 +663,6 @@ Error ResourceLoaderText::load() { if (!missing_resource_properties.is_empty()) { res->set_meta(META_MISSING_RESOURCES, missing_resource_properties); } - - if (progress && resources_total > 0) { - *progress = resource_current / float(resources_total); - } } while (true) { @@ -716,8 +712,6 @@ Error ResourceLoaderText::load() { resource = Ref<Resource>(r); } - resource_current++; - Dictionary missing_resource_properties; while (true) { @@ -770,6 +764,12 @@ Error ResourceLoaderText::load() { } } + resource_current++; + + if (progress && resources_total > 0) { + *progress = resource_current / float(resources_total); + } + if (missing_resource) { missing_resource->set_recording_properties(false); } @@ -779,9 +779,6 @@ Error ResourceLoaderText::load() { } error = OK; - if (progress && resources_total > 0) { - *progress = resource_current / float(resources_total); - } return error; } @@ -2237,6 +2234,35 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Ref<Reso return OK; } +Error ResourceLoaderText::set_uid(Ref<FileAccess> p_f, ResourceUID::ID p_uid) { + open(p_f, true); + ERR_FAIL_COND_V(error != OK, error); + ignore_resource_parsing = true; + + Ref<FileAccess> fw; + + fw = FileAccess::open(local_path + ".uidren", FileAccess::WRITE); + if (is_scene) { + fw->store_string("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]"); + } else { + fw->store_string("[gd_resource type=\"" + res_type + "\" load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]"); + } + + uint8_t c = f->get_8(); + while (!f->eof_reached()) { + fw->store_8(c); + c = f->get_8(); + } + + bool all_ok = fw->get_error() == OK; + + if (!all_ok) { + return ERR_CANT_CREATE; + } + + return OK; +} + Error ResourceFormatSaverText::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) { if (p_path.ends_with(".tscn") && !Ref<PackedScene>(p_resource).is_valid()) { return ERR_FILE_UNRECOGNIZED; @@ -2246,6 +2272,35 @@ Error ResourceFormatSaverText::save(const Ref<Resource> &p_resource, const Strin return saver.save(p_path, p_resource, p_flags); } +Error ResourceFormatSaverText::set_uid(const String &p_path, ResourceUID::ID p_uid) { + String lc = p_path.to_lower(); + if (!lc.ends_with(".tscn") && !lc.ends_with(".tres")) { + return ERR_FILE_UNRECOGNIZED; + } + + String local_path = ProjectSettings::get_singleton()->localize_path(p_path); + Error err = OK; + { + Ref<FileAccess> fo = FileAccess::open(p_path, FileAccess::READ); + if (fo.is_null()) { + ERR_FAIL_V(ERR_CANT_OPEN); + } + + ResourceLoaderText loader; + loader.local_path = local_path; + loader.res_path = loader.local_path; + err = loader.set_uid(fo, p_uid); + } + + if (err == OK) { + Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + da->remove(local_path); + da->rename(local_path + ".uidren", local_path); + } + + return err; +} + bool ResourceFormatSaverText::recognize(const Ref<Resource> &p_resource) const { return true; // All resources recognized! } diff --git a/scene/resources/resource_format_text.h b/scene/resources/resource_format_text.h index f96511fb74..0f95e2fbfd 100644 --- a/scene/resources/resource_format_text.h +++ b/scene/resources/resource_format_text.h @@ -106,6 +106,7 @@ class ResourceLoaderText { VariantParser::ResourceParser rp; friend class ResourceFormatLoaderText; + friend class ResourceFormatSaverText; Error error = OK; @@ -117,6 +118,7 @@ public: void set_local_path(const String &p_local_path); Ref<Resource> get_resource(); Error load(); + Error set_uid(Ref<FileAccess> p_f, ResourceUID::ID p_uid); int get_stage() const; int get_stage_count() const; void set_translation_remapped(bool p_remapped); @@ -195,6 +197,7 @@ class ResourceFormatSaverText : public ResourceFormatSaver { public: static ResourceFormatSaverText *singleton; virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0); + virtual Error set_uid(const String &p_path, ResourceUID::ID p_uid); virtual bool recognize(const Ref<Resource> &p_resource) const; virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const; diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 0008250f8f..4c99563a91 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -2508,14 +2508,6 @@ void VisualShader::_update_shader() const { global_compute_code += " return __rand_from_seed(seed) * (to - from) + from;\n"; global_compute_code += "}\n\n"; - global_compute_code += "vec2 __randv2_range(inout uint seed, vec2 from, vec2 to) {\n"; - global_compute_code += " return vec2(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y));\n"; - global_compute_code += "}\n\n"; - - global_compute_code += "vec3 __randv3_range(inout uint seed, vec3 from, vec3 to) {\n"; - global_compute_code += " return vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n"; - global_compute_code += "}\n\n"; - global_compute_code += "uint __hash(uint x) {\n"; global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp index 4ac663f7f2..9cf42b681c 100644 --- a/scene/resources/visual_shader_particle_nodes.cpp +++ b/scene/resources/visual_shader_particle_nodes.cpp @@ -911,11 +911,12 @@ void VisualShaderNodeParticleRandomness::_bind_methods() { ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeParticleRandomness::set_op_type); ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeParticleRandomness::get_op_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3"), "set_op_type", "get_op_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type"); BIND_ENUM_CONSTANT(OP_TYPE_SCALAR); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D); + BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D); BIND_ENUM_CONSTANT(OP_TYPE_MAX); } @@ -939,6 +940,8 @@ VisualShaderNodeParticleRandomness::PortType VisualShaderNodeParticleRandomness: return PORT_TYPE_VECTOR_2D; case OP_TYPE_VECTOR_3D: return PORT_TYPE_VECTOR_3D; + case OP_TYPE_VECTOR_4D: + return PORT_TYPE_VECTOR_4D; default: break; } @@ -950,48 +953,69 @@ String VisualShaderNodeParticleRandomness::get_output_port_name(int p_port) cons } int VisualShaderNodeParticleRandomness::get_input_port_count() const { - return 2; + return 3; } VisualShaderNodeParticleRandomness::PortType VisualShaderNodeParticleRandomness::get_input_port_type(int p_port) const { - switch (op_type) { - case OP_TYPE_VECTOR_2D: - return PORT_TYPE_VECTOR_2D; - case OP_TYPE_VECTOR_3D: - return PORT_TYPE_VECTOR_3D; - default: + switch (p_port) { + case 0: + return PORT_TYPE_SCALAR_UINT; + case 1: + case 2: + switch (op_type) { + case OP_TYPE_VECTOR_2D: + return PORT_TYPE_VECTOR_2D; + case OP_TYPE_VECTOR_3D: + return PORT_TYPE_VECTOR_3D; + case OP_TYPE_VECTOR_4D: + return PORT_TYPE_VECTOR_4D; + default: + break; + } break; } return PORT_TYPE_SCALAR; } String VisualShaderNodeParticleRandomness::get_input_port_name(int p_port) const { - if (p_port == 0) { - return "min"; - } else if (p_port == 1) { - return "max"; + switch (p_port) { + case 0: + return "seed"; + case 1: + return "min"; + case 2: + return "max"; } return String(); } -String VisualShaderNodeParticleRandomness::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { +bool VisualShaderNodeParticleRandomness::is_input_port_default(int p_port, Shader::Mode p_mode) const { + return p_port == 0; // seed +} + +String VisualShaderNodeParticleRandomness::generate_global_per_node(Shader::Mode p_mode, int p_id) const { String code; - switch (op_type) { - case OP_TYPE_SCALAR: { - code += vformat(" %s = __randf_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]); - } break; - case OP_TYPE_VECTOR_2D: { - code += vformat(" %s = __randv2_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]); - } break; - case OP_TYPE_VECTOR_3D: { - code += vformat(" %s = __randv3_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]); - } break; - default: - break; - } + + code += "vec2 __randv2_range(inout uint seed, vec2 from, vec2 to) {\n"; + code += " return vec2(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y));\n"; + code += "}\n\n"; + + code += "vec3 __randv3_range(inout uint seed, vec3 from, vec3 to) {\n"; + code += " return vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n"; + code += "}\n\n"; + + code += "vec4 __randv4_range(inout uint seed, vec4 from, vec4 to) {\n"; + code += " return vec4(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z), __randf_range(seed, from.w, to.w));\n"; + code += "}\n\n"; + return code; } +String VisualShaderNodeParticleRandomness::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { + static const char *func[(int)OP_TYPE_MAX] = { "__randf_range", "__randv2_range", "__randv3_range", "__randv4_range" }; + return vformat(" %s = %s(%s, %s, %s);\n", p_output_vars[0], func[op_type], p_input_vars[0].is_empty() ? "__seed" : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1], p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]); +} + void VisualShaderNodeParticleRandomness::set_op_type(OpType p_op_type) { ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX)); if (op_type == p_op_type) { @@ -999,16 +1023,20 @@ void VisualShaderNodeParticleRandomness::set_op_type(OpType p_op_type) { } switch (p_op_type) { case OP_TYPE_SCALAR: { - set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); + set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); } break; case OP_TYPE_VECTOR_2D: { - set_input_port_default_value(0, Vector2(), get_input_port_default_value(0)); set_input_port_default_value(1, Vector2(), get_input_port_default_value(1)); + set_input_port_default_value(2, Vector2(), get_input_port_default_value(2)); } break; case OP_TYPE_VECTOR_3D: { - set_input_port_default_value(0, Vector3(), get_input_port_default_value(0)); set_input_port_default_value(1, Vector3(), get_input_port_default_value(1)); + set_input_port_default_value(2, Vector3(), get_input_port_default_value(2)); + } break; + case OP_TYPE_VECTOR_4D: { + set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1)); + set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2)); } break; default: break; @@ -1026,8 +1054,8 @@ bool VisualShaderNodeParticleRandomness::has_output_port_preview(int p_port) con } VisualShaderNodeParticleRandomness::VisualShaderNodeParticleRandomness() { - set_input_port_default_value(0, -1.0); - set_input_port_default_value(1, 1.0); + set_input_port_default_value(1, -1.0); + set_input_port_default_value(2, 1.0); } // VisualShaderNodeParticleAccelerator diff --git a/scene/resources/visual_shader_particle_nodes.h b/scene/resources/visual_shader_particle_nodes.h index c0ab974693..08fb059534 100644 --- a/scene/resources/visual_shader_particle_nodes.h +++ b/scene/resources/visual_shader_particle_nodes.h @@ -216,6 +216,7 @@ public: OP_TYPE_SCALAR, OP_TYPE_VECTOR_2D, OP_TYPE_VECTOR_3D, + OP_TYPE_VECTOR_4D, OP_TYPE_MAX, }; @@ -232,12 +233,14 @@ public: virtual int get_input_port_count() const override; virtual PortType get_input_port_type(int p_port) const override; virtual String get_input_port_name(int p_port) const override; + virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override; virtual int get_output_port_count() const override; virtual PortType get_output_port_type(int p_port) const override; virtual String get_output_port_name(int p_port) const override; virtual bool has_output_port_preview(int p_port) const override; + virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override; virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; void set_op_type(OpType p_type); |