From b3627e29f0bbb67813fe518ad55e9509b4752e6c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 30 Jun 2018 19:58:37 -0300 Subject: [PATCH] -Fixes to OBJ importer, option to disable optimization -Fixes to script language, PlaceHolder can now get and check methods --- core/script_language.cpp | 14 ++++++++++++++ core/script_language.h | 4 ++-- editor/import/resource_importer_obj.cpp | 11 +++++++---- scene/animation/root_motion_view.cpp | 19 +++++++++++++++++-- scene/animation/root_motion_view.h | 4 ++++ 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/core/script_language.cpp b/core/script_language.cpp index 1dab58e29eb..acbe3b34dbf 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -347,6 +347,20 @@ Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_n return Variant::NIL; } +void PlaceHolderScriptInstance::get_method_list(List *p_list) const { + + if (script.is_valid()) { + script->get_script_method_list(p_list); + } +} +bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { + + if (script.is_valid()) { + return script->has_method(p_method); + } + return false; +} + void PlaceHolderScriptInstance::update(const List &p_properties, const Map &p_values) { Set new_values; diff --git a/core/script_language.h b/core/script_language.h index ad66fc55283..e7748f93e21 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -304,8 +304,8 @@ public: virtual void get_property_list(List *p_properties) const; virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = NULL) const; - virtual void get_method_list(List *p_list) const {} - virtual bool has_method(const StringName &p_method) const { return false; } + virtual void get_method_list(List *p_list) const; + virtual bool has_method(const StringName &p_method) const; virtual Variant call(const StringName &p_method, VARIANT_ARG_LIST) { return Variant(); } virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 21803a2184b..b8dd4a87b79 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -188,7 +188,7 @@ static Error _parse_material_library(const String &p_path, Map > &r_meshes, bool p_single_mesh, bool p_generate_tangents, Vector3 p_scale_mesh, List *r_missing_deps) { +static Error _parse_obj(const String &p_path, List > &r_meshes, bool p_single_mesh, bool p_generate_tangents, bool p_optimize, Vector3 p_scale_mesh, List *r_missing_deps) { FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); @@ -200,6 +200,8 @@ static Error _parse_obj(const String &p_path, List > &r_meshes, bool p bool generate_tangents = p_generate_tangents; Vector3 scale_mesh = p_scale_mesh; bool flip_faces = false; + int mesh_flags = p_optimize ? Mesh::ARRAY_COMPRESS_DEFAULT : 0; + //bool flip_faces = p_options["force/flip_faces"]; //bool force_smooth = p_options["force/smooth_shading"]; //bool weld_vertices = p_options["force/weld_vertices"]; @@ -331,7 +333,7 @@ static Error _parse_obj(const String &p_path, List > &r_meshes, bool p surf_tool->set_material(material_map[current_material_library][current_material]); } - mesh = surf_tool->commit(mesh); + mesh = surf_tool->commit(mesh, mesh_flags); if (current_material != String()) { mesh->surface_set_name(mesh->get_surface_count() - 1, current_material.get_basename()); @@ -402,7 +404,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in List > meshes; - Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps); + Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, p_flags & IMPORT_USE_COMPRESSION, Vector3(1, 1, 1), r_missing_deps); if (err != OK) { if (r_err) { @@ -470,6 +472,7 @@ void ResourceImporterOBJ::get_import_options(List *r_options, int r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate_tangents"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "scale_mesh"), Vector3(1, 1, 1))); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "optimize_mesh"), true)); } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map &p_options) const { @@ -480,7 +483,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s List > meshes; - Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["scale_mesh"], NULL); + Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["optimize_mesh"], p_options["scale_mesh"], NULL); ERR_FAIL_COND_V(err != OK, err); ERR_FAIL_COND_V(meshes.size() != 1, ERR_BUG); diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp index 84439957205..a28c63064af 100644 --- a/scene/animation/root_motion_view.cpp +++ b/scene/animation/root_motion_view.cpp @@ -37,6 +37,14 @@ float RootMotionView::get_radius() const { return radius; } +void RootMotionView::set_zero_y(bool p_zero_y) { + zero_y = p_zero_y; +} + +bool RootMotionView::get_zero_y() const { + return zero_y; +} + void RootMotionView::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { @@ -77,9 +85,11 @@ void RootMotionView::_notification(int p_what) { transform.orthonormalize(); //dont want scale, too imprecise transform.affine_invert(); - accumulated = accumulated * transform; + accumulated = transform * accumulated; accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size); - accumulated.origin.y = Math::fposmod(accumulated.origin.y, cell_size); + if (zero_y) { + accumulated.origin.y = 0; + } accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size); VS::get_singleton()->immediate_clear(immediate); @@ -142,13 +152,18 @@ void RootMotionView::_bind_methods() { ClassDB::bind_method(D_METHOD("set_radius", "size"), &RootMotionView::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &RootMotionView::get_radius); + ClassDB::bind_method(D_METHOD("set_zero_y", "enable"), &RootMotionView::set_zero_y); + ClassDB::bind_method(D_METHOD("get_zero_y"), &RootMotionView::get_zero_y); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "animation_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationTree"), "set_animation_path", "get_animation_path"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_size", PROPERTY_HINT_RANGE, "0.1,16,0.01,or_greater"), "set_cell_size", "get_cell_size"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_RANGE, "0.1,16,0.01,or_greater"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "zero_y"), "set_zero_y", "get_zero_y"); } RootMotionView::RootMotionView() { + zero_y = true; radius = 10; cell_size = 1; set_process_internal(true); diff --git a/scene/animation/root_motion_view.h b/scene/animation/root_motion_view.h index 65e9ff480b9..611183d364f 100644 --- a/scene/animation/root_motion_view.h +++ b/scene/animation/root_motion_view.h @@ -13,6 +13,7 @@ public: bool use_in_game; Color color; bool first; + bool zero_y; Transform accumulated; @@ -33,6 +34,9 @@ public: void set_radius(float p_radius); float get_radius() const; + void set_zero_y(bool p_zero_y); + bool get_zero_y() const; + virtual AABB get_aabb() const; virtual PoolVector get_faces(uint32_t p_usage_flags) const;