Skip to content

Commit

Permalink
Remove support for legacy bone binds from godot. All binds are named.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuma committed Aug 21, 2021
1 parent e599f1b commit 521f2fb
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 107 deletions.
2 changes: 0 additions & 2 deletions doc/classes/EditorSceneImporter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,5 @@
</constant>
<constant name="IMPORT_GENERATE_TANGENT_ARRAYS" value="8">
</constant>
<constant name="IMPORT_USE_NAMED_SKIN_BINDS" value="16">
</constant>
</constants>
</class>
24 changes: 7 additions & 17 deletions doc/classes/Skin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
<tutorials>
</tutorials>
<methods>
<method name="add_bind">
<return type="void" />
<argument index="0" name="bone" type="int" />
<argument index="1" name="pose" type="Transform3D" />
<method name="add_named_bind">
<return type="void">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="pose" type="Transform3D">
</argument>
<description>
</description>
</method>
Expand All @@ -19,12 +22,6 @@
<description>
</description>
</method>
<method name="get_bind_bone" qualifiers="const">
<return type="int" />
<argument index="0" name="bind_index" type="int" />
<description>
</description>
</method>
<method name="get_bind_count" qualifiers="const">
<return type="int" />
<description>
Expand All @@ -42,13 +39,6 @@
<description>
</description>
</method>
<method name="set_bind_bone">
<return type="void" />
<argument index="0" name="bind_index" type="int" />
<argument index="1" name="bone" type="int" />
<description>
</description>
</method>
<method name="set_bind_count">
<return type="void" />
<argument index="0" name="bind_count" type="int" />
Expand Down
6 changes: 0 additions & 6 deletions editor/import/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ void EditorSceneImporter::_bind_methods() {
BIND_CONSTANT(IMPORT_ANIMATION);
BIND_CONSTANT(IMPORT_FAIL_ON_MISSING_DEPENDENCIES);
BIND_CONSTANT(IMPORT_GENERATE_TANGENT_ARRAYS);
BIND_CONSTANT(IMPORT_USE_NAMED_SKIN_BINDS);
}

/////////////////////////////////
Expand Down Expand Up @@ -1038,7 +1037,6 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/create_shadow_meshes"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/light_baking", PROPERTY_HINT_ENUM, "Disabled,Dynamic,Static,Static Lightmaps", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 2));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.1));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "skins/use_named_skins"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/bake_reset_animation"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15));
Expand Down Expand Up @@ -1353,10 +1351,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
import_flags |= EditorSceneImporter::IMPORT_ANIMATION;
}

if (bool(p_options["skins/use_named_skins"])) {
import_flags |= EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS;
}

