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 a9522cf248..a6ffc30a83 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 ad85ecc7c0..6b5f1ba353 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 d8a4be5e6d..69dfc556b4 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 c572ab210e..b93b6624d0 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!ia0y~yU~m9o4kiW$23787oeT^NoCO|{#S9GGLLkg|>2BR0 z1_lQ95>H=O_6Mxu{7S}W8Vu_h7#L(TLn2C?^K)}k^GX;%z_}SAt8f#hH0V<3=FcFArU3c`MJ5Nc_j=W;9QiNSdyBeP@Y+mq2TW6 z8<3)x%Fe*RnB(c<7-Dhy?UapP%#H$W|8K^=KNqug4tt|^Fk9;l7LiX3VlRE32G4M7 zQRbhZ)Y`hlGxfc7O9OwxsV(iTGP4^L3l;l%S$3+-n^_3h!oZWnoyMqv0DY$->BJp)=Jh{BPa=D^cDq zF0Zd>F16rsULK<-&scGa>ATj{Q-!Ii4pyteVo8LySDd*k+dOnM^8uv#~vK&JhX z#Xh-Sx9@=>d)I1A3G(`tRcW8!67-^MxB2Ivf5Z+jF{GQPno01;ZMnu?>7&>p!PnkD x*H4}8!=&#XpQP6@B-qFW-|P3a&rSXIK=zSk@yTp1j$@z*@pScbS?83{1OVWx!MXqd literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_cube_off.png b/tools/editor/icons/icon_material_preview_cube_off.png new file mode 100644 index 0000000000000000000000000000000000000000..38d16ba99304a3d59c4cd06ca5bc56017c6708fe GIT binary patch literal 493 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SAt8$iuimLMFfhnwhD4M&=jZ08=9MsjfOAo5Vo7R>LV0FMhJw4N zZ$OG(Dmw!MW3s11~@5B7NJcK&fK?W1&_dS zLsidB<@09-uD>3*`s$813a`Fai8AOhtY32HWQtOm=8~sHp7Wl2GR!@ga3SApwrny_ zM@QMp$w8YQTNGKyd}Fj($>g>@YVBqP4yOCx^*`DC|0Fdn)iL{Q!$q qeieQVR))-3K{t;qd;cpUXAjf+yP4Gw4k&bj;=$9^&t;ucLK6UbHpf%| 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 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SK_d;R`6)XX7#L(TLn2C?^K)}k^GX;%z_}y-G6;BcAa`=8&L{p8(}n^%|IyRdM}_6=+~r>cinLO zbm3sZqwX!mm%>)GZnAyv*~%r|yyvXDe9EQvJsPzF8zUx^IY)6yxT!||X9>SHq2>1M zH_J@lp52+w?`xVo`?sB}#q;04W$X6y$3JioVmNBR!_UxEzNlwodygJH%6sev z1H-Kne<``8fy_n>JJ+sV>l--bU5?rAwVAi_tE;Q0dM#DrJL|-;eJ3YFcxdRO&p)r^ znB89bx@tq%>a|Zk|J=iJp!m&=jhp-B?f<>}@$vE8;^Jb<{^QB7cD-94qGh#o%jrUy z|EH(x|Br}_)D&>4P!U@B{@uG%`Scb6RL+NLF@IQqr=mTfa&ruPHAo`m`)_ zR-V$t8KELeGdh^~2A7wW^{ftG&v)+p`Tb!cs-HeQJiOj{;e~dFfc4i~U+?-* zwU>p#=klM=mzH{$XKjr#lk4Ape}8@b!S~;ncOOk^WoTHn%4O0Lv2#C<&sr866BoDd z<*s$!91AC@ER4`mnt%TBlarGdOmX6P803{1AAi4OW5k@PDw$J@<8sgZb-0-E#Y00x z>THV9?PZxor#HDQ4HC@G&Q8k7@i~%YxN+xBO|PYsHt2ZISa#BQ=9w}L5vg9c#qP7r z-55{ojM0_wN1hv*w4nudnaX76G>8H#*5{;_E&= zIoTs{Xm9!ZdqMvG{<{Spz4ezl-uQaggE`I|AN!M>IKF)OvW1_YKVC*!`n7sXz^xij z&7} zQNOuXtmiB_6nB)qzSey8>Q(mLyLW5%Jc_N~g@&CQN|gPn!NkGZLlSO5O4ee>qc zfo-{ox3{ebTfHGy`f1TlsqUk7FJ8YE){oosJ`W;+kh?X6iHiU^uY+^{)W6$(kxcoss+R|Iaj#;3+9BZIwvA=%8R= zWM^k*Y-eXD%)#O&k$mypyLXEjY*ww>_IlU9tG&|ZLUsH1TMKnoT;#YRylY+kG7Yc! z%QD?VLTzPcosp1^h=_=Yj);iJR@rvv$U+$omZpOV8+Z?}w|B;#fBrd|!K*FtLy1*v ue$(w-okcU>J^Qlm_O`uiGo>uQ{9(OvUpH`7`J_Bh>E!9^=d#Wzp$PzpCt{EQ 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 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SK_lY{zt)B@FfhnwhD4M&=jZ08=9MsjfOAo5Vo7R>LV0FMhJw4N zZ$OG(Dmw!M%W_W_#}JFtwIT2QgTp22&ROnVd*@bMx38o~+gl@Zk?@VO%}0EWrQNwR z{T=iDlJ5E@MbnSWlBex5O#VrCtIZO4E|$(STY~2%e+F}N<4T2fcaplFemlN5_r2}+ zH_fiQXavJ;b6|p^*;irn@90e9bi2wA4-P)|TKcJ{)k)FaZvOY3ci(+@d3kyNlg~fb zZr!@o=y{EXSohKMbFIIB>=af%bi7ZN``g#AvMaB@UikHEY5v+UV|I4-`_ht6tF0;*~vmnFY?3oPE`i*0;+S9N2q^tRk)!)?kQmtL0C zm6d%ve)HzdbcO>ym+u((2A5jR{Tj5gL_w^(^!Y1}=8x7gc?bHzA`t|71qdWip{x)Zv!SLq4>9)%+ReCnoe+|4|>Zs|eH1Ws2 zpp`0;$)BGV{nTubVs;R54dgle;`RIY@6SIinz?f2O7V>mZ%REUshqR)xhyg*wXxVw z=d{zxkX3Q}YJRpS7-Y<`um87M-GAN|iMEMrufLY!ZgpC>cJ11G6*m8Vo;Y!$eWp)Z zX=>`ze}~)ojc?|NH98!4{Ix2!MIa|9MGIl+PM&UQZI!Oe r?)&@f%Qmm2m%1Gk9C!{3Fnkd2bBHnN{`T-Ks4Vkz^>bP0l+XkKaNT(% 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 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SL1P9p!@tZ73=FcFArU3c`MJ5Nc_j=W;9QiNSdyBeP@Y+mq2TW6 z8<3)x%Fe*Rvf0zcF~s6@Ysh`?=x~|;bBcwE%O8K;HuK(uiwnYMEDZI`-rnIMYr@~x zx9-crEqU526q<7Q7xTYcDyDOnpW{v9Z|1I}?fbU4cr9HN@My^z)e9TgW_2DrcWy$9 zN!;X^$#?Elf4gwx*QU3>f7#AI|8w5wzcqFTZYMFY?7yGS?(kvV3XLx2)vH&}2H`~- zd<+ZPe=X?~d?mAiaYLnzT)zUx-A?K<_e$Y!e7QVE9Y=;+(WySuxKkN3&Gj){u$y7l(koK>s*d@qN1Wlm3&IQRVg z{Qt83$1k@CTz>xfYDw(&x9{K2-&Ohf*_StO-k6uazxOw{y!^ZVidC-!SQgrgaJ3fi zoMUQfX{p?m6rY{_`p1zYM`}!@?w)-9*=GLv&lx7Wj13J9@87y*rPq~o|H+dlK6=wP zJ1q=|5NN3j4V7hK2o!PEo9gv%b@+O|wQJVw5n?%5{{P?K^|5;4-KmiVzLS|5l6wq} zO*sAZn_k?WAK5!&{8*X~ezPur=Q77HU1##i3>JozNVT4gX_rmxLqwh)y1d*!UFY;B z4n>p6Clm7X`KP5iPD`!W8yBJ_+8yM@+;|{IZ8E3vv1`7Ub+Tq1<2So?`Es$!RIk{G z=;+@&*RJ(_Hs|uuqpmH76EkM9d1=n^Q*Uc;FMN4Pwcy;^9JAHDe0+7UKUN&lkK1!2 zH>ZbbgX(0@asvsQ$7Q?wgS<2uLbODC`udU*6B&z(i#OcNiHL}3P~cE#3D|zS)#dl8V8xfYnzWI2fPHvqQe^;a%$<-`bjep;UHz-rc6_uUVhV^cXTY=!kjG zvo3#U&2XFH0MFqYhCIqwuUrYaYVx-E^YioHP1Ww*x^?Kw7ZVOe2?+^@oiWFb9b?p*p3#Egz`|9pKAfJee|cem#+wo=`@)?uLE+)oe=pMb<}t~{ z$jr>l-ptHQ-}6$3Mwji~yLa6gZ=^=%g@=A!{rdX)_Bnp(+s{AGcCt;_yJ}UP7Kf8V z;1uOeI_7p~)w&)zs0c;&yC}Ub?Yzm?y4H7+%JkDuKQUCSpLk&l9L%S)J!uA&Yo4xtF6*2UngCf&ZOQ-u 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 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SL1Xc)k1CEZFfhnwhD4M&=jZ08=9MsjfOAo5Vo7R>LV0FMhJw4N zZ$OG(Dmw!M%Slfc#}JFtr6IoA(%~Yu@6YzA_S+v@)gp4cNZ8UMMA7j?n5=Zr(NaT+ zT^-$uu`E$e<&mt)n+y)!o#JrdiG0b-ww9EOCQA?c3NLR=(8yDrb1Rf*;%k0i5zo0j z%9$p{@6VP9-WFYIyPEs^yx%*X&ns`-F2GQcym1Cg!vpz%$Z77+pFMkb{_NSi(^D%& z7;;Zdw(Tol&+fvIR9;@b{jtTx7`^XS50sQ&%a)^ zYM)xmhk5hlW*e$Wwh7LkHS5=(KR-WD?w7ZZTYohx+DS!7@buG7>-X;6TVGW4DP?KU z%AA~>5XeWpO9LIxJUU5lJUw*wbw%}h`lB0kF$H8~+ z@{;T7{<)v~`T6nje)eh8rftg2&Al1EKJFz8gNUnQlfstbbL=UR|9+gBs+}%-oKdmm z&AWGt;?^H7jXkl6Xa9Zv+uLHjG}F@4_piPF`aXBlhI5wdU+sFw#gH&dt?6LG>O=|o zGw06Lz4}<;a=p}3ZSuipcK!(`Q#Ned))u43etMGtUwh~4T@o@fHk)?r*s)UM)aRs) zH*VaQU{#oQ`l<89jFJ=2KW`24;$$#5Ho-@2qSw-bkB?jfyf*IH!{a&0fkV-5{(4iX zUcRZPpE_6fEnK8?dO5>^(!2XQJ3C**@px&vxw##XXikm%P_=i#l%`@nCytowtconc z!onA)PMtbK=k$Aqh8bQ<_puz1x2xG9+3E7`_&v)~;AHxN6W8=@R_4V}$ z_Af2?bWR`o`ucj}EVXlUt=aeAuUFt?*i-RwQO(<1Th}w@Fg7IIE<3m_ck9xnM^}Zd zb{FbA^6>9O@1;U{cXlv3aj>zmCEPaaI;!NgROrw{1DWFo*G6xj=DqaN-m1O-cIV!X zR$^dp5awWsTeo(tZuYEcFJ8U+v}>JrNNB6h=>i${+qZAuxOtOtsmLT1#fcs}W-T)f z3lFdV{QK|GsI_Uy|2O@azfsjwX_3ai=rD`E$5GQ-PfyqXAF%qWQIo=&kkwc18D}st zEYj#ol5nf3sHoTxqV-lsPcKZU^GKrSB$soRIk(x8dHNnV7_#|ZKC?P}y-SPHcyZ(mb!FMM+s%uQtDY`Lds@)v2zw_V03a|9NjjxLD0axJpY( zN-8)N142Xh7eDuV_U!EJ@2jr9T9hbZBG*6Pruf;J>YF*=_C)6M zUtV5z7ZVfP$K8JT^^%_lUhVp~YxCyKKM!>*H0gpJt aKen?r@dutfio6dh?L1xmT-G@yGywo$OM3?Z 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 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SAz>~@wZ3Nz3=FcFArU3c`MJ5Nc_j=W;9QiNSdyBeP@Y+mq2TW6 z8<3)x%Fe*RJkis|F~s8Z)KK4ym{bwl@3Uu~*)px?OoQ(%wG8oP5$@ugP8~-Cf`nsO zR!xW%D_wYytM@GblGzQcYrDD~76p6WHC^fGtql~=388&X~?&iK>%wU?JsV8xm>6}iR5#T7L*HCexYefhd_W%lLg z=j(qy-kGt5|3LS}j4L)>Ch|*dZEeLbzvQ(#x9hb(;K#)S6lpyfQvRH+uHg zty||Z%sX-a&BA#YzQ zqku*2uHTDig=cBq(Y?;w?)*Nc`)Hol!b!zy4IPXQJ4(JjIk|27sne(LZ$7gP+~!S?e5=XwazNw&%?L@DrKRI_H8mw!9M-2rz2j{? z?8p!h+Tr2ma!u{z+gl689Foi?YUyd}?fv~amid6`ZDao?OYK>fl2_PMDn3Yc#4x+& z7^VHLty^!9d`^Iip?=xrm({Ddv>Y`;IF~ksOlWx);>4&LGIjR%?c2Dxx%c)xUeo5J z$jVUsz=3no^F{UN)zb2{r*gIa^PZ`-KxKiXYe+-Dj&-lq-ks6gvSrI2n?GMaJiU?P z!+3$=K}=HK>odR8_Zb+t#j376vEr--i|8pIWmZQfx&Gt7AKu)2f2G#?e+8wBwr?+Y zPvB^92oJx`dV5>u`ZWcr(cij!Z*R-I?Ws1|Q%^_d&UT&d(9qENem*`C6FrusR%V|3 zy`s3LAS2_&@;7N)b7!ASDcY@b`cbd6d3|<9#tUg#S>HKUU+<+ee6!J0@!Gw6_x?>f z-5)Fd%u9`&Gkf;$?39$0ZTt59`+V)%HSUkmAMd|@^~#FzO|8cFPvXZ9AE57_A`q-Iu1PLfU&XrE`f<+c6;`MlG@YnJQ^&;aFHPgg&ebxsLQ E00H~aiU0rr literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_material_preview_sphere_off.png b/tools/editor/icons/icon_material_preview_sphere_off.png new file mode 100644 index 0000000000000000000000000000000000000000..babe2ddca535ebeaa3aa8c0f2fcafd8e6e4f5f3b GIT binary patch literal 1006 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR&H|6fVg?3oArNM~bhqvg z0|NtliKnkC`vX>SAz{%oddeT!G(Ww&0_n*Jr)Dv(kM?24TT4|w(kT1*LLKVG6Z6k#f zJ8phx+RxyB!W2+%VU%c3H^K$W5<{(Z66&3{#AqAtEI?5AIgr7crI-cpr zYKt48O5d&>IB=jKJ3D)^A(Nq-i-OXlH+oJ%F?!Rt#O(U=u6w#ZleYHi%?xk$G-xWV z&B)K+fAPwdko4QzzJ33GzjDit9Sd1h=XWqD?G%`OYTmrnYwPy!H{K^VUAg7q2j9&b zKAd)cSnxxbp=4*wvG?DrrKF{@Pn|w}ioxNN;+e>23EmnaS#RFG+sB_^@2|0B#=Cd@ z>jS1TxP)H3bV+Ej+Cvx9)0n`g%1l;BbgYUy_~ErA@}c%OKxtifxL>q zgcdDE)fYMwS{_`LVG!y(GXLz^v+u88zs}8II4gR^nr~J9Pck@{I)yrFZ1Lz(iE!a& z=&VRO|NQgM#TPUBHUzk;bU4Miztag*;Cer?>-fdvFOAA)YSyGWF+Nb3>nA@+WvYV7 zbR*6n?h;E|R*w~0Mv>9l+S(KSmY3`8tDVS@z|nT{)(s$ao0UPxgx+_=lw#%V|V86`fcs0 zqpN$iucv22z>SF>E$r;=_I|a-UyVIAMb89JY?*uZmWrW?Ny+~8>)-F)xN)O(_QnXK z_d7H<{r`F9%$euh+}t0-pNqM>cqY}?|9|>+;%)mc-@ffLHaEAP@1yp9EX+&&1vC*d-v{r{`9G+Ty65k@bK{Rset_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 f07dbabeb3..02d691239f 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 0000000000..4ef2815a32 --- /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 0000000000..49e92493b3 --- /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 8671734c25..c4f44f6082 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 6b3e23f31f..190dfca464 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 0000000000..2d7e5b177f --- /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 0000000000..a698cf382f --- /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 3a54273d14..f9217e47fa 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 0000000000..1305e91105 --- /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 0000000000..5f58f4fcdb --- /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 479b694f0b..7c7801a203 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()) {