summaryrefslogtreecommitdiff
path: root/tools/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'tools/editor/import')
-rw-r--r--tools/editor/import/SCsub2
-rw-r--r--tools/editor/import/editor_import_collada.cpp58
-rw-r--r--tools/editor/import/resource_importer_scene.cpp141
-rw-r--r--tools/editor/import/resource_importer_scene.h8
-rw-r--r--tools/editor/import/resource_importer_texture.cpp139
-rw-r--r--tools/editor/import/resource_importer_texture.h29
6 files changed, 352 insertions, 25 deletions
diff --git a/tools/editor/import/SCsub b/tools/editor/import/SCsub
index 4bf55189cc..f1fa50148f 100644
--- a/tools/editor/import/SCsub
+++ b/tools/editor/import/SCsub
@@ -2,4 +2,4 @@
Import('env')
Export('env')
-env.add_source_files(env.tool_sources, "*.cpp")
+env.add_source_files(env.editor_sources, "*.cpp")
diff --git a/tools/editor/import/editor_import_collada.cpp b/tools/editor/import/editor_import_collada.cpp
index 10b9dda2cb..a901de1faf 100644
--- a/tools/editor/import/editor_import_collada.cpp
+++ b/tools/editor/import/editor_import_collada.cpp
@@ -29,7 +29,6 @@
#include "editor_import_collada.h"
-#include "collada/collada.h"
#include "scene/3d/spatial.h"
#include "scene/3d/skeleton.h"
#include "scene/3d/path.h"
@@ -40,6 +39,7 @@
#include "scene/resources/animation.h"
#include "scene/resources/packed_scene.h"
#include "os/os.h"
+#include "tools/editor/collada/collada.h"
#include "tools/editor/editor_node.h"
#include <iostream>
@@ -65,6 +65,7 @@ struct ColladaImport {
bool found_directional;
bool force_make_tangents;
bool apply_mesh_xform_to_vertices;
+ bool use_mesh_builtin_materials;
float bake_fps;
@@ -87,7 +88,7 @@ struct ColladaImport {
Error _create_scene(Collada::Node *p_node, Spatial *p_parent);
Error _create_resources(Collada::Node *p_node);
Error _create_material(const String& p_material);
- Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh>& p_mesh, const Map<String,Collada::NodeGeometry::Material>& p_material_map, const Collada::MeshData &meshdata, const Transform& p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes=Vector<Ref<Mesh> >(), bool p_for_morph=false);
+ Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh>& p_mesh, const Map<String,Collada::NodeGeometry::Material>& p_material_map, const Collada::MeshData &meshdata, const Transform& p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes=Vector<Ref<Mesh> >(), bool p_for_morph=false, bool p_use_mesh_material=false);
Error load(const String& p_path, int p_flags, bool p_force_make_tangents=false);
void _fix_param_animation_tracks();
void create_animation(int p_clip,bool p_make_tracks_in_all_bones, bool p_import_value_tracks);
@@ -429,9 +430,10 @@ Error ColladaImport::_create_material(const String& p_target) {
}
} else {
- //material->set_parameter(FixedSpatialMaterial::PARAM_SPECULAR,effect.specular.color);
+ material->set_metalness(effect.specular.color.get_v());
}
+
// EMISSION
if (effect.emission.texture!="") {
@@ -442,17 +444,21 @@ Error ColladaImport::_create_material(const String& p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile,"Texture");
if (texture.is_valid()) {
+ material->set_feature(FixedSpatialMaterial::FEATURE_EMISSION,true);
material->set_texture(FixedSpatialMaterial::TEXTURE_EMISSION,texture);
material->set_emission(Color(1,1,1,1));
//material->set_parameter(FixedSpatialMaterial::PARAM_EMISSION,Color(1,1,1,1));
}else {
- //missing_textures.push_back(texfile.get_file());
+ missing_textures.push_back(texfile.get_file());
}
}
} else {
- //material->set_parameter(FixedSpatialMaterial::PARAM_EMISSION,effect.emission.color);
+ if (effect.emission.color!=Color()) {
+ material->set_feature(FixedSpatialMaterial::FEATURE_EMISSION,true);
+ material->set_emission(effect.emission.color);
+ }
}
// NORMAL
@@ -464,6 +470,7 @@ Error ColladaImport::_create_material(const String& p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile,"Texture");
if (texture.is_valid()) {
+ material->set_feature(FixedSpatialMaterial::FEATURE_NORMAL_MAPPING,true);
material->set_texture(FixedSpatialMaterial::TEXTURE_NORMAL,texture);
//material->set_emission(Color(1,1,1,1));
@@ -476,7 +483,9 @@ Error ColladaImport::_create_material(const String& p_target) {
}
- //material->set_parameter(FixedSpatialMaterial::PARAM_SPECULAR_EXP,effect.shininess);
+ float roughness = Math::sqrt(1.0-((Math::log(effect.shininess)/Math::log(2.0))/8.0)); //not very right..
+ material->set_roughness(roughness);
+
if (effect.double_sided) {
material->set_cull_mode(FixedSpatialMaterial::CULL_DISABLED);
}
@@ -610,7 +619,7 @@ static void _generate_tangents_and_binormals(const PoolVector<int>& p_indices,co
}
}
-Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,const Map<String,Collada::NodeGeometry::Material>& p_material_map,const Collada::MeshData &meshdata,const Transform& p_local_xform,const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data,Vector<Ref<Mesh> > p_morph_meshes,bool p_for_morph) {
+Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,const Map<String,Collada::NodeGeometry::Material>& p_material_map,const Collada::MeshData &meshdata,const Transform& p_local_xform,const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data,Vector<Ref<Mesh> > p_morph_meshes,bool p_for_morph,bool p_use_mesh_material) {
bool local_xform_mirror=p_local_xform.basis.determinant() < 0;
@@ -1494,7 +1503,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,con
p_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES,d,mr,p_for_morph?0:Mesh::ARRAY_COMPRESS_DEFAULT);
if (material.is_valid()) {
- p_mesh->surface_set_material(surface, material);
+ if (p_use_mesh_material) {
+ p_mesh->surface_set_material(surface, material);
+ }
p_mesh->surface_set_name(surface, material->get_name());
}
}
@@ -1753,7 +1764,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
mesh=Ref<Mesh>(memnew( Mesh ));
const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid];
mesh->set_name( meshdata.name );
- Error err = _create_mesh_surfaces(morphs.size()==0,mesh,ng->material_map,meshdata,apply_xform,bone_remap,skin,morph,morphs);
+ Error err = _create_mesh_surfaces(morphs.size()==0,mesh,ng->material_map,meshdata,apply_xform,bone_remap,skin,morph,morphs,false,use_mesh_builtin_materials);
ERR_FAIL_COND_V(err,err);
mesh_cache[meshid]=mesh;
@@ -1764,7 +1775,33 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
}
if (!mesh.is_null()) {
+
mi->set_mesh(mesh);
+ if (!use_mesh_builtin_materials) {
+ const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid];
+
+ for(int i=0;i<meshdata.primitives.size();i++) {
+
+ String matname=meshdata.primitives[i].material;
+
+ if (ng->material_map.has(matname)) {
+ String target=ng->material_map[matname].target;
+
+ Ref<Material> material;
+ if (!material_cache.has(target)) {
+ Error err = _create_material(target);
+ if (!err)
+ material=material_cache[target];
+ } else
+ material=material_cache[target];
+
+ mi->set_surface_material(i,material);
+ } else if (matname!=""){
+ print_line("Warning, unreferenced material in geometry instance: "+matname);
+ }
+
+ }
+ }
}
}
}
@@ -2375,6 +2412,7 @@ Node* EditorSceneImporterCollada::import_scene(const String& p_path, uint32_t p_
if (p_flags&IMPORT_ANIMATION)
flags|=Collada::IMPORT_FLAG_ANIMATION;
+ state.use_mesh_builtin_materials=!(p_flags&IMPORT_MATERIALS_IN_INSTANCES);
state.bake_fps=p_bake_fps;
Error err = state.load(p_path,flags,p_flags&EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS);
@@ -2435,6 +2473,8 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String& p_path
ColladaImport state;
+ state.use_mesh_builtin_materials=false;
+
Error err = state.load(p_path,Collada::IMPORT_FLAG_ANIMATION,p_flags&EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS);
ERR_FAIL_COND_V(err!=OK,RES());
diff --git a/tools/editor/import/resource_importer_scene.cpp b/tools/editor/import/resource_importer_scene.cpp
index 5d886615f3..ae840e9e16 100644
--- a/tools/editor/import/resource_importer_scene.cpp
+++ b/tools/editor/import/resource_importer_scene.cpp
@@ -979,6 +979,131 @@ void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_er
}
+static String _make_extname(const String& p_str) {
+
+ String ext_name=p_str.replace(".","_");
+ ext_name=ext_name.replace(":","_");
+ ext_name=ext_name.replace("\"","_");
+ ext_name=ext_name.replace("<","_");
+ ext_name=ext_name.replace(">","_");
+ ext_name=ext_name.replace("/","_");
+ ext_name=ext_name.replace("|","_");
+ ext_name=ext_name.replace("\\","_");
+ ext_name=ext_name.replace("?","_");
+ ext_name=ext_name.replace("*","_");
+
+ return ext_name;
+}
+
+void ResourceImporterScene::_make_external_resources(Node* p_node,const String& p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>,Ref<Material> >& p_materials, Map<Ref<Mesh>,Ref<Mesh> >& p_meshes) {
+
+ List<PropertyInfo> pi;
+
+ p_node->get_property_list(&pi);
+
+ for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
+
+ if (E->get().type==Variant::OBJECT) {
+
+ Ref<Material> mat = p_node->get(E->get().name);
+ if (p_make_materials && mat.is_valid() && mat->get_name()!="") {
+
+
+ if (!p_materials.has(mat)) {
+
+ String ext_name = p_base_path+"."+_make_extname(mat->get_name())+".mtl";
+ if (FileAccess::exists(ext_name)) {
+ //if exists, use it
+ Ref<Material> existing = ResourceLoader::load(ext_name);
+ p_materials[mat]=existing;
+ } else {
+
+ ResourceSaver::save(ext_name,mat,ResourceSaver::FLAG_CHANGE_PATH);
+ p_materials[mat]=mat;
+ }
+ }
+
+ if (p_materials[mat]!=mat) {
+
+ p_node->set(E->get().name,p_materials[mat]);
+ }
+ } else {
+
+ Ref<Mesh> mesh = p_node->get(E->get().name);
+
+ if (mesh.is_valid()) {
+
+ bool mesh_just_added=false;
+
+ if (p_make_meshes) {
+
+ if (!p_meshes.has(mesh)) {
+
+ String ext_name = p_base_path+"."+_make_extname(mesh->get_name())+".msh";
+ if (FileAccess::exists(ext_name)) {
+ //if exists, use it
+ Ref<Mesh> existing = ResourceLoader::load(ext_name);
+ p_meshes[mesh]=existing;
+ } else {
+
+ ResourceSaver::save(ext_name,mesh,ResourceSaver::FLAG_CHANGE_PATH);
+ p_meshes[mesh]=mesh;
+ mesh_just_added=true;
+ }
+
+
+ }
+ }
+
+
+ if (p_make_materials){
+
+ if (mesh_just_added || !p_meshes.has(mesh)) {
+
+
+ for(int i=0;i<mesh->get_surface_count();i++) {
+ mat=mesh->surface_get_material(i);
+ if (!mat.is_valid() || mat->get_name()=="")
+ continue;
+
+ if (!p_materials.has(mat)) {
+
+ String ext_name = p_base_path+"."+_make_extname(mat->get_name())+".mtl";
+ if (FileAccess::exists(ext_name)) {
+ //if exists, use it
+ Ref<Material> existing = ResourceLoader::load(ext_name);
+ p_materials[mat]=existing;
+ } else {
+
+ ResourceSaver::save(ext_name,mat,ResourceSaver::FLAG_CHANGE_PATH);
+ p_materials[mat]=mat;
+ }
+ }
+
+ if (p_materials[mat]!=mat) {
+
+ mesh->surface_set_material(i,p_materials[mat]);
+ }
+
+ }
+
+ if(!p_make_meshes) {
+ p_meshes[mesh]=Ref<Mesh>(); //save it anyway, so it won't be checked again
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ for(int i=0;i<p_node->get_child_count();i++) {
+
+ _make_external_resources(p_node->get_child(i),p_base_path,p_make_materials,p_make_meshes,p_materials,p_meshes);
+ }
+}
+
+
void ResourceImporterScene::get_import_options(List<ImportOption> *r_options,int p_preset) const {
@@ -998,7 +1123,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options,int
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,"materials/location",PROPERTY_HINT_ENUM,"Node,Mesh"),0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"materials/storage",PROPERTY_HINT_ENUM,"Bult-In,Files"),1));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"materials/storage",PROPERTY_HINT_ENUM,"Bult-In,Files"),0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"geometry/compress"),true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"geometry/ensure_tangents"),true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"geometry/storage",PROPERTY_HINT_ENUM,"Built-In,Files"),0));
@@ -1018,6 +1143,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options,int
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"animation/clip_"+itos(i+1)+"/loops"),false));
}
}
+
Error ResourceImporterScene::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) {
String src_path=p_source_file;
@@ -1063,8 +1189,8 @@ Error ResourceImporterScene::import(const String& p_source_file, const String& p
if (bool(p_options["geometry/ensure_tangents"]))
import_flags|=EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS;
-
-
+ if (int(p_options["materials/location"])==0)
+ import_flags|=EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES;
Error err=OK;
@@ -1138,6 +1264,15 @@ Error ResourceImporterScene::import(const String& p_source_file, const String& p
}
+ bool external_materials = p_options["materials/storage"];
+ bool external_meshes = p_options["geometry/storage"];
+
+ if (external_materials || external_meshes) {
+ Map<Ref<Material>, Ref<Material> > mat_map;
+ Map<Ref<Mesh>, Ref<Mesh> > mesh_map;
+ _make_external_resources(scene,p_source_file.get_basename(),external_materials,external_meshes,mat_map,mesh_map);
+ }
+
progress.step(TTR("Running Custom Script.."),2);
String post_import_script_path = p_options["nodes/custom_script"];
diff --git a/tools/editor/import/resource_importer_scene.h b/tools/editor/import/resource_importer_scene.h
index 8949be30db..cfa44b160a 100644
--- a/tools/editor/import/resource_importer_scene.h
+++ b/tools/editor/import/resource_importer_scene.h
@@ -5,6 +5,8 @@
#include "scene/resources/animation.h"
#include "scene/resources/shape.h"
+class Material;
+
class EditorSceneImporter : public Reference {
GDCLASS(EditorSceneImporter,Reference );
@@ -18,7 +20,8 @@ public:
IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=16,
IMPORT_ANIMATION_KEEP_VALUE_TRACKS=32,
IMPORT_GENERATE_TANGENT_ARRAYS=256,
- IMPORT_FAIL_ON_MISSING_DEPENDENCIES=512
+ IMPORT_FAIL_ON_MISSING_DEPENDENCIES=512,
+ IMPORT_MATERIALS_IN_INSTANCES=1024
};
@@ -72,6 +75,8 @@ 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 _make_external_resources(Node* p_node,const String& p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes);
+
Node* _fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map);
void _create_clips(Node *scene, const Array& p_clips,bool p_bake_all);
@@ -84,4 +89,5 @@ public:
ResourceImporterScene();
};
+
#endif // RESOURCEIMPORTERSCENE_H
diff --git a/tools/editor/import/resource_importer_texture.cpp b/tools/editor/import/resource_importer_texture.cpp
index 3cbe034e4d..21e434fa11 100644
--- a/tools/editor/import/resource_importer_texture.cpp
+++ b/tools/editor/import/resource_importer_texture.cpp
@@ -1,6 +1,106 @@
#include "resource_importer_texture.h"
#include "io/image_loader.h"
#include "scene/resources/texture.h"
+#include "tools/editor/editor_file_system.h"
+#include "io/config_file.h"
+
+
+void ResourceImporterTexture::_texture_reimport_srgb(const Ref<StreamTexture>& p_tex) {
+
+ singleton->mutex->lock();
+ StringName path = p_tex->get_path();
+
+ if (!singleton->make_flags.has(path)) {
+ singleton->make_flags[path]=0;
+ }
+
+ singleton->make_flags[path]|=MAKE_SRGB_FLAG;
+
+ print_line("requesting srgb for "+String(path));
+
+ singleton->mutex->unlock();
+
+}
+
+
+
+void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture>& p_tex) {
+
+
+ singleton->mutex->lock();
+ StringName path = p_tex->get_path();
+
+ if (!singleton->make_flags.has(path)) {
+ singleton->make_flags[path]=0;
+ }
+
+ singleton->make_flags[path]|=MAKE_3D_FLAG;
+
+ print_line("requesting 3d for "+String(path));
+
+ singleton->mutex->unlock();
+
+
+}
+
+void ResourceImporterTexture::update_imports() {
+
+ if (EditorFileSystem::get_singleton()->is_scanning() || EditorFileSystem::get_singleton()->is_importing()) {
+ return; // do nothing for noe
+ }
+ mutex->lock();
+
+ if (make_flags.empty()) {
+ mutex->unlock();
+ return;
+ }
+
+ Vector<String> to_reimport;
+ for (Map<StringName,int>::Element *E=make_flags.front();E;E=E->next()) {
+
+ print_line("checking for reimport "+String(E->key()));
+
+
+ Ref<ConfigFile> cf;
+ cf.instance();
+ String src_path = String(E->key())+".import";
+
+ Error err = cf->load(src_path);
+ 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);
+ 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);
+ changed=true;
+ }
+
+ if (changed) {
+ cf->save(src_path);
+ to_reimport.push_back(E->key());
+ }
+
+ }
+
+ make_flags.clear();
+
+ mutex->unlock();
+
+ if (to_reimport.size()) {
+ EditorFileSystem::get_singleton()->reimport_files(to_reimport);
+ }
+
+}
+
+
String ResourceImporterTexture::get_importer_name() const {
@@ -57,7 +157,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,i
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/filter"),p_preset==PRESET_2D_PIXEL?false:true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/mipmaps"),p_preset==PRESET_3D?true:false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/anisotropic"),false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/srgb",PROPERTY_HINT_ENUM,"Disable,Enable,Detect"),2));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"flags/srgb",PROPERTY_HINT_ENUM,"Disable,Enable,Detect"),2));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/fix_alpha_border"),p_preset!=PRESET_3D?true:false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/premult_alpha"),true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"stream"),false));
@@ -67,7 +167,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,i
}
-void ResourceImporterTexture::_save_stex(const 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) {
+void ResourceImporterTexture::_save_stex(const 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) {
FileAccess *f = FileAccess::open(p_to_path,FileAccess::WRITE);
@@ -86,6 +186,11 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
format|=StreamTexture::FORMAT_BIT_STREAM;
if (p_mipmaps || p_compress_mode==COMPRESS_VIDEO_RAM) //VRAM always uses 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;
+
switch (p_compress_mode) {
case COMPRESS_LOSSLESS: {
@@ -99,7 +204,7 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
int mmc = image.get_mipmap_count() + 1;
- format=StreamTexture::FORMAT_BIT_LOSSLESS;
+ format|=StreamTexture::FORMAT_BIT_LOSSLESS;
f->store_32(format);
f->store_32(mmc);
@@ -130,7 +235,7 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
int mmc = image.get_mipmap_count() + 1;
- format=StreamTexture::FORMAT_BIT_LOSSY;
+ format|=StreamTexture::FORMAT_BIT_LOSSY;
f->store_32(format);
f->store_32(mmc);
@@ -162,7 +267,6 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
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;
@@ -198,7 +302,7 @@ Error ResourceImporterTexture::import(const String& p_source_file, const String&
bool filter= p_options["flags/filter"];
bool mipmaps= p_options["flags/mipmaps"];
bool anisotropic= p_options["flags/anisotropic"];
- bool srgb= p_options["flags/srgb"];
+ int srgb= p_options["flags/srgb"];
bool fix_alpha_border= p_options["process/fix_alpha_border"];
bool premult_alpha= p_options["process/premult_alpha"];
bool stream = p_options["stream"];
@@ -222,7 +326,7 @@ Error ResourceImporterTexture::import(const String& p_source_file, const String&
tex_flags|=Texture::FLAG_MIPMAPS;
if (anisotropic)
tex_flags|=Texture::FLAG_ANISOTROPIC_FILTER;
- if (srgb)
+ if (srgb==1)
tex_flags|=Texture::FLAG_CONVERT_TO_LINEAR;
if (size_limit >0 && (image.get_width()>size_limit || image.get_height()>size_limit )) {
@@ -249,26 +353,41 @@ Error ResourceImporterTexture::import(const String& p_source_file, const String&
image.premultiply_alpha();
}
+ bool detect_3d = p_options["detect_3d"];
+ bool detect_srgb = srgb==2;
if (compress_mode==COMPRESS_VIDEO_RAM) {
//must import in all formats
//Android, GLES 2.x
- _save_stex(image,p_save_path+".etc.stex",compress_mode,lossy,Image::COMPRESS_ETC,mipmaps,tex_flags,stream);
+ _save_stex(image,p_save_path+".etc.stex",compress_mode,lossy,Image::COMPRESS_ETC,mipmaps,tex_flags,stream,detect_3d,detect_srgb);
r_platform_variants->push_back("etc");
//_save_stex(image,p_save_path+".etc2.stex",compress_mode,lossy,Image::COMPRESS_ETC2,mipmaps,tex_flags,stream);
//r_platform_variants->push_back("etc2");
- _save_stex(image,p_save_path+".s3tc.stex",compress_mode,lossy,Image::COMPRESS_S3TC,mipmaps,tex_flags,stream);
+ _save_stex(image,p_save_path+".s3tc.stex",compress_mode,lossy,Image::COMPRESS_S3TC,mipmaps,tex_flags,stream,detect_3d,detect_srgb);
r_platform_variants->push_back("s3tc");
} else {
//import normally
- _save_stex(image,p_save_path+".stex",compress_mode,lossy,Image::COMPRESS_16BIT /*this is ignored */,mipmaps,tex_flags,stream);
+ _save_stex(image,p_save_path+".stex",compress_mode,lossy,Image::COMPRESS_16BIT /*this is ignored */,mipmaps,tex_flags,stream,detect_3d,detect_srgb);
}
return OK;
}
+ResourceImporterTexture *ResourceImporterTexture::singleton=NULL;
+
ResourceImporterTexture::ResourceImporterTexture()
{
+ singleton=this;
+ StreamTexture::request_3d_callback=_texture_reimport_3d;
+ StreamTexture::request_srgb_callback=_texture_reimport_srgb;
+ mutex = Mutex::create();
}
+
+ResourceImporterTexture::~ResourceImporterTexture()
+{
+
+ memdelete(mutex);
+}
+
diff --git a/tools/editor/import/resource_importer_texture.h b/tools/editor/import/resource_importer_texture.h
index 84f7b77838..4c795e132c 100644
--- a/tools/editor/import/resource_importer_texture.h
+++ b/tools/editor/import/resource_importer_texture.h
@@ -2,10 +2,33 @@
#define RESOURCEIMPORTTEXTURE_H
#include "io/resource_import.h"
+class StreamTexture;
class ResourceImporterTexture : public ResourceImporter {
GDCLASS(ResourceImporterTexture,ResourceImporter)
+
+
+
+protected:
+
+ enum {
+ MAKE_3D_FLAG=1,
+ MAKE_SRGB_FLAG=2
+ };
+
+ Mutex *mutex;
+ Map<StringName,int> make_flags;
+
+ static void _texture_reimport_srgb(const Ref<StreamTexture>& p_tex);
+ static void _texture_reimport_3d(const Ref<StreamTexture>& p_tex);
+
+
+
+
+ static ResourceImporterTexture *singleton;
public:
+
+ static ResourceImporterTexture *get_singleton() { return singleton; }
virtual String get_importer_name() const;
virtual String get_visible_name() const;
virtual void get_recognized_extensions(List<String> *p_extensions) const;
@@ -33,11 +56,15 @@ 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_stex(const 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);
+ void _save_stex(const 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);
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);
+
+ void update_imports();
+
ResourceImporterTexture();
+ ~ResourceImporterTexture();
};
#endif // RESOURCEIMPORTTEXTURE_H