mirror of
https://github.com/godotengine/godot
synced 2024-09-05 09:08:28 +00:00
Several bugfixes, improving the import workflow
This commit is contained in:
parent
af3fabeb77
commit
6f2e16306a
|
@ -125,6 +125,7 @@ bool GlobalConfig::_set(const StringName& p_name, const Variant& p_value) {
|
|||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
|
||||
if (p_value.get_type()==Variant::NIL)
|
||||
props.erase(p_name);
|
||||
else {
|
||||
|
|
|
@ -245,7 +245,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width
|
|||
}
|
||||
int Image::get_mipmap_offset(int p_mipmap) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_mipmap,(mipmaps+1),-1);
|
||||
ERR_FAIL_INDEX_V(p_mipmap,get_mipmap_count()+1,-1);
|
||||
|
||||
int ofs,w,h;
|
||||
_get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
|
||||
|
@ -1011,7 +1011,7 @@ void Image::shrink_x2() {
|
|||
}
|
||||
}
|
||||
|
||||
Error Image::generate_mipmaps(bool p_keep_existing) {
|
||||
Error Image::generate_mipmaps() {
|
||||
|
||||
if (!_can_modify(format)) {
|
||||
ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats.");
|
||||
|
@ -1019,15 +1019,14 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
|
|||
|
||||
}
|
||||
|
||||
int mmcount = get_mipmap_count();
|
||||
ERR_FAIL_COND_V(width==0 || height==0,ERR_UNCONFIGURED);
|
||||
|
||||
int mmcount;
|
||||
|
||||
int from_mm=1;
|
||||
if (p_keep_existing) {
|
||||
from_mm=mmcount+1;
|
||||
}
|
||||
int size = _get_dst_image_size(width,height,format,mmcount);
|
||||
|
||||
data.resize(size);
|
||||
print_line("to gen mipmaps w "+itos(width)+" h "+itos(height) +" format "+get_format_name(format)+" mipmaps " +itos(mmcount)+" new size is: "+itos(size));
|
||||
|
||||
PoolVector<uint8_t>::Write wp=data.write();
|
||||
|
||||
|
@ -1043,7 +1042,6 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
|
|||
int ofs,w,h;
|
||||
_get_mipmap_offset_and_size(i,ofs, w,h);
|
||||
|
||||
if (i>=from_mm) {
|
||||
|
||||
switch(format) {
|
||||
|
||||
|
@ -1055,7 +1053,6 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
|
|||
case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
|
||||
default: {}
|
||||
}
|
||||
}
|
||||
|
||||
prev_ofs=ofs;
|
||||
prev_w=w;
|
||||
|
@ -1077,8 +1074,6 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
|
|||
int ofs,w,h;
|
||||
_get_mipmap_offset_and_size(i,ofs, w,h);
|
||||
|
||||
if (i>=from_mm) {
|
||||
|
||||
switch(format) {
|
||||
|
||||
case FORMAT_L8:
|
||||
|
@ -1089,15 +1084,17 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
|
|||
case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
|
||||
default: {}
|
||||
}
|
||||
}
|
||||
|
||||
prev_ofs=ofs;
|
||||
prev_w=w;
|
||||
prev_h=h;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
mipmaps=true;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -1154,7 +1151,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
|
|||
ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT);
|
||||
|
||||
int mm;
|
||||
int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps);
|
||||
int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0);
|
||||
|
||||
if (size!=p_data.size()) {
|
||||
ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()");
|
||||
|
|
|
@ -196,7 +196,7 @@ public:
|
|||
/**
|
||||
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
|
||||
*/
|
||||
Error generate_mipmaps(bool p_keep_existing=false);
|
||||
Error generate_mipmaps();
|
||||
|
||||
void clear_mipmaps();
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "resource_import.h"
|
||||
#include "variant_parser.h"
|
||||
#include "os/os.h"
|
||||
|
||||
Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndType &r_path_and_type) const {
|
||||
|
||||
|
@ -36,7 +37,13 @@ Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndTy
|
|||
}
|
||||
|
||||
if (assign!=String()) {
|
||||
if (assign=="path") {
|
||||
if (assign.begins_with("path.") && r_path_and_type.path==String()) {
|
||||
String feature = assign.get_slicec('.',1);
|
||||
if (OS::get_singleton()->check_feature_support(feature)) {
|
||||
r_path_and_type.path=value;
|
||||
}
|
||||
|
||||
} else if (assign=="path") {
|
||||
r_path_and_type.path=value;
|
||||
} else if (assign=="type") {
|
||||
r_path_and_type.type=value;
|
||||
|
@ -154,6 +161,20 @@ bool ResourceFormatImporter::handles_type(const String& p_type) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
String ResourceFormatImporter::get_internal_resource_path(const String& p_path) const {
|
||||
|
||||
PathAndType pat;
|
||||
Error err = _get_path_and_type(p_path,pat);
|
||||
|
||||
if (err!=OK) {
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
return pat.path;
|
||||
}
|
||||
|
||||
String ResourceFormatImporter::get_resource_type(const String &p_path) const {
|
||||
|
||||
PathAndType pat;
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
|
||||
virtual bool can_be_imported(const String& p_path) const;
|
||||
|
||||
String get_internal_resource_path(const String& p_path) const;
|
||||
|
||||
void add_importer(const Ref<ResourceImporter>& p_importer) { importers.insert(p_importer); }
|
||||
Ref<ResourceImporter> get_importer_by_name(const String& p_name);
|
||||
|
|
|
@ -403,6 +403,8 @@ public:
|
|||
virtual void set_use_vsync(bool p_enable);
|
||||
virtual bool is_vsync_enabled() const;
|
||||
|
||||
virtual bool check_feature_support(const String& p_feature)=0;
|
||||
|
||||
bool is_hidpi_allowed() const { return _allow_hidpi; }
|
||||
OS();
|
||||
virtual ~OS();
|
||||
|
|
|
@ -1081,6 +1081,18 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
|
|||
state.current_line_width=p_material->line_width;
|
||||
}
|
||||
|
||||
if (state.current_depth_test!=(!p_material->shader->spatial.ontop)) {
|
||||
if (p_material->shader->spatial.ontop) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
} else {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
}
|
||||
|
||||
state.current_depth_test=!p_material->shader->spatial.ontop;
|
||||
}
|
||||
|
||||
if (state.current_depth_draw!=p_material->shader->spatial.depth_draw_mode) {
|
||||
switch(p_material->shader->spatial.depth_draw_mode) {
|
||||
case RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS:
|
||||
|
@ -1204,6 +1216,11 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
|
|||
|
||||
} else {
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (t->detect_3d) {
|
||||
t->detect_3d(t->detect_3d_ud);
|
||||
}
|
||||
#endif
|
||||
if (storage->config.srgb_decode_supported) {
|
||||
//if SRGB decode extension is present, simply switch the texture to whathever is needed
|
||||
bool must_srgb=false;
|
||||
|
@ -1216,9 +1233,8 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m
|
|||
if (must_srgb) {
|
||||
glTexParameteri(t->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (!(t->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
|
||||
t->flags|=VS::TEXTURE_FLAG_CONVERT_TO_LINEAR;
|
||||
//notify that texture must be set to linear beforehand, so it works in other platforms when exported
|
||||
if (t->detect_srgb) {
|
||||
t->detect_srgb(t->detect_srgb_ud);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1714,6 +1730,9 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_e
|
|||
state.cull_front=false;
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
state.current_depth_test=true;
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON,false);
|
||||
|
||||
state.current_blend_mode=-1;
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
int current_blend_mode;
|
||||
float current_line_width;
|
||||
int current_depth_draw;
|
||||
bool current_depth_test;
|
||||
GLuint current_main_tex;
|
||||
|
||||
SceneShaderGLES3 scene_shader;
|
||||
|
|
|
@ -218,7 +218,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima
|
|||
if (config.s3tc_supported) {
|
||||
|
||||
|
||||
r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
r_gl_format=GL_RGBA;
|
||||
r_gl_type=GL_UNSIGNED_BYTE;
|
||||
r_compressed=true;
|
||||
|
@ -785,7 +785,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image
|
|||
|
||||
if (texture->compressed) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
glCompressedTexImage2D( blit_target, i, format,w,h,0,size,&read[ofs] );
|
||||
glCompressedTexImage2D( blit_target, i, internal_format,w,h,0,size,&read[ofs] );
|
||||
|
||||
} else {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
@ -814,6 +814,10 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image
|
|||
if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && mipmaps==1 && !texture->ignore_mipmaps && (!(texture->flags&VS::TEXTURE_FLAG_CUBEMAP) || texture->stored_cube_sides==(1<<6)-1)) {
|
||||
//generate mipmaps if they were requested and the image does not contain them
|
||||
glGenerateMipmap(texture->target);
|
||||
} else if (mipmaps>1) {
|
||||
glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(texture->target, GL_TEXTURE_MAX_LEVEL, mipmaps-1);
|
||||
|
||||
}
|
||||
|
||||
texture->mipmaps=mipmaps;
|
||||
|
@ -1066,6 +1070,26 @@ void RasterizerStorageGLES3::textures_keep_original(bool p_enable) {
|
|||
config.keep_original_textures=p_enable;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata) {
|
||||
|
||||
Texture * texture = texture_owner.get(p_texture);
|
||||
ERR_FAIL_COND(!texture);
|
||||
|
||||
texture->detect_3d=p_callback;
|
||||
texture->detect_3d_ud=p_userdata;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata){
|
||||
Texture * texture = texture_owner.get(p_texture);
|
||||
ERR_FAIL_COND(!texture);
|
||||
|
||||
texture->detect_srgb=p_callback;
|
||||
texture->detect_srgb_ud=p_userdata;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_resolution) const {
|
||||
|
||||
Texture * texture = texture_owner.get(p_source);
|
||||
|
@ -1515,12 +1539,12 @@ void RasterizerStorageGLES3::_update_shader(Shader* p_shader) const {
|
|||
actions->uniforms=&p_shader->uniforms;
|
||||
|
||||
|
||||
}
|
||||
} break;
|
||||
case VS::SHADER_PARTICLES: {
|
||||
|
||||
actions=&shaders.actions_particles;
|
||||
actions->uniforms=&p_shader->uniforms;
|
||||
}
|
||||
} break;
|
||||
|
||||
}
|
||||
|
||||
|
@ -6294,6 +6318,25 @@ bool RasterizerStorageGLES3::free(RID p_rid){
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RasterizerStorageGLES3::has_os_feature(const String& p_feature) const {
|
||||
|
||||
if (p_feature=="s3tc")
|
||||
return config.s3tc_supported;
|
||||
|
||||
if (p_feature=="etc")
|
||||
return config.etc_supported;
|
||||
|
||||
if (p_feature=="etc2")
|
||||
return config.etc2_supported;
|
||||
|
||||
if (p_feature=="pvrtc")
|
||||
return config.pvrtc_supported;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////
|
||||
|
||||
|
||||
|
|
|
@ -228,6 +228,12 @@ public:
|
|||
|
||||
Image images[6];
|
||||
|
||||
VisualServer::TextureDetectCallback detect_3d;
|
||||
void *detect_3d_ud;
|
||||
|
||||
VisualServer::TextureDetectCallback detect_srgb;
|
||||
void *detect_srgb_ud;
|
||||
|
||||
Texture() {
|
||||
|
||||
using_srgb=false;
|
||||
|
@ -243,6 +249,10 @@ public:
|
|||
total_data_size=0;
|
||||
target=GL_TEXTURE_2D;
|
||||
mipmaps=0;
|
||||
detect_3d=NULL;
|
||||
detect_3d_ud=NULL;
|
||||
detect_srgb=NULL;
|
||||
detect_srgb_ud=NULL;
|
||||
|
||||
}
|
||||
|
||||
|
@ -281,6 +291,10 @@ public:
|
|||
|
||||
virtual void textures_keep_original(bool p_enable);
|
||||
|
||||
virtual void texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata);
|
||||
virtual void texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata);
|
||||
|
||||
|
||||
/* SKYBOX API */
|
||||
|
||||
struct SkyBox : public RID_Data {
|
||||
|
@ -1237,6 +1251,7 @@ public:
|
|||
void initialize();
|
||||
void finalize();
|
||||
|
||||
virtual bool has_os_feature(const String& p_feature) const;
|
||||
|
||||
|
||||
RasterizerStorageGLES3();
|
||||
|
|
|
@ -582,6 +582,7 @@ Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String& p_code,
|
|||
|
||||
used_name_defines.clear();
|
||||
used_rmode_defines.clear();
|
||||
used_flag_pointers.clear();
|
||||
|
||||
_dump_node_code(parser.get_shader(),1,r_gen_code,*p_actions,actions[p_mode]);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#ifdef UNIX_ENABLED
|
||||
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
#include "thread_posix.h"
|
||||
#include "semaphore_posix.h"
|
||||
|
@ -478,6 +479,13 @@ String OS_Unix::get_data_dir() const {
|
|||
|
||||
}
|
||||
|
||||
bool OS_Unix::check_feature_support(const String& p_feature) {
|
||||
|
||||
return VisualServer::get_singleton()->has_os_feature(p_feature);
|
||||
|
||||
}
|
||||
|
||||
|
||||
String OS_Unix::get_installed_templates_path() const {
|
||||
String p=get_global_settings_path();
|
||||
if (p!="")
|
||||
|
|
|
@ -117,6 +117,8 @@ public:
|
|||
virtual String get_executable_path() const;
|
||||
virtual String get_data_dir() const;
|
||||
|
||||
virtual bool check_feature_support(const String& p_feature);
|
||||
|
||||
//virtual void run( MainLoop * p_main_loop );
|
||||
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ static void _decompress_etc(Image *p_img) {
|
|||
//print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps()));
|
||||
*p_img=Image(p_img->get_width(),p_img->get_height(),p_img->has_mipmaps(),Image::FORMAT_RGB8,dst);
|
||||
if (p_img->has_mipmaps())
|
||||
p_img->generate_mipmaps(true);
|
||||
p_img->generate_mipmaps();
|
||||
|
||||
|
||||
}
|
||||
|
@ -112,16 +112,17 @@ static void _compress_etc(Image *p_img) {
|
|||
img.convert(Image::FORMAT_RGB8);
|
||||
|
||||
|
||||
int mmc=img.get_mipmap_count();
|
||||
if (mmc==0)
|
||||
img.generate_mipmaps(); // force mipmaps, so it works on most hardware
|
||||
|
||||
|
||||
PoolVector<uint8_t> res_data;
|
||||
PoolVector<uint8_t> dst_data;
|
||||
PoolVector<uint8_t>::Read r = img.get_data().read();
|
||||
|
||||
int target_size = Image::get_image_data_size(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC,p_img->has_mipmaps()?-1:0);
|
||||
int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC) : 0;
|
||||
|
||||
dst_data.resize(target_size);
|
||||
int mc=0;
|
||||
int ofs=0;
|
||||
PoolVector<uint8_t>::Write w=dst_data.write();
|
||||
|
||||
|
||||
rg_etc1::etc1_pack_params pp;
|
||||
|
@ -133,9 +134,9 @@ static void _compress_etc(Image *p_img) {
|
|||
int bh=MAX(imgh/4,1);
|
||||
const uint8_t *src = &r[img.get_mipmap_offset(i)];
|
||||
int mmsize = MAX(bw,1)*MAX(bh,1)*8;
|
||||
dst_data.resize(dst_data.size()+mmsize);
|
||||
PoolVector<uint8_t>::Write w=dst_data.write();
|
||||
uint8_t *dst = &w[dst_data.size()-mmsize];
|
||||
|
||||
uint8_t *dst = &w[ofs];
|
||||
ofs+=mmsize;
|
||||
|
||||
|
||||
//print_line("bh: "+itos(bh)+" bw: "+itos(bw));
|
||||
|
|
|
@ -64,10 +64,9 @@ void image_compress_squish(Image *p_image) {
|
|||
|
||||
p_image->convert(Image::FORMAT_RGBA8); //always expects rgba
|
||||
|
||||
int mm_count = p_image->get_mipmap_count();
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
int target_size = Image::get_image_data_size(w,h,target_format,mm_count);
|
||||
int target_size = Image::get_image_data_size(w,h,target_format,p_image->has_mipmaps()?-1:0);
|
||||
int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w,h,target_format) : 0;
|
||||
data.resize(target_size);
|
||||
|
||||
PoolVector<uint8_t>::Read rb = p_image->get_data().read();
|
||||
|
|
|
@ -906,7 +906,7 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
|
|||
|
||||
}
|
||||
|
||||
void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker) {
|
||||
void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) {
|
||||
|
||||
|
||||
for(int i=0;i<p_mesh->get_surface_count();i++) {
|
||||
|
@ -914,7 +914,16 @@ void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_b
|
|||
if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
|
||||
continue; //only triangles
|
||||
|
||||
Baker::MaterialCache material = _get_material_cache(p_mesh->surface_get_material(i),p_baker);
|
||||
Ref<Material> src_material;
|
||||
|
||||
if (p_override_material.is_valid()) {
|
||||
src_material=p_override_material;
|
||||
} else if (i<p_materials.size() && p_materials[i].is_valid()) {
|
||||
src_material=p_materials[i];
|
||||
} else {
|
||||
src_material=p_mesh->surface_get_material(i);
|
||||
}
|
||||
Baker::MaterialCache material = _get_material_cache(src_material,p_baker);
|
||||
|
||||
Array a = p_mesh->surface_get_arrays(i);
|
||||
|
||||
|
@ -1009,6 +1018,10 @@ void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){
|
|||
Baker::PlotMesh pm;
|
||||
pm.local_xform=xf;
|
||||
pm.mesh=mesh;
|
||||
for(int i=0;i<mesh->get_surface_count();i++) {
|
||||
pm.instance_materials.push_back(mi->get_surface_material(i));
|
||||
}
|
||||
pm.override_material=mi->get_material_override();
|
||||
p_baker->mesh_list.push_back(pm);
|
||||
|
||||
}
|
||||
|
@ -1083,7 +1096,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){
|
|||
|
||||
print_line("plotting mesh "+itos(pmc++)+"/"+itos(baker.mesh_list.size()));
|
||||
|
||||
_plot_mesh(E->get().local_xform,E->get().mesh,&baker);
|
||||
_plot_mesh(E->get().local_xform,E->get().mesh,&baker,E->get().instance_materials,E->get().override_material);
|
||||
}
|
||||
|
||||
_fixup_plot(0,0,0,0,0,&baker);
|
||||
|
|
|
@ -114,6 +114,8 @@ private:
|
|||
int axis_cell_size[3];
|
||||
|
||||
struct PlotMesh {
|
||||
Ref<Material> override_material;
|
||||
Vector<Ref<Material> > instance_materials;
|
||||
Ref<Mesh> mesh;
|
||||
Transform local_xform;
|
||||
};
|
||||
|
@ -141,7 +143,7 @@ private:
|
|||
Vector<Color> _get_bake_texture(Image &p_image,const Color& p_color);
|
||||
Baker::MaterialCache _get_material_cache(Ref<Material> p_material,Baker *p_baker);
|
||||
void _plot_face(int p_idx, int p_level, int p_x,int p_y,int p_z,const Vector3 *p_vtx, const Vector2* p_uv, const Baker::MaterialCache& p_material, const Rect3 &p_aabb,Baker *p_baker);
|
||||
void _plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker);
|
||||
void _plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker,const Vector<Ref<Material> >& p_materials,const Ref<Material>& p_override_material);
|
||||
void _find_meshes(Node *p_at_node,Baker *p_baker);
|
||||
void _fixup_plot(int p_idx, int p_level,int p_x,int p_y, int p_z,Baker *p_baker);
|
||||
|
||||
|
|
|
@ -456,6 +456,26 @@ ImageTexture::~ImageTexture() {
|
|||
//////////////////////////////////////////
|
||||
|
||||
|
||||
void StreamTexture::_requested_3d(void* p_ud) {
|
||||
|
||||
StreamTexture *st = (StreamTexture *)p_ud;
|
||||
Ref<StreamTexture> stex(st);
|
||||
ERR_FAIL_COND(!request_3d_callback);
|
||||
request_3d_callback(stex);
|
||||
}
|
||||
|
||||
void StreamTexture::_requested_srgb(void* p_ud) {
|
||||
|
||||
StreamTexture *st = (StreamTexture *)p_ud;
|
||||
Ref<StreamTexture> stex(st);
|
||||
ERR_FAIL_COND(!request_srgb_callback);
|
||||
request_srgb_callback(stex);
|
||||
|
||||
}
|
||||
|
||||
StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback=NULL;
|
||||
StreamTexture::TextureFormatRequestCallback StreamTexture::request_srgb_callback=NULL;
|
||||
|
||||
|
||||
uint32_t StreamTexture::get_flags() const {
|
||||
|
||||
|
@ -490,6 +510,23 @@ Error StreamTexture::_load_data(const String& p_path,int &tw,int &th,int& flags,
|
|||
print_line("flags: "+itos(flags));
|
||||
print_line("df: "+itos(df));
|
||||
|
||||
|
||||
if (request_3d_callback && df&FORMAT_BIT_DETECT_3D) {
|
||||
print_line("request detect 3D at "+p_path);
|
||||
VS::get_singleton()->texture_set_detect_3d_callback(texture,_requested_3d,this);
|
||||
} else {
|
||||
print_line("not requesting detect 3D at "+p_path);
|
||||
VS::get_singleton()->texture_set_detect_3d_callback(texture,NULL,NULL);
|
||||
}
|
||||
|
||||
if (request_srgb_callback && df&FORMAT_BIT_DETECT_SRGB) {
|
||||
print_line("request detect srgb at "+p_path);
|
||||
VS::get_singleton()->texture_set_detect_srgb_callback(texture,_requested_srgb,this);
|
||||
} else {
|
||||
VS::get_singleton()->texture_set_detect_srgb_callback(texture,NULL,NULL);
|
||||
print_line("not requesting detect srgb at "+p_path);
|
||||
}
|
||||
|
||||
if (!(df&FORMAT_BIT_STREAM)) {
|
||||
p_size_limit=0;
|
||||
}
|
||||
|
@ -635,6 +672,7 @@ Error StreamTexture::_load_data(const String& p_path,int &tw,int &th,int& flags,
|
|||
{
|
||||
PoolVector<uint8_t>::Write w=img_data.write();
|
||||
int bytes = f->get_buffer(w.ptr(),total_size - ofs);
|
||||
print_line("requested read: "+itos(total_size - ofs)+" but got: "+itos(bytes));
|
||||
|
||||
memdelete(f);
|
||||
|
||||
|
@ -722,6 +760,12 @@ void StreamTexture::set_flags(uint32_t p_flags){
|
|||
|
||||
void StreamTexture::reload_from_file() {
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
String ipath = get_import_path();
|
||||
if (ipath.is_resource_file() && ipath!=path_to_file) {
|
||||
path_to_file=ipath;
|
||||
}
|
||||
#endif
|
||||
load(path_to_file);
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,8 @@ public:
|
|||
FORMAT_BIT_LOSSY=1<<21,
|
||||
FORMAT_BIT_STREAM=1<<22,
|
||||
FORMAT_BIT_HAS_MIPMAPS=1<<23,
|
||||
FORMAT_BIT_DETECT_3D=1<<24,
|
||||
FORMAT_BIT_DETECT_SRGB=1<<25,
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -191,6 +193,9 @@ private:
|
|||
|
||||
virtual void reload_from_file();
|
||||
|
||||
static void _requested_3d(void* p_ud);
|
||||
static void _requested_srgb(void* p_ud);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
|
@ -198,6 +203,11 @@ protected:
|
|||
public:
|
||||
|
||||
|
||||
typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture>&);
|
||||
|
||||
static TextureFormatRequestCallback request_3d_callback;
|
||||
static TextureFormatRequestCallback request_srgb_callback;
|
||||
|
||||
uint32_t get_flags() const;
|
||||
Image::Format get_format() const;
|
||||
Error load(const String& p_path);
|
||||
|
|
|
@ -196,6 +196,8 @@ public:
|
|||
|
||||
virtual RID texture_create_radiance_cubemap(RID p_source,int p_resolution=-1) const=0;
|
||||
|
||||
virtual void texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata)=0;
|
||||
virtual void texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata)=0;
|
||||
|
||||
virtual void textures_keep_original(bool p_enable)=0;
|
||||
|
||||
|
@ -512,6 +514,7 @@ public:
|
|||
virtual VS::InstanceType get_base_type(RID p_rid) const=0;
|
||||
virtual bool free(RID p_rid)=0;
|
||||
|
||||
virtual bool has_os_feature(const String& p_feature) const=0;
|
||||
|
||||
static RasterizerStorage*base_signleton;
|
||||
RasterizerStorage();
|
||||
|
|
|
@ -157,6 +157,12 @@ RID VisualServerRaster::get_test_cube() {
|
|||
return test_cube;
|
||||
}
|
||||
|
||||
|
||||
bool VisualServerRaster::has_os_feature(const String& p_feature) const {
|
||||
|
||||
return VSG::storage->has_os_feature(p_feature);
|
||||
}
|
||||
|
||||
VisualServerRaster::VisualServerRaster() {
|
||||
|
||||
VSG::canvas = memnew( VisualServerCanvas);
|
||||
|
|
|
@ -622,7 +622,8 @@ public:
|
|||
BIND3(texture_set_size_override,RID,int,int)
|
||||
BIND2RC(RID,texture_create_radiance_cubemap,RID,int)
|
||||
|
||||
|
||||
BIND3(texture_set_detect_3d_callback,RID,TextureDetectCallback,void*)
|
||||
BIND3(texture_set_detect_srgb_callback,RID,TextureDetectCallback,void*)
|
||||
|
||||
BIND2(texture_set_path,RID,const String&)
|
||||
BIND1RC(String,texture_get_path,RID)
|
||||
|
@ -1135,6 +1136,8 @@ public:
|
|||
|
||||
virtual bool has_feature(Features p_feature) const;
|
||||
|
||||
virtual bool has_os_feature(const String& p_feature) const;
|
||||
|
||||
|
||||
VisualServerRaster();
|
||||
~VisualServerRaster();
|
||||
|
|
|
@ -129,6 +129,11 @@ public:
|
|||
|
||||
virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable)=0;
|
||||
|
||||
typedef void (*TextureDetectCallback)(void*);
|
||||
|
||||
virtual void texture_set_detect_3d_callback(RID p_texture,TextureDetectCallback p_callback,void* p_userdata)=0;
|
||||
virtual void texture_set_detect_srgb_callback(RID p_texture,TextureDetectCallback p_callback,void* p_userdata)=0;
|
||||
|
||||
struct TextureInfo {
|
||||
RID texture;
|
||||
Size2 size;
|
||||
|
@ -938,6 +943,8 @@ public:
|
|||
|
||||
virtual bool has_feature(Features p_feature) const=0;
|
||||
|
||||
virtual bool has_os_feature(const String& p_feature) const=0;
|
||||
|
||||
VisualServer();
|
||||
virtual ~VisualServer();
|
||||
|
||||
|
|
|
@ -1028,7 +1028,7 @@ void EditorFileSystem::_notification(int p_what) {
|
|||
|
||||
bool EditorFileSystem::is_scanning() const {
|
||||
|
||||
return scanning;
|
||||
return scanning || scanning_changes;
|
||||
}
|
||||
float EditorFileSystem::get_scanning_progress() const {
|
||||
|
||||
|
@ -1393,6 +1393,7 @@ void EditorFileSystem::_reimport_file(const String& p_file) {
|
|||
f->store_line("type=\""+importer->get_resource_type()+"\"");
|
||||
}
|
||||
|
||||
|
||||
if (importer->get_save_extension()=="") {
|
||||
//no path
|
||||
} else if (import_variants.size()) {
|
||||
|
@ -1400,7 +1401,10 @@ void EditorFileSystem::_reimport_file(const String& p_file) {
|
|||
for(List<String>::Element *E=import_variants.front();E;E=E->next()) {
|
||||
|
||||
|
||||
f->store_line("path."+E->get()+"=\""+base_path.c_escape()+"."+E->get()+"."+importer->get_save_extension()+"\"");
|
||||
String path = base_path.c_escape()+"."+E->get()+"."+importer->get_save_extension();
|
||||
|
||||
f->store_line("path."+E->get()+"=\""+path+"\"");
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
|
@ -1426,6 +1430,8 @@ void EditorFileSystem::_reimport_file(const String& p_file) {
|
|||
f->store_line("");
|
||||
|
||||
//store options in provided order, to avoid file changing
|
||||
|
||||
|
||||
for (List<ResourceImporter::ImportOption>::Element *E=opts.front();E;E=E->next()) {
|
||||
|
||||
String base = E->get().option.name;
|
||||
|
@ -1442,11 +1448,25 @@ void EditorFileSystem::_reimport_file(const String& p_file) {
|
|||
//update modified times, to avoid reimport
|
||||
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
|
||||
fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file+".import");
|
||||
|
||||
//if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it
|
||||
//to reload properly
|
||||
if (ResourceCache::has(p_file)) {
|
||||
|
||||
Resource *r = ResourceCache::get(p_file);
|
||||
|
||||
if (r->get_import_path()!=String()) {
|
||||
|
||||
String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_file);
|
||||
r->set_import_path(dst_path);
|
||||
r->set_import_last_modified_time(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFileSystem::reimport_files(const Vector<String>& p_files) {
|
||||
|
||||
|
||||
importing=true;
|
||||
EditorProgress pr("reimport",TTR("(Re)Importing Assets"),p_files.size());
|
||||
for(int i=0;i<p_files.size();i++) {
|
||||
pr.step(p_files[i].get_file(),i);
|
||||
|
@ -1455,6 +1475,10 @@ void EditorFileSystem::reimport_files(const Vector<String>& p_files) {
|
|||
}
|
||||
|
||||
_save_filesystem_cache();
|
||||
importing=false;
|
||||
if (!is_scanning()) {
|
||||
emit_signal("filesystem_changed");
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFileSystem::_bind_methods() {
|
||||
|
@ -1503,6 +1527,7 @@ EditorFileSystem::EditorFileSystem() {
|
|||
|
||||
thread = NULL;
|
||||
scanning=false;
|
||||
importing=false;
|
||||
use_threads=true;
|
||||
thread_sources=NULL;
|
||||
new_filesystem=NULL;
|
||||
|
|
|
@ -133,6 +133,7 @@ class EditorFileSystem : public Node {
|
|||
|
||||
bool abort_scan;
|
||||
bool scanning;
|
||||
bool importing;
|
||||
float scan_total;
|
||||
|
||||
|
||||
|
@ -210,6 +211,7 @@ public:
|
|||
|
||||
EditorFileSystemDirectory *get_filesystem();
|
||||
bool is_scanning() const;
|
||||
bool is_importing() const { return importing; }
|
||||
float get_scanning_progress() const;
|
||||
void scan();
|
||||
void scan_changes();
|
||||
|
|
|
@ -308,6 +308,8 @@ void EditorNode::_notification(int p_what) {
|
|||
|
||||
}
|
||||
|
||||
ResourceImporterTexture::get_singleton()->update_imports();
|
||||
|
||||
}
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
|
@ -411,8 +413,10 @@ void EditorNode::_fs_changed() {
|
|||
if (E->get()->get_import_path()!=String()) {
|
||||
//imported resource
|
||||
uint64_t mt = FileAccess::get_modified_time(E->get()->get_import_path());
|
||||
print_line("testing modified: "+E->get()->get_import_path()+" "+itos(mt)+" vs "+itos(E->get()->get_import_last_modified_time()));
|
||||
|
||||
if (mt!=E->get()->get_import_last_modified_time()) {
|
||||
print_line("success");
|
||||
changed.push_back(E->get());
|
||||
}
|
||||
|
||||
|
|
|
@ -430,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!="") {
|
||||
|
@ -443,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
|
||||
|
@ -465,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));
|
||||
|
||||
|
@ -477,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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -277,12 +277,10 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b
|
|||
Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() );
|
||||
Set<Ref<SpatialEditorGizmo> > found_gizmos;
|
||||
|
||||
//uint32_t closest=0;
|
||||
//float closest_dist=0;
|
||||
|
||||
r_includes_current=false;
|
||||
|
||||
List<_RayResult> results;
|
||||
ObjectID closest=0;
|
||||
Spatial *item=NULL;
|
||||
float closest_dist=1e20;
|
||||
int selected_handle=-1;
|
||||
|
||||
for (int i=0;i<instances.size();i++) {
|
||||
|
||||
|
@ -318,84 +316,30 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b
|
|||
if (dist<0)
|
||||
continue;
|
||||
|
||||
if (dist < closest_dist) {
|
||||
closest=instances[i];
|
||||
closest_dist=dist;
|
||||
selected_handle=handle;
|
||||
item=spat;
|
||||
}
|
||||
|
||||
// if (editor_selection->is_selected(spat))
|
||||
// r_includes_current=true;
|
||||
|
||||
if (editor_selection->is_selected(spat))
|
||||
r_includes_current=true;
|
||||
|
||||
_RayResult res;
|
||||
res.item=spat;
|
||||
res.depth=dist;
|
||||
res.handle=handle;
|
||||
results.push_back(res);
|
||||
}
|
||||
|
||||
|
||||
if (results.empty())
|
||||
if (!item)
|
||||
return 0;
|
||||
|
||||
results.sort();
|
||||
Spatial *s=NULL;
|
||||
if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle>=0)) {
|
||||
|
||||
|
||||
if (!r_includes_current || results.size()==1 || (r_gizmo_handle && results.front()->get().handle>=0)) {
|
||||
|
||||
//return the nearest one
|
||||
s = results.front()->get().item;
|
||||
if (r_gizmo_handle)
|
||||
*r_gizmo_handle=results.front()->get().handle;
|
||||
|
||||
} else {
|
||||
|
||||
//returns the next one from a curent selection
|
||||
List<_RayResult>::Element *E=results.front();
|
||||
List<_RayResult>::Element *S=NULL;
|
||||
|
||||
|
||||
while(true) {
|
||||
|
||||
//very strange loop algorithm that complies with object selection standards (tm).
|
||||
|
||||
if (S==E) {
|
||||
//went all around and anothing was found
|
||||
//since can't rotate the selection
|
||||
//just return the first one
|
||||
|
||||
s=results.front()->get().item;
|
||||
break;
|
||||
*r_gizmo_handle=selected_handle;
|
||||
|
||||
}
|
||||
|
||||
if (!S && editor_selection->is_selected(E->get().item)) {
|
||||
//found an item currently in the selection,
|
||||
//so start from this one
|
||||
S=E;
|
||||
}
|
||||
|
||||
if (S && !editor_selection->is_selected(E->get().item)) {
|
||||
// free item after a selected item, this one is desired.
|
||||
s=E->get().item;
|
||||
break;
|
||||
}
|
||||
|
||||
E=E->next();
|
||||
if (!E) {
|
||||
|
||||
if (!S) {
|
||||
//did a loop but nothing was selected, select first
|
||||
s=results.front()->get().item;
|
||||
break;
|
||||
|
||||
}
|
||||
E=results.front();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
return s->get_instance_ID();
|
||||
return closest;
|
||||
|
||||
}
|
||||
|
||||
|
@ -3143,7 +3087,7 @@ void SpatialEditor::_init_indicators() {
|
|||
|
||||
indicator_mat.instance();
|
||||
indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true);
|
||||
indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true);
|
||||
//indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true);
|
||||
indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true);
|
||||
indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true);
|
||||
|
||||
|
|
|
@ -2484,7 +2484,7 @@ void GIProbeGizmo::redraw(){
|
|||
|
||||
}
|
||||
|
||||
add_lines(lines,SpatialEditorGizmos::singleton->reflection_probe_material_internal);
|
||||
add_lines(lines,SpatialEditorGizmos::singleton->gi_probe_material_internal);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
|
||||
|
@ -3406,7 +3406,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
|
|||
reflection_probe_material = create_line_material(Color(0.5,1.0,0.7));
|
||||
reflection_probe_material_internal = create_line_material(Color(0.3,0.8,0.5,0.15));
|
||||
gi_probe_material = create_line_material(Color(0.7,1.0,0.5));
|
||||
gi_probe_material_internal = create_line_material(Color(0.5,0.8,0.3,0.4));
|
||||
gi_probe_material_internal = create_line_material(Color(0.5,0.8,0.3,0.1));
|
||||
joint_material = create_line_material(Color(0.6,0.8,1.0));
|
||||
|
||||
stream_player_icon = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial ));
|
||||
|
|
Loading…
Reference in a new issue