bool ensure_tangents = p_options["meshes/ensure_tangents"];
if (ensure_tangents) {
import_flags |= EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS;
Expand Down
1 change: 0 additions & 1 deletion editor/import/resource_importer_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class EditorSceneImporter : public RefCounted {
IMPORT_ANIMATION = 2,
IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 4,
IMPORT_GENERATE_TANGENT_ARRAYS = 8,
IMPORT_USE_NAMED_SKIN_BINDS = 16,

};

Expand Down
2 changes: 0 additions & 2 deletions modules/gltf/doc_classes/GLTFState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@
</member>
<member name="scene_name" type="String" setter="set_scene_name" getter="get_scene_name" default="&quot;&quot;">
</member>
<member name="use_named_skin_binds" type="bool" setter="set_use_named_skin_binds" getter="get_use_named_skin_binds" default="false">
</member>
</members>
<constants>
</constants>
Expand Down
2 changes: 0 additions & 2 deletions modules/gltf/editor_scene_importer_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ Node *PackedSceneGLTF::import_scene(const String &p_path, uint32_t p_flags,
if (r_state == Ref<GLTFState>()) {
r_state.instantiate();
}
r_state->use_named_skin_binds =
p_flags & EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS;

Ref<GLTFDocument> gltf_document;
gltf_document.instantiate();
Expand Down
18 changes: 1 addition & 17 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4281,12 +4281,7 @@ Error GLTFDocument::_create_skins(Ref<GLTFState> state) {
xform = gltf_skin->inverse_binds[joint_i];
}

if (state->use_named_skin_binds) {
skin->add_named_bind(bone_name, xform);
} else {
int32_t bone_i = gltf_skin->joint_i_to_bone_i[joint_i];
skin->add_bind(bone_i, xform);
}
skin->add_named_bind(bone_name, xform);
}

gltf_skin->godot_skin = skin;
Expand All @@ -4313,9 +4308,6 @@ bool GLTFDocument::_skins_are_same(const Ref<Skin> skin_a, const Ref<Skin> skin_
}

for (int i = 0; i < skin_a->get_bind_count(); ++i) {
if (skin_a->get_bind_bone(i) != skin_b->get_bind_bone(i)) {
return false;
}
if (skin_a->get_bind_name(i) != skin_b->get_bind_name(i)) {
return false;
}
Expand Down Expand Up @@ -5861,10 +5853,6 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) {
Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skeleton_gltf_i];
for (int32_t bind_i = 0; bind_i < skin->get_bind_count(); bind_i++) {
String godot_bone_name = skin->get_bind_name(bind_i);
if (godot_bone_name.is_empty()) {
int32_t bone = skin->get_bind_bone(bind_i);
godot_bone_name = skeleton->get_bone_name(bone);
}
if (skeleton->find_bone(godot_bone_name) == -1) {
godot_bone_name = skeleton->get_bone_name(0);
}
Expand Down Expand Up @@ -5903,10 +5891,6 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) {
String bone_name = skeleton->get_bone_name(bind_i);
String godot_bone_name = skin->get_bind_name(bind_i);
int32_t bone = -1;
if (skin->get_bind_bone(bind_i) != -1) {
bone = skin->get_bind_bone(bind_i);
godot_bone_name = skeleton->get_bone_name(bone);
}
bone = skeleton->find_bone(godot_bone_name);
if (bone == -1) {
continue;
Expand Down
11 changes: 0 additions & 11 deletions modules/gltf/gltf_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_minor_version", "minor_version"), &GLTFState::set_minor_version);
ClassDB::bind_method(D_METHOD("get_glb_data"), &GLTFState::get_glb_data);
ClassDB::bind_method(D_METHOD("set_glb_data", "glb_data"), &GLTFState::set_glb_data);
ClassDB::bind_method(D_METHOD("get_use_named_skin_binds"), &GLTFState::get_use_named_skin_binds);
ClassDB::bind_method(D_METHOD("set_use_named_skin_binds", "use_named_skin_binds"), &GLTFState::set_use_named_skin_binds);
ClassDB::bind_method(D_METHOD("get_nodes"), &GLTFState::get_nodes);
ClassDB::bind_method(D_METHOD("set_nodes", "nodes"), &GLTFState::set_nodes);
ClassDB::bind_method(D_METHOD("get_buffers"), &GLTFState::get_buffers);
Expand Down Expand Up @@ -85,7 +83,6 @@ void GLTFState::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "major_version"), "set_major_version", "get_major_version"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "minor_version"), "set_minor_version", "get_minor_version"); // int
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "glb_data"), "set_glb_data", "get_glb_data"); // Vector<uint8_t>
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_named_skin_binds"), "set_use_named_skin_binds", "get_use_named_skin_binds"); // bool
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_nodes", "get_nodes"); // Vector<Ref<GLTFNode>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffers"), "set_buffers", "get_buffers"); // Vector<Vector<uint8_t>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffer_views", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_buffer_views", "get_buffer_views"); // Vector<Ref<GLTFBufferView>>
Expand Down Expand Up @@ -138,14 +135,6 @@ void GLTFState::set_glb_data(Vector<uint8_t> p_glb_data) {
glb_data = p_glb_data;
}

bool GLTFState::get_use_named_skin_binds() {
return use_named_skin_binds;
}

void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
use_named_skin_binds = p_use_named_skin_binds;
}

