void ScriptDebuggerLocal::profiling_end() { int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo[ofs], pinfo.size() - ofs); } SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort; sort.sort(pinfo.ptr(), ofs); uint64_t total_us = 0; for (int i = 0; i < ofs; i++) { total_us += pinfo[i].self_time; } float total_time = total_us / 1000000.0; for (int i = 0; i < ofs; i++) { print_line(itos(i) + ":" + pinfo[i].signature); float tt = USEC_TO_SEC(pinfo[i].total_time); float st = USEC_TO_SEC(pinfo[i].self_time); print_line("\ttotal_ms: " + rtos(tt) + "\tself_ms: " + rtos(st) + "total%: " + itos(tt * 100 / total_time) + "\tself%: " + itos(st * 100 / total_time) + "\tcalls: " + itos(pinfo[i].call_count)); } for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->profiling_stop(); } profiling = false; }
void _import_inc(String p_font) { Ref<Font> font = ResourceLoader::load(p_font); if (!font.is_valid()) return; Ref<ImageTexture> tex = font->get_texture(0); if (tex.is_null()) return; FileAccessRef f=FileAccess::open(p_font.basename()+".inc",FileAccess::WRITE); Vector<CharType> ck = font->get_char_keys(); f->store_line("static const int _builtin_font_height="+itos(font->get_height())+";"); f->store_line("static const int _builtin_font_ascent="+itos(font->get_ascent())+";"); f->store_line("static const int _builtin_font_charcount="+itos(ck.size())+";"); f->store_line("static const int _builtin_font_charrects["+itos(ck.size())+"][8]={"); f->store_line("/* charidx , ofs_x, ofs_y, size_x, size_y, valign, halign, advance */"); for(int i=0;i<ck.size();i++) { CharType k=ck[i]; Font::Character c=font->get_character(k); f->store_line("{"+itos(k)+","+rtos(c.rect.pos.x)+","+rtos(c.rect.pos.y)+","+rtos(c.rect.size.x)+","+rtos(c.rect.size.y)+","+rtos(c.v_align)+","+rtos(c.h_align)+","+rtos(c.advance)+"},"); } f->store_line("};"); Vector<Font::KerningPairKey> kp=font->get_kerning_pair_keys(); f->store_line("static const int _builtin_font_kerning_pair_count="+itos(kp.size())+";"); f->store_line("static const int _builtin_font_kerning_pairs["+itos(kp.size())+"][3]={"); for(int i=0;i<kp.size();i++) { int d = font->get_kerning_pair(kp[i].A,kp[i].B); f->store_line("{"+itos(kp[i].A)+","+itos(kp[i].B)+","+itos(d)+"},"); } f->store_line("};"); Image img = tex->get_data(); f->store_line("static const int _builtin_font_img_width="+itos(img.get_width())+";"); f->store_line("static const int _builtin_font_img_height="+itos(img.get_height())+";"); f->store_line("static const unsigned char _builtin_font_img_data["+itos(img.get_width()*img.get_height()*2)+"]={"); for(int i=0;i<img.get_height();i++) { for(int j=0;j<img.get_width();j++) { Color c = img.get_pixel(j,i); int v = CLAMP(((c.r+c.g+c.b)/3.0)*255,0,255); int a = CLAMP(c.a*255,0,255); f->store_line(itos(v)+","+itos(a)+","); } } f->store_line("};"); }
void ScriptDebuggerLocal::idle_poll() { if (!profiling) return; uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum; if (diff < 1000000) //show every one second return; idle_accum = OS::get_singleton()->get_ticks_usec(); int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo[ofs], pinfo.size() - ofs); } SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort; sort.sort(pinfo.ptr(), ofs); //falta el frame time uint64_t script_time_us = 0; for (int i = 0; i < ofs; i++) { script_time_us += pinfo[i].self_time; } float script_time = USEC_TO_SEC(script_time_us); float total_time = frame_time; //print script total print_line("FRAME: total: " + rtos(frame_time) + " script: " + rtos(script_time) + "/" + itos(script_time * 100 / total_time) + " %"); for (int i = 0; i < ofs; i++) { print_line(itos(i) + ":" + pinfo[i].signature); float tt = USEC_TO_SEC(pinfo[i].total_time); float st = USEC_TO_SEC(pinfo[i].self_time); print_line("\ttotal: " + rtos(tt) + "/" + itos(tt * 100 / total_time) + " % \tself: " + rtos(st) + "/" + itos(st * 100 / total_time) + " % tcalls: " + itos(pinfo[i].call_count)); } }
CameraMatrix::operator String() const { String str; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) str += String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]); return str; }
String VisualScriptYield::get_text() const { switch (yield_mode) { case YIELD_RETURN: return ""; break; case YIELD_FRAME: return "Next Frame"; break; case YIELD_PHYSICS_FRAME: return "Next Fixed Frame"; break; case YIELD_WAIT: return rtos(wait_time) + " sec(s)"; break; } return String(); }
void OrientedPathFollow::_validate_property(PropertyInfo &property) const { if (property.name == "offset") { float max = 10000; if (path && path->get_curve().is_valid()) max = path->get_curve()->get_baked_length(); property.hint_string = "0," + rtos(max) + ",0.01"; } }
MainLoop *test() { List<String> cmdlargs = OS::get_singleton()->get_cmdline_args(); if (cmdlargs.empty()) { //try editor! print_line("usage: godot -test shader_lang <shader>"); return NULL; } String test = cmdlargs.back()->get(); FileAccess *fa = FileAccess::open(test, FileAccess::READ); if (!fa) { ERR_FAIL_V(NULL); } String code; while (true) { CharType c = fa->get_8(); if (fa->eof_reached()) break; code += c; } SL sl; print_line("tokens:\n\n" + sl.token_debug(code)); Map<StringName, SL::FunctionInfo> dt; dt["fragment"].built_ins["ALBEDO"] = SL::TYPE_VEC3; dt["fragment"].can_discard = true; Vector<StringName> rm; rm.push_back("popo"); Set<String> types; types.insert("spatial"); Error err = sl.compile(code, dt, rm, types); if (err) { print_line("Error at line: " + rtos(sl.get_error_line()) + ": " + sl.get_error_text()); return NULL; } else { String code; recreate_code(&code, sl.get_shader()); print_line("code:\n\n" + code); } return NULL; }
String EditorProfiler::_get_time_as_text(Metric &m,float p_time,int p_calls) { int dmode = display_mode->get_selected(); if (dmode==DISPLAY_FRAME_TIME) { return rtos(p_time); } else if (dmode==DISPLAY_AVERAGE_TIME) { if (p_calls==0) return "0"; else return rtos(p_time/p_calls); } else if (dmode==DISPLAY_FRAME_PERCENT) { return _get_percent_txt(p_time,m.frame_time); } else if (dmode==DISPLAY_FIXED_FRAME_PERCENT) { return _get_percent_txt(p_time,m.fixed_frame_time); } return "err"; }
void PathFollow2D::_get_property_list( List<PropertyInfo> *p_list) const{ float max=10000; if (path && path->get_curve().is_valid()) max=path->get_curve()->get_baked_length(); p_list->push_back( PropertyInfo( Variant::REAL, "offset", PROPERTY_HINT_RANGE,"0,"+rtos(max)+",0.01")); p_list->push_back( PropertyInfo( Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE,"0,1,0.0001",PROPERTY_USAGE_EDITOR)); p_list->push_back( PropertyInfo( Variant::REAL, "h_offset") ); p_list->push_back( PropertyInfo( Variant::REAL, "v_offset") ); p_list->push_back( PropertyInfo( Variant::BOOL, "rotate") ); p_list->push_back( PropertyInfo( Variant::BOOL, "cubic_interp")); p_list->push_back( PropertyInfo( Variant::BOOL, "loop")); p_list->push_back( PropertyInfo( Variant::REAL, "lookahead",PROPERTY_HINT_RANGE,"0.001,1024.0,0.001")); }
Basis::operator String() const { String mtx; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { if (i!=0 || j!=0) mtx+=", "; mtx+=rtos( elements[i][j] ); } } return mtx; }
String JSON::_print_var(const Variant& p_var) { switch(p_var.get_type()) { case Variant::NIL: return "null"; case Variant::BOOL: return p_var.operator bool() ? "true": "false"; case Variant::INT: return itos(p_var); case Variant::REAL: return rtos(p_var); case Variant::INT_ARRAY: case Variant::REAL_ARRAY: case Variant::STRING_ARRAY: case Variant::ARRAY: { String s = "["; Array a = p_var; for(int i=0;i<a.size();i++) { if (i>0) s+=", "; s+=_print_var(a[i]); } s+="]"; return s; }; case Variant::DICTIONARY: { String s = "{"; Dictionary d = p_var; List<Variant> keys; d.get_key_list(&keys); for (List<Variant>::Element *E=keys.front();E;E=E->next()) { if (E!=keys.front()) s+=", "; s+=_print_var(String(E->get())); s+=":"; s+=_print_var(d[E->get()]); } s+="}"; return s; }; default: return "\""+String(p_var).c_escape()+"\""; } }
String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) { String colon = ":"; String end_statement = ""; if (!p_indent.empty()) { colon += " "; end_statement += "\n"; } switch (p_var.get_type()) { case Variant::NIL: return "null"; case Variant::BOOL: return p_var.operator bool() ? "true" : "false"; case Variant::INT: return itos(p_var); case Variant::REAL: return rtos(p_var); case Variant::POOL_INT_ARRAY: case Variant::POOL_REAL_ARRAY: case Variant::POOL_STRING_ARRAY: case Variant::ARRAY: { String s = "["; s += end_statement; Array a = p_var; for (int i = 0; i < a.size(); i++) { if (i > 0) { s += ","; s += end_statement; } s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(a[i], p_indent, p_cur_indent + 1, p_sort_keys); } s += end_statement + _make_indent(p_indent, p_cur_indent) + "]"; return s; }; case Variant::DICTIONARY: { String s = "{"; s += end_statement; Dictionary d = p_var; List<Variant> keys; d.get_key_list(&keys); if (p_sort_keys) keys.sort(); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { if (E != keys.front()) { s += ","; s += end_statement; } s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys); s += colon; s += _print_var(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys); } s += end_statement + _make_indent(p_indent, p_cur_indent) + "}"; return s; }; default: return "\"" + String(p_var).json_escape() + "\""; } }
String InputEventMagnifyGesture::as_text() const { return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")"; }
RES ResourceFormatLoaderImage::load(const String &p_path,const String& p_original_path) { if (p_path.extension()=="cube") { // open as cubemap txture CubeMap* ptr = memnew(CubeMap); Ref<CubeMap> cubemap( ptr ); Error err; FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); if (err) { ERR_FAIL_COND_V( err, RES() ); } String base_path=p_path.substr( 0, p_path.find_last("/")+1 ); for(int i=0;i<6;i++) { String file = f->get_line().strip_edges(); Image image; Error err = ImageLoader::load_image(base_path+file,&image); if (err) { memdelete(f); ERR_FAIL_COND_V( err, RES() ); } if (i==0) { //cubemap->create(image.get_width(),image.get_height(),image.get_format(),Texture::FLAGS_DEFAULT|Texture::FLAG_CUBEMAP); } static const CubeMap::Side cube_side[6]= { CubeMap::SIDE_LEFT, CubeMap::SIDE_RIGHT, CubeMap::SIDE_BOTTOM, CubeMap::SIDE_TOP, CubeMap::SIDE_FRONT, CubeMap::SIDE_BACK }; cubemap->set_side(cube_side[i],image); } memdelete(f); cubemap->set_name(p_path.get_file()); return cubemap; } else { // simple image ImageTexture* ptr = memnew(ImageTexture); Ref<ImageTexture> texture( ptr ); uint64_t begtime; double total; Image image; if (debug_load_times) begtime=OS::get_singleton()->get_ticks_usec(); Error err = ImageLoader::load_image(p_path,&image); if (!err && debug_load_times) { double total=(double)(OS::get_singleton()->get_ticks_usec()-begtime)/1000000.0; print_line("IMAGE: "+itos(image.get_width())+"x"+itos(image.get_height())); print_line(" -load: "+rtos(total)); } ERR_EXPLAIN("Failed loading image: "+p_path); ERR_FAIL_COND_V(err, RES()); #ifdef DEBUG_ENABLED #ifdef TOOLS_ENABLED if (max_texture_size && (image.get_width() > max_texture_size || image.get_height() > max_texture_size)) { if (bool(Globals::get_singleton()->get("debug/max_texture_size_alert"))) { OS::get_singleton()->alert("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+".","BAD ARTIST, NO COOKIE!"); } ERR_EXPLAIN("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+"."); ERR_FAIL_V(RES()); } #endif #endif uint32_t flags=0; if (bool(GLOBAL_DEF("texture_import/filter",true))) flags|=Texture::FLAG_FILTER; if (bool(GLOBAL_DEF("texture_import/gen_mipmaps",true))) flags|=Texture::FLAG_MIPMAPS; if (bool(GLOBAL_DEF("texture_import/repeat",true))) flags|=Texture::FLAG_REPEAT; if (debug_load_times) begtime=OS::get_singleton()->get_ticks_usec(); //print_line("img: "+p_path+" flags: "+itos(flags)); texture->create_from_image( image,flags ); texture->set_name(p_path.get_file()); if (debug_load_times) { total=(double)(OS::get_singleton()->get_ticks_usec()-begtime)/1000000.0; print_line(" -make texture: "+rtos(total)); } return RES( texture ); } }
Color::operator String() const { return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a); }
Vector<Ref<Texture> > EditorInterface::make_mesh_previews(const Vector<Ref<Mesh> > &p_meshes, int p_preview_size) { int size = p_preview_size; RID scenario = VS::get_singleton()->scenario_create(); RID viewport = VS::get_singleton()->viewport_create(); VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ALWAYS); VS::get_singleton()->viewport_set_vflip(viewport, true); VS::get_singleton()->viewport_set_scenario(viewport, scenario); VS::get_singleton()->viewport_set_size(viewport, size, size); VS::get_singleton()->viewport_set_transparent_background(viewport, true); VS::get_singleton()->viewport_set_active(viewport, true); RID viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); RID camera = VS::get_singleton()->camera_create(); VS::get_singleton()->viewport_attach_camera(viewport, camera); VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0); RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); RID light_instance = VS::get_singleton()->instance_create2(light, scenario); VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); RID light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0)); RID light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); //sphere = VS::get_singleton()->mesh_create(); RID mesh_instance = VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_scenario(mesh_instance, scenario); EditorProgress ep("mlib", TTR("Creating Mesh Previews"), p_meshes.size()); Vector<Ref<Texture> > textures; for (int i = 0; i < p_meshes.size(); i++) { Ref<Mesh> mesh = p_meshes[i]; if (!mesh.is_valid()) { textures.push_back(Ref<Texture>()); continue; } Rect3 aabb = mesh->get_aabb(); print_line("aabb: " + aabb); Vector3 ofs = aabb.position + aabb.size * 0.5; aabb.position -= ofs; Transform xform; xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.25); xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.25) * xform.basis; Rect3 rot_aabb = xform.xform(aabb); print_line("rot_aabb: " + rot_aabb); float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; if (m == 0) continue; m = 1.0 / m; m *= 0.5; print_line("scale: " + rtos(m)); xform.basis.scale(Vector3(m, m, m)); xform.origin = -xform.basis.xform(ofs); //-ofs*m; xform.origin.z -= rot_aabb.size.z * 2; RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(), scenario); VS::get_singleton()->instance_set_transform(inst, xform); ep.step(TTR("Thumbnail.."), i); Main::iteration(); Main::iteration(); Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture); ERR_CONTINUE(!img.is_valid() || img->empty()); Ref<ImageTexture> it(memnew(ImageTexture)); it->create_from_image(img); //print_line("loaded image, size: "+rtos(m)+" dist: "+rtos(dist)+" empty?"+itos(img.empty())+" w: "+itos(it->get_width())+" h: "+itos(it->get_height())); VS::get_singleton()->free(inst); textures.push_back(it); } VS::get_singleton()->free(mesh_instance); VS::get_singleton()->free(viewport); VS::get_singleton()->free(light); VS::get_singleton()->free(light_instance); VS::get_singleton()->free(light2); VS::get_singleton()->free(light_instance2); VS::get_singleton()->free(camera); VS::get_singleton()->free(scenario); return textures; }
void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_data) { if (p_msg=="debug_enter") { Array msg; msg.push_back("get_stack_dump"); ppeer->put_var(msg); ERR_FAIL_COND(p_data.size()!=2); bool can_continue=p_data[0]; String error = p_data[1]; step->set_disabled(!can_continue); next->set_disabled(!can_continue); reason->set_text(error); reason->set_tooltip(error); breaked=true; dobreak->set_disabled(true); docontinue->set_disabled(false); emit_signal("breaked",true,can_continue); OS::get_singleton()->move_window_to_foreground(); if (error!="") { tabs->set_current_tab(0); } profiler->set_enabled(false); EditorNode::get_singleton()->get_pause_button()->set_pressed(true); EditorNode::get_singleton()->make_bottom_panel_item_visible(this); } else if (p_msg=="debug_exit") { breaked=false; step->set_disabled(true); next->set_disabled(true); reason->set_text(""); reason->set_tooltip(""); back->set_disabled(true); forward->set_disabled(true); dobreak->set_disabled(false); docontinue->set_disabled(true); emit_signal("breaked",false,false,Variant()); //tabs->set_current_tab(0); profiler->set_enabled(true); profiler->disable_seeking(); EditorNode::get_singleton()->get_pause_button()->set_pressed(false); } else if (p_msg=="message:click_ctrl") { clicked_ctrl->set_text(p_data[0]); clicked_ctrl_type->set_text(p_data[1]); } else if (p_msg=="message:scene_tree") { inspect_scene_tree->clear(); Map<int,TreeItem*> lv; updating_scene_tree=true; for(int i=0;i<p_data.size();i+=4) { TreeItem *p; int level = p_data[i]; if (level==0) { p = NULL; } else { ERR_CONTINUE(!lv.has(level-1)); p=lv[level-1]; } TreeItem *it = inspect_scene_tree->create_item(p); ObjectID id = ObjectID(p_data[i+3]); it->set_text(0,p_data[i+1]); if (has_icon(p_data[i+2],"EditorIcons")) it->set_icon(0,get_icon(p_data[i+2],"EditorIcons")); it->set_metadata(0,id); if (id==inspected_object_id) { it->select(0); } if (p) { if (!unfold_cache.has(id)) { it->set_collapsed(true); } } else { if (unfold_cache.has(id)) { //reverse for root it->set_collapsed(true); } } lv[level]=it; } updating_scene_tree=false; le_clear->set_disabled(false); le_set->set_disabled(false); } else if (p_msg=="message:inspect_object") { ObjectID id = p_data[0]; String type = p_data[1]; Variant path = p_data[2]; //what to do yet, i don't know int prop_count=p_data[3]; int idx=4; if (inspected_object->last_edited_id!=id) { inspected_object->prop_list.clear(); inspected_object->prop_values.clear(); } for(int i=0;i<prop_count;i++) { PropertyInfo pinfo; pinfo.name=p_data[idx++]; pinfo.type=Variant::Type(int(p_data[idx++])); pinfo.hint=PropertyHint(int(p_data[idx++])); pinfo.hint_string=p_data[idx++]; if (pinfo.name.begins_with("*")) { pinfo.name=pinfo.name.substr(1,pinfo.name.length()); pinfo.usage=PROPERTY_USAGE_CATEGORY; } else { pinfo.usage=PROPERTY_USAGE_EDITOR; } if (inspected_object->last_edited_id!=id) { //don't update.. it's the same, instead refresh inspected_object->prop_list.push_back(pinfo); } inspected_object->prop_values[pinfo.name]=p_data[idx++]; if (inspected_object->last_edited_id==id) { //same, just update value, don't rebuild inspected_object->update_single(pinfo.name.ascii().get_data()); } } if (inspected_object->last_edited_id!=id) { //only if different inspected_object->update(); } inspected_object->last_edited_id=id; inspect_properties->edit(inspected_object); } else if (p_msg=="message:video_mem") { vmem_tree->clear(); TreeItem* root=vmem_tree->create_item(); int total=0; for(int i=0;i<p_data.size();i+=4) { TreeItem *it = vmem_tree->create_item(root); String type=p_data[i+1]; int bytes=p_data[i+3].operator int(); it->set_text(0,p_data[i+0]); //path it->set_text(1,type); //type it->set_text(2,p_data[i+2]); //type it->set_text(3,String::humanize_size(bytes)); //type total+=bytes; if (has_icon(type,"EditorIcons")) it->set_icon(0,get_icon(type,"EditorIcons")); } vmem_total->set_tooltip(TTR("Bytes:")+" "+itos(total)); vmem_total->set_text(String::humanize_size(total)); } else if (p_msg=="stack_dump") { stack_dump->clear(); TreeItem *r = stack_dump->create_item(); for(int i=0;i<p_data.size();i++) { Dictionary d = p_data[i]; ERR_CONTINUE(!d.has("function")); ERR_CONTINUE(!d.has("file")); ERR_CONTINUE(!d.has("line")); ERR_CONTINUE(!d.has("id")); TreeItem *s = stack_dump->create_item(r); d["frame"]=i; s->set_metadata(0,d); // String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"]; String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"]); s->set_text(0,line); if (i==0) s->select(0); } } else if (p_msg=="stack_frame_vars") { variables->clear(); int ofs =0; int mcount = p_data[ofs]; ofs++; for(int i=0;i<mcount;i++) { String n = p_data[ofs+i*2+0]; Variant v = p_data[ofs+i*2+1]; if (n.begins_with("*")) { n=n.substr(1,n.length()); } variables->add_property("members/"+n,v); } ofs+=mcount*2; mcount = p_data[ofs]; ofs++; for(int i=0;i<mcount;i++) { String n = p_data[ofs+i*2+0]; Variant v = p_data[ofs+i*2+1]; if (n.begins_with("*")) { n=n.substr(1,n.length()); } variables->add_property("locals/"+n,v); } variables->update(); inspector->edit(variables); } else if (p_msg=="output") { //OUT for(int i=0;i<p_data.size();i++) { String t = p_data[i]; //LOG if (EditorNode::get_log()->is_hidden()) { log_forced_visible=true; if (EditorNode::get_singleton()->are_bottom_panels_hidden()) { EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log()); } } EditorNode::get_log()->add_message(t); } } else if (p_msg=="performance") { Array arr = p_data[0]; Vector<float> p; p.resize(arr.size()); for(int i=0;i<arr.size();i++) { p[i]=arr[i]; if (i<perf_items.size()) { perf_items[i]->set_text(1,rtos(p[i])); if (p[i]>perf_max[i]) perf_max[i]=p[i]; } } perf_history.push_front(p); perf_draw->update(); } else if (p_msg=="error") { Array err = p_data[0]; Array vals; vals.push_back(err[0]); vals.push_back(err[1]); vals.push_back(err[2]); vals.push_back(err[3]); bool warning = err[9]; bool e; String time = String("%d:%02d:%02d:%04d").sprintf(vals,&e); String txt=time+" - "+(err[8].is_zero()?String(err[7]):String(err[8])); String tooltip=TTR("Type:")+String(warning?TTR("Warning"):TTR("Error")); tooltip+="\n"+TTR("Description:")+" "+String(err[8]); tooltip+="\n"+TTR("Time:")+" "+time; tooltip+="\nC "+TTR("Error:")+" "+String(err[7]); tooltip+="\nC "+TTR("Source:")+" "+String(err[5])+":"+String(err[6]); tooltip+="\nC "+TTR("Function:")+" "+String(err[4]); error_list->add_item(txt,EditorNode::get_singleton()->get_gui_base()->get_icon(warning?"Warning":"Error","EditorIcons")); error_list->set_item_tooltip( error_list->get_item_count() -1,tooltip ); int scc = p_data[1]; Array stack; stack.resize(scc); for(int i=0;i<scc;i++) { stack[i]=p_data[2+i]; } error_list->set_item_metadata( error_list->get_item_count() -1,stack ); error_count++; /* int count = p_data[1]; Array cstack; OutputError oe = errors.front()->get(); packet_peer_stream->put_var(oe.hr); packet_peer_stream->put_var(oe.min); packet_peer_stream->put_var(oe.sec); packet_peer_stream->put_var(oe.msec); packet_peer_stream->put_var(oe.source_func); packet_peer_stream->put_var(oe.source_file); packet_peer_stream->put_var(oe.source_line); packet_peer_stream->put_var(oe.error); packet_peer_stream->put_var(oe.error_descr); packet_peer_stream->put_var(oe.warning); packet_peer_stream->put_var(oe.callstack); */ } else if (p_msg=="profile_sig") { //cache a signature print_line("SIG: "+String(Variant(p_data))); profiler_signature[p_data[1]]=p_data[0]; } else if (p_msg=="profile_frame" || p_msg=="profile_total") { EditorProfiler::Metric metric; metric.valid=true; metric.frame_number=p_data[0]; metric.frame_time=p_data[1]; metric.idle_time=p_data[2]; metric.fixed_time=p_data[3]; metric.fixed_frame_time=p_data[4]; int frame_data_amount = p_data[6]; int frame_function_amount = p_data[7]; if (frame_data_amount) { EditorProfiler::Metric::Category frame_time; frame_time.signature="category_frame_time"; frame_time.name="Frame Time"; frame_time.total_time=metric.frame_time; EditorProfiler::Metric::Category::Item item; item.calls=1; item.line=0; item.name="Fixed Time"; item.total=metric.fixed_time; item.self=item.total; item.signature="fixed_time"; frame_time.items.push_back(item); item.name="Idle Time"; item.total=metric.idle_time; item.self=item.total; item.signature="idle_time"; frame_time.items.push_back(item); item.name="Fixed Frame Time"; item.total=metric.fixed_frame_time; item.self=item.total; item.signature="fixed_frame_time"; frame_time.items.push_back(item); metric.categories.push_back(frame_time); } int idx=8; for(int i=0;i<frame_data_amount;i++) { EditorProfiler::Metric::Category c; String name=p_data[idx++]; Array values=p_data[idx++]; c.name=name.capitalize(); c.items.resize(values.size()/2); c.total_time=0; c.signature="categ::"+name; for(int i=0;i<values.size();i+=2) { EditorProfiler::Metric::Category::Item item; item.name=values[i]; item.calls=1; item.self=values[i+1]; item.total=item.self; item.signature="categ::"+name+"::"+item.name; item.name=item.name.capitalize(); c.total_time+=item.total; c.items[i/2]=item; } metric.categories.push_back(c); } EditorProfiler::Metric::Category funcs; funcs.total_time=p_data[5]; //script time funcs.items.resize(frame_function_amount); funcs.name="Script Functions"; funcs.signature="script_functions"; for(int i=0;i<frame_function_amount;i++) { int signature = p_data[idx++]; int calls = p_data[idx++]; float total = p_data[idx++]; float self = p_data[idx++]; EditorProfiler::Metric::Category::Item item; if (profiler_signature.has(signature)) { item.signature=profiler_signature[signature]; String name = profiler_signature[signature]; Vector<String> strings = name.split("::"); if (strings.size()==3) { item.name=strings[2]; item.script=strings[0]; item.line=strings[1].to_int(); } } else { item.name="SigErr "+itos(signature); } item.calls=calls; item.self=self; item.total=total; funcs.items[i]=item; } metric.categories.push_back(funcs); if (p_msg=="profile_frame") profiler->add_frame_metric(metric,false); else profiler->add_frame_metric(metric,true); } else if (p_msg=="kill_me") { editor->call_deferred("stop_child_process"); } }
InputEvent::operator String() const { String str="Device "+itos(device)+" ID "+itos(ID)+" "; switch(type) { case NONE: { return "Event: None"; } break; case KEY: { str+= "Event: Key "; str=str+"Unicode: "+String::chr(key.unicode)+" Scan: "+itos( key.scancode )+" Echo: "+String(key.echo?"True":"False")+" Pressed"+String(key.pressed?"True":"False")+" Mod: "; if (key.mod.shift) str+="S"; if (key.mod.control) str+="C"; if (key.mod.alt) str+="A"; if (key.mod.meta) str+="M"; return str; } break; case MOUSE_MOTION: { str+= "Event: Motion "; str=str+" Pos: " +itos(mouse_motion.x)+","+itos(mouse_motion.y)+" Rel: "+itos(mouse_motion.relative_x)+","+itos(mouse_motion.relative_y)+" Mask: "; for (int i=0;i<8;i++) { if ((1<<i)&mouse_motion.button_mask) str+=itos(i+1); } str+=" Mod: "; if (key.mod.shift) str+="S"; if (key.mod.control) str+="C"; if (key.mod.alt) str+="A"; if (key.mod.meta) str+="M"; return str; } break; case MOUSE_BUTTON: { str+= "Event: Button "; str=str+"Pressed: "+itos(mouse_button.pressed)+" Pos: " +itos(mouse_button.x)+","+itos(mouse_button.y)+" Button: "+itos(mouse_button.button_index)+" Mask: "; for (int i=0;i<8;i++) { if ((1<<i)&mouse_button.button_mask) str+=itos(i+1); } str+=" Mod: "; if (key.mod.shift) str+="S"; if (key.mod.control) str+="C"; if (key.mod.alt) str+="A"; if (key.mod.meta) str+="M"; str+=String(" DoubleClick: ")+(mouse_button.doubleclick?"Yes":"No"); return str; } break; case JOYSTICK_MOTION: { str+= "Event: JoyMotion "; str=str+"Axis: "+itos(joy_motion.axis)+" Value: " +rtos(joy_motion.axis_value); return str; } break; case JOYSTICK_BUTTON: { str+= "Event: JoyButton "; str=str+"Pressed: "+itos(joy_button.pressed)+" Index: " +itos(joy_button.button_index)+" pressure "+rtos(joy_button.pressure); return str; } break; case SCREEN_TOUCH: { str+= "Event: ScreenTouch "; str=str+"Pressed: "+itos(screen_touch.pressed)+" Index: " +itos(screen_touch.index)+" pos "+rtos(screen_touch.x)+","+rtos(screen_touch.y); return str; } break; case SCREEN_DRAG: { str+= "Event: ScreenDrag "; str=str+" Index: " +itos(screen_drag.index)+" pos "+rtos(screen_drag.x)+","+rtos(screen_drag.y); return str; } break; case ACTION: { str+= "Event: Action: "+InputMap::get_singleton()->get_action_from_id(action.action)+" Pressed: "+itos(action.pressed); return str; } break; } return ""; }
Plane::operator String() const { return normal.operator String() + ", " + rtos(d); }
static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) { switch (p_type) { case SL::TYPE_BOOL: return p_values[0].boolean ? "true" : "false"; case SL::TYPE_BVEC2: return String() + "bvec2(" + (p_values[0].boolean ? "true" : "false") + (p_values[1].boolean ? "true" : "false") + ")"; case SL::TYPE_BVEC3: return String() + "bvec3(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + ")"; case SL::TYPE_BVEC4: return String() + "bvec4(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + "," + (p_values[3].boolean ? "true" : "false") + ")"; case SL::TYPE_INT: return rtos(p_values[0].sint); case SL::TYPE_IVEC2: return String() + "ivec2(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + ")"; case SL::TYPE_IVEC3: return String() + "ivec3(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + ")"; case SL::TYPE_IVEC4: return String() + "ivec4(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + "," + rtos(p_values[3].sint) + ")"; case SL::TYPE_UINT: return rtos(p_values[0].real); case SL::TYPE_UVEC2: return String() + "uvec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")"; case SL::TYPE_UVEC3: return String() + "uvec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")"; case SL::TYPE_UVEC4: return String() + "uvec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")"; case SL::TYPE_FLOAT: return rtos(p_values[0].real); case SL::TYPE_VEC2: return String() + "vec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")"; case SL::TYPE_VEC3: return String() + "vec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")"; case SL::TYPE_VEC4: return String() + "vec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")"; default: ERR_FAIL_V(String()); } }
Vector3::operator String() const { return (rtos(x)+", "+rtos(y)+", "+rtos(z)); }
void ShaderEditor::_draw_node(int p_node) { VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node); Ref<StyleBox> style = active_nodes.has(p_node)?get_stylebox("panel","PopupMenu"):get_stylebox("panel_disabled","PopupMenu"); Ref<Font> font = get_font("font","PopupMenu"); Color font_color = get_color("font_color","PopupMenu"); Color font_color_title = get_color("font_color_hover","PopupMenu"); Size2 size=get_node_size(p_node); Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset; if (click_type==CLICK_NODE && click_node==p_node) { pos+=click_motion-click_pos; } RID ci = get_canvas_item(); style->draw(ci,Rect2(pos,size)); Point2 ofs=style->get_offset()+pos; Point2 ascent=Point2(0,font->get_ascent()); float w = size.width-style->get_minimum_size().width; float h = font->get_height()+get_constant("vseparation","PopupMenu"); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, VisualServer::shader_node_get_type_info(type).name,font_color_title); ofs.y+=h; Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons"); Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons"); float icon_h_ofs = Math::floor(( font->get_height()-vec_icon->get_height())/2.0 )+1; for(int i=0;i<VisualServer::shader_get_input_count(type);i++) { String name = VisualServer::shader_get_input_name(type,i); font->draw_halign( ci, ofs+ascent, HALIGN_LEFT,w, name,font_color); Ref<Texture> icon = VisualServer::shader_is_input_vector(type,i)?vec_icon:real_icon; icon->draw(ci,ofs+Point2(-real_icon->get_width(),icon_h_ofs)); ofs.y+=h; } for(int i=0;i<VisualServer::shader_get_output_count(type);i++) { String name = VisualServer::shader_get_output_name(type,i); font->draw_halign( ci, ofs+ascent, HALIGN_RIGHT,w, name,font_color); Ref<Texture> icon = VisualServer::shader_is_output_vector(type,i)?vec_icon:real_icon; icon->draw(ci,ofs+Point2(w,icon_h_ofs)); ofs.y+=h; } switch(type) { case VS::NODE_IN: case VS::NODE_OUT: case VS::NODE_PARAMETER: case VS::NODE_VEC_IN: case VS::NODE_COLOR_PARAMETER: case VS::NODE_VEC_OUT: case VS::NODE_TEXTURE_PARAMETER: case VS::NODE_TEXTURE_2D_PARAMETER: case VS::NODE_TEXTURE_CUBE_PARAMETER: case VS::NODE_TRANSFORM_CONSTANT: case VS::NODE_TRANSFORM_PARAMETER: case VS::NODE_VEC_PARAMETER: case VS::NODE_LABEL: { String text = shader_graph.node_get_param(p_node); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); } break; case VS::NODE_TIME: case VS::NODE_CONSTANT: { String text = rtos(shader_graph.node_get_param(p_node)); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); } break; case VS::NODE_VEC_CONSTANT: { String text = Vector3(shader_graph.node_get_param(p_node)); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); } break; case VS::NODE_COLOR_CONSTANT: { Color color = shader_graph.node_get_param(p_node); Rect2 r(ofs,Size2(w,h)); VisualServer::get_singleton()->canvas_item_add_rect(ci,r,color); } break; case VS::NODE_TEXTURE: case VS::NODE_VEC_TEXTURE_2D: case VS::NODE_VEC_TEXTURE_CUBE: { Rect2 r(ofs,Size2(w,(pos.y+size.y-style->get_margin(MARGIN_BOTTOM))-ofs.y)); Vector<Point2> points; Vector<Point2> uvs; points.resize(4); uvs.resize(4); points[0]=r.pos; points[1]=r.pos+Point2(r.size.x,0); points[2]=r.pos+r.size; points[3]=r.pos+Point2(0,r.size.y); uvs[0]=Point2(0,0); uvs[1]=Point2(1,0); uvs[2]=Point2(1,1); uvs[3]=Point2(0,1); Ref<Texture> texture = shader_graph.node_get_param(p_node).operator RefPtr(); if (texture.is_null() || texture->get_width()==0) { texture=get_icon("Click2Edit","EditorIcons"); } VisualServer::get_singleton()->canvas_item_add_primitive(ci,points,Vector<Color>(),uvs,texture->get_rid()); } break; default: {} } }
void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float p_time, float p_delta, float p_interp, bool p_allow_discrete) { if (p_anim->node_cache.size() != p_anim->animation->get_track_count()) { // animation hasn't been "node-cached" _generate_node_caches(p_anim); } ERR_FAIL_COND(p_anim->node_cache.size() != p_anim->animation->get_track_count()); Animation *a = p_anim->animation.operator->(); bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint(); for (int i = 0; i < a->get_track_count(); i++) { TrackNodeCache *nc = p_anim->node_cache[i]; if (!nc) // no node cache for this track, skip it continue; if (a->track_get_key_count(i) == 0) continue; // do nothing if track is empty switch (a->track_get_type(i)) { case Animation::TYPE_TRANSFORM: { if (!nc->spatial) continue; Vector3 loc; Quat rot; Vector3 scale; Error err = a->transform_track_interpolate(i, p_time, &loc, &rot, &scale); //ERR_CONTINUE(err!=OK); //used for testing, should be removed if (err != OK) continue; if (nc->accum_pass != accum_pass) { ERR_CONTINUE(cache_update_size >= NODE_CACHE_UPDATE_MAX); cache_update[cache_update_size++] = nc; nc->accum_pass = accum_pass; nc->loc_accum = loc; nc->rot_accum = rot; nc->scale_accum = scale; } else { nc->loc_accum = nc->loc_accum.linear_interpolate(loc, p_interp); nc->rot_accum = nc->rot_accum.slerp(rot, p_interp); nc->scale_accum = nc->scale_accum.linear_interpolate(scale, p_interp); } } break; case Animation::TYPE_VALUE: { if (!nc->node) continue; //StringName property=a->track_get_path(i).get_property(); Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_property()); ERR_CONTINUE(!E); //should it continue, or create a new one? TrackNodeCache::PropertyAnim *pa = &E->get(); if (a->value_track_get_update_mode(i) == Animation::UPDATE_CONTINUOUS || (p_delta == 0 && a->value_track_get_update_mode(i) == Animation::UPDATE_DISCRETE)) { //delta == 0 means seek Variant value = a->value_track_interpolate(i, p_time); if (value == Variant()) continue; //thanks to trigger mode, this should be solved now.. /* if (p_delta==0 && value.get_type()==Variant::STRING) continue; // doing this with strings is messy, should find another way */ if (pa->accum_pass != accum_pass) { ERR_CONTINUE(cache_update_prop_size >= NODE_CACHE_UPDATE_MAX); cache_update_prop[cache_update_prop_size++] = pa; pa->value_accum = value; pa->accum_pass = accum_pass; } else { Variant::interpolate(pa->value_accum, value, p_interp, pa->value_accum); } } else if (p_allow_discrete && p_delta != 0) { List<int> indices; a->value_track_get_key_indices(i, p_time, p_delta, &indices); for (List<int>::Element *F = indices.front(); F; F = F->next()) { Variant value = a->track_get_key_value(i, F->get()); switch (pa->special) { case SP_NONE: { bool valid; pa->object->set(pa->prop, value, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { ERR_PRINTS("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid. Animation '" + a->get_name() + "' at node '" + get_path() + "'."); } #endif } break; case SP_NODE2D_POS: { #ifdef DEBUG_ENABLED if (value.get_type() != Variant::VECTOR2) { ERR_PRINTS("Position key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2(). Animation '" + a->get_name() + "' at node '" + get_path() + "'."); } #endif static_cast<Node2D *>(pa->object)->set_position(value); } break; case SP_NODE2D_ROT: { #ifdef DEBUG_ENABLED if (value.is_num()) { ERR_PRINTS("Rotation key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not numerical. Animation '" + a->get_name() + "' at node '" + get_path() + "'."); } #endif static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)value)); } break; case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED if (value.get_type() != Variant::VECTOR2) { ERR_PRINTS("Scale key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()." + a->get_name() + "' at node '" + get_path() + "'."); } #endif static_cast<Node2D *>(pa->object)->set_scale(value); } break; } } } } break; case Animation::TYPE_METHOD: { if (!nc->node) continue; if (p_delta == 0) continue; if (!p_allow_discrete) break; List<int> indices; a->method_track_get_key_indices(i, p_time, p_delta, &indices); for (List<int>::Element *E = indices.front(); E; E = E->next()) { StringName method = a->method_track_get_name(i, E->get()); Vector<Variant> params = a->method_track_get_params(i, E->get()); int s = params.size(); ERR_CONTINUE(s > VARIANT_ARG_MAX); if (can_call) { MessageQueue::get_singleton()->push_call( nc->node, method, s >= 1 ? params[0] : Variant(), s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), s >= 5 ? params[4] : Variant()); } } } break; } } }
Variant::operator String() const { switch( type ) { case NIL: return ""; case BOOL: return _data._bool ? "True" : "False"; case INT: return String::num(_data._int); case REAL: return String::num(_data._real); case STRING: return *reinterpret_cast<const String*>(_data._mem); case VECTOR2: return operator Vector2(); case RECT2: return operator Rect2(); case MATRIX32: return operator Matrix32(); case VECTOR3: return operator Vector3(); case PLANE: return operator Plane(); //case QUAT: case _AABB: return operator AABB(); case QUAT: return operator Quat(); case MATRIX3: return operator Matrix3(); case TRANSFORM: return operator Transform(); case NODE_PATH: return operator NodePath(); case INPUT_EVENT: return operator InputEvent(); case COLOR: return String::num( operator Color().r)+","+String::num( operator Color().g)+","+String::num( operator Color().b)+","+String::num( operator Color().a) ; case DICTIONARY: { const Dictionary &d =*reinterpret_cast<const Dictionary*>(_data._mem); //const String *K=NULL; String str; List<Variant> keys; d.get_key_list(&keys); Vector<_VariantStrPair> pairs; for(List<Variant>::Element *E=keys.front();E;E=E->next()) { _VariantStrPair sp; sp.key=String(E->get()); sp.value=d[E->get()]; pairs.push_back(sp); } pairs.sort(); for(int i=0;i<pairs.size();i++) { if (i>0) str+=", "; str+="("+pairs[i].key+":"+pairs[i].value+")"; } return str; } break; case VECTOR3_ARRAY: { DVector<Vector3> vec = operator DVector<Vector3>(); String str; for(int i=0;i<vec.size();i++) { if (i>0) str+=", "; str=str+Variant( vec[i] ); } return str; } break; case STRING_ARRAY: { DVector<String> vec = operator DVector<String>(); String str; for(int i=0;i<vec.size();i++) { if (i>0) str+=", "; str=str+vec[i]; } return str; } break; case INT_ARRAY: { DVector<int> vec = operator DVector<int>(); String str; for(int i=0;i<vec.size();i++) { if (i>0) str+=", "; str=str+itos(vec[i]); } return str; } break; case REAL_ARRAY: { DVector<real_t> vec = operator DVector<real_t>(); String str; for(int i=0;i<vec.size();i++) { if (i>0) str+=", "; str=str+rtos(vec[i]); } return str; } break; case ARRAY: { Array arr = operator Array(); String str; for (int i=0; i<arr.size(); i++) { if (i) str+=", "; str += String(arr[i]); }; return str; } break; case OBJECT: { if (_get_obj().obj) return "["+_get_obj().obj->get_type()+":"+itos(_get_obj().obj->get_instance_ID())+"]"; else return "[Object:null]"; } break; default: { return "["+get_type_name(type)+"]"; } } return ""; }
void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) { if (!p_merge) p_library->clear(); for(int i=0;i<p_scene->get_child_count();i++) { Node *child = p_scene->get_child(i); if (!child->cast_to<MeshInstance>()) { if (child->get_child_count()>0) { child=child->get_child(0); if (!child->cast_to<MeshInstance>()) { continue; } } else continue; } MeshInstance *mi = child->cast_to<MeshInstance>(); Ref<Mesh> mesh=mi->get_mesh(); if (mesh.is_null()) continue; int id = p_library->find_item_name(mi->get_name()); if (id<0) { id=p_library->get_last_unused_item_id(); p_library->create_item(id); p_library->set_item_name(id,mi->get_name()); } p_library->set_item_mesh(id,mesh); Ref<Shape> collision; for(int j=0;j<mi->get_child_count();j++) { #if 1 Node *child2 = mi->get_child(j); if (!child2->cast_to<StaticBody>()) continue; StaticBody *sb = child2->cast_to<StaticBody>(); if (sb->get_shape_count()==0) continue; collision=sb->get_shape(0); if (!collision.is_null()) break; #endif } if (!collision.is_null()) { p_library->set_item_shape(id,collision); } } //generate previews! if (1) { Vector<int> ids = p_library->get_item_list(); RID vp = VS::get_singleton()->viewport_create(); VS::ViewportRect vr; vr.x=0; vr.y=0; vr.width=EditorSettings::get_singleton()->get("grid_map/preview_size"); vr.height=EditorSettings::get_singleton()->get("grid_map/preview_size"); VS::get_singleton()->viewport_set_rect(vp,vr); VS::get_singleton()->viewport_set_as_render_target(vp,true); VS::get_singleton()->viewport_set_render_target_update_mode(vp,VS::RENDER_TARGET_UPDATE_ALWAYS); RID scen = VS::get_singleton()->scenario_create(); VS::get_singleton()->viewport_set_scenario(vp,scen); RID cam = VS::get_singleton()->camera_create(); VS::get_singleton()->camera_set_transform(cam, Transform() ); VS::get_singleton()->viewport_attach_camera(vp,cam); RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); RID lightinst = VS::get_singleton()->instance_create2(light,scen); VS::get_singleton()->camera_set_orthogonal(cam,1.0,0.01,1000.0); EditorProgress ep("mlib","Creating Mesh Library",ids.size()); for(int i=0;i<ids.size();i++) { int id=ids[i]; Ref<Mesh> mesh = p_library->get_item_mesh(id); if (!mesh.is_valid()) continue; AABB aabb= mesh->get_aabb(); print_line("aabb: "+aabb); Vector3 ofs = aabb.pos + aabb.size*0.5; aabb.pos-=ofs; Transform xform; xform.basis=Matrix3().rotated(Vector3(0,1,0),Math_PI*0.25); xform.basis = Matrix3().rotated(Vector3(1,0,0),-Math_PI*0.25)*xform.basis; AABB rot_aabb = xform.xform(aabb); print_line("rot_aabb: "+rot_aabb); float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; if (m==0) continue; m=1.0/m; m*=0.5; print_line("scale: "+rtos(m)); xform.basis.scale(Vector3(m,m,m)); xform.origin=-xform.basis.xform(ofs); //-ofs*m; xform.origin.z-=rot_aabb.size.z*2; RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(),scen); VS::get_singleton()->instance_set_transform(inst,xform); ep.step("Thumbnail..",i); VS::get_singleton()->viewport_queue_screen_capture(vp); Main::iteration(); Image img = VS::get_singleton()->viewport_get_screen_capture(vp); ERR_CONTINUE(img.empty()); Ref<ImageTexture> it( memnew( ImageTexture )); it->create_from_image(img); p_library->set_item_preview(id,it); // print_line("loaded image, size: "+rtos(m)+" dist: "+rtos(dist)+" empty?"+itos(img.empty())+" w: "+itos(it->get_width())+" h: "+itos(it->get_height())); VS::get_singleton()->free(inst); } VS::get_singleton()->free(lightinst); VS::get_singleton()->free(light); VS::get_singleton()->free(vp); VS::get_singleton()->free(cam); VS::get_singleton()->free(scen); } }
static String _encode_variant(const Variant& p_variant) { switch(p_variant.get_type()) { case Variant::BOOL: { bool val = p_variant; return (val?"true":"false"); } break; case Variant::INT: { int val = p_variant; return itos(val); } break; case Variant::REAL: { float val = p_variant; return rtos(val)+(val==int(val)?".0":""); } break; case Variant::STRING: { String val = p_variant; return "\""+val.xml_escape()+"\""; } break; case Variant::COLOR: { Color val = p_variant; return "#"+val.to_html(); } break; case Variant::STRING_ARRAY: case Variant::INT_ARRAY: case Variant::REAL_ARRAY: case Variant::ARRAY: { Array arr = p_variant; String str="["; for(int i=0;i<arr.size();i++) { if (i>0) str+=", "; str+=_encode_variant(arr[i]); } str+="]"; return str; } break; case Variant::DICTIONARY: { Dictionary d = p_variant; String str="{"; List<Variant> keys; d.get_key_list(&keys); for(List<Variant>::Element *E=keys.front();E;E=E->next()) { if (E!=keys.front()) str+=", "; str+=_encode_variant(E->get()); str+=":"; str+=_encode_variant(d[E->get()]); } str+="}"; return str; } break; case Variant::IMAGE: { String str="img("; Image img=p_variant; if (!img.empty()) { String format; switch(img.get_format()) { case Image::FORMAT_GRAYSCALE: format="grayscale"; break; case Image::FORMAT_INTENSITY: format="intensity"; break; case Image::FORMAT_GRAYSCALE_ALPHA: format="grayscale_alpha"; break; case Image::FORMAT_RGB: format="rgb"; break; case Image::FORMAT_RGBA: format="rgba"; break; case Image::FORMAT_INDEXED : format="indexed"; break; case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break; case Image::FORMAT_BC1: format="bc1"; break; case Image::FORMAT_BC2: format="bc2"; break; case Image::FORMAT_BC3: format="bc3"; break; case Image::FORMAT_BC4: format="bc4"; break; case Image::FORMAT_BC5: format="bc5"; break; case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break; default: {} } str+=format+", "; str+=itos(img.get_mipmaps())+", "; str+=itos(img.get_width())+", "; str+=itos(img.get_height())+", "; DVector<uint8_t> data = img.get_data(); int ds=data.size(); DVector<uint8_t>::Read r = data.read(); for(int i=0;i<ds;i++) { uint8_t byte = r[i]; const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; char bstr[3]={ hex[byte>>4], hex[byte&0xF], 0}; str+=bstr; } } str+=")"; return str; } break; case Variant::INPUT_EVENT: { InputEvent ev = p_variant; switch(ev.type) { case InputEvent::KEY: { String mods; if (ev.key.mod.control) mods+="C"; if (ev.key.mod.shift) mods+="S"; if (ev.key.mod.alt) mods+="A"; if (ev.key.mod.meta) mods+="M"; if (mods!="") mods=", "+mods; return "key("+keycode_get_string(ev.key.scancode)+mods+")"; } break; case InputEvent::MOUSE_BUTTON: { return "mbutton("+itos(ev.device)+", "+itos(ev.mouse_button.button_index)+")"; } break; case InputEvent::JOYSTICK_BUTTON: { return "jbutton("+itos(ev.device)+", "+itos(ev.joy_button.button_index)+")"; } break; case InputEvent::JOYSTICK_MOTION: { return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis)+")"; } break; default: { return "nil"; } break; } } break; default: {} }
void AnimationTreeEditor::_popup_edit_dialog() { updating_edit=true; for(int i=0;i<2;i++) edit_scroll[i]->hide(); for(int i=0;i<4;i++) { edit_line[i]->hide(); edit_label[i]->hide(); } edit_option->hide(); edit_button->hide();; filter_button->hide(); edit_check->hide();; Point2 pos = anim_tree->node_get_pos(edited_node)-Point2(h_scroll->get_val(),v_scroll->get_val()); Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Size2 size = get_node_size(edited_node); Point2 popup_pos( pos.x+style->get_margin(MARGIN_LEFT), pos.y+size.y-style->get_margin(MARGIN_BOTTOM)); popup_pos+=get_global_pos(); if (renaming_edit) { edit_label[0]->set_text("New name:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(edited_node); edit_line[0]->show(); edit_dialog->set_size(Size2(150,50)); } else { AnimationTreePlayer::NodeType type=anim_tree->node_get_type(edited_node); switch(type) { case AnimationTreePlayer::NODE_ANIMATION: if (anim_tree->get_master_player()!=NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>()) { AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>(); master_anim_popup->clear(); List<StringName> sn; ap->get_animation_list(&sn); sn.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E=sn.front();E;E=E->next()) { master_anim_popup->add_item(E->get()); } master_anim_popup->set_pos(popup_pos); master_anim_popup->popup(); } else { property_editor->edit(this,"",Variant::OBJECT,anim_tree->animation_node_get_animation(edited_node),PROPERTY_HINT_RESOURCE_TYPE,"Animation"); property_editor->set_pos(popup_pos); property_editor->popup(); updating_edit=false; } return; case AnimationTreePlayer::NODE_TIMESCALE: edit_label[0]->set_text("Scale:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node))); edit_line[0]->show(); edit_dialog->set_size(Size2(150,50)); break; case AnimationTreePlayer::NODE_ONESHOT: edit_label[0]->set_text("Fade In (s):"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node))); edit_line[0]->show(); edit_label[1]->set_text("Fade Out (s):"); edit_label[1]->set_pos(Point2(5,55)); edit_label[1]->show(); edit_line[1]->set_begin(Point2(15,75)); edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node))); edit_line[1]->show(); edit_option->clear(); edit_option->add_item("Blend",0); edit_option->add_item("Mix",1); edit_option->set_begin(Point2(15,105)); edit_option->select( anim_tree->oneshot_node_get_mix_mode(edited_node)); edit_option->show(); edit_check->set_text("Auto Restart:"); edit_check->set_begin(Point2(15,125)); edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node)); edit_check->show(); edit_label[2]->set_text("Restart (s):"); edit_label[2]->set_pos(Point2(5,145)); edit_label[2]->show(); edit_line[2]->set_begin(Point2(15,165)); edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node))); edit_line[2]->show(); edit_label[3]->set_text("Random Restart (s):"); edit_label[3]->set_pos(Point2(5,195)); edit_label[3]->show(); edit_line[3]->set_begin(Point2(15,215)); edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node))); edit_line[3]->show(); filter_button->set_begin(Point2(10,245)); filter_button->show(); edit_button->set_begin(Point2(10,268)); edit_button->set_text("Start!"); edit_button->show(); edit_dialog->set_size(Size2(180,293)); break; case AnimationTreePlayer::NODE_MIX: edit_label[0]->set_text("Amount:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->mix_node_get_amount(edited_node)); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); edit_dialog->set_size(Size2(150,50)); break; case AnimationTreePlayer::NODE_BLEND2: edit_label[0]->set_text("Blend:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->blend2_node_get_amount(edited_node)); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); filter_button->set_begin(Point2(10,47)); filter_button->show(); edit_dialog->set_size(Size2(150,74)); break; case AnimationTreePlayer::NODE_BLEND3: edit_label[0]->set_text("Blend:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(-1); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->blend3_node_get_amount(edited_node)); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); edit_dialog->set_size(Size2(150,50)); break; case AnimationTreePlayer::NODE_BLEND4: edit_label[0]->set_text("Blend 0:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->blend4_node_get_amount(edited_node).x); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); edit_label[1]->set_text("Blend 1:"); edit_label[1]->set_pos(Point2(5,55)); edit_label[1]->show(); edit_scroll[1]->set_min(0); edit_scroll[1]->set_max(1); edit_scroll[1]->set_val(anim_tree->blend4_node_get_amount(edited_node).y); edit_scroll[1]->set_begin(Point2(15,75)); edit_scroll[1]->show(); edit_dialog->set_size(Size2(150,100)); break; case AnimationTreePlayer::NODE_TRANSITION: { edit_label[0]->set_text("X-Fade Time (s):"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); edit_line[0]->show(); edit_label[1]->set_text("Current:"); edit_label[1]->set_pos(Point2(5,55)); edit_label[1]->show(); edit_option->set_begin(Point2(15,75)); edit_option->clear();; for(int i=0;i<anim_tree->transition_node_get_input_count(edited_node);i++) { edit_option->add_item(itos(i),i); } edit_option->select(anim_tree->transition_node_get_current(edited_node)); edit_option->show(); edit_dialog->set_size(Size2(150,100)); } break; default: {} } } edit_dialog->set_pos(popup_pos); edit_dialog->popup(); updating_edit=false; }
MainLoop* test() { { // print_line("NUM: "+itos(237641278346127)); print_line("NUM: "+itos(-128)); return NULL; } { Vector3 v(1,2,3); v.normalize(); float a=0.3; //Quat q(v,a); Matrix3 m(v,a); Vector3 v2(7,3,1); v2.normalize(); float a2=0.8; //Quat q(v,a); Matrix3 m2(v2,a2); Quat q=m; Quat q2=m2; Matrix3 m3 = m.inverse() * m2; Quat q3 = (q.inverse() * q2);//.normalized(); print_line(Quat(m3)); print_line(q3); print_line("before v: "+v+" a: "+rtos(a)); q.get_axis_and_angle(v,a); print_line("after v: "+v+" a: "+rtos(a)); } return NULL; String ret; List<String> args; args.push_back("-l"); Error err = OS::get_singleton()->execute("/bin/ls",args,true,NULL,&ret); print_line("error: "+itos(err)); print_line(ret); return NULL; Matrix3 m3; m3.rotate(Vector3(1,0,0),0.2); m3.rotate(Vector3(0,1,0),1.77); m3.rotate(Vector3(0,0,1),212); Matrix3 m32; m32.set_euler(m3.get_euler()); print_line("ELEULEEEEEEEEEEEEEEEEEER: "+m3.get_euler()+" vs "+m32.get_euler()); return NULL; { Dictionary d; d["momo"]=1; Dictionary b=d; b["44"]=4; } return NULL; print_line("inters: "+rtos(Geometry::segment_intersects_circle(Vector2(-5,0),Vector2(-2,0),Vector2(),1.0))); print_line("cross: "+Vector3(1,2,3).cross(Vector3(4,5,7))); print_line("dot: "+rtos(Vector3(1,2,3).dot(Vector3(4,5,7)))); print_line("abs: "+Vector3(-1,2,-3).abs()); print_line("distance_to: "+rtos(Vector3(1,2,3).distance_to(Vector3(4,5,7)))); print_line("distance_squared_to: "+rtos(Vector3(1,2,3).distance_squared_to(Vector3(4,5,7)))); print_line("plus: "+(Vector3(1,2,3)+Vector3(Vector3(4,5,7)))); print_line("minus: "+(Vector3(1,2,3)-Vector3(Vector3(4,5,7)))); print_line("mul: "+(Vector3(1,2,3)*Vector3(Vector3(4,5,7)))); print_line("div: "+(Vector3(1,2,3)/Vector3(Vector3(4,5,7)))); print_line("mul scalar: "+(Vector3(1,2,3)*2)); print_line("premul scalar: "+(2*Vector3(1,2,3))); print_line("div scalar: "+(Vector3(1,2,3)/3.0)); print_line("length: "+rtos(Vector3(1,2,3).length())); print_line("length squared: "+rtos(Vector3(1,2,3).length_squared())); print_line("normalized: "+Vector3(1,2,3).normalized()); print_line("inverse: "+Vector3(1,2,3).inverse()); { Vector3 v(4,5,7); v.normalize(); print_line("normalize: "+v); } { Vector3 v(4,5,7); v+=Vector3(1,2,3); print_line("+=: "+v); } { Vector3 v(4,5,7); v-=Vector3(1,2,3); print_line("-=: "+v); } { Vector3 v(4,5,7); v*=Vector3(1,2,3); print_line("*=: "+v); } { Vector3 v(4,5,7); v/=Vector3(1,2,3); print_line("/=: "+v); } { Vector3 v(4,5,7); v*=2.0; print_line("scalar *=: "+v); } { Vector3 v(4,5,7); v/=2.0; print_line("scalar /=: "+v); } #if 0 print_line(String("C:\\momo\\.\\popo\\..\\gongo").simplify_path()); print_line(String("res://../popo/..//gongo").simplify_path()); print_line(String("res://..").simplify_path()); DVector<uint8_t> a; DVector<uint8_t> b; a.resize(20); b=a; b.resize(30); a=b; #endif #if 0 String za = String::utf8("á"); printf("unicode: %x\n",za[0]); CharString cs=za.utf8(); for(int i=0;i<cs.size();i++) { uint32_t v = uint8_t(cs[i]); printf("%i - %x\n",i,v); } return NULL; print_line(String("C:\\window\\system\\momo").path_to("C:\\window\\momonga")); print_line(String("res://momo/sampler").path_to("res://pindonga")); print_line(String("/margarito/terere").path_to("/margarito/pilates")); print_line(String("/algo").path_to("/algo")); print_line(String("c:").path_to("c:\\")); print_line(String("/").path_to("/")); print_line(itos(sizeof(Variant))); return NULL; Vector<StringName> path; path.push_back("three"); path.push_back("two"); path.push_back("one"); path.push_back("comeon"); path.revert(); NodePath np(path,true); print_line(np); return NULL; bool a=2; print_line(Variant(a)); Matrix32 mat2_1; mat2_1.rotate(0.5); Matrix32 mat2_2; mat2_2.translate(Vector2(1,2)); Matrix32 mat2_3 = mat2_1 * mat2_2; mat2_3.affine_invert(); print_line(mat2_3.elements[0]); print_line(mat2_3.elements[1]); print_line(mat2_3.elements[2]); Transform mat3_1; mat3_1.basis.rotate(Vector3(0,0,1),0.5); Transform mat3_2; mat3_2.translate(Vector3(1,2,0)); Transform mat3_3 = mat3_1 * mat3_2; mat3_3.affine_invert(); print_line(mat3_3.basis.get_axis(0)); print_line(mat3_3.basis.get_axis(1)); print_line(mat3_3.origin); #endif return NULL; }
void AnimationPlayer::_animation_update_transforms() { for (int i = 0; i < cache_update_size; i++) { TrackNodeCache *nc = cache_update[i]; ERR_CONTINUE(nc->accum_pass != accum_pass); if (nc->spatial) { Transform t; t.origin = nc->loc_accum; t.basis = nc->rot_accum; t.basis.scale(nc->scale_accum); if (nc->skeleton && nc->bone_idx >= 0) { nc->skeleton->set_bone_pose(nc->bone_idx, t); } else if (nc->spatial) { nc->spatial->set_transform(t); } } } cache_update_size = 0; for (int i = 0; i < cache_update_prop_size; i++) { TrackNodeCache::PropertyAnim *pa = cache_update_prop[i]; ERR_CONTINUE(pa->accum_pass != accum_pass); switch (pa->special) { case SP_NONE: { bool valid; pa->object->set(pa->prop, pa->value_accum, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { ERR_PRINTS("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property"); } #endif } break; case SP_NODE2D_POS: { #ifdef DEBUG_ENABLED if (pa->value_accum.get_type() != Variant::VECTOR2) { ERR_PRINTS("Position key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()"); } #endif static_cast<Node2D *>(pa->object)->set_position(pa->value_accum); } break; case SP_NODE2D_ROT: { #ifdef DEBUG_ENABLED if (pa->value_accum.is_num()) { ERR_PRINTS("Rotation key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not numerical"); } #endif static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum)); } break; case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED if (pa->value_accum.get_type() != Variant::VECTOR2) { ERR_PRINTS("Scale key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()"); } #endif static_cast<Node2D *>(pa->object)->set_scale(pa->value_accum); } break; } } cache_update_prop_size = 0; }
RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_original_path, Error *r_error) { if (r_error) *r_error=ERR_CANT_OPEN; if (p_path.extension()=="cube") { // open as cubemap txture CubeMap* ptr = memnew(CubeMap); Ref<CubeMap> cubemap( ptr ); Error err; FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); if (err) { ERR_FAIL_COND_V( err, RES() ); } String base_path=p_path.substr( 0, p_path.find_last("/")+1 ); for(int i=0;i<6;i++) { String file = f->get_line().strip_edges(); Image image; Error err = ImageLoader::load_image(base_path+file,&image); if (err) { memdelete(f); ERR_FAIL_COND_V( err, RES() ); } if (i==0) { //cubemap->create(image.get_width(),image.get_height(),image.get_format(),Texture::FLAGS_DEFAULT|Texture::FLAG_CUBEMAP); } static const CubeMap::Side cube_side[6]= { CubeMap::SIDE_LEFT, CubeMap::SIDE_RIGHT, CubeMap::SIDE_BOTTOM, CubeMap::SIDE_TOP, CubeMap::SIDE_FRONT, CubeMap::SIDE_BACK }; cubemap->set_side(cube_side[i],image); } memdelete(f); cubemap->set_name(p_path.get_file()); if (r_error) *r_error=OK; return cubemap; } else { // simple image ImageTexture* ptr = memnew(ImageTexture); Ref<ImageTexture> texture( ptr ); uint64_t begtime; double total; Image image; if (debug_load_times) begtime=OS::get_singleton()->get_ticks_usec(); Error err = ImageLoader::load_image(p_path,&image); if (!err && debug_load_times) { double total=(double)(OS::get_singleton()->get_ticks_usec()-begtime)/1000000.0; print_line("IMAGE: "+itos(image.get_width())+"x"+itos(image.get_height())); print_line(" -load: "+rtos(total)); } ERR_EXPLAIN("Failed loading image: "+p_path); ERR_FAIL_COND_V(err, RES()); if (r_error) *r_error=ERR_FILE_CORRUPT; #ifdef DEBUG_ENABLED #ifdef TOOLS_ENABLED if (max_texture_size && (image.get_width() > max_texture_size || image.get_height() > max_texture_size)) { if (bool(Globals::get_singleton()->get("debug/max_texture_size_alert"))) { OS::get_singleton()->alert("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+".","BAD ARTIST, NO COOKIE!"); } ERR_EXPLAIN("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+"."); ERR_FAIL_V(RES()); } #endif #endif uint32_t flags=0; FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ); Map<String,bool> flags_found; if (f2) { while(!f2->eof_reached()) { String l2 = f2->get_line(); int eqpos = l2.find("="); if (eqpos!=-1) { String flag=l2.substr(0,eqpos).strip_edges(); String val=l2.substr(eqpos+1,l2.length()).strip_edges().to_lower(); flags_found[flag]=(val=="true" || val=="1")?true:false; } } memdelete(f2); } if (flags_found.has("filter")) { if (flags_found["filter"]) flags|=Texture::FLAG_FILTER; } else if (bool(GLOBAL_DEF("image_loader/filter",true))) { flags|=Texture::FLAG_FILTER; } if (flags_found.has("gen_mipmaps")) { if (flags_found["gen_mipmaps"]) flags|=Texture::FLAG_MIPMAPS; } else if (bool(GLOBAL_DEF("image_loader/gen_mipmaps",true))) { flags|=Texture::FLAG_MIPMAPS; } if (flags_found.has("repeat")) { if (flags_found["repeat"]) flags|=Texture::FLAG_REPEAT; } else if (bool(GLOBAL_DEF("image_loader/repeat",true))) { flags|=Texture::FLAG_REPEAT; } if (flags_found.has("anisotropic")) { if (flags_found["anisotropic"]) flags|=Texture::FLAG_ANISOTROPIC_FILTER; } if (flags_found.has("tolinear")) { if (flags_found["tolinear"]) flags|=Texture::FLAG_CONVERT_TO_LINEAR; } if (flags_found.has("mirroredrepeat")) { if (flags_found["mirroredrepeat"]) flags|=Texture::FLAG_MIRRORED_REPEAT; } if (debug_load_times) begtime=OS::get_singleton()->get_ticks_usec(); //print_line("img: "+p_path+" flags: "+itos(flags)); texture->create_from_image( image,flags ); texture->set_name(p_path.get_file()); if (debug_load_times) { total=(double)(OS::get_singleton()->get_ticks_usec()-begtime)/1000000.0; print_line(" -make texture: "+rtos(total)); } if (r_error) *r_error=OK; return RES( texture ); } }