summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_import_collada.cpp44
-rw-r--r--editor/import/editor_import_plugin.cpp2
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp158
-rw-r--r--editor/import/editor_scene_importer_gltf.h17
-rw-r--r--editor/import/resource_importer_bitmask.cpp3
-rw-r--r--editor/import/resource_importer_layered_texture.cpp162
-rw-r--r--editor/import/resource_importer_layered_texture.h58
-rw-r--r--editor/import/resource_importer_obj.cpp30
-rw-r--r--editor/import/resource_importer_scene.cpp26
-rw-r--r--editor/import/resource_importer_scene.h3
-rw-r--r--editor/import/resource_importer_texture.cpp403
-rw-r--r--editor/import/resource_importer_texture.h42
-rw-r--r--editor/import/resource_importer_texture_atlas.cpp32
-rw-r--r--editor/import/resource_importer_wav.cpp16
-rw-r--r--editor/import/resource_importer_wav.h6
15 files changed, 578 insertions, 424 deletions
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index e2d8dc8962..2f97f4aa31 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -363,7 +363,7 @@ Error ColladaImport::_create_material(const String &p_target) {
ERR_FAIL_COND_V(!collada.state.effect_map.has(src_mat.instance_effect), ERR_INVALID_PARAMETER);
Collada::Effect &effect = collada.state.effect_map[src_mat.instance_effect];
- Ref<SpatialMaterial> material = memnew(SpatialMaterial);
+ Ref<StandardMaterial3D> material = memnew(StandardMaterial3D);
if (src_mat.name != "")
material->set_name(src_mat.name);
@@ -380,12 +380,12 @@ Error ColladaImport::_create_material(const String &p_target) {
if (texfile.begins_with("/")) {
texfile = texfile.replace_first("/", "res://");
}
- Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
+ Ref<Texture2D> texture = ResourceLoader::load(texfile, "Texture2D");
if (texture.is_valid()) {
- material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
+ material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, texture);
material->set_albedo(Color(1, 1, 1, 1));
- //material->set_parameter(SpatialMaterial::PARAM_DIFFUSE,Color(1,1,1,1));
+ //material->set_parameter(StandardMaterial3D::PARAM_DIFFUSE,Color(1,1,1,1));
} else {
missing_textures.push_back(texfile.get_file());
}
@@ -405,13 +405,13 @@ Error ColladaImport::_create_material(const String &p_target) {
texfile = texfile.replace_first("/", "res://");
}
- Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
+ Ref<Texture2D> texture = ResourceLoader::load(texfile, "Texture2D");
if (texture.is_valid()) {
- material->set_texture(SpatialMaterial::TEXTURE_METALLIC, texture);
+ material->set_texture(StandardMaterial3D::TEXTURE_METALLIC, texture);
material->set_specular(1.0);
- //material->set_texture(SpatialMaterial::PARAM_SPECULAR,texture);
- //material->set_parameter(SpatialMaterial::PARAM_SPECULAR,Color(1,1,1,1));
+ //material->set_texture(StandardMaterial3D::PARAM_SPECULAR,texture);
+ //material->set_parameter(StandardMaterial3D::PARAM_SPECULAR,Color(1,1,1,1));
} else {
missing_textures.push_back(texfile.get_file());
}
@@ -432,21 +432,21 @@ Error ColladaImport::_create_material(const String &p_target) {
texfile = texfile.replace_first("/", "res://");
}
- Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
+ Ref<Texture2D> texture = ResourceLoader::load(texfile, "Texture2D");
if (texture.is_valid()) {
- material->set_feature(SpatialMaterial::FEATURE_EMISSION, true);
- material->set_texture(SpatialMaterial::TEXTURE_EMISSION, texture);
+ material->set_feature(StandardMaterial3D::FEATURE_EMISSION, true);
+ material->set_texture(StandardMaterial3D::TEXTURE_EMISSION, texture);
material->set_emission(Color(1, 1, 1, 1));
- //material->set_parameter(SpatialMaterial::PARAM_EMISSION,Color(1,1,1,1));
+ //material->set_parameter(StandardMaterial3D::PARAM_EMISSION,Color(1,1,1,1));
} else {
missing_textures.push_back(texfile.get_file());
}
}
} else {
if (effect.emission.color != Color()) {
- material->set_feature(SpatialMaterial::FEATURE_EMISSION, true);
+ material->set_feature(StandardMaterial3D::FEATURE_EMISSION, true);
material->set_emission(effect.emission.color);
}
}
@@ -462,13 +462,13 @@ Error ColladaImport::_create_material(const String &p_target) {
texfile = texfile.replace_first("/", "res://");
}
- Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
+ Ref<Texture2D> texture = ResourceLoader::load(texfile, "Texture2D");
if (texture.is_valid()) {
- material->set_feature(SpatialMaterial::FEATURE_NORMAL_MAPPING, true);
- material->set_texture(SpatialMaterial::TEXTURE_NORMAL, texture);
+ material->set_feature(StandardMaterial3D::FEATURE_NORMAL_MAPPING, true);
+ material->set_texture(StandardMaterial3D::TEXTURE_NORMAL, texture);
//material->set_emission(Color(1,1,1,1));
- //material->set_texture(SpatialMaterial::PARAM_NORMAL,texture);
+ //material->set_texture(StandardMaterial3D::PARAM_NORMAL,texture);
} else {
//missing_textures.push_back(texfile.get_file());
}
@@ -479,9 +479,11 @@ Error ColladaImport::_create_material(const String &p_target) {
material->set_roughness(roughness);
if (effect.double_sided) {
- material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
+ material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
+ }
+ if (effect.unshaded) {
+ material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
}
- material->set_flag(SpatialMaterial::FLAG_UNSHADED, effect.unshaded);
material_cache[p_target] = material;
return OK;
@@ -877,7 +879,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
{
- Ref<SpatialMaterial> material;
+ Ref<StandardMaterial3D> material;
{
@@ -984,7 +986,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, p_use_compression ? Mesh::ARRAY_COMPRESS_DEFAULT : 0);
+ p_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, d, mr, Dictionary(), p_use_compression ? Mesh::ARRAY_COMPRESS_DEFAULT : 0);
if (material.is_valid()) {
if (p_use_mesh_material) {
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
index 53a654c971..aad378c94f 100644
--- a/editor/import/editor_import_plugin.cpp
+++ b/editor/import/editor_import_plugin.cpp
@@ -162,7 +162,7 @@ void EditorImportPlugin::_bind_methods() {
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_import_options", PropertyInfo(Variant::INT, "preset")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_save_extension"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type"));
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::REAL, "get_priority"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::FLOAT, "get_priority"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_import_order"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files")));
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index d4664e1bb9..731d094745 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -764,10 +764,10 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const
return dst_buffer;
}
-PoolVector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
+Vector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
- PoolVector<int> ret;
+ Vector<int> ret;
if (attribs.size() == 0)
return ret;
@@ -776,7 +776,7 @@ PoolVector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &sta
const int ret_size = attribs.size();
ret.resize(ret_size);
{
- PoolVector<int>::Write w = ret.write();
+ int *w = ret.ptrw();
for (int i = 0; i < ret_size; i++) {
w[i] = int(attribs_ptr[i]);
}
@@ -784,10 +784,10 @@ PoolVector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &sta
return ret;
}
-PoolVector<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
+Vector<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
- PoolVector<float> ret;
+ Vector<float> ret;
if (attribs.size() == 0)
return ret;
@@ -796,7 +796,7 @@ PoolVector<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState
const int ret_size = attribs.size();
ret.resize(ret_size);
{
- PoolVector<float>::Write w = ret.write();
+ float *w = ret.ptrw();
for (int i = 0; i < ret_size; i++) {
w[i] = float(attribs_ptr[i]);
}
@@ -804,10 +804,10 @@ PoolVector<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState
return ret;
}
-PoolVector<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
+Vector<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
- PoolVector<Vector2> ret;
+ Vector<Vector2> ret;
if (attribs.size() == 0)
return ret;
@@ -817,7 +817,7 @@ PoolVector<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState
const int ret_size = attribs.size() / 2;
ret.resize(ret_size);
{
- PoolVector<Vector2>::Write w = ret.write();
+ Vector2 *w = ret.ptrw();
for (int i = 0; i < ret_size; i++) {
w[i] = Vector2(attribs_ptr[i * 2 + 0], attribs_ptr[i * 2 + 1]);
}
@@ -825,10 +825,10 @@ PoolVector<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState
return ret;
}
-PoolVector<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
+Vector<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
- PoolVector<Vector3> ret;
+ Vector<Vector3> ret;
if (attribs.size() == 0)
return ret;
@@ -838,7 +838,7 @@ PoolVector<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState
const int ret_size = attribs.size() / 3;
ret.resize(ret_size);
{
- PoolVector<Vector3>::Write w = ret.write();
+ Vector3 *w = ret.ptrw();
for (int i = 0; i < ret_size; i++) {
w[i] = Vector3(attribs_ptr[i * 3 + 0], attribs_ptr[i * 3 + 1], attribs_ptr[i * 3 + 2]);
}
@@ -846,10 +846,10 @@ PoolVector<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState
return ret;
}
-PoolVector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
+Vector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
- PoolVector<Color> ret;
+ Vector<Color> ret;
if (attribs.size() == 0)
return ret;
@@ -866,7 +866,7 @@ PoolVector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &
const int ret_size = attribs.size() / vec_len;
ret.resize(ret_size);
{
- PoolVector<Color>::Write w = ret.write();
+ Color *w = ret.ptrw();
for (int i = 0; i < ret_size; i++) {
w[i] = Color(attribs_ptr[i * vec_len + 0], attribs_ptr[i * vec_len + 1], attribs_ptr[i * vec_len + 2], vec_len == 4 ? attribs_ptr[i * 4 + 3] : 1.0);
}
@@ -984,11 +984,15 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
static const Mesh::PrimitiveType primitives2[7] = {
Mesh::PRIMITIVE_POINTS,
Mesh::PRIMITIVE_LINES,
- Mesh::PRIMITIVE_LINE_LOOP,
- Mesh::PRIMITIVE_LINE_STRIP,
+ Mesh::PRIMITIVE_LINES, //loop not supported, should ce converted
+ Mesh::PRIMITIVE_LINES,
Mesh::PRIMITIVE_TRIANGLES,
Mesh::PRIMITIVE_TRIANGLE_STRIP,
- Mesh::PRIMITIVE_TRIANGLE_FAN,
+ Mesh::PRIMITIVE_TRIANGLES, //fan not supported, should be converted
+#ifndef _MSC_VER
+#warning line loop and triangle fan are not supported and need to be converted to lines and triangles
+#endif
+
};
primitive = primitives2[mode];
@@ -1017,10 +1021,10 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
array[Mesh::ARRAY_BONES] = _decode_accessor_as_ints(state, a["JOINTS_0"], true);
}
if (a.has("WEIGHTS_0")) {
- PoolVector<float> weights = _decode_accessor_as_floats(state, a["WEIGHTS_0"], true);
+ Vector<float> weights = _decode_accessor_as_floats(state, a["WEIGHTS_0"], true);
{ //gltf does not seem to normalize the weights for some reason..
int wc = weights.size();
- PoolVector<float>::Write w = weights.write();
+ float *w = weights.ptrw();
for (int k = 0; k < wc; k += 4) {
float total = 0.0;
@@ -1040,13 +1044,13 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
}
if (p.has("indices")) {
- PoolVector<int> indices = _decode_accessor_as_ints(state, p["indices"], false);
+ Vector<int> indices = _decode_accessor_as_ints(state, p["indices"], false);
if (primitive == Mesh::PRIMITIVE_TRIANGLES) {
//swap around indices, convert ccw to cw for front face
const int is = indices.size();
- const PoolVector<int>::Write w = indices.write();
+ int *w = indices.ptrw();
for (int k = 0; k < is; k += 3) {
SWAP(w[k + 1], w[k + 2]);
}
@@ -1055,13 +1059,13 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
} else if (primitive == Mesh::PRIMITIVE_TRIANGLES) {
//generate indices because they need to be swapped for CW/CCW
- const PoolVector<Vector3> &vertices = array[Mesh::ARRAY_VERTEX];
+ const Vector<Vector3> &vertices = array[Mesh::ARRAY_VERTEX];
ERR_FAIL_COND_V(vertices.size() == 0, ERR_PARSE_ERROR);
- PoolVector<int> indices;
+ Vector<int> indices;
const int vs = vertices.size();
indices.resize(vs);
{
- const PoolVector<int>::Write w = indices.write();
+ int *w = indices.ptrw();
for (int k = 0; k < vs; k += 3) {
w[k] = k;
w[k + 1] = k + 2;
@@ -1123,8 +1127,8 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
array_copy[Mesh::ARRAY_INDEX] = Variant();
if (t.has("POSITION")) {
- PoolVector<Vector3> varr = _decode_accessor_as_vec3(state, t["POSITION"], true);
- const PoolVector<Vector3> src_varr = array[Mesh::ARRAY_VERTEX];
+ Vector<Vector3> varr = _decode_accessor_as_vec3(state, t["POSITION"], true);
+ const Vector<Vector3> src_varr = array[Mesh::ARRAY_VERTEX];
const int size = src_varr.size();
ERR_FAIL_COND_V(size == 0, ERR_PARSE_ERROR);
{
@@ -1132,9 +1136,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
const int max_idx = varr.size();
varr.resize(size);
- const PoolVector<Vector3>::Write w_varr = varr.write();
- const PoolVector<Vector3>::Read r_varr = varr.read();
- const PoolVector<Vector3>::Read r_src_varr = src_varr.read();
+ Vector3 *w_varr = varr.ptrw();
+ const Vector3 *r_varr = varr.ptr();
+ const Vector3 *r_src_varr = src_varr.ptr();
for (int l = 0; l < size; l++) {
if (l < max_idx) {
w_varr[l] = r_varr[l] + r_src_varr[l];
@@ -1146,17 +1150,17 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
array_copy[Mesh::ARRAY_VERTEX] = varr;
}
if (t.has("NORMAL")) {
- PoolVector<Vector3> narr = _decode_accessor_as_vec3(state, t["NORMAL"], true);
- const PoolVector<Vector3> src_narr = array[Mesh::ARRAY_NORMAL];
+ Vector<Vector3> narr = _decode_accessor_as_vec3(state, t["NORMAL"], true);
+ const Vector<Vector3> src_narr = array[Mesh::ARRAY_NORMAL];
int size = src_narr.size();
ERR_FAIL_COND_V(size == 0, ERR_PARSE_ERROR);
{
int max_idx = narr.size();
narr.resize(size);
- const PoolVector<Vector3>::Write w_narr = narr.write();
- const PoolVector<Vector3>::Read r_narr = narr.read();
- const PoolVector<Vector3>::Read r_src_narr = src_narr.read();
+ Vector3 *w_narr = narr.ptrw();
+ const Vector3 *r_narr = narr.ptr();
+ const Vector3 *r_src_narr = src_narr.ptr();
for (int l = 0; l < size; l++) {
if (l < max_idx) {
w_narr[l] = r_narr[l] + r_src_narr[l];
@@ -1168,11 +1172,11 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
array_copy[Mesh::ARRAY_NORMAL] = narr;
}
if (t.has("TANGENT")) {
- const PoolVector<Vector3> tangents_v3 = _decode_accessor_as_vec3(state, t["TANGENT"], true);
- const PoolVector<float> src_tangents = array[Mesh::ARRAY_TANGENT];
+ const Vector<Vector3> tangents_v3 = _decode_accessor_as_vec3(state, t["TANGENT"], true);
+ const Vector<float> src_tangents = array[Mesh::ARRAY_TANGENT];
ERR_FAIL_COND_V(src_tangents.size() == 0, ERR_PARSE_ERROR);
- PoolVector<float> tangents_v4;
+ Vector<float> tangents_v4;
{
@@ -1180,10 +1184,10 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
int size4 = src_tangents.size();
tangents_v4.resize(size4);
- const PoolVector<float>::Write w4 = tangents_v4.write();
+ float *w4 = tangents_v4.ptrw();
- const PoolVector<Vector3>::Read r3 = tangents_v3.read();
- const PoolVector<float>::Read r4 = src_tangents.read();
+ const Vector3 *r3 = tangents_v3.ptr();
+ const float *r4 = src_tangents.ptr();
for (int l = 0; l < size4 / 4; l++) {
@@ -1277,7 +1281,7 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b
} else {
uri = p_base_path.plus_file(uri).replace("\\", "/"); //fix for windows
- Ref<Texture> texture = ResourceLoader::load(uri);
+ Ref<Texture2D> texture = ResourceLoader::load(uri);
state.images.push_back(texture);
continue;
}
@@ -1362,11 +1366,11 @@ Error EditorSceneImporterGLTF::_parse_textures(GLTFState &state) {
return OK;
}
-Ref<Texture> EditorSceneImporterGLTF::_get_texture(GLTFState &state, const GLTFTextureIndex p_texture) {
- ERR_FAIL_INDEX_V(p_texture, state.textures.size(), Ref<Texture>());
+Ref<Texture2D> EditorSceneImporterGLTF::_get_texture(GLTFState &state, const GLTFTextureIndex p_texture) {
+ ERR_FAIL_INDEX_V(p_texture, state.textures.size(), Ref<Texture2D>());
const GLTFImageIndex image = state.textures[p_texture].src_image;
- ERR_FAIL_INDEX_V(image, state.images.size(), Ref<Texture>());
+ ERR_FAIL_INDEX_V(image, state.images.size(), Ref<Texture2D>());
return state.images[image];
}
@@ -1381,7 +1385,7 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
const Dictionary &d = materials[i];
- Ref<SpatialMaterial> material;
+ Ref<StandardMaterial3D> material;
material.instance();
if (d.has("name")) {
material->set_name(d["name"]);
@@ -1401,7 +1405,7 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
if (mr.has("baseColorTexture")) {
const Dictionary &bct = mr["baseColorTexture"];
if (bct.has("index")) {
- material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, _get_texture(state, bct["index"]));
+ material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, _get_texture(state, bct["index"]));
}
if (!mr.has("baseColorFactor")) {
material->set_albedo(Color(1, 1, 1));
@@ -1423,11 +1427,11 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
if (mr.has("metallicRoughnessTexture")) {
const Dictionary &bct = mr["metallicRoughnessTexture"];
if (bct.has("index")) {
- const Ref<Texture> t = _get_texture(state, bct["index"]);
- material->set_texture(SpatialMaterial::TEXTURE_METALLIC, t);
- material->set_metallic_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_BLUE);
- material->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, t);
- material->set_roughness_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_GREEN);
+ const Ref<Texture2D> t = _get_texture(state, bct["index"]);
+ material->set_texture(StandardMaterial3D::TEXTURE_METALLIC, t);
+ material->set_metallic_texture_channel(StandardMaterial3D::TEXTURE_CHANNEL_BLUE);
+ material->set_texture(StandardMaterial3D::TEXTURE_ROUGHNESS, t);
+ material->set_roughness_texture_channel(StandardMaterial3D::TEXTURE_CHANNEL_GREEN);
if (!mr.has("metallicFactor")) {
material->set_metallic(1);
}
@@ -1441,8 +1445,8 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
if (d.has("normalTexture")) {
const Dictionary &bct = d["normalTexture"];
if (bct.has("index")) {
- material->set_texture(SpatialMaterial::TEXTURE_NORMAL, _get_texture(state, bct["index"]));
- material->set_feature(SpatialMaterial::FEATURE_NORMAL_MAPPING, true);
+ material->set_texture(StandardMaterial3D::TEXTURE_NORMAL, _get_texture(state, bct["index"]));
+ material->set_feature(StandardMaterial3D::FEATURE_NORMAL_MAPPING, true);
}
if (bct.has("scale")) {
material->set_normal_scale(bct["scale"]);
@@ -1451,9 +1455,9 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
if (d.has("occlusionTexture")) {
const Dictionary &bct = d["occlusionTexture"];
if (bct.has("index")) {
- material->set_texture(SpatialMaterial::TEXTURE_AMBIENT_OCCLUSION, _get_texture(state, bct["index"]));
- material->set_ao_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_RED);
- material->set_feature(SpatialMaterial::FEATURE_AMBIENT_OCCLUSION, true);
+ material->set_texture(StandardMaterial3D::TEXTURE_AMBIENT_OCCLUSION, _get_texture(state, bct["index"]));
+ material->set_ao_texture_channel(StandardMaterial3D::TEXTURE_CHANNEL_RED);
+ material->set_feature(StandardMaterial3D::FEATURE_AMBIENT_OCCLUSION, true);
}
}
@@ -1461,7 +1465,7 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
const Array &arr = d["emissiveFactor"];
ERR_FAIL_COND_V(arr.size() != 3, ERR_PARSE_ERROR);
const Color c = Color(arr[0], arr[1], arr[2]).to_srgb();
- material->set_feature(SpatialMaterial::FEATURE_EMISSION, true);
+ material->set_feature(StandardMaterial3D::FEATURE_EMISSION, true);
material->set_emission(c);
}
@@ -1469,8 +1473,8 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
if (d.has("emissiveTexture")) {
const Dictionary &bct = d["emissiveTexture"];
if (bct.has("index")) {
- material->set_texture(SpatialMaterial::TEXTURE_EMISSION, _get_texture(state, bct["index"]));
- material->set_feature(SpatialMaterial::FEATURE_EMISSION, true);
+ material->set_texture(StandardMaterial3D::TEXTURE_EMISSION, _get_texture(state, bct["index"]));
+ material->set_feature(StandardMaterial3D::FEATURE_EMISSION, true);
material->set_emission(Color(0, 0, 0));
}
}
@@ -1478,17 +1482,16 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
if (d.has("doubleSided")) {
const bool ds = d["doubleSided"];
if (ds) {
- material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
+ material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
}
}
if (d.has("alphaMode")) {
const String &am = d["alphaMode"];
if (am == "BLEND") {
- material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
- material->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_ALPHA_OPAQUE_PREPASS);
+ material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA_DEPTH_PRE_PASS);
} else if (am == "MASK") {
- material->set_flag(SpatialMaterial::FLAG_USE_ALPHA_SCISSOR, true);
+ material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA_SCISSOR);
if (d.has("alphaCutoff")) {
material->set_alpha_scissor_threshold(d["alphaCutoff"]);
} else {
@@ -2180,6 +2183,8 @@ Error EditorSceneImporterGLTF::_map_skin_joints_indices_to_skeleton_bone_indices
const GLTFNodeIndex node_i = skin.joints_original[joint_index];
const GLTFNode *node = state.nodes[node_i];
+ skin.joint_i_to_name.insert(joint_index, node->name);
+
const int bone_index = skeleton.godot_skeleton->find_bone(node->name);
ERR_FAIL_COND_V(bone_index < 0, FAILED);
@@ -2201,12 +2206,18 @@ Error EditorSceneImporterGLTF::_create_skins(GLTFState &state) {
const bool has_ibms = !gltf_skin.inverse_binds.empty();
for (int joint_i = 0; joint_i < gltf_skin.joints_original.size(); ++joint_i) {
- int bone_i = gltf_skin.joint_i_to_bone_i[joint_i];
+ Transform xform;
if (has_ibms) {
- skin->add_bind(bone_i, gltf_skin.inverse_binds[joint_i]);
+ xform = gltf_skin.inverse_binds[joint_i];
+ }
+
+ if (state.use_named_skin_binds) {
+ StringName name = gltf_skin.joint_i_to_name[joint_i];
+ skin->add_named_bind(name, xform);
} else {
- skin->add_bind(bone_i, Transform());
+ int bone_i = gltf_skin.joint_i_to_bone_i[joint_i];
+ skin->add_bind(bone_i, xform);
}
}
@@ -2394,9 +2405,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) {
}
}
- const PoolVector<float> times = _decode_accessor_as_floats(state, input, false);
+ const Vector<float> times = _decode_accessor_as_floats(state, input, false);
if (path == "translation") {
- const PoolVector<Vector3> translations = _decode_accessor_as_vec3(state, output, false);
+ const Vector<Vector3> translations = _decode_accessor_as_vec3(state, output, false);
track->translation_track.interpolation = interp;
track->translation_track.times = Variant(times); //convert via variant
track->translation_track.values = Variant(translations); //convert via variant
@@ -2406,12 +2417,12 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) {
track->rotation_track.times = Variant(times); //convert via variant
track->rotation_track.values = rotations; //convert via variant
} else if (path == "scale") {
- const PoolVector<Vector3> scales = _decode_accessor_as_vec3(state, output, false);
+ const Vector<Vector3> scales = _decode_accessor_as_vec3(state, output, false);
track->scale_track.interpolation = interp;
track->scale_track.times = Variant(times); //convert via variant
track->scale_track.values = Variant(scales); //convert via variant
} else if (path == "weights") {
- const PoolVector<float> weights = _decode_accessor_as_floats(state, output, false);
+ const Vector<float> weights = _decode_accessor_as_floats(state, output, false);
ERR_FAIL_INDEX_V(state.nodes[node]->mesh, state.meshes.size(), ERR_PARSE_ERROR);
const GLTFMesh *mesh = &state.meshes[state.nodes[node]->mesh];
@@ -2424,7 +2435,7 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) {
ERR_FAIL_COND_V_MSG(weights.size() != expected_value_count, ERR_PARSE_ERROR, "Invalid weight data, expected " + itos(expected_value_count) + " weight values, got " + itos(weights.size()) + " instead.");
const int wlen = weights.size() / wc;
- PoolVector<float>::Read r = weights.read();
+ const float *r = weights.ptr();
for (int k = 0; k < wc; k++) { //separate tracks, having them together is not such a good idea
GLTFAnimation::Channel<float> cf;
cf.interpolation = interp;
@@ -2615,7 +2626,7 @@ struct EditorSceneImporterGLTFInterpolate {
const float t2 = t * t;
const float t3 = t2 * t;
- return 0.5f * ((2.0f * p1) + (-p0 + p2) * t + (2.0f * p0 - 5.0f * p1 + 4 * p2 - p3) * t2 + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3);
+ return 0.5f * ((2.0f * p1) + (-p0 + p2) * t + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * t2 + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3);
}
T bezier(T start, T control_1, T control_2, T end, float t) {
@@ -2992,6 +3003,7 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla
state.major_version = version.get_slice(".", 0).to_int();
state.minor_version = version.get_slice(".", 1).to_int();
+ state.use_named_skin_binds = p_flags & IMPORT_USE_NAMED_SKIN_BINDS;
/* STEP 0 PARSE SCENE */
Error err = _parse_scenes(state);
diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h
index 78d7106b0d..5d2711483b 100644
--- a/editor/import/editor_scene_importer_gltf.h
+++ b/editor/import/editor_scene_importer_gltf.h
@@ -231,6 +231,7 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
// A mapping from the joint indices (in the order of joints_original) to the
// Godot Skeleton's bone_indices
Map<int, int> joint_i_to_bone_i;
+ Map<int, StringName> joint_i_to_name;
// The Actual Skin that will be created as a mapping between the IBM's of this skin
// to the generated skeleton for the mesh instances.
@@ -298,6 +299,8 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
int minor_version;
Vector<uint8_t> glb_data;
+ bool use_named_skin_binds;
+
Vector<GLTFNode *> nodes;
Vector<Vector<uint8_t> > buffers;
Vector<GLTFBufferView> buffer_views;
@@ -310,7 +313,7 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
Vector<int> root_nodes;
Vector<GLTFTexture> textures;
- Vector<Ref<Texture> > images;
+ Vector<Ref<Texture2D> > images;
Vector<GLTFSkin> skins;
Vector<GLTFCamera> cameras;
@@ -335,7 +338,7 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
String _sanitize_bone_name(const String &name);
String _gen_unique_bone_name(GLTFState &state, const GLTFSkeletonIndex skel_i, const String &p_name);
- Ref<Texture> _get_texture(GLTFState &state, const GLTFTextureIndex p_texture);
+ Ref<Texture2D> _get_texture(GLTFState &state, const GLTFTextureIndex p_texture);
Error _parse_json(const String &p_path, GLTFState &state);
Error _parse_glb(const String &p_path, GLTFState &state);
@@ -352,11 +355,11 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
Error _decode_buffer_view(GLTFState &state, double *dst, const GLTFBufferViewIndex p_buffer_view, const int skip_every, const int skip_bytes, const int element_size, const int count, const GLTFType type, const int component_count, const int component_type, const int component_size, const bool normalized, const int byte_offset, const bool for_vertex);
Vector<double> _decode_accessor(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
- PoolVector<float> _decode_accessor_as_floats(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
- PoolVector<int> _decode_accessor_as_ints(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
- PoolVector<Vector2> _decode_accessor_as_vec2(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
- PoolVector<Vector3> _decode_accessor_as_vec3(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
- PoolVector<Color> _decode_accessor_as_color(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
+ Vector<float> _decode_accessor_as_floats(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
+ Vector<int> _decode_accessor_as_ints(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
+ Vector<Vector2> _decode_accessor_as_vec2(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
+ Vector<Vector3> _decode_accessor_as_vec3(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
+ Vector<Color> _decode_accessor_as_color(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Quat> _decode_accessor_as_quat(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Transform2D> _decode_accessor_as_xform2d(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Basis> _decode_accessor_as_basis(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp
index c6fdbd1378..252af9050b 100644
--- a/editor/import/resource_importer_bitmask.cpp
+++ b/editor/import/resource_importer_bitmask.cpp
@@ -75,7 +75,7 @@ String ResourceImporterBitMap::get_preset_name(int p_idx) const {
void ResourceImporterBitMap::get_import_options(List<ImportOption> *r_options, int p_preset) const {
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "create_from", PROPERTY_HINT_ENUM, "Black & White,Alpha"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "threshold", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.5));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "threshold", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.5));
}
Error ResourceImporterBitMap::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
@@ -94,7 +94,6 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String &
Ref<BitMap> bitmap;
bitmap.instance();
bitmap->create(Size2(w, h));
- image->lock();
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp
index 9b819bc341..d472070808 100644
--- a/editor/import/resource_importer_layered_texture.cpp
+++ b/editor/import/resource_importer_layered_texture.cpp
@@ -38,26 +38,74 @@
#include "editor/editor_node.h"
#include "scene/resources/texture.h"
+#if 0
String ResourceImporterLayeredTexture::get_importer_name() const {
- return is_3d ? "texture_3d" : "texture_array";
+ switch (mode) {
+ case MODE_CUBEMAP: {
+ return "cubemap_texture";
+ } break;
+ case MODE_2D_ARRAY: {
+ return "2d_array_texture";
+ } break;
+ case MODE_CUBEMAP_ARRAY: {
+ return "cubemap_array_texture";
+ } break;
+ }
+
+ ERR_FAIL_V("");
}
String ResourceImporterLayeredTexture::get_visible_name() const {
- return is_3d ? "Texture3D" : "TextureArray";
+ switch (mode) {
+ case MODE_CUBEMAP: {
+ return "Cubemap";
+ } break;
+ case MODE_2D_ARRAY: {
+ return "Texture2DArray";
+ } break;
+ case MODE_CUBEMAP_ARRAY: {
+ return "CubemapArray";
+ } break;
+ }
+
+ ERR_FAIL_V("");
}
void ResourceImporterLayeredTexture::get_recognized_extensions(List<String> *p_extensions) const {
ImageLoader::get_recognized_extensions(p_extensions);
}
String ResourceImporterLayeredTexture::get_save_extension() const {
- return is_3d ? "tex3d" : "texarr";
+ switch (mode) {
+ case MODE_CUBEMAP: {
+ return "cube";
+ } break;
+ case MODE_2D_ARRAY: {
+ return "tex2darr";
+ } break;
+ case MODE_CUBEMAP_ARRAY: {
+ return "cubearr";
+ } break;
+ }
+
+ ERR_FAIL_V(String());
}
String ResourceImporterLayeredTexture::get_resource_type() const {
- return is_3d ? "Texture3D" : "TextureArray";
+ switch (mode) {
+ case MODE_CUBEMAP: {
+ return "Cubemap";
+ } break;
+ case MODE_2D_ARRAY: {
+ return "Texture2DArray";
+ } break;
+ case MODE_CUBEMAP_ARRAY: {
+ return "CubemapArray";
+ } break;
+ }
+ ERR_FAIL_V(String());
}
bool ResourceImporterLayeredTexture::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
@@ -66,47 +114,48 @@ bool ResourceImporterLayeredTexture::get_option_visibility(const String &p_optio
}
int ResourceImporterLayeredTexture::get_preset_count() const {
- return 3;
+ return 0;
}
String ResourceImporterLayeredTexture::get_preset_name(int p_idx) const {
- static const char *preset_names[] = {
- "3D",
- "2D",
- "ColorCorrect"
- };
-
- return preset_names[p_idx];
+ return "";
}
void ResourceImporterLayeredTexture::get_import_options(List<ImportOption> *r_options, int p_preset) const {
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Video RAM,Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 1 : 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Video RAM,Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 1));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress/no_bptc_if_rgb"), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirrored"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/filter"), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/mipmaps"), p_preset == PRESET_COLOR_CORRECT ? 0 : 1));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/srgb", PROPERTY_HINT_ENUM, "Disable,Enable"), p_preset == PRESET_3D ? 1 : 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slices/horizontal", PROPERTY_HINT_RANGE, "1,256,1"), p_preset == PRESET_COLOR_CORRECT ? 16 : 8));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slices/vertical", PROPERTY_HINT_RANGE, "1,256,1"), p_preset == PRESET_COLOR_CORRECT ? 1 : 8));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/channel_pack", PROPERTY_HINT_ENUM, "sRGB Friendly,Optimized"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/mipmaps"), true));
+ if (mode == MODE_2D_ARRAY) {
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slices/horizontal", PROPERTY_HINT_RANGE, "1,256,1"), 8));
+ }
+ if (mode == MODE_2D_ARRAY || mode == MODE_CUBEMAP_ARRAY) {
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slices/vertical", PROPERTY_HINT_RANGE, "1,256,1"), 8));
+ }
}
-void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_images, const String &p_to_path, int p_compress_mode, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags) {
+void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_images, const String &p_to_path, int p_compress_mode, Image::CompressMode p_vram_compression, bool p_mipmaps) {
FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE);
f->store_8('G');
f->store_8('D');
- if (is_3d) {
- f->store_8('3');
- } else {
- f->store_8('A');
+ switch (mode) {
+ case MODE_2D_ARRAY: f->store_8('A'); break;
+ case MODE_CUBEMAP: f->store_8('C'); break;
+ case MODE_CUBEMAP_ARRAY: f->store_8('X'); break;
}
+
f->store_8('T'); //godot streamable texture
f->store_32(p_images[0]->get_width());
f->store_32(p_images[0]->get_height());
f->store_32(p_images.size()); //depth
- f->store_32(p_texture_flags);
+ uint32_t flags = 0;
+ if (p_mipmaps) {
+ flags |= TEXTURE_FLAGS_MIPMAPS;
+ }
+ f->store_32(flags);
if (p_compress_mode != COMPRESS_VIDEO_RAM) {
//vram needs to do a first compression to tell what the format is, for the rest its ok
f->store_32(p_images[0]->get_format());
@@ -138,11 +187,11 @@ void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_imag
image->shrink_x2();
}
- PoolVector<uint8_t> data = Image::lossless_packer(image);
+ Vector<uint8_t> data = Image::lossless_packer(image);
int data_len = data.size();
f->store_32(data_len);
- PoolVector<uint8_t>::Read r = data.read();
+ const uint8_t* r = data.ptr();
f->store_buffer(r.ptr(), data_len);
}
@@ -161,10 +210,10 @@ void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_imag
f->store_32(p_compress_mode); // 0 - lossless (PNG), 1 - vram, 2 - uncompressed
}
- PoolVector<uint8_t> data = image->get_data();
+ Vector<uint8_t> data = image->get_data();
int dl = data.size();
- PoolVector<uint8_t>::Read r = data.read();
+ const uint8_t* r = data.ptr();
f->store_buffer(r.ptr(), dl);
} break;
case COMPRESS_UNCOMPRESSED: {
@@ -177,10 +226,10 @@ void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_imag
image->clear_mipmaps();
}
- PoolVector<uint8_t> data = image->get_data();
+ Vector<uint8_t> data = image->get_data();
int dl = data.size();
- PoolVector<uint8_t>::Read r = data.read();
+ const uint8_t* r = data.ptr();
f->store_buffer(r.ptr(), dl);
@@ -195,12 +244,18 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
int compress_mode = p_options["compress/mode"];
int no_bptc_if_rgb = p_options["compress/no_bptc_if_rgb"];
- int repeat = p_options["flags/repeat"];
- bool filter = p_options["flags/filter"];
bool mipmaps = p_options["flags/mipmaps"];
- int srgb = p_options["flags/srgb"];
- int hslices = p_options["slices/horizontal"];
- int vslices = p_options["slices/vertical"];
+ int channel_pack = p_options["compress/channel_pack"];
+ int hslices = (p_options.has("slices/horizontal")) ? int(p_options["slices/horizontal"]) : 0;
+ int vslices = (p_options.has("slices/vertical")) ? int(p_options["slices/vertical"]) : 0;
+
+ if (mode == MODE_CUBEMAP) {
+ hslices = 3;
+ vslices = 2;
+ } else if (mode == MODE_CUBEMAP_ARRAY) {
+ hslices = 3;
+ vslices *= 2; //put cubemaps vertically
+ }
Ref<Image> image;
image.instance();
@@ -208,17 +263,9 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
if (err != OK)
return err;
- int tex_flags = 0;
- if (repeat > 0)
- tex_flags |= Texture::FLAG_REPEAT;
- if (repeat == 2)
- tex_flags |= Texture::FLAG_MIRRORED_REPEAT;
- if (filter)
- tex_flags |= Texture::FLAG_FILTER;
- if (mipmaps || compress_mode == COMPRESS_VIDEO_RAM)
- tex_flags |= Texture::FLAG_MIPMAPS;
- if (srgb == 1)
- tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR;
+ if (compress_mode == COMPRESS_VIDEO_RAM) {
+ mipmaps = true;
+ }
Vector<Ref<Image> > slices;
@@ -228,7 +275,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
//optimize
if (compress_mode == COMPRESS_VIDEO_RAM) {
//if using video ram, optimize
- if (srgb) {
+ if (channel_pack == 0) {
//remove alpha if not needed, so compression is more efficient
if (image->get_format() == Image::FORMAT_RGBA8 && !image->detect_alpha()) {
image->convert(Image::FORMAT_RGB8);
@@ -266,8 +313,8 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
encode_bptc = true;
if (no_bptc_if_rgb) {
- Image::DetectChannels channels = image->get_detected_channels();
- if (channels != Image::DETECTED_LA && channels != Image::DETECTED_RGBA) {
+ Image::UsedChannels channels = image->detect_used_channels();
+ if (channels != Image::USED_CHANNELS_LA && channels != Image::USED_CHANNELS_RGBA) {
encode_bptc = false;
}
}
@@ -277,14 +324,14 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
if (encode_bptc) {
- _save_tex(slices, p_save_path + ".bptc." + extension, compress_mode, Image::COMPRESS_BPTC, mipmaps, tex_flags);
+ _save_tex(slices, p_save_path + ".bptc." + extension, compress_mode, Image::COMPRESS_BPTC, mipmaps);
r_platform_variants->push_back("bptc");
ok_on_pc = true;
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) {
- _save_tex(slices, p_save_path + ".s3tc." + extension, compress_mode, Image::COMPRESS_S3TC, mipmaps, tex_flags);
+ _save_tex(slices, p_save_path + ".s3tc." + extension, compress_mode, Image::COMPRESS_S3TC, mipmaps);
r_platform_variants->push_back("s3tc");
ok_on_pc = true;
formats_imported.push_back("s3tc");
@@ -292,20 +339,20 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) {
- _save_tex(slices, p_save_path + ".etc2." + extension, compress_mode, Image::COMPRESS_ETC2, mipmaps, tex_flags);
+ _save_tex(slices, p_save_path + ".etc2." + extension, compress_mode, Image::COMPRESS_ETC2, mipmaps);
r_platform_variants->push_back("etc2");
formats_imported.push_back("etc2");
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) {
- _save_tex(slices, p_save_path + ".etc." + extension, compress_mode, Image::COMPRESS_ETC, mipmaps, tex_flags);
+ _save_tex(slices, p_save_path + ".etc." + extension, compress_mode, Image::COMPRESS_ETC, mipmaps);
r_platform_variants->push_back("etc");
formats_imported.push_back("etc");
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) {
- _save_tex(slices, p_save_path + ".pvrtc." + extension, compress_mode, Image::COMPRESS_PVRTC4, mipmaps, tex_flags);
+ _save_tex(slices, p_save_path + ".pvrtc." + extension, compress_mode, Image::COMPRESS_PVRTC4, mipmaps);
r_platform_variants->push_back("pvrtc");
formats_imported.push_back("pvrtc");
}
@@ -315,7 +362,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
}
} else {
//import normally
- _save_tex(slices, p_save_path + "." + extension, compress_mode, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags);
+ _save_tex(slices, p_save_path + "." + extension, compress_mode, Image::COMPRESS_S3TC /*this is ignored */, mipmaps);
}
if (r_metadata) {
@@ -396,8 +443,9 @@ ResourceImporterLayeredTexture *ResourceImporterLayeredTexture::singleton = NULL
ResourceImporterLayeredTexture::ResourceImporterLayeredTexture() {
singleton = this;
- is_3d = true;
+ mode = MODE_CUBEMAP;
}
ResourceImporterLayeredTexture::~ResourceImporterLayeredTexture() {
}
+#endif
diff --git a/editor/import/resource_importer_layered_texture.h b/editor/import/resource_importer_layered_texture.h
index 6dc4b6ed3c..6a6bc89a81 100644
--- a/editor/import/resource_importer_layered_texture.h
+++ b/editor/import/resource_importer_layered_texture.h
@@ -28,18 +28,61 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#if 0
+/*************************************************************************/
+/* resource_importer_layered_texture.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#ifndef RESOURCE_IMPORTER_LAYERED_TEXTURE_H
#define RESOURCE_IMPORTER_LAYERED_TEXTURE_H
#include "core/image.h"
#include "core/io/resource_importer.h"
+
class StreamTexture;
class ResourceImporterLayeredTexture : public ResourceImporter {
GDCLASS(ResourceImporterLayeredTexture, ResourceImporter);
+public:
+ enum Mode {
+ MODE_CUBEMAP,
+ MODE_2D_ARRAY,
+ MODE_CUBEMAP_ARRAY
+ };
+
+ enum TextureFlags {
+ TEXTURE_FLAGS_MIPMAPS = 1
+ };
- bool is_3d;
+private:
+ Mode mode;
static const char *compression_formats[];
protected:
@@ -57,12 +100,6 @@ public:
virtual String get_save_extension() const;
virtual String get_resource_type() const;
- enum Preset {
- PRESET_3D,
- PRESET_2D,
- PRESET_COLOR_CORRECT,
- };
-
enum CompressMode {
COMPRESS_LOSSLESS,
COMPRESS_VIDEO_RAM,
@@ -75,7 +112,7 @@ public:
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
- void _save_tex(const Vector<Ref<Image> > &p_images, const String &p_to_path, int p_compress_mode, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags);
+ void _save_tex(const Vector<Ref<Image> > &p_images, const String &p_to_path, int p_compress_mode, Image::CompressMode p_vram_compression, bool p_mipmaps);
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL);
@@ -84,8 +121,11 @@ public:
virtual bool are_import_settings_valid(const String &p_path) const;
virtual String get_import_settings_string() const;
- void set_3d(bool p_3d) { is_3d = p_3d; }
+ void set_mode(Mode p_mode) { mode = p_mode; }
+
ResourceImporterLayeredTexture();
~ResourceImporterLayeredTexture();
};
#endif // RESOURCE_IMPORTER_LAYERED_TEXTURE_H
+
+#endif
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index bdd6a197f8..7fd3bcc478 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -42,12 +42,12 @@ uint32_t EditorOBJImporter::get_import_flags() const {
return IMPORT_SCENE;
}
-static Error _parse_material_library(const String &p_path, Map<String, Ref<SpatialMaterial> > &material_map, List<String> *r_missing_deps) {
+static Error _parse_material_library(const String &p_path, Map<String, Ref<StandardMaterial3D> > &material_map, List<String> *r_missing_deps) {
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open MTL file '%s', it may not exist or not be readable.", p_path));
- Ref<SpatialMaterial> current;
+ Ref<StandardMaterial3D> current;
String current_name;
String base_path = p_path.get_base_dir();
while (true) {
@@ -102,7 +102,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
c.a = d;
current->set_albedo(c);
if (c.a < 0.99) {
- current->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ current->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
}
} else if (l.begins_with("Tr ")) {
//normal
@@ -114,7 +114,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
c.a = 1.0 - d;
current->set_albedo(c);
if (c.a < 0.99) {
- current->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ current->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
}
} else if (l.begins_with("map_Ka ")) {
@@ -133,10 +133,10 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
path = base_path.plus_file(p);
}
- Ref<Texture> texture = ResourceLoader::load(path);
+ Ref<Texture2D> texture = ResourceLoader::load(path);
if (texture.is_valid()) {
- current->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
+ current->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, texture);
} else if (r_missing_deps) {
r_missing_deps->push_back(path);
}
@@ -153,10 +153,10 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
path = base_path.plus_file(p);
}
- Ref<Texture> texture = ResourceLoader::load(path);
+ Ref<Texture2D> texture = ResourceLoader::load(path);
if (texture.is_valid()) {
- current->set_texture(SpatialMaterial::TEXTURE_METALLIC, texture);
+ current->set_texture(StandardMaterial3D::TEXTURE_METALLIC, texture);
} else if (r_missing_deps) {
r_missing_deps->push_back(path);
}
@@ -173,10 +173,10 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
path = base_path.plus_file(p);
}
- Ref<Texture> texture = ResourceLoader::load(path);
+ Ref<Texture2D> texture = ResourceLoader::load(path);
if (texture.is_valid()) {
- current->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, texture);
+ current->set_texture(StandardMaterial3D::TEXTURE_ROUGHNESS, texture);
} else if (r_missing_deps) {
r_missing_deps->push_back(path);
}
@@ -187,11 +187,11 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
String p = l.replace("map_bump", "").replace("\\", "/").strip_edges();
String path = base_path.plus_file(p);
- Ref<Texture> texture = ResourceLoader::load(path);
+ Ref<Texture2D> texture = ResourceLoader::load(path);
if (texture.is_valid()) {
- current->set_feature(SpatialMaterial::FEATURE_NORMAL_MAPPING, true);
- current->set_texture(SpatialMaterial::TEXTURE_NORMAL, texture);
+ current->set_feature(StandardMaterial3D::FEATURE_NORMAL_MAPPING, true);
+ current->set_texture(StandardMaterial3D::TEXTURE_NORMAL, texture);
} else if (r_missing_deps) {
r_missing_deps->push_back(path);
}
@@ -221,7 +221,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p
Vector<Vector2> uvs;
String name;
- Map<String, Map<String, Ref<SpatialMaterial> > > material_map;
+ Map<String, Map<String, Ref<StandardMaterial3D> > > material_map;
Ref<SurfaceTool> surf_tool = memnew(SurfaceTool);
surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
@@ -397,7 +397,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p
current_material_library = l.replace("mtllib", "").strip_edges();
if (!material_map.has(current_material_library)) {
- Map<String, Ref<SpatialMaterial> > lib;
+ Map<String, Ref<StandardMaterial3D> > lib;
Error err = _parse_material_library(current_material_library, lib, r_missing_deps);
if (err == ERR_CANT_OPEN) {
String dir = p_path.get_base_dir();
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 0774d0b5dc..9fb6be50d9 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -324,19 +324,19 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
for (int i = 0; i < m->get_surface_count(); i++) {
- Ref<SpatialMaterial> mat = m->surface_get_material(i);
+ Ref<StandardMaterial3D> mat = m->surface_get_material(i);
if (!mat.is_valid())
continue;
if (_teststr(mat->get_name(), "alpha")) {
- mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
mat->set_name(_fixstr(mat->get_name(), "alpha"));
}
if (_teststr(mat->get_name(), "vcol")) {
- mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
- mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
mat->set_name(_fixstr(mat->get_name(), "vcol"));
}
}
@@ -1160,7 +1160,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
bool scenes_out = p_preset == PRESET_MULTIPLE_SCENES || p_preset == PRESET_MULTIPLE_SCENES_AND_MATERIALS;
bool animations_out = p_preset == PRESET_SEPARATE_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MATERIALS_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_MATERIALS_AND_ANIMATIONS;
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/custom_script", PROPERTY_HINT_FILE, script_ext_hint), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "nodes/storage", PROPERTY_HINT_ENUM, "Single Scene,Instanced Sub-Scenes"), scenes_out ? 1 : 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "materials/location", PROPERTY_HINT_ENUM, "Node,Mesh"), (meshes_out || materials_out) ? 1 : 0));
@@ -1170,17 +1170,18 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/ensure_tangents"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/storage", PROPERTY_HINT_ENUM, "Built-In,Files (.mesh),Files (.tres)"), meshes_out ? 1 : 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/light_baking", PROPERTY_HINT_ENUM, "Disabled,Enable,Gen Lightmaps", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.1));
+ 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, "external_files/store_in_subdir"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "animation/filter_script", PROPERTY_HINT_MULTILINE_TEXT), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "animation/storage", PROPERTY_HINT_ENUM, "Built-In,Files (.anim),Files (.tres)", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), animations_out));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/keep_custom_tracks"), animations_out));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/optimizer/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/optimizer/max_linear_error"), 0.05));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/optimizer/max_angular_error"), 0.01));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/optimizer/max_angle"), 22));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/optimizer/max_linear_error"), 0.05));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/optimizer/max_angular_error"), 0.01));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/optimizer/max_angle"), 22));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/optimizer/remove_unused_tracks"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "animation/clips/amount", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0));
for (int i = 0; i < 256; i++) {
@@ -1313,6 +1314,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
if (int(p_options["materials/location"]) == 0)
import_flags |= EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES;
+ if (bool(p_options["skins/use_named_skins"]))
+ import_flags |= EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS;
+
Error err = OK;
List<String> missing_deps; // for now, not much will be done with this
Node *scene = importer->import_scene(src_path, import_flags, fps, &missing_deps, &err);
@@ -1473,7 +1477,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
} else {
post_import_script = Ref<EditorScenePostImport>(memnew(EditorScenePostImport));
- post_import_script->set_script(scr.get_ref_ptr());
+ post_import_script->set_script(scr);
if (!post_import_script->get_script_instance()) {
EditorNode::add_io_error(TTR("Invalid/broken script for post-import (check console):") + " " + post_import_script_path);
post_import_script.unref();
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index 2691b224eb..20e7af15b5 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -59,7 +59,8 @@ public:
IMPORT_GENERATE_TANGENT_ARRAYS = 256,
IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 512,
IMPORT_MATERIALS_IN_INSTANCES = 1024,
- IMPORT_USE_COMPRESSION = 2048
+ IMPORT_USE_COMPRESSION = 2048,
+ IMPORT_USE_NAMED_SKIN_BINDS = 4096,
};
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 88547280ce..3254b32dae 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -32,20 +32,22 @@
#include "core/io/config_file.h"
#include "core/io/image_loader.h"
+#include "core/version.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
-#include "scene/resources/texture.h"
-void ResourceImporterTexture::_texture_reimport_srgb(const Ref<StreamTexture> &p_tex) {
+void ResourceImporterTexture::_texture_reimport_roughness(const Ref<StreamTexture> &p_tex, const String &p_normal_path, VS::TextureDetectRoughnessChannel p_channel) {
singleton->mutex->lock();
StringName path = p_tex->get_path();
if (!singleton->make_flags.has(path)) {
- singleton->make_flags[path] = 0;
+ singleton->make_flags[path] = MakeInfo();
}
- singleton->make_flags[path] |= MAKE_SRGB_FLAG;
+ singleton->make_flags[path].flags |= MAKE_ROUGHNESS_FLAG;
+ singleton->make_flags[path].channel_for_roughness = p_channel;
+ singleton->make_flags[path].normal_path_for_roughness = p_normal_path;
singleton->mutex->unlock();
}
@@ -56,10 +58,10 @@ void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture> &p_t
StringName path = p_tex->get_path();
if (!singleton->make_flags.has(path)) {
- singleton->make_flags[path] = 0;
+ singleton->make_flags[path] = MakeInfo();
}
- singleton->make_flags[path] |= MAKE_3D_FLAG;
+ singleton->make_flags[path].flags |= MAKE_3D_FLAG;
singleton->mutex->unlock();
}
@@ -70,10 +72,10 @@ void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture>
StringName path = p_tex->get_path();
if (!singleton->make_flags.has(path)) {
- singleton->make_flags[path] = 0;
+ singleton->make_flags[path] = MakeInfo();
}
- singleton->make_flags[path] |= MAKE_NORMAL_FLAG;
+ singleton->make_flags[path].flags |= MAKE_NORMAL_FLAG;
singleton->mutex->unlock();
}
@@ -91,7 +93,7 @@ void ResourceImporterTexture::update_imports() {
}
Vector<String> to_reimport;
- for (Map<StringName, int>::Element *E = make_flags.front(); E; E = E->next()) {
+ for (Map<StringName, MakeInfo>::Element *E = make_flags.front(); E; E = E->next()) {
Ref<ConfigFile> cf;
cf.instance();
@@ -101,22 +103,27 @@ void ResourceImporterTexture::update_imports() {
ERR_CONTINUE(err != OK);
bool changed = false;
- if (E->get() & MAKE_SRGB_FLAG && int(cf->get_value("params", "flags/srgb")) == 2) {
- cf->set_value("params", "flags/srgb", 1);
+
+ if (E->get().flags & MAKE_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) {
+ cf->set_value("params", "compress/normal_map", 1);
changed = true;
}
- if (E->get() & MAKE_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) {
- cf->set_value("params", "compress/normal_map", 1);
+ if (E->get().flags & MAKE_ROUGHNESS_FLAG && int(cf->get_value("params", "roughness/mode")) == 0) {
+ cf->set_value("params", "roughness/mode", E->get().channel_for_roughness + 2);
+ cf->set_value("params", "roughness/src_normal", E->get().normal_path_for_roughness);
changed = true;
}
- if (E->get() & MAKE_3D_FLAG && bool(cf->get_value("params", "detect_3d"))) {
- cf->set_value("params", "detect_3d", false);
- cf->set_value("params", "compress/mode", 2);
- cf->set_value("params", "flags/repeat", true);
- cf->set_value("params", "flags/filter", true);
- cf->set_value("params", "flags/mipmaps", true);
+ if (E->get().flags & MAKE_3D_FLAG && bool(cf->get_value("params", "detect_3d/compress_to"))) {
+ int compress_to = cf->get_value("params", "detect_3d/compress_to");
+ cf->set_value("params", "detect_3d/compress_to", 0);
+ if (compress_to == 1) {
+ cf->set_value("params", "compress/mode", COMPRESS_VRAM_COMPRESSED);
+ } else if (compress_to == 2) {
+ cf->set_value("params", "compress/mode", COMPRESS_BASIS_UNIVERSAL);
+ }
+ cf->set_value("params", "mipmaps/generate", true);
changed = true;
}
@@ -142,7 +149,7 @@ String ResourceImporterTexture::get_importer_name() const {
String ResourceImporterTexture::get_visible_name() const {
- return "Texture";
+ return "Texture2D";
}
void ResourceImporterTexture::get_recognized_extensions(List<String> *p_extensions) const {
@@ -161,17 +168,20 @@ bool ResourceImporterTexture::get_option_visibility(const String &p_option, cons
if (p_option == "compress/lossy_quality") {
int compress_mode = int(p_options["compress/mode"]);
- if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VIDEO_RAM) {
+ if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VRAM_COMPRESSED) {
return false;
}
} else if (p_option == "compress/hdr_mode") {
int compress_mode = int(p_options["compress/mode"]);
- if (compress_mode != COMPRESS_VIDEO_RAM) {
+ if (compress_mode < COMPRESS_VRAM_COMPRESSED) {
return false;
}
+ } else if (p_option == "mipmaps/limit") {
+ return p_options["mipmaps/generate"];
+
} else if (p_option == "compress/bptc_ldr") {
int compress_mode = int(p_options["compress/mode"]);
- if (compress_mode != COMPRESS_VIDEO_RAM) {
+ if (compress_mode < COMPRESS_VRAM_COMPRESSED) {
return false;
}
if (!ProjectSettings::get_singleton()->get("rendering/vram_compression/import_bptc")) {
@@ -199,202 +209,233 @@ String ResourceImporterTexture::get_preset_name(int p_idx) const {
void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, int p_preset) const {
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,Video RAM,Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 2 : 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,VRAM Compressed,VRAM Uncompressed,Basis Universal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 2 : 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_mode", PROPERTY_HINT_ENUM, "Enabled,Force RGBE"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/bptc_ldr", PROPERTY_HINT_ENUM, "Enabled,RGBA Only"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/normal_map", PROPERTY_HINT_ENUM, "Detect,Enable,Disabled"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirrored"), p_preset == PRESET_3D ? 1 : 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/filter"), p_preset != PRESET_2D_PIXEL));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/mipmaps"), p_preset == PRESET_3D));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/anisotropic"), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/srgb", PROPERTY_HINT_ENUM, "Disable,Enable,Detect"), 2));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/channel_pack", PROPERTY_HINT_ENUM, "sRGB Friendly,Optimized"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/streamed"), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "mipmaps/generate"), (p_preset == PRESET_3D ? true : false)));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "mipmaps/limit", PROPERTY_HINT_RANGE, "-1,256"), -1));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "roughness/mode", PROPERTY_HINT_ENUM, "Detect,Disabled,Red,Green,Blue,Alpha,Gray"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "roughness/src_normal", PROPERTY_HINT_FILE, "*.png,*.jpg"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/fix_alpha_border"), p_preset != PRESET_3D));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/premult_alpha"), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/HDR_as_SRGB"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/invert_color"), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "stream"), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "size_limit", PROPERTY_HINT_RANGE, "0,4096,1"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "detect_3d"), p_preset == PRESET_DETECT));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "svg/scale", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 1.0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/HDR_as_SRGB"), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "process/size_limit", PROPERTY_HINT_RANGE, "0,4096,1"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "detect_3d/compress_to", PROPERTY_HINT_ENUM, "Disabled,VRAM Compressed,Basis Universal"), (p_preset == PRESET_DETECT) ? 1 : 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "svg/scale", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 1.0));
}
-void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal, bool p_force_po2_for_compressed) {
-
- FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE);
- f->store_8('G');
- f->store_8('D');
- f->store_8('S');
- f->store_8('T'); //godot streamable texture
-
- bool resize_to_po2 = false;
+void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality, bool p_force_rgbe) {
- if (p_compress_mode == COMPRESS_VIDEO_RAM && p_force_po2_for_compressed && (p_mipmaps || p_texture_flags & Texture::FLAG_REPEAT)) {
- resize_to_po2 = true;
- f->store_16(next_power_of_2(p_image->get_width()));
- f->store_16(p_image->get_width());
- f->store_16(next_power_of_2(p_image->get_height()));
- f->store_16(p_image->get_height());
- } else {
- f->store_16(p_image->get_width());
- f->store_16(0);
- f->store_16(p_image->get_height());
- f->store_16(0);
- }
- f->store_32(p_texture_flags);
+ switch (p_compress_mode) {
+ case COMPRESS_LOSSLESS: {
- uint32_t format = 0;
+ f->store_32(StreamTexture::DATA_FORMAT_LOSSLESS);
+ f->store_16(p_image->get_width());
+ f->store_16(p_image->get_height());
+ f->store_32(p_image->get_mipmap_count());
+ f->store_32(p_image->get_format());
- if (p_streamable)
- format |= StreamTexture::FORMAT_BIT_STREAM;
- if (p_mipmaps)
- format |= StreamTexture::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
- if (p_detect_3d)
- format |= StreamTexture::FORMAT_BIT_DETECT_3D;
- if (p_detect_srgb)
- format |= StreamTexture::FORMAT_BIT_DETECT_SRGB;
- if (p_detect_normal)
- format |= StreamTexture::FORMAT_BIT_DETECT_NORMAL;
+ for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
- if ((p_compress_mode == COMPRESS_LOSSLESS || p_compress_mode == COMPRESS_LOSSY) && p_image->get_format() > Image::FORMAT_RGBA8) {
- p_compress_mode = COMPRESS_UNCOMPRESSED; //these can't go as lossy
- }
-
- switch (p_compress_mode) {
- case COMPRESS_LOSSLESS: {
+ Vector<uint8_t> data = Image::lossless_packer(p_image->get_image_from_mipmap(i));
+ int data_len = data.size();
+ f->store_32(data_len);
- Ref<Image> image = p_image->duplicate();
- if (p_mipmaps) {
- image->generate_mipmaps();
- } else {
- image->clear_mipmaps();
+ const uint8_t *r = data.ptr();
+ f->store_buffer(r, data_len);
}
- int mmc = image->get_mipmap_count() + 1;
-
- format |= StreamTexture::FORMAT_BIT_LOSSLESS;
- f->store_32(format);
- f->store_32(mmc);
+ } break;
+ case COMPRESS_LOSSY: {
- for (int i = 0; i < mmc; i++) {
+ f->store_32(StreamTexture::DATA_FORMAT_LOSSY);
+ f->store_16(p_image->get_width());
+ f->store_16(p_image->get_height());
+ f->store_32(p_image->get_mipmap_count());
+ f->store_32(p_image->get_format());
- if (i > 0) {
- image->shrink_x2();
- }
+ for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
- PoolVector<uint8_t> data = Image::lossless_packer(image);
+ Vector<uint8_t> data = Image::lossy_packer(p_image->get_image_from_mipmap(i), p_lossy_quality);
int data_len = data.size();
f->store_32(data_len);
- PoolVector<uint8_t>::Read r = data.read();
- f->store_buffer(r.ptr(), data_len);
+ const uint8_t *r = data.ptr();
+ f->store_buffer(r, data_len);
}
-
} break;
- case COMPRESS_LOSSY: {
+ case COMPRESS_VRAM_COMPRESSED: {
+
Ref<Image> image = p_image->duplicate();
- if (p_mipmaps) {
- image->generate_mipmaps();
+
+ if (p_force_rgbe && image->get_format() >= Image::FORMAT_RF && image->get_format() < Image::FORMAT_RGBE9995) {
+ image->convert(Image::FORMAT_RGBE9995);
} else {
- image->clear_mipmaps();
+ image->compress_from_channels(p_compress_format, p_channels, p_lossy_quality);
}
- int mmc = image->get_mipmap_count() + 1;
+ f->store_32(StreamTexture::DATA_FORMAT_IMAGE);
+ f->store_16(image->get_width());
+ f->store_16(image->get_height());
+ f->store_32(image->get_mipmap_count());
+ f->store_32(image->get_format());
- format |= StreamTexture::FORMAT_BIT_LOSSY;
- f->store_32(format);
- f->store_32(mmc);
+ Vector<uint8_t> data = image->get_data();
+ int dl = data.size();
+ const uint8_t *r = data.ptr();
+ f->store_buffer(r, dl);
+ } break;
+ case COMPRESS_VRAM_UNCOMPRESSED: {
- for (int i = 0; i < mmc; i++) {
+ f->store_32(StreamTexture::DATA_FORMAT_IMAGE);
+ f->store_16(p_image->get_width());
+ f->store_16(p_image->get_height());
+ f->store_32(p_image->get_mipmap_count());
+ f->store_32(p_image->get_format());
- if (i > 0) {
- image->shrink_x2();
- }
+ Vector<uint8_t> data = p_image->get_data();
+ int dl = data.size();
+ const uint8_t *r = data.ptr();
+
+ f->store_buffer(r, dl);
- PoolVector<uint8_t> data = Image::lossy_packer(image, p_lossy_quality);
+ } break;
+ case COMPRESS_BASIS_UNIVERSAL: {
+
+ f->store_32(StreamTexture::DATA_FORMAT_BASIS_UNIVERSAL);
+ f->store_16(p_image->get_width());
+ f->store_16(p_image->get_height());
+ f->store_32(p_image->get_mipmap_count());
+ f->store_32(p_image->get_format());
+
+ for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
+
+ Vector<uint8_t> data = Image::basis_universal_packer(p_image->get_image_from_mipmap(i), p_channels);
int data_len = data.size();
f->store_32(data_len);
- PoolVector<uint8_t>::Read r = data.read();
- f->store_buffer(r.ptr(), data_len);
+ const uint8_t *r = data.ptr();
+ f->store_buffer(r, data_len);
}
} break;
- case COMPRESS_VIDEO_RAM: {
+ }
+}
- Ref<Image> image = p_image->duplicate();
- if (resize_to_po2) {
- image->resize_to_po2();
- }
- if (p_mipmaps) {
- image->generate_mipmaps(p_force_normal);
- }
+void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_roughness, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel) {
- if (p_force_rgbe && image->get_format() >= Image::FORMAT_R8 && image->get_format() <= Image::FORMAT_RGBE9995) {
- image->convert(Image::FORMAT_RGBE9995);
- } else {
- Image::CompressSource csource = Image::COMPRESS_SOURCE_GENERIC;
- if (p_force_normal) {
- csource = Image::COMPRESS_SOURCE_NORMAL;
- } else if (p_texture_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
- csource = Image::COMPRESS_SOURCE_SRGB;
- }
+ FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE);
+ f->store_8('G');
+ f->store_8('S');
+ f->store_8('T');
+ f->store_8('2'); //godot streamable texture 2D
- image->compress(p_vram_compression, csource, p_lossy_quality);
- }
+ //format version
+ f->store_32(StreamTexture::FORMAT_VERSION);
+ //texture may be resized later, so original size must be saved first
+ f->store_32(p_image->get_width());
+ f->store_32(p_image->get_height());
- format |= image->get_format();
+ uint32_t flags = 0;
+ if (p_streamable)
+ flags |= StreamTexture::FORMAT_BIT_STREAM;
+ if (p_mipmaps)
+ flags |= StreamTexture::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
+ if (p_detect_3d)
+ flags |= StreamTexture::FORMAT_BIT_DETECT_3D;
+ if (p_detect_roughness)
+ flags |= StreamTexture::FORMAT_BIT_DETECT_ROUGNESS;
+ if (p_detect_normal)
+ flags |= StreamTexture::FORMAT_BIT_DETECT_NORMAL;
+
+ f->store_32(flags);
+ f->store_32(p_limit_mipmap);
+ //reserverd for future use
+ f->store_32(0);
+ f->store_32(0);
+ f->store_32(0);
+
+ /*
+ print_line("streamable " + itos(p_streamable));
+ print_line("mipmaps " + itos(p_mipmaps));
+ print_line("detect_3d " + itos(p_detect_3d));
+ print_line("roughness " + itos(p_detect_roughness));
+ print_line("normal " + itos(p_detect_normal));
+*/
- f->store_32(format);
+ if ((p_compress_mode == COMPRESS_LOSSLESS || p_compress_mode == COMPRESS_LOSSY) && p_image->get_format() > Image::FORMAT_RGBA8) {
+ p_compress_mode = COMPRESS_VRAM_UNCOMPRESSED; //these can't go as lossy
+ }
- PoolVector<uint8_t> data = image->get_data();
- int dl = data.size();
- PoolVector<uint8_t>::Read r = data.read();
- f->store_buffer(r.ptr(), dl);
- } break;
- case COMPRESS_UNCOMPRESSED: {
+ Ref<Image> image = p_image->duplicate();
- Ref<Image> image = p_image->duplicate();
- if (p_mipmaps) {
- image->generate_mipmaps();
- } else {
- image->clear_mipmaps();
- }
+ if (((p_compress_mode == COMPRESS_BASIS_UNIVERSAL) || (p_compress_mode == COMPRESS_VRAM_COMPRESSED && p_force_po2_for_compressed)) && p_mipmaps) {
+ image->resize_to_po2();
+ }
- format |= image->get_format();
- f->store_32(format);
+ if (p_mipmaps && (!image->has_mipmaps() || p_force_normal)) {
+ image->generate_mipmaps(p_force_normal);
+ }
- PoolVector<uint8_t> data = image->get_data();
- int dl = data.size();
- PoolVector<uint8_t>::Read r = data.read();
+ if (!p_mipmaps) {
+ image->clear_mipmaps();
+ }
- f->store_buffer(r.ptr(), dl);
+ if (image->has_mipmaps() && p_normal.is_valid()) {
+ image->generate_mipmap_roughness(p_roughness_channel, p_normal);
+ }
- } break;
+ if (p_force_rgbe && image->get_format() >= Image::FORMAT_RF && image->get_format() < Image::FORMAT_RGBE9995) {
+ image->convert(Image::FORMAT_RGBE9995);
}
+ Image::CompressSource csource = Image::COMPRESS_SOURCE_GENERIC;
+ if (p_force_normal) {
+ csource = Image::COMPRESS_SOURCE_NORMAL;
+ } else if (p_srgb_friendly) {
+ csource = Image::COMPRESS_SOURCE_SRGB;
+ }
+
+ Image::UsedChannels used_channels = image->detect_used_channels(csource);
+
+ save_to_stex_format(f, image, p_compress_mode, used_channels, p_vram_compression, p_lossy_quality, p_force_rgbe);
+
memdelete(f);
}
Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
- int compress_mode = p_options["compress/mode"];
+ CompressMode compress_mode = CompressMode(int(p_options["compress/mode"]));
float lossy = p_options["compress/lossy_quality"];
- int repeat = p_options["flags/repeat"];
- bool filter = p_options["flags/filter"];
- bool mipmaps = p_options["flags/mipmaps"];
- bool anisotropic = p_options["flags/anisotropic"];
- int srgb = p_options["flags/srgb"];
+ int pack_channels = p_options["compress/channel_pack"];
+ bool mipmaps = p_options["mipmaps/generate"];
+ uint32_t mipmap_limit = int(mipmaps ? int(p_options["mipmaps/limit"]) : int(-1));
bool fix_alpha_border = p_options["process/fix_alpha_border"];
bool premult_alpha = p_options["process/premult_alpha"];
bool invert_color = p_options["process/invert_color"];
- bool stream = p_options["stream"];
- int size_limit = p_options["size_limit"];
+ bool stream = p_options["compress/streamed"];
+ int size_limit = p_options["process/size_limit"];
bool hdr_as_srgb = p_options["process/HDR_as_SRGB"];
int normal = p_options["compress/normal_map"];
float scale = p_options["svg/scale"];
- bool force_rgbe = p_options["compress/hdr_mode"];
+ bool force_rgbe = int(p_options["compress/hdr_mode"]) == 1;
int bptc_ldr = p_options["compress/bptc_ldr"];
+ int roughness = p_options["roughness/mode"];
+ String normal_map = p_options["roughness/src_normal"];
+
+ Ref<Image> normal_image;
+ Image::RoughnessChannel roughness_channel;
+ if (mipmaps && roughness > 1 && FileAccess::exists(normal_map)) {
+ normal_image.instance();
+ if (ImageLoader::load_image(normal_map, normal_image) == OK) {
+ roughness_channel = Image::RoughnessChannel(roughness - 2);
+ }
+ }
Ref<Image> image;
image.instance();
Error err = ImageLoader::load_image(p_source_file, image, NULL, hdr_as_srgb, scale);
@@ -403,20 +444,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
Array formats_imported;
- int tex_flags = 0;
- if (repeat > 0)
- tex_flags |= Texture::FLAG_REPEAT;
- if (repeat == 2)
- tex_flags |= Texture::FLAG_MIRRORED_REPEAT;
- if (filter)
- tex_flags |= Texture::FLAG_FILTER;
- if (mipmaps || compress_mode == COMPRESS_VIDEO_RAM)
- tex_flags |= Texture::FLAG_MIPMAPS;
- if (anisotropic)
- tex_flags |= Texture::FLAG_ANISOTROPIC_FILTER;
- if (srgb == 1)
- tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR;
-
if (size_limit > 0 && (image->get_width() > size_limit || image->get_height() > size_limit)) {
//limit size
if (image->get_width() >= image->get_height()) {
@@ -449,41 +476,45 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
int height = image->get_height();
int width = image->get_width();
- image->lock();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
image->set_pixel(i, j, image->get_pixel(i, j).inverted());
}
}
- image->unlock();
}
- bool detect_3d = p_options["detect_3d"];
- bool detect_srgb = srgb == 2;
+ if (compress_mode == COMPRESS_BASIS_UNIVERSAL && image->get_format() >= Image::FORMAT_RF) {
+ //basis universal does not support float formats, fall back
+ compress_mode = COMPRESS_VRAM_COMPRESSED;
+ }
+
+ bool detect_3d = int(p_options["detect_3d/compress_to"]) > 0;
+ bool detect_roughness = roughness == 0;
bool detect_normal = normal == 0;
bool force_normal = normal == 1;
+ bool srgb_friendly_pack = pack_channels == 0;
- if (compress_mode == COMPRESS_VIDEO_RAM) {
+ if (compress_mode == COMPRESS_VRAM_COMPRESSED) {
//must import in all formats, in order of priority (so platform choses the best supported one. IE, etc2 over etc).
//Android, GLES 2.x
bool ok_on_pc = false;
bool is_hdr = (image->get_format() >= Image::FORMAT_RF && image->get_format() <= Image::FORMAT_RGBE9995);
- bool is_ldr = (image->get_format() >= Image::FORMAT_L8 && image->get_format() <= Image::FORMAT_RGBA5551);
+ bool is_ldr = (image->get_format() >= Image::FORMAT_L8 && image->get_format() <= Image::FORMAT_RGB565);
bool can_bptc = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_bptc");
bool can_s3tc = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc");
if (can_bptc) {
- Image::DetectChannels channels = image->get_detected_channels();
+ Image::UsedChannels channels = image->detect_used_channels();
if (is_hdr) {
- if (channels == Image::DETECTED_LA || channels == Image::DETECTED_RGBA) {
+ if (channels == Image::USED_CHANNELS_LA || channels == Image::USED_CHANNELS_RGBA) {
can_bptc = false;
}
} else if (is_ldr) {
//handle "RGBA Only" setting
- if (bptc_ldr == 1 && channels != Image::DETECTED_LA && channels != Image::DETECTED_RGBA) {
+ if (bptc_ldr == 1 && channels != Image::USED_CHANNELS_LA && channels != Image::USED_CHANNELS_RGBA) {
can_bptc = false;
}
}
@@ -497,7 +528,7 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
}
if (can_bptc || can_s3tc) {
- _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, can_bptc ? Image::COMPRESS_BPTC : Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, false);
+ _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, can_bptc ? Image::COMPRESS_BPTC : Image::COMPRESS_S3TC, mipmaps, stream, detect_3d, detect_roughness, force_rgbe, detect_normal, force_normal, srgb_friendly_pack, false, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("s3tc");
formats_imported.push_back("s3tc");
ok_on_pc = true;
@@ -505,20 +536,20 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) {
- _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, true);
+ _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, stream, detect_3d, detect_roughness, force_rgbe, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("etc2");
formats_imported.push_back("etc2");
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) {
- _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, true);
+ _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, stream, detect_3d, detect_roughness, force_rgbe, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("etc");
formats_imported.push_back("etc");
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) {
- _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, true);
+ _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, stream, detect_3d, detect_roughness, force_rgbe, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("pvrtc");
formats_imported.push_back("pvrtc");
}
@@ -528,12 +559,12 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
}
} else {
//import normally
- _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, false);
+ _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, stream, detect_3d, detect_roughness, force_rgbe, detect_normal, force_normal, srgb_friendly_pack, false, mipmap_limit, normal_image, roughness_channel);
}
if (r_metadata) {
Dictionary metadata;
- metadata["vram_texture"] = compress_mode == COMPRESS_VIDEO_RAM;
+ metadata["vram_texture"] = compress_mode == COMPRESS_VRAM_COMPRESSED;
if (formats_imported.size()) {
metadata["imported_formats"] = formats_imported;
}
@@ -609,7 +640,7 @@ ResourceImporterTexture::ResourceImporterTexture() {
singleton = this;
StreamTexture::request_3d_callback = _texture_reimport_3d;
- StreamTexture::request_srgb_callback = _texture_reimport_srgb;
+ StreamTexture::request_roughness_callback = _texture_reimport_roughness;
StreamTexture::request_normal_callback = _texture_reimport_normal;
mutex = Mutex::create();
}
diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h
index fbfd47f4f0..19d5498b4a 100644
--- a/editor/import/resource_importer_texture.h
+++ b/editor/import/resource_importer_texture.h
@@ -33,30 +33,57 @@
#include "core/image.h"
#include "core/io/resource_importer.h"
+#include "core/os/file_access.h"
+#include "scene/resources/texture.h"
+#include "servers/visual_server.h"
class StreamTexture;
class ResourceImporterTexture : public ResourceImporter {
GDCLASS(ResourceImporterTexture, ResourceImporter);
+public:
+ enum CompressMode {
+ COMPRESS_LOSSLESS,
+ COMPRESS_LOSSY,
+ COMPRESS_VRAM_COMPRESSED,
+ COMPRESS_VRAM_UNCOMPRESSED,
+ COMPRESS_BASIS_UNIVERSAL
+ };
+
protected:
enum {
MAKE_3D_FLAG = 1,
- MAKE_SRGB_FLAG = 2,
+ MAKE_ROUGHNESS_FLAG = 2,
MAKE_NORMAL_FLAG = 4
};
Mutex *mutex;
- Map<StringName, int> make_flags;
+ struct MakeInfo {
+
+ int flags;
+ String normal_path_for_roughness;
+ VS::TextureDetectRoughnessChannel channel_for_roughness;
+ MakeInfo() {
+ flags = 0;
+ channel_for_roughness = VS::TEXTURE_DETECT_ROUGNHESS_R;
+ }
+ };
+
+ Map<StringName, MakeInfo> make_flags;
- static void _texture_reimport_srgb(const Ref<StreamTexture> &p_tex);
+ static void _texture_reimport_roughness(const Ref<StreamTexture> &p_tex, const String &p_normal_path, VisualServer::TextureDetectRoughnessChannel p_channel);
static void _texture_reimport_3d(const Ref<StreamTexture> &p_tex);
static void _texture_reimport_normal(const Ref<StreamTexture> &p_tex);
static ResourceImporterTexture *singleton;
static const char *compression_formats[];
+ void _save_stex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel);
+
public:
+ void save_to_stex_format(FileAccess *f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality, bool p_force_rgbe);
+
static ResourceImporterTexture *get_singleton() { return singleton; }
virtual String get_importer_name() const;
virtual String get_visible_name() const;
@@ -71,21 +98,12 @@ public:
PRESET_3D,
};
- enum CompressMode {
- COMPRESS_LOSSLESS,
- COMPRESS_LOSSY,
- COMPRESS_VIDEO_RAM,
- COMPRESS_UNCOMPRESSED
- };
-
virtual int get_preset_count() const;
virtual String get_preset_name(int p_idx) const;
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
- void _save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal, bool p_force_po2_for_compressed);
-
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL);
void update_imports();
diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp
index 335e1114e6..3172cc7279 100644
--- a/editor/import/resource_importer_texture_atlas.cpp
+++ b/editor/import/resource_importer_texture_atlas.cpp
@@ -58,7 +58,7 @@ String ResourceImporterTextureAtlas::get_save_extension() const {
String ResourceImporterTextureAtlas::get_resource_type() const {
- return "Texture";
+ return "Texture2D";
}
bool ResourceImporterTextureAtlas::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
@@ -143,8 +143,8 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr
int px = xi, py = yi;
int sx = px, sy = py;
- sx = CLAMP(sx, 0, src_width);
- sy = CLAMP(sy, 0, src_height);
+ sx = CLAMP(sx, 0, src_width - 1);
+ sy = CLAMP(sy, 0, src_height - 1);
Color color = p_src_image->get_pixel(sx, sy);
if (p_transposed) {
SWAP(px, py);
@@ -165,8 +165,8 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr
for (int xi = (xf < width ? int(xf) : width - 1); xi >= (xt > 0 ? xt : 0); xi--) {
int px = xi, py = yi;
int sx = px, sy = py;
- sx = CLAMP(sx, 0, src_width);
- sy = CLAMP(sy, 0, src_height);
+ sx = CLAMP(sx, 0, src_width - 1);
+ sy = CLAMP(sy, 0, src_height - 1);
Color color = p_src_image->get_pixel(sx, sy);
if (p_transposed) {
SWAP(px, py);
@@ -286,12 +286,10 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
new_atlas.instance();
new_atlas->create(atlas_width, atlas_height, false, Image::FORMAT_RGBA8);
- new_atlas->lock();
-
for (int i = 0; i < pack_data_files.size(); i++) {
PackData &pack_data = pack_data_files.write[i];
- pack_data.image->lock();
+
for (int j = 0; j < pack_data.chart_pieces.size(); j++) {
const EditorAtlasPacker::Chart &chart = charts[pack_data.chart_pieces[j]];
for (int k = 0; k < chart.faces.size(); k++) {
@@ -304,16 +302,14 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
_plot_triangle(positions, chart.final_offset, chart.transposed, new_atlas, pack_data.image);
}
}
- pack_data.image->unlock();
}
- new_atlas->unlock();
//save the atlas
new_atlas->save_png(p_group_file);
//update cache if existing, else create
- Ref<Texture> cache;
+ Ref<Texture2D> cache;
if (ResourceCache::has(p_group_file)) {
Resource *resptr = ResourceCache::get(p_group_file);
cache.reference_ptr(resptr);
@@ -331,7 +327,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
PackData &pack_data = pack_data_files.write[idx];
- Ref<Texture> texture;
+ Ref<Texture2D> texture;
if (!pack_data.is_mesh) {
Vector2 offset = charts[pack_data.chart_pieces[0]].vertices[0] + charts[pack_data.chart_pieces[0]].final_offset;
@@ -350,9 +346,9 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
for (int i = 0; i < pack_data.chart_pieces.size(); i++) {
const EditorAtlasPacker::Chart &chart = charts[pack_data.chart_pieces[i]];
- PoolVector<Vector2> vertices;
- PoolVector<int> indices;
- PoolVector<Vector2> uvs;
+ Vector<Vector2> vertices;
+ Vector<int> indices;
+ Vector<Vector2> uvs;
int vc = chart.vertices.size();
int fc = chart.faces.size();
vertices.resize(vc);
@@ -360,9 +356,9 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
indices.resize(fc * 3);
{
- PoolVector<Vector2>::Write vw = vertices.write();
- PoolVector<int>::Write iw = indices.write();
- PoolVector<Vector2>::Write uvw = uvs.write();
+ Vector2 *vw = vertices.ptrw();
+ int *iw = indices.ptrw();
+ Vector2 *uvw = uvs.ptrw();
for (int j = 0; j < vc; j++) {
vw[j] = chart.vertices[j];
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 2d43fa089d..71f81051bc 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -82,7 +82,7 @@ void ResourceImporterWAV::get_import_options(List<ImportOption> *r_options, int
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/8_bit"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/mono"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/max_rate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "force/max_rate_hz", PROPERTY_HINT_EXP_RANGE, "11025,192000,1"), 44100));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "force/max_rate_hz", PROPERTY_HINT_EXP_RANGE, "11025,192000,1"), 44100));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/trim"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/normalize"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/loop"), false));
@@ -467,7 +467,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
is16 = false;
}
- PoolVector<uint8_t> dst_data;
+ Vector<uint8_t> dst_data;
AudioStreamSample::Format dst_format;
if (compression == 1) {
@@ -490,8 +490,8 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
right.write[i] = data[i * 2 + 1];
}
- PoolVector<uint8_t> bleft;
- PoolVector<uint8_t> bright;
+ Vector<uint8_t> bleft;
+ Vector<uint8_t> bright;
_compress_ima_adpcm(left, bleft);
_compress_ima_adpcm(right, bright);
@@ -499,9 +499,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
int dl = bleft.size();
dst_data.resize(dl * 2);
- PoolVector<uint8_t>::Write w = dst_data.write();
- PoolVector<uint8_t>::Read rl = bleft.read();
- PoolVector<uint8_t>::Read rr = bright.read();
+ uint8_t *w = dst_data.ptrw();
+ const uint8_t *rl = bleft.ptr();
+ const uint8_t *rr = bright.ptr();
for (int i = 0; i < dl; i++) {
w[i * 2 + 0] = rl[i];
@@ -514,7 +514,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
dst_format = is16 ? AudioStreamSample::FORMAT_16_BITS : AudioStreamSample::FORMAT_8_BITS;
dst_data.resize(data.size() * (is16 ? 2 : 1));
{
- PoolVector<uint8_t>::Write w = dst_data.write();
+ uint8_t *w = dst_data.ptrw();
int ds = data.size();
for (int i = 0; i < ds; i++) {
diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h
index 59d33feef0..6df5b88b13 100644
--- a/editor/import/resource_importer_wav.h
+++ b/editor/import/resource_importer_wav.h
@@ -49,7 +49,7 @@ public:
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
- static void _compress_ima_adpcm(const Vector<float> &p_data, PoolVector<uint8_t> &dst_data) {
+ static void _compress_ima_adpcm(const Vector<float> &p_data, Vector<uint8_t> &dst_data) {
/*p_sample_data->data = (void*)malloc(len);
xm_s8 *dataptr=(xm_s8*)p_sample_data->data;*/
@@ -76,10 +76,10 @@ public:
datalen++;
dst_data.resize(datalen / 2 + 4);
- PoolVector<uint8_t>::Write w = dst_data.write();
+ uint8_t *w = dst_data.ptrw();
int i, step_idx = 0, prev = 0;
- uint8_t *out = w.ptr();
+ uint8_t *out = w;
//int16_t xm_prev=0;
const float *in = p_data.ptr();