From d3495b128a700b6f830ec90ff0b544ad1333b867 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 23 May 2016 17:10:26 -0300 Subject: [PATCH] -Improve resource previews -Also fixed draw_texture_rect() tile parameter --- scene/gui/box_container.cpp | 1 + servers/visual/visual_server_raster.cpp | 5 +- tools/editor/editor_node.cpp | 14 +- tools/editor/editor_node.h | 2 + tools/editor/editor_plugin.cpp | 8 + tools/editor/editor_plugin.h | 3 +- tools/editor/icons/icon_checkerboard.png | Bin 0 -> 253 bytes .../icons/icon_material_preview_cube.png | Bin 0 -> 502 bytes .../icons/icon_material_preview_cube_off.png | Bin 0 -> 493 bytes .../icons/icon_material_preview_light_1.png | Bin 0 -> 1283 bytes .../icon_material_preview_light_1_off.png | Bin 0 -> 1329 bytes .../icons/icon_material_preview_light_2.png | Bin 0 -> 1341 bytes .../icon_material_preview_light_2_off.png | Bin 0 -> 1363 bytes .../icons/icon_material_preview_sphere.png | Bin 0 -> 1051 bytes .../icon_material_preview_sphere_off.png | Bin 0 -> 1006 bytes .../plugins/color_ramp_editor_plugin.cpp | 15 +- .../editor/plugins/color_ramp_editor_plugin.h | 2 +- .../editor/plugins/material_editor_plugin.cpp | 381 ++++++++++++++++ tools/editor/plugins/material_editor_plugin.h | 71 +++ tools/editor/plugins/mesh_editor_plugin.cpp | 425 +++++++----------- tools/editor/plugins/mesh_editor_plugin.h | 68 ++- .../plugins/mesh_instance_editor_plugin.cpp | 300 +++++++++++++ .../plugins/mesh_instance_editor_plugin.h | 69 +++ tools/editor/plugins/sample_editor_plugin.cpp | 9 +- .../editor/plugins/texture_editor_plugin.cpp | 141 ++++++ tools/editor/plugins/texture_editor_plugin.h | 49 ++ tools/editor/script_editor_debugger.cpp | 1 + 27 files changed, 1244 insertions(+), 320 deletions(-) create mode 100644 tools/editor/icons/icon_checkerboard.png create mode 100644 tools/editor/icons/icon_material_preview_cube.png create mode 100644 tools/editor/icons/icon_material_preview_cube_off.png create mode 100644 tools/editor/icons/icon_material_preview_light_1.png create mode 100644 tools/editor/icons/icon_material_preview_light_1_off.png create mode 100644 tools/editor/icons/icon_material_preview_light_2.png create mode 100644 tools/editor/icons/icon_material_preview_light_2_off.png create mode 100644 tools/editor/icons/icon_material_preview_sphere.png create mode 100644 tools/editor/icons/icon_material_preview_sphere_off.png create mode 100644 tools/editor/plugins/material_editor_plugin.cpp create mode 100644 tools/editor/plugins/material_editor_plugin.h create mode 100644 tools/editor/plugins/mesh_instance_editor_plugin.cpp create mode 100644 tools/editor/plugins/mesh_instance_editor_plugin.h create mode 100644 tools/editor/plugins/texture_editor_plugin.cpp create mode 100644 tools/editor/plugins/texture_editor_plugin.h diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index a9522cf2486..a6ffc30a835 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -280,6 +280,7 @@ BoxContainer::AlignMode BoxContainer::get_alignment() const { void BoxContainer::add_spacer(bool p_begin) { Control *c = memnew( Control ); + c->set_stop_mouse(false); if (vertical) c->set_v_size_flags(SIZE_EXPAND_FILL); else diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index ad85ecc7c07..6b5f1ba3536 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -3661,8 +3661,11 @@ void VisualServerRaster::canvas_item_add_texture_rect(RID p_item, const Rect2& p rect->modulate=p_modulate; rect->rect=p_rect; rect->flags=0; - if (p_tile) + if (p_tile) { rect->flags|=Rasterizer::CANVAS_RECT_TILE; + rect->flags|=Rasterizer::CANVAS_RECT_REGION; + rect->source=Rect2(0,0,p_rect.size.width,p_rect.size.height); + } if (p_rect.size.x<0) { diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index d8a4be5e6d3..69dfc556b4a 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -64,6 +64,8 @@ #include "addon_editor_plugin.h" #include "plugins/spatial_editor_plugin.h" #include "plugins/sample_editor_plugin.h" +#include "plugins/texture_editor_plugin.h" +#include "plugins/material_editor_plugin.h" #include "plugins/sample_library_editor_plugin.h" #include "plugins/sample_player_editor_plugin.h" #include "plugins/camera_editor_plugin.h" @@ -72,6 +74,7 @@ #include "plugins/item_list_editor_plugin.h" #include "plugins/stream_editor_plugin.h" #include "plugins/multimesh_editor_plugin.h" +#include "plugins/mesh_instance_editor_plugin.h" #include "plugins/mesh_editor_plugin.h" #include "plugins/theme_editor_plugin.h" @@ -5818,6 +5821,7 @@ EditorNode::EditorNode() { HBoxContainer *prop_editor_hb = memnew( HBoxContainer ); prop_editor_base->add_child(prop_editor_hb); + prop_editor_vb=prop_editor_base; resource_new_button = memnew( ToolButton ); resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it.")); @@ -6223,9 +6227,9 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( MultiMeshEditorPlugin(this) ) ); add_editor_plugin( memnew( MeshInstanceEditorPlugin(this) ) ); add_editor_plugin( memnew( AnimationTreeEditorPlugin(this) ) ); - add_editor_plugin( memnew( SamplePlayerEditorPlugin(this) ) ); + //add_editor_plugin( memnew( SamplePlayerEditorPlugin(this) ) ); - this is kind of useless at this point add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) ); - add_editor_plugin( memnew( StreamEditorPlugin(this) ) ); + //add_editor_plugin( memnew( StreamEditorPlugin(this) ) ); add_editor_plugin( memnew( StyleBoxEditorPlugin(this) ) ); add_editor_plugin( memnew( ParticlesEditorPlugin(this) ) ); add_editor_plugin( memnew( ResourcePreloaderEditorPlugin(this) ) ); @@ -6244,9 +6248,11 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( Polygon2DEditorPlugin(this) ) ); add_editor_plugin( memnew( LightOccluder2DEditorPlugin(this) ) ); add_editor_plugin( memnew( NavigationPolygonEditorPlugin(this) ) ); - add_editor_plugin( memnew( ColorRampEditorPlugin(this,true) ) ); - add_editor_plugin( memnew( ColorRampEditorPlugin(this,false) ) ); + add_editor_plugin( memnew( ColorRampEditorPlugin(this) ) ); add_editor_plugin( memnew( CollisionShape2DEditorPlugin(this) ) ); + add_editor_plugin( memnew( TextureEditorPlugin(this) ) ); + add_editor_plugin( memnew( MaterialEditorPlugin(this) ) ); + add_editor_plugin( memnew( MeshEditorPlugin(this) ) ); for(int i=0;iget_bottom_split()->add_child(p_control); } break; + case CONTAINER_PROPERTY_EDITOR_BOTTOM: { + + EditorNode::get_singleton()->get_property_editor_vb()->add_child(p_control); + + } break; + } } @@ -319,6 +325,8 @@ void EditorPlugin::_bind_methods() { BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_BOTTOM ); BIND_CONSTANT( CONTAINER_CANVAS_EDITOR_MENU ); BIND_CONSTANT( CONTAINER_CANVAS_EDITOR_SIDE ); + BIND_CONSTANT( CONTAINER_PROPERTY_EDITOR_BOTTOM ); + BIND_CONSTANT( DOCK_SLOT_LEFT_UL ); BIND_CONSTANT( DOCK_SLOT_LEFT_BL ); diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h index c572ab210e4..b93b6624d05 100644 --- a/tools/editor/editor_plugin.h +++ b/tools/editor/editor_plugin.h @@ -73,7 +73,8 @@ public: CONTAINER_SPATIAL_EDITOR_BOTTOM, CONTAINER_CANVAS_EDITOR_MENU, CONTAINER_CANVAS_EDITOR_SIDE, - CONTAINER_CANVAS_EDITOR_BOTTOM + CONTAINER_CANVAS_EDITOR_BOTTOM, + CONTAINER_PROPERTY_EDITOR_BOTTOM }; enum DockSlot { diff --git a/tools/editor/icons/icon_checkerboard.png b/tools/editor/icons/icon_checkerboard.png new file mode 100644 index 0000000000000000000000000000000000000000..5f658c765ea0a147b1c50665822adcc067de286c GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGH$&H|6fVg?3oArNM~bhqvgP>{XE z)7O>#0joH_lJS`a!+M~QY-UJAiF1B#Zfaf$kjuc}T$GwvlA5AWo>`Ki;O^-gkfN8$ z4iqo;ba4#HxcBzvLCymP9IO|%e0f*#&b~>ygpE5l=+nQ*7Irz2{xdRjU0hc0TNU@V zzHdHA7X&24t-Jc|cV4|R3rvLJ!ymbb-2LC>;Q|al-pPHCH*kUr+-Az#wo7b>f<|}< ONX*mK&t;ucLK6Vz<3{ZO literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_cube.png b/tools/editor/icons/icon_material_preview_cube.png new file mode 100644 index 0000000000000000000000000000000000000000..53daaa83648f2fd4343263e53c2549aceb5d76af GIT binary patch literal 502 zcmV0000TX;fHrLvL+uWo~o;00000Lvm$d zbY)~9cWHEJAV*0}P-HG;2LJ#8Y)M2xR5;7+l(9+!K@f)j*T(z7Bfh$u6h1diX z@&Fd;OyyIUMuZ~|kRpYJq)BD(JA{A_V9Kh*to!t%1zUN~uM?UcX3^Wi}WL9<=!Vd?d6+ zqtRuz+dY?3R*W%RtycGXthI(Q2CLPIg%Iz31prBskn6f9?RNXrwr#Zq>?I>2WLbvI zW`m*=ssJP+B4++^Y{ap1_)qu;2)Ds70M^GKWFZ8P$K$Iwj-LVWZwOf_Mbqi@cClF8 zH5v{6q)})o>C!!kwF95jsQ`S)wJ=nJGlo~Gt&FAySFbuB&00000NkvXXu0mjfdN#*Y literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_light_1.png b/tools/editor/icons/icon_material_preview_light_1.png new file mode 100644 index 0000000000000000000000000000000000000000..fccdd01f9c9bbc35efb5d6c1464d25b8c91c9c07 GIT binary patch literal 1283 zcmV+e1^oJnP)w70MZ zY|7O-TZ-60^3cI>;)}F%(pIR2vOVufg$f&kyv;`+WYUMcD18vISdex@S_v3NC0YLj zSJse(+nemBHSNv0XAey^W1IUv9XRLv`yGD24`1Lw5&*?83=aT;ccP53fyKqejm5>q z4aV320NQj<8Xl!l12O=)t*xz1QIzg%HoL89+HZS%dzDJ1A`Z<$2)DTj09RF2;`8~` zY&P4a>w2(OtF7eo`MdOiHzey&OKbOnp-=XWePf?WqL?SV3nx;EB zIeC*Y*4x_JdTnB2VkVVJZCREjEXxw9RBCHtVq&JXwe=cftaoy9@}_B;ZX%JGRTQOP z*L5EOKr~HLcXoD+t5>fM&d<-kRum=j@ZrO+L!r=z08p>jh3mTTdc6byOw;`H(xppx zYPDK69*?)*zkh$h@As#R#bSj3fU2rQlB5>S`Nx{3U0hyXzUjKIO9-KoB%xR=BA?IW z!Z5M5R&@Yiny_ zY-~)#VllC~xhYDelCUgGn5M}ynap-56dH|2qeq%IMghpVTrM1s$Ipku;iHsN$~ni~ zyLWN<@?{i@#REpjJEAD1G#m~ejmP8XbGcl&K@6pgv3|zbSs{cmH8mAGG)R(!>({Si zX=w?)y}j`HeE2s_O-;pw5C&uHEMu%+e)8nWj1a=TckkX(Pft&~5aR7m9LIs{y5O8c z2=R|%LJ0Kq^t2BT4__P`8|x>8P}+P+DWw43Itd}5l;S-Slv3K2xlcOwJ~g$vXfbIgYdCI8NT{_3l?Hm5(l5xX^o8 zY;|=N%gf8iX0xc(YVdeGc=hTPPMtah&N&DnxOMB+gVoj52fMqwD~{uAQUET1x~}Vm z`T6<9LZM)}2g3ULI_Bo)VB0nrV|e!L86G`)1X-5BId=<%g7x(2(_cC|I*I@s0PcIi zRuqMLJf6SdLI^>*Ty`Z%qK097Un-SSk|h0FtyW(H*rNc5&*xM3_V#*5Mn*mdus%3A z_?=~0)&2c_?Ck8owryeCwy0LCux%UVa=99d#eV4P>k}_ty!i3lxpP+nfj|cU`M<*9 zlm82cmX?;&ot>RuK7amvePd&zeCEuVF97%ez^Ci_P$rWpBoc{Pzu*69Fc=JUb#;Xp zW6?k$Ffu+qJ~KW(J`)H8Mi^t!?(XiR06eOyw(Gk7)r}iB5`MqGI}(X_(FoWRx~_kw zC`zBEX-8C5Jsg_M7#mnvSXf(FSXgT$w%o*_90&x0!Cl5PM1002ovPDHLkV1kGzVvqm; literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_light_1_off.png b/tools/editor/icons/icon_material_preview_light_1_off.png new file mode 100644 index 0000000000000000000000000000000000000000..84953f18665298fa677d070e9ec1dfe34bfd8df5 GIT binary patch literal 1329 zcmV-117=N4xSn-~n)4`>5}fvF&_++vI6 z_Q$<#?>+bIgGIU@+4JcnC-3u|^S;mf058D+?1@Ao5&(i-P+67-$H&L-j*pMum1TJl z0ByP_jha0T4mbcf+S}XPZQJfyUS8e~1Oh9yT20e5P3#m4A?#)m0Jfqi#N~1+%gf6L z+uGXpQA(FoRaF@P$?bMW$HvA+-EMbyVPPRBNz#_z@0Y99YKT&Luv)F|TU}k%R8`$3 zgz%1z4%4zM$uNw*cs%~anKNfTdGO%D<4UFSjDC>l=uHpRx<|&2j3eR85y3OoLosJlQUgi zU0DKv1Ofr2QmI4+1_mOFi;H6_2nK^7 zgg^)(7-P72@#2K8>)$cP9&^sinx+W~0Gg%=kHD5bB+CMG6u^X5&| z>vh<+4N58DoFkD)oDxDD_INzBF+?~TQ=|EO{fD@jtPn2_b|Cg+i^-X!L{O;o)vV$gY$S0+iC`Ede3qZ{PecP)bR&nB&ToD_=FvUFmfC zjc_>ZZx*rb-6gSY8@6qOF}5Q}(&==5c6Rp1+1c4=0KiPs+%Qd3bvm8(QmJ$x7K?T7 zkY%%3q|<4rstVII!5Bj(lRlzD%Lawc?t=@P% z{`ttr$cLFsW_4v{<^IEm4>Q?p7J)#(-6Z+ zqwfq24ZWRACjTfD3Tp&_tF5i={jssJ(dp^wr?+q4{>J5U&9=0(NQFY7gE4j_5{bMI z0I5`JigP~i_xt}`Utg~%iqhe9ItPy*KYrley?ftwc6L4{%>k=v+P2s0Z4Ow6EX(gE z5{WSYxO(;K*SfC%0>Ij_oyX(xT9)NB3_}B8H~?6xs%`+tMIsTNN~J6SJ5IG5ert~X n=Jd8orP7N)AV3Vm5CHHOjzC;Ai}vB|00000NkvXXu0mjfaNT(% literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_light_2.png b/tools/editor/icons/icon_material_preview_light_2.png new file mode 100644 index 0000000000000000000000000000000000000000..55b18e08a18c269a2dd45b7d39408c0d01c4425c GIT binary patch literal 1341 zcmV-D1;YA?P)-faP#C$Xw-O1#@0>KENYs@4>sD<({m)1N?ll6Tl=}Ktxe{f)5XO_ zgu`KIng&WKoK7c(hlg?L(j{=tt!y@{4Gs=|>+yKPFJ8RZZETDJuqBg8cQ6<{<954` zQc5WRR4NsWj*ensVF7bplKr9wZo;!E$I{@1NzzoCKF$^Qs)YMefH0^`)=g;>w zCf?fG!u0es2q7347(lsP#>U15wzjr#;=~D2!X1d3mj)qay>r0AT&6 zumwS&cDwyxNsY-Z%d&J`rzcOI{2`moMj2y&6pO`I04fv!aX1`urBdk|85#Kuz{b$f z(D(U#zF4hRQ7V;CC=__1P~gR45v5WIuV23|27|$$0)YU3_Uzd&gM))#N|Mw8!1iz9 z@X`N;LvwTUsm{*MFP=Pkvaz|jxqJHb>CXW;0KlQD>hQ~#FVmq=DC~4PKXJKSQdd{k z`=TiJNRl)%Ha0dtHa0ddNz#ZYiap)k-A4h~Wm#@lRrRau*RO}1PG`5z=W9YeV7;oU zekuq;Kv9$-YQ3 zSS(gMByI};T3T9~50M;B?^>Zyc%vu^X<+^VKpH?dmj>j600000NkvXXu0mjfSx#-r literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_light_2_off.png b/tools/editor/icons/icon_material_preview_light_2_off.png new file mode 100644 index 0000000000000000000000000000000000000000..3caf92ecbe6c560df0567a8dd9e0e1b662e5ebb2 GIT binary patch literal 1363 zcmV-Z1+4msP)ch0000TX;fHrLvL+uWo~o;00000Lvm$d zbY)~9cWHEJAV*0}P-HG;2LJ#B$w@>(R5;6ZR84CeR}?+(&5R|FKgOzr6x(tWIXF}y zLC97e8&bt}F&Mgtiy>VET0(bO1tYRB!rhcWz~movnTCX9(KMyOO%tbqU?^@SoZ3|k zk?Rjl6iJ1VnM@{+#^dqccszc>G|kA?)|O(Lrad}3dTM%ldi>F&N9&nPW~r~Q z?N~ z2M>_RWU#ijhFmTO%d!v-hl%UD7#titvbeaosVK_xVzJoR-xviTmdoWs(P(tY=kv8v zN(lfk#*j=VkxHd-@!~~LO0m4W3`vqe2q8Y7uQeKt4wcL0Lwk;)qAbg&0Kj$KzKMy6 z=w1v;DMm&{z!-yNS@3$jpp=4h4nhcA*99R26B85Bm6es4EX(fzfS5|9z68J@K76(^nLCeEEZ2fyEcAPE4xc=4iq z?b@}k0c-()VB2=Vwr#bgrNydNt49)v#NqvsOQjNS+_(Wk2nGfQVB0o|#Ue_j62jpy z9LK?}Tep@=rP956z5csx+gl<42Y?d@1YWMKtu1Ssmgws0^17}|R8@s6%WxbA+uPgN z+1UZ56p|z%kx00jrZrYqSAX;S{l!|XW@G=d{GYKUNg|>s{##Z!j^kREh0B*O|4^&d zGJ+tiRIAlL0hj^+q9}@D7)E?}czC!}D(x&TE>;qW#9>L2M9w*E+XiC{j^lta22In< zt5>fsba!_fmo8oUB%jZ>8iw)GvMgPQL?WI_rE+3wYU;D;>FJLOg+hLPef_5=PoC@) z3I#V53UzdJba)9NP*qjGbLURx=FOY;s@3YEVHh+XkDokq=FEH9Z1xXL(>4eIPbd^h zrqk(}r%#`5-o1PG8;{5HYinz(q-k1@AP6U8u~-rSvf1p@EWe*hrP2T}KR^FfyTO%3I>D3Fbo#}{szrF VU%=$zS>FHv002ovPDHLkV1i&vdj|jj literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_sphere.png b/tools/editor/icons/icon_material_preview_sphere.png new file mode 100644 index 0000000000000000000000000000000000000000..9ba7e00ee83ffa5dc0e1ecdbd33dcdd3bda09367 GIT binary patch literal 1051 zcmV+$1mydPP)iZmakJv}`a)9DR5&bsS3jyle|uC1+UDwT3msb6RySn@g9Qo12dsV<1Mv2xJ=&0SV*rdR{+v?5GIBu~_VT0B*iz0T4KS zy8EM=S86KUE!Pc)L+@OR#cnF0l5-}2hyg&jboJ!Pwzta5%ipk*wr7XJ&dv@qGc!{= zI5_k%0D8P06NyBE6&00-0|9@4AVhK>n;-xYBO)R-H8n3qUWi--@JEhNjvs&1S6yBG z!ShF+J1oW+fGB^qyv)DH??-k>m>rbNmDzhjM9lpB{GFzzrdyMflk_@kYuH~@*K>$!yh)706)+WjA z+MyOeVm6T~E-5a(`|Di;z%|=5Pl7osnmHNN2V{8g8i-s2MQk!=`+a_|Fk{XT3IKnm z)9HJv3MxS;R0*YmRFH(`R6+qIRF#|ex3&rk3%!oxtcF4%1pss4KnbGfqJPgOW^XH% z3WfelnJSn85ZF0{0?ygdB%@a5QKOaagU;9O#E>&*LSzA!LGT_vf= zsLdz@70OH_1wjHHkH`Dr*|XoNDzE-}IuXo5^HyyDZD%jT<+A zYiMZb8yy`@oI3U1X8`s*E+k63ySu-#EQ|4Y{GMf5oSU2bYh+|(w!Xgp^VZhZ3-Md= z-|On?Isxo`DEIOgmhGfGU0N0>D=n*Q?`VG;BEbT$&+9Ajd4j>9Kbf>{x3_nE(%;|r z^NADh>VFMeX=`gU{r&v~0G`YS?0x|Iu6%pNw_CtIE+A!Tc^Q%$W)O#-Ikf99;2&Hp?$$4|$^L*dW^F7b|9KrEJo^EXcBmhDcID7UC01&S^WP5vC!r`zR zfEU0S05zvhovhkSCJg{_u73uWKG;g7q~`SL3ZKt+xvQ(|N+1w8S6yBGhHYoLv$MM& zi^YDMo}T`8aBy%j5{a;s_TP4?>*(mX+0%3N15yb9Bm^Kx5+E{}EF+P~SIf)GUjq26 zIM`Jp_SV3_z;J78Yojp&F-AlnBI4{WLQ-5Vm$Y2E^zMt7F9ItotFr*?ynrbpt!Qs= zztPmxRA<|^_V@SSd9=8=p#&wLhyWtF5Sz-Lo~x~XzrQoS9+xA8;qXnfu<*-A;c)m9 z0Cc%r#_#ug8XFpG%FD~j06_8~%vt7OODGg-?C$Qq4`4q}D5RL~?vJlfl>kIl(bCcq ztnyS>C)u*7z+*IUuh(D0#USpop&>60fI9{%h^ZEbBZA0!Zvgen0g=q!+g;ME)e z5{bm0&CSj4*Voqz05O_dsI2ySPvmF`r9xFfD6~k7Bv?cX0Eu{F&*$^`qtR%Nuuw%L zh(caR?krXy3h$AM$I-{>GIyCNd}Trb;2@n&ACe@MAT*aU2~rDmIXwkPs46m9TPrIo zkxr*~F1~${0AK=vS`6M8Jlxpah|!@W9V$BWJQ>wVmrzw*U;87~*47q$@Y93Y=u(sb zXpqZ5?@dpC?-VWze&xxiP)989p)tnXox1xwNh~cb&5n$Wuu#~MNQ4Imhd)kzGxak` zDHY69k%XPi+9WYFG<3hOukXFFv9UXAu~;(ixGA##`OM7B=L-u9@mJ>-M?^_te}Dhw z?UCC*^!E0?GdDLopG+q2oeu{2UuXH*{QUe}Hk%EGLZQIk-rn=_@^W`3ld)G#^rXqjmP6b zDwSH9oSgjHvOaxu>(&VWZ?hH4vW#U}ZU8=~!M+KgYIJne^;!+KbUn7V262j+AT9(i c9QzCS8zNQq>e^W~MF0Q*07*qoM6N<$f=MRNH2?qr literal 0 HcmV?d00001 diff --git a/tools/editor/plugins/color_ramp_editor_plugin.cpp b/tools/editor/plugins/color_ramp_editor_plugin.cpp index 854a0149a52..267f3aa5bdf 100644 --- a/tools/editor/plugins/color_ramp_editor_plugin.cpp +++ b/tools/editor/plugins/color_ramp_editor_plugin.cpp @@ -6,16 +6,13 @@ #include "spatial_editor_plugin.h" #include "canvas_item_editor_plugin.h" -ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node, bool p_2d) { +ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) { editor=p_node; ramp_editor = memnew( ColorRampEdit ); - _2d=p_2d; - if (p_2d) - add_control_to_container(CONTAINER_CANVAS_EDITOR_BOTTOM,ramp_editor); - else - add_control_to_container(CONTAINER_SPATIAL_EDITOR_BOTTOM,ramp_editor); + + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,ramp_editor); ramp_editor->set_custom_minimum_size(Size2(100, 48)); ramp_editor->hide(); @@ -33,10 +30,8 @@ void ColorRampEditorPlugin::edit(Object *p_object) { bool ColorRampEditorPlugin::handles(Object *p_object) const { - if (_2d) - return p_object->is_type("ColorRamp") && CanvasItemEditor::get_singleton()->is_visible() == true; - else - return p_object->is_type("ColorRamp") && SpatialEditor::get_singleton()->is_visible() == true; + return p_object->is_type("ColorRamp"); + } void ColorRampEditorPlugin::make_visible(bool p_visible) { diff --git a/tools/editor/plugins/color_ramp_editor_plugin.h b/tools/editor/plugins/color_ramp_editor_plugin.h index f07dbabeb37..02d691239fb 100644 --- a/tools/editor/plugins/color_ramp_editor_plugin.h +++ b/tools/editor/plugins/color_ramp_editor_plugin.h @@ -30,7 +30,7 @@ public: virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); - ColorRampEditorPlugin(EditorNode *p_node, bool p_2d); + ColorRampEditorPlugin(EditorNode *p_node); ~ColorRampEditorPlugin(); }; diff --git a/tools/editor/plugins/material_editor_plugin.cpp b/tools/editor/plugins/material_editor_plugin.cpp new file mode 100644 index 00000000000..4ef2815a324 --- /dev/null +++ b/tools/editor/plugins/material_editor_plugin.cpp @@ -0,0 +1,381 @@ +#include "material_editor_plugin.h" +#include "scene/main/viewport.h" + +void MaterialEditor::_input_event(InputEvent p_event) { + + +} + +void MaterialEditor::_notification(int p_what) { + + if (p_what==NOTIFICATION_FIXED_PROCESS) { + + } + + + if (p_what==NOTIFICATION_READY) { + + //get_scene()->connect("node_removed",this,"_node_removed"); + + if (first_enter) { + //it's in propertyeditor so.. could be moved around + + light_1_switch->set_normal_texture(get_icon("MaterialPreviewLight1","EditorIcons")); + light_1_switch->set_pressed_texture(get_icon("MaterialPreviewLight1Off","EditorIcons")); + light_2_switch->set_normal_texture(get_icon("MaterialPreviewLight2","EditorIcons")); + light_2_switch->set_pressed_texture(get_icon("MaterialPreviewLight2Off","EditorIcons")); + + sphere_switch->set_normal_texture(get_icon("MaterialPreviewSphereOff","EditorIcons")); + sphere_switch->set_pressed_texture(get_icon("MaterialPreviewSphere","EditorIcons")); + box_switch->set_normal_texture(get_icon("MaterialPreviewCubeOff","EditorIcons")); + box_switch->set_pressed_texture(get_icon("MaterialPreviewCube","EditorIcons")); + + first_enter=false; + } + + } + + if (p_what==NOTIFICATION_DRAW) { + + + Ref checkerboard = get_icon("Checkerboard","EditorIcons"); + Size2 size = get_size(); + + draw_texture_rect(checkerboard,Rect2(Point2(),size),true); + + } +} + + + +void MaterialEditor::edit(Ref p_material) { + + material=p_material; + + if (!material.is_null()) { + sphere_mesh->surface_set_material(0,material); + box_mesh->surface_set_material(0,material); + } else { + + hide(); + } + +} + + +void MaterialEditor::_button_pressed(Node* p_button) { + + if (p_button==light_1_switch) { + light1->set_enabled(!light_1_switch->is_pressed()); + } + + if (p_button==light_2_switch) { + light2->set_enabled(!light_2_switch->is_pressed()); + } + + if (p_button==box_switch) { + box_instance->show(); + sphere_instance->hide(); + box_switch->set_pressed(true); + sphere_switch->set_pressed(false); + } + + if (p_button==sphere_switch) { + box_instance->hide(); + sphere_instance->show(); + box_switch->set_pressed(false); + sphere_switch->set_pressed(true); + } + +} + +void MaterialEditor::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_input_event"),&MaterialEditor::_input_event); + ObjectTypeDB::bind_method(_MD("_button_pressed"),&MaterialEditor::_button_pressed); + +} + +MaterialEditor::MaterialEditor() { + + viewport = memnew( Viewport ); + Ref world; + world.instance(); + viewport->set_world(world); //use own world + add_child(viewport); + viewport->set_process_input(false); + + camera = memnew( Camera ); + camera->set_transform(Transform(Matrix3(),Vector3(0,0,3))); + camera->set_perspective(45,0.1,10); + viewport->add_child(camera); + + light1 = memnew( DirectionalLight ); + light1->set_transform(Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + viewport->add_child(light1); + + light2 = memnew( DirectionalLight ); + light2->set_transform(Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + light2->set_color(Light::COLOR_DIFFUSE,Color(0.7,0.7,0.7)); + light2->set_color(Light::COLOR_SPECULAR,Color(0.7,0.7,0.7)); + viewport->add_child(light2); + + sphere_instance = memnew( MeshInstance ); + viewport->add_child(sphere_instance); + + box_instance = memnew( MeshInstance ); + viewport->add_child(box_instance); + + Transform box_xform; + box_xform.basis.rotate(Vector3(1,0,0),Math::deg2rad(-25)); + box_xform.basis = box_xform.basis * Matrix3().rotated(Vector3(0,1,0),Math::deg2rad(-25)); + box_xform.basis.scale(Vector3(0.8,0.8,0.8)); + box_instance->set_transform(box_xform); + + { + + sphere_mesh.instance(); + + + int lats=32; + int lons=32; + float radius=1.0; + + DVector vertices; + DVector normals; + DVector uvs; + DVector tangents; + Matrix3 tt = Matrix3(Vector3(0,1,0),Math_PI*0.5); + + for(int i = 1; i <= lats; i++) { + double lat0 = Math_PI * (-0.5 + (double) (i - 1) / lats); + double z0 = Math::sin(lat0); + double zr0 = Math::cos(lat0); + + double lat1 = Math_PI * (-0.5 + (double) i / lats); + double z1 = Math::sin(lat1); + double zr1 = Math::cos(lat1); + + for(int j = lons; j >= 1; j--) { + + double lng0 = 2 * Math_PI * (double) (j - 1) / lons; + double x0 = Math::cos(lng0); + double y0 = Math::sin(lng0); + + double lng1 = 2 * Math_PI * (double) (j) / lons; + double x1 = Math::cos(lng1); + double y1 = Math::sin(lng1); + + + Vector3 v[4]={ + Vector3(x1 * zr0, z0, y1 *zr0), + Vector3(x1 * zr1, z1, y1 *zr1), + Vector3(x0 * zr1, z1, y0 *zr1), + Vector3(x0 * zr0, z0, y0 *zr0) + }; + + #define ADD_POINT(m_idx) \ + normals.push_back(v[m_idx]);\ + vertices.push_back(v[m_idx]*radius);\ + { Vector2 uv(Math::atan2(v[m_idx].x,v[m_idx].z),Math::atan2(-v[m_idx].y,v[m_idx].z));\ + uv/=Math_PI;\ + uv*=4.0;\ + uv=uv*0.5+Vector2(0.5,0.5);\ + uvs.push_back(uv);\ + }\ + { Vector3 t = tt.xform(v[m_idx]);\ + tangents.push_back(t.x);\ + tangents.push_back(t.y);\ + tangents.push_back(t.z);\ + tangents.push_back(1.0);\ + } + + + + ADD_POINT(0); + ADD_POINT(1); + ADD_POINT(2); + + ADD_POINT(2); + ADD_POINT(3); + ADD_POINT(0); + } + } + + Array arr; + arr.resize(VS::ARRAY_MAX); + arr[VS::ARRAY_VERTEX]=vertices; + arr[VS::ARRAY_NORMAL]=normals; + arr[VS::ARRAY_TANGENT]=tangents; + arr[VS::ARRAY_TEX_UV]=uvs; + + sphere_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,arr); + + sphere_instance->set_mesh(sphere_mesh); + + } + { + + + box_mesh.instance(); + + DVector vertices; + DVector normals; + DVector tangents; + DVector uvs; + + int vtx_idx=0; + #define ADD_VTX(m_idx);\ + vertices.push_back( face_points[m_idx] );\ + normals.push_back( normal_points[m_idx] );\ + tangents.push_back( normal_points[m_idx][1] );\ + tangents.push_back( normal_points[m_idx][2] );\ + tangents.push_back( normal_points[m_idx][0] );\ + tangents.push_back( 1.0 );\ + uvs.push_back( Vector3(uv_points[m_idx*2+0],uv_points[m_idx*2+1],0) );\ + vtx_idx++;\ + + for (int i=0;i<6;i++) { + + + Vector3 face_points[4]; + Vector3 normal_points[4]; + float uv_points[8]={0,0,0,1,1,1,1,0}; + + for (int j=0;j<4;j++) { + + float v[3]; + v[0]=1.0; + v[1]=1-2*((j>>1)&1); + v[2]=v[1]*(1-2*(j&1)); + + for (int k=0;k<3;k++) { + + if (i<3) + face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1); + else + face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1); + } + normal_points[j]=Vector3(); + normal_points[j][i%3]=(i>=3?-1:1); + } + + //tri 1 + ADD_VTX(0); + ADD_VTX(1); + ADD_VTX(2); + //tri 2 + ADD_VTX(2); + ADD_VTX(3); + ADD_VTX(0); + + } + + + + Array d; + d.resize(VS::ARRAY_MAX); + d[VisualServer::ARRAY_NORMAL]= normals ; + d[VisualServer::ARRAY_TANGENT]= tangents ; + d[VisualServer::ARRAY_TEX_UV]= uvs ; + d[VisualServer::ARRAY_VERTEX]= vertices ; + + DVector indices; + indices.resize(vertices.size()); + for(int i=0;iadd_surface(Mesh::PRIMITIVE_TRIANGLES,d); + box_instance->set_mesh(box_mesh); + box_instance->hide(); + + + + } + + set_custom_minimum_size(Size2(1,150)); + + HBoxContainer *hb = memnew( HBoxContainer ); + add_child(hb); + hb->set_area_as_parent_rect(2); + + VBoxContainer *vb_shape = memnew( VBoxContainer ); + hb->add_child(vb_shape); + + sphere_switch = memnew( TextureButton ); + sphere_switch->set_toggle_mode(true); + sphere_switch->set_pressed(true); + vb_shape->add_child(sphere_switch); + sphere_switch->connect("pressed",this,"_button_pressed",varray(sphere_switch)); + + box_switch = memnew( TextureButton ); + box_switch->set_toggle_mode(true); + box_switch->set_pressed(false); + vb_shape->add_child(box_switch); + box_switch->connect("pressed",this,"_button_pressed",varray(box_switch)); + + hb->add_spacer(); + + VBoxContainer *vb_light = memnew( VBoxContainer ); + hb->add_child(vb_light); + + light_1_switch = memnew( TextureButton ); + light_1_switch->set_toggle_mode(true); + vb_light->add_child(light_1_switch); + light_1_switch->connect("pressed",this,"_button_pressed",varray(light_1_switch)); + + light_2_switch = memnew( TextureButton ); + light_2_switch->set_toggle_mode(true); + vb_light->add_child(light_2_switch); + light_2_switch->connect("pressed",this,"_button_pressed",varray(light_2_switch)); + + first_enter=true; + +} + + +void MaterialEditorPlugin::edit(Object *p_object) { + + Material * s = p_object->cast_to(); + if (!s) + return; + + material_editor->edit(Ref(s)); +} + +bool MaterialEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("Material"); +} + +void MaterialEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + material_editor->show(); +// material_editor->set_process(true); + } else { + + material_editor->hide(); +// material_editor->set_process(false); + } + +} + +MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) { + + editor=p_node; + material_editor = memnew( MaterialEditor ); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,material_editor); + material_editor->hide(); + + + +} + + +MaterialEditorPlugin::~MaterialEditorPlugin() +{ +} + + diff --git a/tools/editor/plugins/material_editor_plugin.h b/tools/editor/plugins/material_editor_plugin.h new file mode 100644 index 00000000000..49e92493b34 --- /dev/null +++ b/tools/editor/plugins/material_editor_plugin.h @@ -0,0 +1,71 @@ +#ifndef MATERIAL_EDITOR_PLUGIN_H +#define MATERIAL_EDITOR_PLUGIN_H + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/resources/material.h" +#include "scene/3d/light.h" +#include "scene/3d/mesh_instance.h" +#include "scene/3d/camera.h" + + +class MaterialEditor : public Control { + + OBJ_TYPE(MaterialEditor, Control); + + + Viewport *viewport; + MeshInstance *sphere_instance; + MeshInstance *box_instance; + DirectionalLight *light1; + DirectionalLight *light2; + Camera *camera; + + Ref sphere_mesh; + Ref box_mesh; + + TextureButton *sphere_switch; + TextureButton *box_switch; + + TextureButton *light_1_switch; + TextureButton *light_2_switch; + + + Ref material; + + + void _button_pressed(Node* p_button); + bool first_enter; + +protected: + void _notification(int p_what); + void _input_event(InputEvent p_event); + static void _bind_methods(); +public: + + void edit(Ref p_material); + MaterialEditor(); +}; + + +class MaterialEditorPlugin : public EditorPlugin { + + OBJ_TYPE( MaterialEditorPlugin, EditorPlugin ); + + MaterialEditor *material_editor; + EditorNode *editor; + +public: + + virtual String get_name() const { return "Material"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + MaterialEditorPlugin(EditorNode *p_node); + ~MaterialEditorPlugin(); + +}; + +#endif // MATERIAL_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/mesh_editor_plugin.cpp b/tools/editor/plugins/mesh_editor_plugin.cpp index 8671734c253..c4f44f60821 100644 --- a/tools/editor/plugins/mesh_editor_plugin.cpp +++ b/tools/editor/plugins/mesh_editor_plugin.cpp @@ -1,300 +1,199 @@ #include "mesh_editor_plugin.h" -#include "scene/3d/physics_body.h" -#include "scene/3d/body_shape.h" -#include "scene/gui/box_container.h" -#include "scene/3d/navigation_mesh.h" -#include "spatial_editor_plugin.h" +void MeshEditor::_input_event(InputEvent p_event) { -void MeshInstanceEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; - options->hide(); + if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + + rot_x-=p_event.mouse_motion.relative_y*0.01; + rot_y-=p_event.mouse_motion.relative_x*0.01; + if (rot_x<-Math_PI/2) + rot_x=-Math_PI/2; + else if (rot_x>Math_PI/2) { + rot_x=Math_PI/2; + } + _update_rotation(); + } +} + +void MeshEditor::_notification(int p_what) { + + if (p_what==NOTIFICATION_FIXED_PROCESS) { + } + + if (p_what==NOTIFICATION_READY) { + + //get_scene()->connect("node_removed",this,"_node_removed"); + + if (first_enter) { + //it's in propertyeditor so.. could be moved around + + light_1_switch->set_normal_texture(get_icon("MaterialPreviewLight1","EditorIcons")); + light_1_switch->set_pressed_texture(get_icon("MaterialPreviewLight1Off","EditorIcons")); + light_2_switch->set_normal_texture(get_icon("MaterialPreviewLight2","EditorIcons")); + light_2_switch->set_pressed_texture(get_icon("MaterialPreviewLight2Off","EditorIcons")); + first_enter=false; + } + + } + + if (p_what==NOTIFICATION_DRAW) { + + + Ref checkerboard = get_icon("Checkerboard","EditorIcons"); + Size2 size = get_size(); + + draw_texture_rect(checkerboard,Rect2(Point2(),size),true); + + } } +void MeshEditor::_update_rotation() { - -void MeshInstanceEditor::edit(MeshInstance *p_mesh) { - - node=p_mesh; + Transform t; + t.basis.rotate(Vector3(0, 1, 0), rot_y); + t.basis.rotate(Vector3(1, 0, 0), rot_x); + mesh_instance->set_transform(t); } -void MeshInstanceEditor::_menu_option(int p_option) { +void MeshEditor::edit(Ref p_mesh) { + + mesh=p_mesh; + mesh_instance->set_mesh(mesh); - Ref mesh = node->get_mesh(); if (mesh.is_null()) { - err_dialog->set_text(TTR("Mesh is empty!")); - err_dialog->popup_centered_minsize(); + + hide(); + } else { + rot_x=0; + rot_y=0; + _update_rotation(); + } + +} + + +void MeshEditor::_button_pressed(Node* p_button) { + + if (p_button==light_1_switch) { + light1->set_enabled(!light_1_switch->is_pressed()); + } + + if (p_button==light_2_switch) { + light2->set_enabled(!light_2_switch->is_pressed()); + } + + +} + +void MeshEditor::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_input_event"),&MeshEditor::_input_event); + ObjectTypeDB::bind_method(_MD("_button_pressed"),&MeshEditor::_button_pressed); + +} + +MeshEditor::MeshEditor() { + + viewport = memnew( Viewport ); + Ref world; + world.instance(); + viewport->set_world(world); //use own world + add_child(viewport); + viewport->set_process_input(false); + + camera = memnew( Camera ); + camera->set_transform(Transform(Matrix3(),Vector3(0,0,3))); + camera->set_perspective(45,0.1,10); + viewport->add_child(camera); + + light1 = memnew( DirectionalLight ); + light1->set_transform(Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + viewport->add_child(light1); + + light2 = memnew( DirectionalLight ); + light2->set_transform(Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + light2->set_color(Light::COLOR_DIFFUSE,Color(0.7,0.7,0.7)); + light2->set_color(Light::COLOR_SPECULAR,Color(0.7,0.7,0.7)); + viewport->add_child(light2); + + mesh_instance = memnew( MeshInstance ); + viewport->add_child(mesh_instance); + + + + set_custom_minimum_size(Size2(1,150)); + + HBoxContainer *hb = memnew( HBoxContainer ); + add_child(hb); + hb->set_area_as_parent_rect(2); + + hb->add_spacer(); + + VBoxContainer *vb_light = memnew( VBoxContainer ); + hb->add_child(vb_light); + + light_1_switch = memnew( TextureButton ); + light_1_switch->set_toggle_mode(true); + vb_light->add_child(light_1_switch); + light_1_switch->connect("pressed",this,"_button_pressed",varray(light_1_switch)); + + light_2_switch = memnew( TextureButton ); + light_2_switch->set_toggle_mode(true); + vb_light->add_child(light_2_switch); + light_2_switch->connect("pressed",this,"_button_pressed",varray(light_2_switch)); + + first_enter=true; + + rot_x=0; + rot_y=0; + + +} + + +void MeshEditorPlugin::edit(Object *p_object) { + + Mesh * s = p_object->cast_to(); + if (!s) return; - } - - switch(p_option) { - case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: - case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { - - bool trimesh_shape = (p_option==MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); - - EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - - List selection = editor_selection->get_selected_node_list(); - - if (selection.empty()) { - Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); - if (shape.is_null()) - return; - - CollisionShape *cshape = memnew( CollisionShape ); - cshape->set_shape(shape); - StaticBody *body = memnew( StaticBody ); - body->add_child(cshape); - - Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); - - if (trimesh_shape) - ur->create_action(TTR("Create Static Trimesh Body")); - else - ur->create_action(TTR("Create Static Convex Body")); - - ur->add_do_method(node,"add_child",body); - ur->add_do_method(body,"set_owner",owner); - ur->add_do_method(cshape,"set_owner",owner); - ur->add_do_reference(body); - ur->add_undo_method(node,"remove_child",body); - ur->commit_action(); - return; - } - - if (trimesh_shape) - ur->create_action(TTR("Create Static Trimesh Body")); - else - ur->create_action(TTR("Create Static Convex Body")); - - for (List::Element *E=selection.front();E;E=E->next()) { - - MeshInstance *instance = E->get()->cast_to(); - if (!instance) - continue; - - Ref m = instance->get_mesh(); - if (m.is_null()) - continue; - - Ref shape = trimesh_shape ? m->create_trimesh_shape() : m->create_convex_shape(); - if (shape.is_null()) - continue; - - CollisionShape *cshape = memnew( CollisionShape ); - cshape->set_shape(shape); - StaticBody *body = memnew( StaticBody ); - body->add_child(cshape); - - Node *owner = instance==get_tree()->get_edited_scene_root() ? instance : instance->get_owner(); - - ur->add_do_method(instance,"add_child",body); - ur->add_do_method(body,"set_owner",owner); - ur->add_do_method(cshape,"set_owner",owner); - ur->add_do_reference(body); - ur->add_undo_method(instance,"remove_child",body); - } - - ur->commit_action(); - - } break; - - case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: - case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { - - if (node==get_tree()->get_edited_scene_root()) { - err_dialog->set_text(TTR("This doesn't work on scene root!")); - err_dialog->popup_centered_minsize(); - return; - } - - bool trimesh_shape = (p_option==MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); - - Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); - if (shape.is_null()) - return; - - CollisionShape *cshape = memnew( CollisionShape ); - cshape->set_shape(shape); - - Node *owner = node->get_owner(); - - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - - if (trimesh_shape) - ur->create_action(TTR("Create Trimesh Shape")); - else - ur->create_action(TTR("Create Convex Shape")); - - ur->add_do_method(node->get_parent(),"add_child",cshape); - ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); - ur->add_do_method(cshape,"set_owner",owner); - ur->add_do_reference(cshape); - ur->add_undo_method(node->get_parent(),"remove_child",cshape); - ur->commit_action(); - - } break; - - case MENU_OPTION_CREATE_NAVMESH: { - - Ref nmesh = memnew( NavigationMesh ); - - if (nmesh.is_null()) - return; - - nmesh->create_from_mesh(mesh); - NavigationMeshInstance *nmi = memnew( NavigationMeshInstance ); - nmi->set_navigation_mesh(nmesh); - - Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); - - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - ur->create_action(TTR("Create Navigation Mesh")); - - ur->add_do_method(node,"add_child",nmi); - ur->add_do_method(nmi,"set_owner",owner); - - ur->add_do_reference(nmi); - ur->add_undo_method(node,"remove_child",nmi); - ur->commit_action(); - } break; - - case MENU_OPTION_CREATE_OUTLINE_MESH: { - - outline_dialog->popup_centered(Vector2(200, 90)); - } break; - } + mesh_editor->edit(Ref(s)); } -void MeshInstanceEditor::_create_outline_mesh() { +bool MeshEditorPlugin::handles(Object *p_object) const { - Ref mesh = node->get_mesh(); - if (mesh.is_null()) { - err_dialog->set_text(TTR("MeshInstance lacks a Mesh!")); - err_dialog->popup_centered_minsize(); - return; - } - - Ref mesho = mesh->create_outline(outline_size->get_val()); - - if (mesho.is_null()) { - err_dialog->set_text(TTR("Could not create outline!")); - err_dialog->popup_centered_minsize(); - return; - } - - MeshInstance *mi = memnew( MeshInstance ); - mi->set_mesh(mesho); - Node *owner=node->get_owner(); - if (get_tree()->get_edited_scene_root()==node) { - owner=node; - } - - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - - ur->create_action(TTR("Create Outline")); - - ur->add_do_method(node,"add_child",mi); - ur->add_do_method(mi,"set_owner",owner); - - ur->add_do_reference(mi); - ur->add_undo_method(node,"remove_child",mi); - ur->commit_action(); + return p_object->is_type("Mesh"); } -void MeshInstanceEditor::_bind_methods() { - - ObjectTypeDB::bind_method("_menu_option",&MeshInstanceEditor::_menu_option); - ObjectTypeDB::bind_method("_create_outline_mesh",&MeshInstanceEditor::_create_outline_mesh); -} - -MeshInstanceEditor::MeshInstanceEditor() { - - - options = memnew( MenuButton ); - SpatialEditor::get_singleton()->add_control_to_menu_panel(options); - - options->set_text("Mesh"); - options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance","EditorIcons")); - - options->get_popup()->add_item(TTR("Create Trimesh Static Body"),MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); - options->get_popup()->add_item(TTR("Create Convex Static Body"),MENU_OPTION_CREATE_STATIC_CONVEX_BODY); - options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"),MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); - options->get_popup()->add_item(TTR("Create Convex Collision Sibling"),MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); - options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create Navigation Mesh"),MENU_OPTION_CREATE_NAVMESH); - options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create Outline Mesh.."),MENU_OPTION_CREATE_OUTLINE_MESH); - - options->get_popup()->connect("item_pressed", this,"_menu_option"); - - outline_dialog = memnew( ConfirmationDialog ); - outline_dialog->set_title(TTR("Create Outline Mesh")); - outline_dialog->get_ok()->set_text(TTR("Create")); - - VBoxContainer *outline_dialog_vbc = memnew( VBoxContainer ); - outline_dialog->add_child(outline_dialog_vbc); - outline_dialog->set_child_rect(outline_dialog_vbc); - - outline_size = memnew( SpinBox ); - outline_size->set_min(0.001); - outline_size->set_max(1024); - outline_size->set_step(0.001); - outline_size->set_val(0.05); - outline_dialog_vbc->add_margin_child(TTR("Outline Size:"),outline_size); - - add_child(outline_dialog); - outline_dialog->connect("confirmed",this,"_create_outline_mesh"); - - err_dialog = memnew( AcceptDialog ); - add_child(err_dialog); - -} - - -void MeshInstanceEditorPlugin::edit(Object *p_object) { - - mesh_editor->edit(p_object->cast_to()); -} - -bool MeshInstanceEditorPlugin::handles(Object *p_object) const { - - return p_object->is_type("MeshInstance"); -} - -void MeshInstanceEditorPlugin::make_visible(bool p_visible) { +void MeshEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - mesh_editor->options->show(); + mesh_editor->show(); +// mesh_editor->set_process(true); } else { - mesh_editor->options->hide(); - mesh_editor->edit(NULL); + mesh_editor->hide(); +// mesh_editor->set_process(false); } } -MeshInstanceEditorPlugin::MeshInstanceEditorPlugin(EditorNode *p_node) { +MeshEditorPlugin::MeshEditorPlugin(EditorNode *p_node) { editor=p_node; - mesh_editor = memnew( MeshInstanceEditor ); - editor->get_viewport()->add_child(mesh_editor); + mesh_editor = memnew( MeshEditor ); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,mesh_editor); + mesh_editor->hide(); + + - mesh_editor->options->hide(); } -MeshInstanceEditorPlugin::~MeshInstanceEditorPlugin() +MeshEditorPlugin::~MeshEditorPlugin() { } - - diff --git a/tools/editor/plugins/mesh_editor_plugin.h b/tools/editor/plugins/mesh_editor_plugin.h index 6b3e23f31fe..190dfca4643 100644 --- a/tools/editor/plugins/mesh_editor_plugin.h +++ b/tools/editor/plugins/mesh_editor_plugin.h @@ -1,68 +1,66 @@ #ifndef MESH_EDITOR_PLUGIN_H #define MESH_EDITOR_PLUGIN_H - #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" +#include "scene/resources/material.h" +#include "scene/3d/light.h" #include "scene/3d/mesh_instance.h" -#include "scene/gui/spin_box.h" +#include "scene/3d/camera.h" + +class MeshEditor : public Control { + + OBJ_TYPE(MeshEditor, Control); -class MeshInstanceEditor : public Node { - OBJ_TYPE(MeshInstanceEditor, Node ); + float rot_x; + float rot_y; + + Viewport *viewport; + MeshInstance *mesh_instance; + DirectionalLight *light1; + DirectionalLight *light2; + Camera *camera; + + Ref mesh; - enum Menu { + TextureButton *light_1_switch; + TextureButton *light_2_switch; - MENU_OPTION_CREATE_STATIC_TRIMESH_BODY, - MENU_OPTION_CREATE_STATIC_CONVEX_BODY, - MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE, - MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE, - MENU_OPTION_CREATE_NAVMESH, - MENU_OPTION_CREATE_OUTLINE_MESH, - }; - - MeshInstance *node; - - MenuButton *options; - - ConfirmationDialog *outline_dialog; - SpinBox *outline_size; - - AcceptDialog *err_dialog; - - void _menu_option(int p_option); - void _create_outline_mesh(); - -friend class MeshInstanceEditorPlugin; + void _button_pressed(Node* p_button); + bool first_enter; + void _update_rotation(); protected: - void _node_removed(Node *p_node); + void _notification(int p_what); + void _input_event(InputEvent p_event); static void _bind_methods(); public: - void edit(MeshInstance *p_mesh); - MeshInstanceEditor(); + void edit(Ref p_mesh); + MeshEditor(); }; -class MeshInstanceEditorPlugin : public EditorPlugin { - OBJ_TYPE( MeshInstanceEditorPlugin, EditorPlugin ); +class MeshEditorPlugin : public EditorPlugin { - MeshInstanceEditor *mesh_editor; + OBJ_TYPE( MeshEditorPlugin, EditorPlugin ); + + MeshEditor *mesh_editor; EditorNode *editor; public: - virtual String get_name() const { return "MeshInstance"; } + virtual String get_name() const { return "Mesh"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); - MeshInstanceEditorPlugin(EditorNode *p_node); - ~MeshInstanceEditorPlugin(); + MeshEditorPlugin(EditorNode *p_node); + ~MeshEditorPlugin(); }; diff --git a/tools/editor/plugins/mesh_instance_editor_plugin.cpp b/tools/editor/plugins/mesh_instance_editor_plugin.cpp new file mode 100644 index 00000000000..2d7e5b177f1 --- /dev/null +++ b/tools/editor/plugins/mesh_instance_editor_plugin.cpp @@ -0,0 +1,300 @@ +#include "mesh_instance_editor_plugin.h" + +#include "scene/3d/physics_body.h" +#include "scene/3d/body_shape.h" +#include "scene/gui/box_container.h" +#include "scene/3d/navigation_mesh.h" +#include "spatial_editor_plugin.h" + +void MeshInstanceEditor::_node_removed(Node *p_node) { + + if(p_node==node) { + node=NULL; + options->hide(); + } + +} + + + +void MeshInstanceEditor::edit(MeshInstance *p_mesh) { + + node=p_mesh; + +} + +void MeshInstanceEditor::_menu_option(int p_option) { + + Ref mesh = node->get_mesh(); + if (mesh.is_null()) { + err_dialog->set_text(TTR("Mesh is empty!")); + err_dialog->popup_centered_minsize(); + return; + } + + switch(p_option) { + case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: + case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { + + bool trimesh_shape = (p_option==MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + + EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + List selection = editor_selection->get_selected_node_list(); + + if (selection.empty()) { + Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); + if (shape.is_null()) + return; + + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + StaticBody *body = memnew( StaticBody ); + body->add_child(cshape); + + Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); + + if (trimesh_shape) + ur->create_action(TTR("Create Static Trimesh Body")); + else + ur->create_action(TTR("Create Static Convex Body")); + + ur->add_do_method(node,"add_child",body); + ur->add_do_method(body,"set_owner",owner); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(body); + ur->add_undo_method(node,"remove_child",body); + ur->commit_action(); + return; + } + + if (trimesh_shape) + ur->create_action(TTR("Create Static Trimesh Body")); + else + ur->create_action(TTR("Create Static Convex Body")); + + for (List::Element *E=selection.front();E;E=E->next()) { + + MeshInstance *instance = E->get()->cast_to(); + if (!instance) + continue; + + Ref m = instance->get_mesh(); + if (m.is_null()) + continue; + + Ref shape = trimesh_shape ? m->create_trimesh_shape() : m->create_convex_shape(); + if (shape.is_null()) + continue; + + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + StaticBody *body = memnew( StaticBody ); + body->add_child(cshape); + + Node *owner = instance==get_tree()->get_edited_scene_root() ? instance : instance->get_owner(); + + ur->add_do_method(instance,"add_child",body); + ur->add_do_method(body,"set_owner",owner); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(body); + ur->add_undo_method(instance,"remove_child",body); + } + + ur->commit_action(); + + } break; + + case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: + case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { + + if (node==get_tree()->get_edited_scene_root()) { + err_dialog->set_text(TTR("This doesn't work on scene root!")); + err_dialog->popup_centered_minsize(); + return; + } + + bool trimesh_shape = (p_option==MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); + + Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); + if (shape.is_null()) + return; + + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + + Node *owner = node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + if (trimesh_shape) + ur->create_action(TTR("Create Trimesh Shape")); + else + ur->create_action(TTR("Create Convex Shape")); + + ur->add_do_method(node->get_parent(),"add_child",cshape); + ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(cshape); + ur->add_undo_method(node->get_parent(),"remove_child",cshape); + ur->commit_action(); + + } break; + + case MENU_OPTION_CREATE_NAVMESH: { + + Ref nmesh = memnew( NavigationMesh ); + + if (nmesh.is_null()) + return; + + nmesh->create_from_mesh(mesh); + NavigationMeshInstance *nmi = memnew( NavigationMeshInstance ); + nmi->set_navigation_mesh(nmesh); + + Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action(TTR("Create Navigation Mesh")); + + ur->add_do_method(node,"add_child",nmi); + ur->add_do_method(nmi,"set_owner",owner); + + ur->add_do_reference(nmi); + ur->add_undo_method(node,"remove_child",nmi); + ur->commit_action(); + } break; + + case MENU_OPTION_CREATE_OUTLINE_MESH: { + + outline_dialog->popup_centered(Vector2(200, 90)); + } break; + } + +} + +void MeshInstanceEditor::_create_outline_mesh() { + + Ref mesh = node->get_mesh(); + if (mesh.is_null()) { + err_dialog->set_text(TTR("MeshInstance lacks a Mesh!")); + err_dialog->popup_centered_minsize(); + return; + } + + Ref mesho = mesh->create_outline(outline_size->get_val()); + + if (mesho.is_null()) { + err_dialog->set_text(TTR("Could not create outline!")); + err_dialog->popup_centered_minsize(); + return; + } + + MeshInstance *mi = memnew( MeshInstance ); + mi->set_mesh(mesho); + Node *owner=node->get_owner(); + if (get_tree()->get_edited_scene_root()==node) { + owner=node; + } + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + ur->create_action(TTR("Create Outline")); + + ur->add_do_method(node,"add_child",mi); + ur->add_do_method(mi,"set_owner",owner); + + ur->add_do_reference(mi); + ur->add_undo_method(node,"remove_child",mi); + ur->commit_action(); +} + +void MeshInstanceEditor::_bind_methods() { + + ObjectTypeDB::bind_method("_menu_option",&MeshInstanceEditor::_menu_option); + ObjectTypeDB::bind_method("_create_outline_mesh",&MeshInstanceEditor::_create_outline_mesh); +} + +MeshInstanceEditor::MeshInstanceEditor() { + + + options = memnew( MenuButton ); + SpatialEditor::get_singleton()->add_control_to_menu_panel(options); + + options->set_text("Mesh"); + options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance","EditorIcons")); + + options->get_popup()->add_item(TTR("Create Trimesh Static Body"),MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + options->get_popup()->add_item(TTR("Create Convex Static Body"),MENU_OPTION_CREATE_STATIC_CONVEX_BODY); + options->get_popup()->add_separator(); + options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"),MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); + options->get_popup()->add_item(TTR("Create Convex Collision Sibling"),MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); + options->get_popup()->add_separator(); + options->get_popup()->add_item(TTR("Create Navigation Mesh"),MENU_OPTION_CREATE_NAVMESH); + options->get_popup()->add_separator(); + options->get_popup()->add_item(TTR("Create Outline Mesh.."),MENU_OPTION_CREATE_OUTLINE_MESH); + + options->get_popup()->connect("item_pressed", this,"_menu_option"); + + outline_dialog = memnew( ConfirmationDialog ); + outline_dialog->set_title(TTR("Create Outline Mesh")); + outline_dialog->get_ok()->set_text(TTR("Create")); + + VBoxContainer *outline_dialog_vbc = memnew( VBoxContainer ); + outline_dialog->add_child(outline_dialog_vbc); + outline_dialog->set_child_rect(outline_dialog_vbc); + + outline_size = memnew( SpinBox ); + outline_size->set_min(0.001); + outline_size->set_max(1024); + outline_size->set_step(0.001); + outline_size->set_val(0.05); + outline_dialog_vbc->add_margin_child(TTR("Outline Size:"),outline_size); + + add_child(outline_dialog); + outline_dialog->connect("confirmed",this,"_create_outline_mesh"); + + err_dialog = memnew( AcceptDialog ); + add_child(err_dialog); + +} + + +void MeshInstanceEditorPlugin::edit(Object *p_object) { + + mesh_editor->edit(p_object->cast_to()); +} + +bool MeshInstanceEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("MeshInstance"); +} + +void MeshInstanceEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + mesh_editor->options->show(); + } else { + + mesh_editor->options->hide(); + mesh_editor->edit(NULL); + } + +} + +MeshInstanceEditorPlugin::MeshInstanceEditorPlugin(EditorNode *p_node) { + + editor=p_node; + mesh_editor = memnew( MeshInstanceEditor ); + editor->get_viewport()->add_child(mesh_editor); + + mesh_editor->options->hide(); +} + + +MeshInstanceEditorPlugin::~MeshInstanceEditorPlugin() +{ +} + + diff --git a/tools/editor/plugins/mesh_instance_editor_plugin.h b/tools/editor/plugins/mesh_instance_editor_plugin.h new file mode 100644 index 00000000000..a698cf382fd --- /dev/null +++ b/tools/editor/plugins/mesh_instance_editor_plugin.h @@ -0,0 +1,69 @@ +#ifndef MESH_INSTANCE_EDITOR_PLUGIN_H +#define MESH_INSTANCE_EDITOR_PLUGIN_H + + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/3d/mesh_instance.h" +#include "scene/gui/spin_box.h" + + +class MeshInstanceEditor : public Node { + + OBJ_TYPE(MeshInstanceEditor, Node ); + + + enum Menu { + + MENU_OPTION_CREATE_STATIC_TRIMESH_BODY, + MENU_OPTION_CREATE_STATIC_CONVEX_BODY, + MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE, + MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE, + MENU_OPTION_CREATE_NAVMESH, + MENU_OPTION_CREATE_OUTLINE_MESH, + }; + + MeshInstance *node; + + MenuButton *options; + + ConfirmationDialog *outline_dialog; + SpinBox *outline_size; + + AcceptDialog *err_dialog; + + void _menu_option(int p_option); + void _create_outline_mesh(); + +friend class MeshInstanceEditorPlugin; + +protected: + void _node_removed(Node *p_node); + static void _bind_methods(); +public: + + void edit(MeshInstance *p_mesh); + MeshInstanceEditor(); +}; + +class MeshInstanceEditorPlugin : public EditorPlugin { + + OBJ_TYPE( MeshInstanceEditorPlugin, EditorPlugin ); + + MeshInstanceEditor *mesh_editor; + EditorNode *editor; + +public: + + virtual String get_name() const { return "MeshInstance"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + MeshInstanceEditorPlugin(EditorNode *p_node); + ~MeshInstanceEditorPlugin(); + +}; + +#endif // MESH_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/sample_editor_plugin.cpp b/tools/editor/plugins/sample_editor_plugin.cpp index 3a54273d142..f9217e47fa4 100644 --- a/tools/editor/plugins/sample_editor_plugin.cpp +++ b/tools/editor/plugins/sample_editor_plugin.cpp @@ -328,7 +328,7 @@ void SampleEditor::_update_sample() { return; //bye or unsupported generate_preview_texture(sample,peakdisplay); - info_label->set_text(TTR("Length:")+" "+vformat(TTR("%d frames"), sample->get_length())+" ("+String::num(sample->get_length()/(float)sample->get_mix_rate(),2)+" s), "+(sample->get_format()==Sample::FORMAT_PCM16?TTR("16 Bits"):TTR("8 Bits"))+", "+(sample->is_stereo()?TTR("Stereo"):TTR("Mono"))+"."); + info_label->set_text(TTR("Length:")+" "+String::num(sample->get_length()/(float)sample->get_mix_rate(),2)+"s"); library->add_sample("default",sample); } @@ -404,6 +404,8 @@ SampleEditor::SampleEditor() { play->connect("pressed", this,"_play_pressed"); stop->connect("pressed", this,"_stop_pressed"); + set_custom_minimum_size(Size2(1,150)); + } @@ -438,10 +440,7 @@ SampleEditorPlugin::SampleEditorPlugin(EditorNode *p_node) { editor=p_node; sample_editor = memnew( SampleEditor ); - editor->get_viewport()->add_child(sample_editor); - sample_editor->set_area_as_parent_rect(); - sample_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); - sample_editor->set_margin( MARGIN_TOP, 120 ); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,sample_editor); sample_editor->hide(); diff --git a/tools/editor/plugins/texture_editor_plugin.cpp b/tools/editor/plugins/texture_editor_plugin.cpp new file mode 100644 index 00000000000..1305e911052 --- /dev/null +++ b/tools/editor/plugins/texture_editor_plugin.cpp @@ -0,0 +1,141 @@ +#include "texture_editor_plugin.h" + +#include "io/resource_loader.h" +#include "globals.h" +#include "tools/editor/editor_settings.h" + +void TextureEditor::_input_event(InputEvent p_event) { + + +} + +void TextureEditor::_notification(int p_what) { + + if (p_what==NOTIFICATION_FIXED_PROCESS) { + + } + + + if (p_what==NOTIFICATION_READY) { + + //get_scene()->connect("node_removed",this,"_node_removed"); + + } + + if (p_what==NOTIFICATION_DRAW) { + + + Ref checkerboard = get_icon("Checkerboard","EditorIcons"); + Size2 size = get_size(); + + draw_texture_rect(checkerboard,Rect2(Point2(),size),true); + + int tex_width = texture->get_width() * size.height / texture ->get_height(); + int tex_height = size.height; + + if (tex_width>size.width) { + tex_width=size.width; + tex_height=texture->get_height() * tex_width / texture->get_width(); + } + + int ofs_x = (size.width - tex_width)/2; + int ofs_y = (size.height - tex_height)/2; + + draw_texture_rect(texture,Rect2(ofs_x,ofs_y,tex_width,tex_height)); + + Ref font = get_font("font","Label"); + + String format; + if (texture->cast_to()) { + format = Image::get_format_name(texture->cast_to()->get_format()); + } else { + format=texture->get_type(); + } + String text = itos(texture->get_width())+"x"+itos(texture->get_height())+" "+format; + + Size2 rect = font->get_string_size(text); + + Vector2 draw_from = size-rect+Size2(-2,font->get_ascent()-2); + if (draw_from.x<0) + draw_from.x=0; + + draw_string(font,draw_from+Vector2(2,2),text,Color(0,0,0,0.5),size.width); + draw_string(font,draw_from-Vector2(2,2),text,Color(0,0,0,0.5),size.width); + draw_string(font,draw_from,text,Color(1,1,1,1),size.width); + } +} + + + +void TextureEditor::edit(Ref p_texture) { + + texture=p_texture; + + if (!texture.is_null()) + update(); + else { + + hide(); + } + +} + + + +void TextureEditor::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_input_event"),&TextureEditor::_input_event); + +} + +TextureEditor::TextureEditor() { + + set_custom_minimum_size(Size2(1,150)); + +} + + +void TextureEditorPlugin::edit(Object *p_object) { + + Texture * s = p_object->cast_to(); + if (!s) + return; + + texture_editor->edit(Ref(s)); +} + +bool TextureEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("Texture"); +} + +void TextureEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + texture_editor->show(); +// texture_editor->set_process(true); + } else { + + texture_editor->hide(); +// texture_editor->set_process(false); + } + +} + +TextureEditorPlugin::TextureEditorPlugin(EditorNode *p_node) { + + editor=p_node; + texture_editor = memnew( TextureEditor ); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,texture_editor); + texture_editor->hide(); + + + +} + + +TextureEditorPlugin::~TextureEditorPlugin() +{ +} + + diff --git a/tools/editor/plugins/texture_editor_plugin.h b/tools/editor/plugins/texture_editor_plugin.h new file mode 100644 index 00000000000..5f58f4fcdbc --- /dev/null +++ b/tools/editor/plugins/texture_editor_plugin.h @@ -0,0 +1,49 @@ +#ifndef TEXTURE_EDITOR_PLUGIN_H +#define TEXTURE_EDITOR_PLUGIN_H + + + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/resources/texture.h" + + +class TextureEditor : public Control { + + OBJ_TYPE(TextureEditor, Control); + + + Ref texture; + +protected: + void _notification(int p_what); + void _input_event(InputEvent p_event); + static void _bind_methods(); +public: + + void edit(Ref p_texture); + TextureEditor(); +}; + + +class TextureEditorPlugin : public EditorPlugin { + + OBJ_TYPE( TextureEditorPlugin, EditorPlugin ); + + TextureEditor *texture_editor; + EditorNode *editor; + +public: + + virtual String get_name() const { return "Texture"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + TextureEditorPlugin(EditorNode *p_node); + ~TextureEditorPlugin(); + +}; + +#endif // TEXTURE_EDITOR_PLUGIN_H diff --git a/tools/editor/script_editor_debugger.cpp b/tools/editor/script_editor_debugger.cpp index 479b694f0b9..7c7801a2032 100644 --- a/tools/editor/script_editor_debugger.cpp +++ b/tools/editor/script_editor_debugger.cpp @@ -944,6 +944,7 @@ void ScriptEditorDebugger::_notification(int p_what) { } last_error_count=error_count; } + if (connection.is_null()) { if (server->is_connection_available()) {