From 144494600620dbaeee454fb454b84f2388d6fe25 Mon Sep 17 00:00:00 2001 From: cheece <666mon@gmail.com> Date: Tue, 24 Feb 2015 20:13:21 -0430 Subject: COLLADA load normals from morph target if the file has normals use them! --- tools/editor/io_plugins/editor_import_collada.cpp | 54 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'tools/editor/io_plugins') diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index 529ed3374b..36d412d66c 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -1354,8 +1354,60 @@ Error ColladaImport::_create_mesh_surfaces(Ref& p_mesh,const Map::Write(); DVector normals; DVector tangents; + if(md.vertices[vertex_src_id].sources.has("NORMAL")){ + //has normals + normals.resize(vlen); + std::cout << "has normals" << std::endl; + String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"]; + std::cout << "normals source: "<< normal_src_id.utf8().get_data() <array.size() != vertex_src->array.size(), ERR_INVALID_DATA); + int stride=m->stride; + if (stride==0) + stride=3; + + + //read normals from morph target + DVector::Write vertw = normals.write(); + + for(int m_i=0;m_iarray.size()/stride;m_i++) { + + int pos = m_i*stride; + Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] ); + + #ifndef NO_UP_AXIS_SWAP + if (collada.state.up_axis==Vector3::AXIS_Z) { + + SWAP( vtx.z, vtx.y ); + vtx.z = -vtx.z; + + } + #endif + + Collada::Vertex vertex; + vertex.vertex=vtx; + vertex.fix_unit_scale(collada); + vtx=vertex.vertex; + + vtx = p_local_xform.xform(vtx); + + + if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting + + + for (Set ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) { + + vertw[E->get()]=vtx; + } + } + } + + }else{ + _generate_normals(index_array,vertices,normals);//no normals + } if (final_tangent_array.size() && final_uv_array.size()) { _generate_tangents_and_binormals(index_array,vertices,final_uv_array,normals,tangents); -- cgit v1.2.3 From 4d2198110b4af7f203eeef95697255569e49bce7 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 3 Mar 2015 14:39:13 -0300 Subject: merges from okam repo --- tools/editor/io_plugins/editor_import_collada.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tools/editor/io_plugins') diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index 529ed3374b..6dd46843cc 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -285,13 +285,16 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) { case Collada::CameraData::MODE_ORTHOGONAL: { - if (cd.orthogonal.x_mag) { + if (cd.orthogonal.y_mag) { - camera->set_orthogonal(cd.orthogonal.x_mag,cd.z_near,cd.z_far); + camera->set_keep_aspect_mode(Camera::KEEP_HEIGHT); + camera->set_orthogonal(cd.orthogonal.y_mag*2.0 ,cd.z_near,cd.z_far); - } else if (!cd.orthogonal.x_mag && cd.orthogonal.y_mag) { + } else if (!cd.orthogonal.y_mag && cd.orthogonal.x_mag) { - camera->set_orthogonal(cd.orthogonal.y_mag * cd.aspect,cd.z_near,cd.z_far); + + camera->set_keep_aspect_mode(Camera::KEEP_WIDTH); + camera->set_orthogonal(cd.orthogonal.x_mag*2.0,cd.z_near,cd.z_far); } } break; -- cgit v1.2.3 From 90a84b4ddb64f4adc024766435f3fc75605f9aab Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 20 Mar 2015 00:26:01 -0300 Subject: wip distance field font import font import may not work if using distance field, this is WIP --- .../io_plugins/editor_font_import_plugin.cpp | 347 ++++++++++++++++++--- 1 file changed, 297 insertions(+), 50 deletions(-) (limited to 'tools/editor/io_plugins') diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index 1fd7d26f8b..05a42218a2 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -47,6 +47,12 @@ class _EditorFontImportOptions : public Object { OBJ_TYPE(_EditorFontImportOptions,Object); public: + enum FontMode { + + FONT_BITMAP, + FONT_DISTANCE_FIELD + }; + enum ColorType { COLOR_WHITE, COLOR_CUSTOM, @@ -69,6 +75,9 @@ public: CHARSET_CUSTOM_LATIN }; + + FontMode font_mode; + CharacterSet character_set; String custom_file; @@ -91,7 +100,6 @@ public: bool color_use_monochrome; String gradient_image; - bool disable_filter; bool round_advance; @@ -100,7 +108,10 @@ public: bool _set(const StringName& p_name, const Variant& p_value) { String n = p_name; - if (n=="extra_space/char") + if (n=="mode/mode") { + font_mode=FontMode(int(p_value)); + _change_notify(); + } else if (n=="extra_space/char") char_extra_spacing=p_value; else if (n=="extra_space/space") space_extra_spacing=p_value; @@ -169,7 +180,9 @@ public: bool _get(const StringName& p_name,Variant &r_ret) const{ String n = p_name; - if (n=="extra_space/char") + if (n=="mode/mode") + r_ret=font_mode; + else if (n=="extra_space/char") r_ret=char_extra_spacing; else if (n=="extra_space/space") r_ret=space_extra_spacing; @@ -231,6 +244,9 @@ public: void _get_property_list( List *p_list) const{ + + p_list->push_back(PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Bitmap,Distance Field")); + p_list->push_back(PropertyInfo(Variant::INT,"extra_space/char",PROPERTY_HINT_RANGE,"-64,64,1")); p_list->push_back(PropertyInfo(Variant::INT,"extra_space/space",PROPERTY_HINT_RANGE,"-64,64,1")); p_list->push_back(PropertyInfo(Variant::INT,"extra_space/top",PROPERTY_HINT_RANGE,"-64,64,1")); @@ -240,35 +256,45 @@ public: if (character_set>=CHARSET_CUSTOM) p_list->push_back(PropertyInfo(Variant::STRING,"character_set/custom",PROPERTY_HINT_FILE)); - p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled")); - if (shadow) { - p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset")); - p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color")); - p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING)); - } + int usage = PROPERTY_USAGE_DEFAULT; - p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled")); - if (shadow2) { - p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset")); - p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color")); - p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING)); + if (font_mode==FONT_DISTANCE_FIELD) { + usage = PROPERTY_USAGE_NOEDITOR; } - p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image")); - if (color_type==COLOR_CUSTOM) { - p_list->push_back(PropertyInfo(Variant::COLOR,"color/color")); + { + p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled",PROPERTY_HINT_NONE,"",usage)); + if (shadow) { + p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage)); + p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING,"",usage)); + } + + p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled",PROPERTY_HINT_NONE,"",usage)); + if (shadow2) { + p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage)); + p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING,"",usage)); + } + + p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image",usage)); + if (color_type==COLOR_CUSTOM) { + p_list->push_back(PropertyInfo(Variant::COLOR,"color/color",PROPERTY_HINT_NONE,"",usage)); + + } + if (color_type==COLOR_GRADIENT_RANGE) { + p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"color/end",PROPERTY_HINT_NONE,"",usage)); + } + if (color_type==COLOR_GRADIENT_IMAGE) { + p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_FILE,"",usage)); + } + p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome",PROPERTY_HINT_NONE,"",usage)); } - if (color_type==COLOR_GRADIENT_RANGE) { - p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin")); - p_list->push_back(PropertyInfo(Variant::COLOR,"color/end")); - } - if (color_type==COLOR_GRADIENT_IMAGE) { - p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_FILE)); - } - p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome")); + p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/round_advance")); p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/disable_filter")); @@ -307,6 +333,7 @@ public: gradient_end=Color(0.5,0.5,0.5,1); color_use_monochrome=false; + font_mode=FONT_BITMAP; round_advance=true; disable_filter=false; @@ -314,6 +341,8 @@ public: _EditorFontImportOptions() { + font_mode=FONT_BITMAP; + char_extra_spacing=0; top_extra_spacing=0; bottom_extra_spacing=0; @@ -706,6 +735,137 @@ struct _EditorKerningKey { }; + +static unsigned char get_SDF_radial( + unsigned char *fontmap, + int w, int h, + int x, int y, + int max_radius ) +{ + // hideous brute force method + float d2 = max_radius*max_radius+1.0; + unsigned char v = fontmap[x+y*w]; + for( int radius = 1; (radius <= max_radius) && (radius*radius < d2); ++radius ) + { + int line, lo, hi; + // north + line = y - radius; + if( (line >= 0) && (line < h) ) + { + lo = x - radius; + hi = x + radius; + if( lo < 0 ) { lo = 0; } + if( hi >= w ) { hi = w-1; } + int idx = line * w + lo; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = i - x; + float ny = line - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + ++idx; + } + } + // south + line = y + radius; + if( (line >= 0) && (line < h) ) + { + lo = x - radius; + hi = x + radius; + if( lo < 0 ) { lo = 0; } + if( hi >= w ) { hi = w-1; } + int idx = line * w + lo; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = i - x; + float ny = line - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + ++idx; + } + } + // west + line = x - radius; + if( (line >= 0) && (line < w) ) + { + lo = y - radius + 1; + hi = y + radius - 1; + if( lo < 0 ) { lo = 0; } + if( hi >= h ) { hi = h-1; } + int idx = lo * w + line; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = line - x; + float ny = i - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + idx += w; + } + } + // east + line = x + radius; + if( (line >= 0) && (line < w) ) + { + lo = y - radius + 1; + hi = y + radius - 1; + if( lo < 0 ) { lo = 0; } + if( hi >= h ) { hi = h-1; } + int idx = lo * w + line; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = line - x; + float ny = i - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + idx += w; + } + } + } + d2 = sqrtf( d2 ); + if( v==0 ) + { + d2 = -d2; + } + d2 *= 127.5 / max_radius; + d2 += 127.5; + if( d2 < 0.0 ) d2 = 0.0; + if( d2 > 255.0 ) d2 = 255.0; + return (unsigned char)(d2 + 0.5); +} + + Ref EditorFontImportPlugin::generate_font(const Ref& p_from, const String &p_existing) { Ref from = p_from; @@ -754,7 +914,11 @@ Ref EditorFontImportPlugin::generate_font(const Refget_option("mode/mode"); + + int scaler=(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD)?16:1; + + error = FT_Set_Pixel_Sizes(face,0,size*scaler); FT_GlyphSlot slot = face->glyph; @@ -822,7 +986,7 @@ Ref EditorFontImportPlugin::generate_font(const Refglyph, ft_render_mode_normal ); + else error = FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono ); if (error) { skip=true; } else if (!skip) { @@ -847,28 +1011,35 @@ Ref EditorFontImportPlugin::generate_font(const Refbitmap.resize( slot->bitmap.width*slot->bitmap.rows ); - fdata->width=slot->bitmap.width; - fdata->height=slot->bitmap.rows; - fdata->character=charcode; - fdata->glyph=FT_Get_Char_Index(face,charcode); - if (charcode=='x') - xsize=slot->bitmap.width; - if (charcode<127) { - if (slot->bitmap_top>max_up) { - - max_up=slot->bitmap_top; - } + int w = slot->bitmap.width; + int h = slot->bitmap.rows; + int p = slot->bitmap.pitch; + print_line("pitch "+itos(slot->bitmap.pitch)); + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { - if ( (slot->bitmap_top - fdata->height)bitmap_top - fdata->height; - } + fdata->width=sdfw; + fdata->height=sdfh; + } else { + fdata->width=w; + fdata->height=h; } + fdata->character=charcode; + fdata->glyph=FT_Get_Char_Index(face,charcode); + if (charcode=='x') + xsize=w/scaler; + + fdata->valign=slot->bitmap_top; fdata->halign=slot->bitmap_left; @@ -878,12 +1049,87 @@ Ref EditorFontImportPlugin::generate_font(const Refadvance=slot->advance.x/float(1<<6); + fdata->advance/=scaler; + + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { + + fdata->halign = fdata->halign / scaler - 1.5; + fdata->valign = fdata->valign / scaler + 1.5; + fdata->advance/=scaler; + + } + fdata->advance+=font_spacing; - for (int i=0;ibitmap.width;i++) { - for (int j=0;jbitmap.rows;j++) { - fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + if (charcode<127) { + int top = fdata->valign; + int hmax = h/scaler; + + if (top>max_up) { + + max_up=top; + } + + + if ( (top - hmax)bitmap.buffer; + for( int j = 0; j < h; ++j ) { + for( int i = 0; i < w; ++i ) { + smooth_buf[scaler*2+i+(j+scaler*2)*sw] = 255 * ((buf[j*p+(i>>3)] >> (7 - (i & 7))) & 1); + } + } + + // do the SDF + int sdfw = fdata->width; + int sdfh = fdata->height; + + fdata->bitmap.resize( sdfw*sdfh ); + + for( int j = 0; j < sdfh; ++j ) { + for( int i = 0; i < sdfw; ++i ) { + int pd_idx = j*sdfw+i; + + //fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + + fdata->bitmap[pd_idx] = + //get_SDF + get_SDF_radial + ( smooth_buf, sw, sh, + i*scaler + (scaler >>1), j*scaler + (scaler >>1), + 2*scaler ); + + } + } + + delete [] smooth_buf; + + } else { + fdata->bitmap.resize( slot->bitmap.width*slot->bitmap.rows ); + for (int i=0;ibitmap.width;i++) { + for (int j=0;jbitmap.rows;j++) { + + fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + } } } @@ -907,6 +1153,7 @@ Ref EditorFontImportPlugin::generate_font(const Refglyph, ft_render_mode_normal )) { spd->advance = slot->advance.x>>6; //round to nearest or store as float + spd->advance/=scaler; spd->advance+=font_spacing; } else { @@ -955,7 +1202,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref EditorFontImportPlugin::generate_font(const Ref::Write w = pixels.write(); - print_line("val: "+itos(font_data_list[i]->valign)); + //print_line("val: "+itos(font_data_list[i]->valign)); for(int y=0;yvalign,0,height-1); @@ -1251,7 +1498,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref atlast = memnew( ImageTexture ); atlast->create_from_image(atlas); -- cgit v1.2.3 From acc6f3b285f058104fd6431bed2c4cfe4dc05a58 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 21 Mar 2015 00:43:33 -0300 Subject: signed distance field font support --- tools/editor/io_plugins/editor_font_import_plugin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/editor/io_plugins') diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index 05a42218a2..0562153199 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -984,7 +984,7 @@ Ref EditorFontImportPlugin::generate_font(const Refglyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono ); if (error) { @@ -1016,7 +1016,8 @@ Ref EditorFontImportPlugin::generate_font(const Refbitmap.width; int h = slot->bitmap.rows; int p = slot->bitmap.pitch; - print_line("pitch "+itos(slot->bitmap.pitch)); + + print_line("W: "+itos(w)+" P: "+itos(slot->bitmap.pitch)); if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { @@ -1049,8 +1050,6 @@ Ref EditorFontImportPlugin::generate_font(const Refadvance=slot->advance.x/float(1<<6); - fdata->advance/=scaler; - if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { fdata->halign = fdata->halign / scaler - 1.5; @@ -1150,7 +1149,7 @@ Ref EditorFontImportPlugin::generate_font(const Refofs_x=0; spd->ofs_y=0; - if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, ft_render_mode_normal )) { + if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono )) { spd->advance = slot->advance.x>>6; //round to nearest or store as float spd->advance/=scaler; @@ -1498,7 +1497,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref atlast = memnew( ImageTexture ); atlast->create_from_image(atlas); @@ -1531,6 +1530,7 @@ Ref EditorFontImportPlugin::generate_font(const Refclear(); font->set_height(height+bottom_space+top_space); font->set_ascent(ascent+top_space); + font->set_distance_field_hint(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD); //register texures { -- cgit v1.2.3