Refactored Mesh internals and formats.
-Changed how mesh data is organized, hoping to make it more efficient on Vulkan and GLES. -Removed compression, it now always uses the most efficient format. -Added support for custom arrays (up to 8 custom formats) -Added support for 8 weights in skeleton data. -Added a simple optional versioning system for imported assets, to reimport if binary is newer -Fixes #43979 (I needed to test) WARNING: -NOT backwards compatible with previous 4.x-devel, will most likely never be, but it will force reimport scenes due to version change. -NOT backwards compatible with 3.x scenes, this will be eventually re-added. -Skeletons not working any longer, will fix in next PR.
This commit is contained in:
@@ -357,10 +357,12 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
|
||||
|
||||
List<String> to_check;
|
||||
|
||||
String importer_name;
|
||||
String source_file = "";
|
||||
String source_md5 = "";
|
||||
Vector<String> dest_files;
|
||||
String dest_md5 = "";
|
||||
int version = 0;
|
||||
|
||||
while (true) {
|
||||
assign = Variant();
|
||||
@@ -384,6 +386,10 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
|
||||
for (int i = 0; i < fa.size(); i++) {
|
||||
to_check.push_back(fa[i]);
|
||||
}
|
||||
} else if (assign == "importer_version") {
|
||||
version = value;
|
||||
} else if (assign == "importer") {
|
||||
importer_name = value;
|
||||
} else if (!p_only_imported_files) {
|
||||
if (assign == "source_file") {
|
||||
source_file = value;
|
||||
@@ -399,6 +405,12 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
|
||||
|
||||
memdelete(f);
|
||||
|
||||
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
|
||||
|
||||
if (importer->get_format_version() > version) {
|
||||
return true; // version changed, reimport
|
||||
}
|
||||
|
||||
// Read the md5's from a separate file (so the import parameters aren't dependent on the file version
|
||||
String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(p_path);
|
||||
FileAccess *md5s = FileAccess::open(base_path + ".md5", FileAccess::READ, &err);
|
||||
@@ -1576,6 +1588,10 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
|
||||
f->store_line("[remap]");
|
||||
f->store_line("");
|
||||
f->store_line("importer=\"" + importer->get_importer_name() + "\"");
|
||||
int version = importer->get_format_version();
|
||||
if (version > 0) {
|
||||
f->store_line("importer_version=" + itos(importer->get_format_version()));
|
||||
}
|
||||
if (importer->get_resource_type() != "") {
|
||||
f->store_line("type=\"" + importer->get_resource_type() + "\"");
|
||||
}
|
||||
|
||||
@@ -844,19 +844,19 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
|
||||
|
||||
for (int k = 0; k < vertex_array.size(); k++) {
|
||||
if (normal_src) {
|
||||
surftool->add_normal(vertex_array[k].normal);
|
||||
surftool->set_normal(vertex_array[k].normal);
|
||||
if (binormal_src && tangent_src) {
|
||||
surftool->add_tangent(vertex_array[k].tangent);
|
||||
surftool->set_tangent(vertex_array[k].tangent);
|
||||
}
|
||||
}
|
||||
if (uv_src) {
|
||||
surftool->add_uv(Vector2(vertex_array[k].uv.x, vertex_array[k].uv.y));
|
||||
surftool->set_uv(Vector2(vertex_array[k].uv.x, vertex_array[k].uv.y));
|
||||
}
|
||||
if (uv2_src) {
|
||||
surftool->add_uv2(Vector2(vertex_array[k].uv2.x, vertex_array[k].uv2.y));
|
||||
surftool->set_uv2(Vector2(vertex_array[k].uv2.x, vertex_array[k].uv2.y));
|
||||
}
|
||||
if (color_src) {
|
||||
surftool->add_color(vertex_array[k].color);
|
||||
surftool->set_color(vertex_array[k].color);
|
||||
}
|
||||
|
||||
if (has_weights) {
|
||||
@@ -876,8 +876,8 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
|
||||
}
|
||||
}
|
||||
|
||||
surftool->add_bones(bones);
|
||||
surftool->add_weights(weights);
|
||||
surftool->set_bones(bones);
|
||||
surftool->set_weights(weights);
|
||||
}
|
||||
|
||||
surftool->add_vertex(vertex_array[k].vertex);
|
||||
@@ -923,7 +923,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
|
||||
mr.push_back(a);
|
||||
}
|
||||
|
||||
p_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, d, mr, Dictionary(), p_use_compression ? Mesh::ARRAY_COMPRESS_DEFAULT : 0);
|
||||
p_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, d, mr, Dictionary(), 0);
|
||||
|
||||
if (material.is_valid()) {
|
||||
if (p_use_mesh_material) {
|
||||
|
||||
@@ -970,8 +970,7 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool compress_vert_data = state.import_flags & IMPORT_USE_COMPRESSION;
|
||||
uint32_t mesh_flags = compress_vert_data ? Mesh::ARRAY_COMPRESS_DEFAULT : 0;
|
||||
uint32_t mesh_flags = 0;
|
||||
|
||||
Array meshes = state.json["meshes"];
|
||||
for (GLTFMeshIndex i = 0; i < meshes.size(); i++) {
|
||||
|
||||
@@ -210,7 +210,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
|
||||
bool generate_tangents = p_generate_tangents;
|
||||
Vector3 scale_mesh = p_scale_mesh;
|
||||
Vector3 offset_mesh = p_offset_mesh;
|
||||
int mesh_flags = p_optimize ? Mesh::ARRAY_COMPRESS_DEFAULT : 0;
|
||||
int mesh_flags = 0;
|
||||
|
||||
Vector<Vector3> vertices;
|
||||
Vector<Vector3> normals;
|
||||
@@ -294,7 +294,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
|
||||
norm += normals.size() + 1;
|
||||
}
|
||||
ERR_FAIL_INDEX_V(norm, normals.size(), ERR_FILE_CORRUPT);
|
||||
surf_tool->add_normal(normals[norm]);
|
||||
surf_tool->set_normal(normals[norm]);
|
||||
}
|
||||
|
||||
if (face[idx].size() >= 2 && face[idx][1] != String()) {
|
||||
@@ -303,7 +303,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
|
||||
uv += uvs.size() + 1;
|
||||
}
|
||||
ERR_FAIL_INDEX_V(uv, uvs.size(), ERR_FILE_CORRUPT);
|
||||
surf_tool->add_uv(uvs[uv]);
|
||||
surf_tool->set_uv(uvs[uv]);
|
||||
}
|
||||
|
||||
int vtx = face[idx][0].to_int() - 1;
|
||||
@@ -473,6 +473,10 @@ String ResourceImporterOBJ::get_resource_type() const {
|
||||
return "Mesh";
|
||||
}
|
||||
|
||||
int ResourceImporterOBJ::get_format_version() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ResourceImporterOBJ::get_preset_count() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
|
||||
virtual String get_save_extension() const override;
|
||||
virtual String get_resource_type() const override;
|
||||
virtual int get_format_version() const override;
|
||||
|
||||
virtual int get_preset_count() const override;
|
||||
virtual String get_preset_name(int p_idx) const override;
|
||||
|
||||
@@ -172,6 +172,10 @@ String ResourceImporterScene::get_resource_type() const {
|
||||
return "PackedScene";
|
||||
}
|
||||
|
||||
int ResourceImporterScene::get_format_version() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ResourceImporterScene::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
|
||||
if (p_option.begins_with("animation/")) {
|
||||
if (p_option != "animation/import" && !bool(p_options["animation/import"])) {
|
||||
|
||||
@@ -133,6 +133,7 @@ public:
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
|
||||
virtual String get_save_extension() const override;
|
||||
virtual String get_resource_type() const override;
|
||||
virtual int get_format_version() const override;
|
||||
|
||||
virtual int get_preset_count() const override;
|
||||
virtual String get_preset_name(int p_idx) const override;
|
||||
|
||||
@@ -1625,13 +1625,13 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
||||
int pointidx = 0;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
bones.write[0] = parent;
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(rootcolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(rootcolor);
|
||||
surface_tool->add_vertex(v0 - grests[parent].basis[j].normalized() * dist * 0.05);
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(rootcolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(rootcolor);
|
||||
surface_tool->add_vertex(v0 + grests[parent].basis[j].normalized() * dist * 0.05);
|
||||
|
||||
if (j == closest) {
|
||||
@@ -1654,24 +1654,24 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
||||
point += axis * dist * 0.1;
|
||||
|
||||
bones.write[0] = parent;
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(bonecolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(bonecolor);
|
||||
surface_tool->add_vertex(v0);
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(bonecolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(bonecolor);
|
||||
surface_tool->add_vertex(point);
|
||||
|
||||
bones.write[0] = parent;
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(bonecolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(bonecolor);
|
||||
surface_tool->add_vertex(point);
|
||||
bones.write[0] = i;
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(bonecolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(bonecolor);
|
||||
surface_tool->add_vertex(v1);
|
||||
points[pointidx++] = point;
|
||||
}
|
||||
@@ -1680,13 +1680,13 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
||||
SWAP(points[1], points[2]);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
bones.write[0] = parent;
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(bonecolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(bonecolor);
|
||||
surface_tool->add_vertex(points[j]);
|
||||
surface_tool->add_bones(bones);
|
||||
surface_tool->add_weights(weights);
|
||||
surface_tool->add_color(bonecolor);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->set_color(bonecolor);
|
||||
surface_tool->add_vertex(points[(j + 1) % 4]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5345,7 +5345,7 @@ void Node3DEditor::_init_indicators() {
|
||||
Vector2 ofs = Vector2(Math::cos((Math_PI * 2.0 * k) / m), Math::sin((Math_PI * 2.0 * k) / m));
|
||||
Vector3 normal = ivec * ofs.x + ivec2 * ofs.y;
|
||||
|
||||
surftool->add_normal(basis.xform(normal));
|
||||
surftool->set_normal(basis.xform(normal));
|
||||
surftool->add_vertex(vertex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user