Array GLTFState::get_nodes() {
return GLTFDocument::to_array(nodes);
}
Expand Down
5 changes: 0 additions & 5 deletions modules/gltf/gltf_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class GLTFState : public Resource {
int minor_version = 0;
Vector<uint8_t> glb_data;

bool use_named_skin_binds = false;

Vector<Ref<GLTFNode>> nodes;
Vector<Vector<uint8_t>> buffers;
Vector<Ref<GLTFBufferView>> buffer_views;
Expand Down Expand Up @@ -104,9 +102,6 @@ class GLTFState : public Resource {
Vector<uint8_t> get_glb_data();
void set_glb_data(Vector<uint8_t> p_glb_data);

bool get_use_named_skin_binds();
void set_use_named_skin_binds(bool p_use_named_skin_binds);

Array get_nodes();
void set_nodes(Array p_nodes);

Expand Down
10 changes: 1 addition & 9 deletions scene/3d/skeleton_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,6 @@ void Skeleton3D::_notification(int p_what) {
ERR_PRINT("Skin bind #" + itos(i) + " contains named bind '" + String(bind_name) + "' but Skeleton3D has no bone by that name.");
E->get()->skin_bone_indices_ptrs[i] = 0;
}
} else if (skin->get_bind_bone(i) >= 0) {
int bind_index = skin->get_bind_bone(i);
if (bind_index >= len) {
ERR_PRINT("Skin bind #" + itos(i) + " contains bone index bind: " + itos(bind_index) + " , which is greater than the skeleton bone count: " + itos(len) + ".");
E->get()->skin_bone_indices_ptrs[i] = 0;
} else {
E->get()->skin_bone_indices_ptrs[i] = bind_index;
}
} else {
ERR_PRINT("Skin bind #" + itos(i) + " does not contain a name nor a bone index.");
E->get()->skin_bone_indices_ptrs[i] = 0;
Expand Down Expand Up @@ -913,7 +905,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) {

for (int i = 0; i < len; i++) {
//the inverse is what is actually required
skin->set_bind_bone(i, i);
skin->set_bind_name(i, get_bone_name(i));
skin->set_bind_pose(i, skin->get_bind_pose(i).affine_inverse());
}
}
Expand Down
29 changes: 3 additions & 26 deletions scene/resources/skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ void Skin::set_bind_count(int p_size) {
emit_changed();
}

void Skin::add_bind(int p_bone, const Transform3D &p_pose) {
uint32_t index = bind_count;
set_bind_count(bind_count + 1);
set_bind_bone(index, p_bone);
set_bind_pose(index, p_pose);
}

void Skin::add_named_bind(const String &p_name, const Transform3D &p_pose) {
uint32_t index = bind_count;
set_bind_count(bind_count + 1);
Expand All @@ -62,12 +55,6 @@ void Skin::set_bind_name(int p_index, const StringName &p_name) {
}
}

void Skin::set_bind_bone(int p_index, int p_bone) {
ERR_FAIL_INDEX(p_index, bind_count);
binds_ptr[p_index].bone = p_bone;
emit_changed();
}

void Skin::set_bind_pose(int p_index, const Transform3D &p_pose) {
ERR_FAIL_INDEX(p_index, bind_count);
binds_ptr[p_index].pose = p_pose;
Expand All @@ -93,10 +80,7 @@ bool Skin::_set(const StringName &p_name, const Variant &p_value) {
} else if (name.begins_with("bind/")) {
int index = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
if (what == "bone") {
set_bind_bone(index, p_value);
return true;
} else if (what == "name") {
if (what == "name") {
set_bind_name(index, p_value);
return true;
} else if (what == "pose") {
Expand All @@ -115,10 +99,7 @@ bool Skin::_get(const StringName &p_name, Variant &r_ret) const {
} else if (name.begins_with("bind/")) {
int index = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
if (what == "bone") {
r_ret = get_bind_bone(index);
return true;
} else if (what == "name") {
if (what == "name") {
r_ret = get_bind_name(index);
return true;
} else if (what == "pose") {
Expand All @@ -133,7 +114,6 @@ void Skin::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::INT, "bind_count", PROPERTY_HINT_RANGE, "0,16384,1,or_greater"));
for (int i = 0; i < get_bind_count(); i++) {
p_list->push_back(PropertyInfo(Variant::STRING_NAME, "bind/" + itos(i) + "/name"));
p_list->push_back(PropertyInfo(Variant::INT, "bind/" + itos(i) + "/bone", PROPERTY_HINT_RANGE, "0,16384,1,or_greater", get_bind_name(i) != StringName() ? PROPERTY_USAGE_NOEDITOR : PROPERTY_USAGE_DEFAULT));
p_list->push_back(PropertyInfo(Variant::TRANSFORM3D, "bind/" + itos(i) + "/pose"));
}
}
Expand All @@ -142,17 +122,14 @@ void Skin::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bind_count", "bind_count"), &Skin::set_bind_count);
ClassDB::bind_method(D_METHOD("get_bind_count"), &Skin::get_bind_count);

ClassDB::bind_method(D_METHOD("add_bind", "bone", "pose"), &Skin::add_bind);
ClassDB::bind_method(D_METHOD("add_named_bind", "name", "pose"), &Skin::add_named_bind);

ClassDB::bind_method(D_METHOD("set_bind_pose", "bind_index", "pose"), &Skin::set_bind_pose);
ClassDB::bind_method(D_METHOD("get_bind_pose", "bind_index"), &Skin::get_bind_pose);

ClassDB::bind_method(D_METHOD("set_bind_name", "bind_index", "name"), &Skin::set_bind_name);
ClassDB::bind_method(D_METHOD("get_bind_name", "bind_index"), &Skin::get_bind_name);

ClassDB::bind_method(D_METHOD("set_bind_bone", "bind_index", "bone"), &Skin::set_bind_bone);
ClassDB::bind_method(D_METHOD("get_bind_bone", "bind_index"), &Skin::get_bind_bone);

ClassDB::bind_method(D_METHOD("clear_binds"), &Skin::clear_binds);
}

Expand Down
9 changes: 0 additions & 9 deletions scene/resources/skin.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,11 @@ class Skin : public Resource {
void set_bind_count(int p_size);
inline int get_bind_count() const { return bind_count; }

void add_bind(int p_bone, const Transform3D &p_pose);
void add_named_bind(const String &p_name, const Transform3D &p_pose);

void set_bind_bone(int p_index, int p_bone);
void set_bind_pose(int p_index, const Transform3D &p_pose);
void set_bind_name(int p_index, const StringName &p_name);

inline int get_bind_bone(int p_index) const {
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(p_index, bind_count, -1);
#endif
return binds_ptr[p_index].bone;
}

inline StringName get_bind_name(int p_index) const {
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(p_index, bind_count, StringName());
Expand Down

0 comments on commit 521f2fb

Please sign in to comment.