SceneView3D.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. // Portions Copyright (c) 2008-2015 the Urho3D project.
  2. //
  3. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  4. // LICENSE: Atomic Game Engine Editor and Tools EULA
  5. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  6. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  7. //
  8. #include <Atomic/IO/Log.h>
  9. #include <Atomic/Core/CoreEvents.h>
  10. #include <Atomic/Scene/SceneEvents.h>
  11. #include <Atomic/Scene/Scene.h>
  12. #include <Atomic/Scene/PrefabComponent.h>
  13. #include <Atomic/Graphics/Camera.h>
  14. #include <Atomic/Graphics/Graphics.h>
  15. #include <Atomic/Graphics/DebugRenderer.h>
  16. #include <Atomic/Graphics/Viewport.h>
  17. #include <Atomic/Graphics/Octree.h>
  18. #include <Atomic/Graphics/Material.h>
  19. #include <Atomic/Atomic3D/Terrain.h>
  20. #include <Atomic/Atomic3D/Model.h>
  21. #include <Atomic/Atomic3D/StaticModel.h>
  22. #include <Atomic/Atomic3D/AnimatedModel.h>
  23. #include <Atomic/Atomic3D/AnimationController.h>
  24. #include <Atomic/Input/Input.h>
  25. #include <Atomic/IO/FileSystem.h>
  26. #include <Atomic/Resource/ResourceCache.h>
  27. #include <Atomic/Resource/XMLFile.h>
  28. #include <Atomic/Physics/PhysicsWorld.h>
  29. #include <Atomic/UI/UI.h>
  30. #include <Atomic/UI/UIEvents.h>
  31. #include <Atomic/Resource/ResourceEvents.h>
  32. #include <ToolCore/Assets/Asset.h>
  33. #include <ToolCore/Assets/AssetDatabase.h>
  34. #include "../../EditorMode/AEEditorEvents.h"
  35. #include "SceneView3D.h"
  36. #include "SceneEditor3D.h"
  37. #include "SceneEditor3DEvents.h"
  38. using namespace ToolCore;
  39. namespace AtomicEditor
  40. {
  41. SceneView3D ::SceneView3D(Context* context, SceneEditor3D *sceneEditor) :
  42. UISceneView(context),
  43. yaw_(0.0f),
  44. pitch_(0.0f),
  45. mouseLeftDown_(false),
  46. mouseMoved_(false),
  47. enabled_(true),
  48. cameraMove_(false)
  49. {
  50. sceneEditor_ = sceneEditor;
  51. ResourceCache* cache = GetSubsystem<ResourceCache>();
  52. scene_ = sceneEditor->GetScene();
  53. debugRenderer_ = scene_->GetComponent<DebugRenderer>();
  54. if (debugRenderer_.Null())
  55. {
  56. debugRenderer_ = scene_->CreateComponent<DebugRenderer>();
  57. }
  58. octree_ = scene_->GetComponent<Octree>();
  59. if (octree_.Null())
  60. {
  61. LOGWARNING("Scene without an octree loaded");
  62. octree_ = scene_->CreateComponent<Octree>();
  63. }
  64. cameraNode_ = scene_->CreateChild("__atomic_sceneview3d_camera");
  65. cameraNode_->SetTemporary(true);
  66. camera_ = cameraNode_->CreateComponent<Camera>();
  67. debugRenderer_ = scene_->GetComponent<DebugRenderer>();
  68. assert(debugRenderer_.NotNull());
  69. octree_ = scene_->GetComponent<Octree>();
  70. assert(octree_.NotNull());
  71. cameraNode_->SetPosition(Vector3(0, 0, -10));
  72. SetView(scene_, camera_);
  73. SetAutoUpdate(false);
  74. SubscribeToEvent(E_UPDATE, HANDLER(SceneView3D, HandleUpdate));
  75. SubscribeToEvent(E_EDITORACTIVENODECHANGE, HANDLER(SceneView3D, HandleEditorActiveNodeChange));
  76. SubscribeToEvent(E_POSTRENDERUPDATE, HANDLER(SceneView3D, HandlePostRenderUpdate));
  77. SubscribeToEvent(scene_, E_NODEREMOVED, HANDLER(SceneView3D, HandleNodeRemoved));
  78. SubscribeToEvent(E_MOUSEMOVE, HANDLER(SceneView3D,HandleMouseMove));
  79. SubscribeToEvent(this, E_DRAGENTERWIDGET, HANDLER(SceneView3D, HandleDragEnterWidget));
  80. SubscribeToEvent(this, E_DRAGEXITWIDGET, HANDLER(SceneView3D, HandleDragExitWidget));
  81. SubscribeToEvent(this, E_DRAGENDED, HANDLER(SceneView3D, HandleDragEnded));
  82. SubscribeToEvent(E_UIUNHANDLEDSHORTCUT, HANDLER(SceneView3D, HandleUIUnhandledShortcut));
  83. SubscribeToEvent(E_UIWIDGETFOCUSESCAPED, HANDLER(SceneView3D, HandleUIWidgetFocusEscaped));
  84. SetIsFocusable(true);
  85. }
  86. SceneView3D::~SceneView3D()
  87. {
  88. }
  89. void SceneView3D::Enable()
  90. {
  91. if (enabled_)
  92. return;
  93. enabled_ = true;
  94. SetVisibility(UI_WIDGET_VISIBILITY_VISIBLE);
  95. }
  96. void SceneView3D::Disable()
  97. {
  98. if (!enabled_)
  99. return;
  100. enabled_ = false;
  101. SetVisibility(UI_WIDGET_VISIBILITY_INVISIBLE);
  102. }
  103. bool SceneView3D::GetOrbitting()
  104. {
  105. Input* input = GetSubsystem<Input>();
  106. return framedNode_.NotNull() && MouseInView() && input->GetKeyDown(KEY_ALT) && input->GetMouseButtonDown(MOUSEB_LEFT);
  107. }
  108. bool SceneView3D::GetZooming()
  109. {
  110. Input* input = GetSubsystem<Input>();
  111. return MouseInView() && input->GetKeyDown(KEY_ALT) && input->GetMouseMoveWheel();
  112. }
  113. void SceneView3D::MoveCamera(float timeStep)
  114. {
  115. if (!enabled_ && !GetFocus())
  116. return;
  117. Input* input = GetSubsystem<Input>();
  118. bool shiftDown = false;
  119. if (input->GetKeyDown(KEY_LSHIFT) || input->GetKeyDown(KEY_RSHIFT))
  120. shiftDown = true;
  121. bool mouseInView = MouseInView();
  122. bool orbitting = GetOrbitting();
  123. bool zooming = GetZooming();
  124. // Movement speed as world units per second
  125. float MOVE_SPEED = 20.0f;
  126. // Mouse sensitivity as degrees per pixel
  127. const float MOUSE_SENSITIVITY = 0.2f;
  128. if (shiftDown)
  129. MOVE_SPEED *= 3.0f;
  130. // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
  131. if ((mouseInView && input->GetMouseButtonDown(MOUSEB_RIGHT)) || orbitting)
  132. {
  133. SetFocus();
  134. IntVector2 mouseMove = input->GetMouseMove();
  135. yaw_ += MOUSE_SENSITIVITY * mouseMove.x_;
  136. pitch_ += MOUSE_SENSITIVITY * mouseMove.y_;
  137. pitch_ = Clamp(pitch_, -90.0f, 90.0f);
  138. }
  139. // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
  140. Quaternion q(pitch_, yaw_, 0.0f);
  141. if (!zooming)
  142. cameraNode_->SetRotation(q);
  143. if (orbitting)
  144. {
  145. BoundingBox bbox;
  146. sceneEditor_->GetSelectionBoundingBox(bbox);
  147. if (bbox.defined_)
  148. {
  149. Vector3 centerPoint = bbox.Center();
  150. Vector3 d = cameraNode_->GetWorldPosition() - centerPoint;
  151. cameraNode_->SetWorldPosition(centerPoint - q * Vector3(0.0, 0.0, d.Length()));
  152. }
  153. }
  154. if (zooming)
  155. {
  156. Ray ray = GetCameraRay();
  157. Vector3 wpos = cameraNode_->GetWorldPosition();
  158. wpos += ray.direction_ * (float (input->GetMouseMoveWheel()) * (shiftDown ? 0.6f : 0.2f));
  159. cameraNode_->SetWorldPosition(wpos);
  160. }
  161. #ifdef ATOMIC_PLATFORM_WINDOWS
  162. bool superdown = input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL);
  163. #else
  164. bool superdown = input->GetKeyDown(KEY_LGUI) || input->GetKeyDown(KEY_RGUI);
  165. #endif
  166. if (!orbitting && mouseInView && !superdown && input->GetMouseButtonDown(MOUSEB_RIGHT)) {
  167. // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
  168. // Use the Translate() function (default local space) to move relative to the node's orientation.
  169. if (input->GetKeyDown(KEY_W))
  170. {
  171. SetFocus();
  172. cameraNode_->Translate(Vector3::FORWARD * MOVE_SPEED * timeStep);
  173. }
  174. if (input->GetKeyDown(KEY_S))
  175. {
  176. SetFocus();
  177. cameraNode_->Translate(Vector3::BACK * MOVE_SPEED * timeStep);
  178. }
  179. if (input->GetKeyDown(KEY_A))
  180. { SetFocus();
  181. cameraNode_->Translate(Vector3::LEFT * MOVE_SPEED * timeStep);
  182. }
  183. if (input->GetKeyDown(KEY_D))
  184. {
  185. SetFocus();
  186. cameraNode_->Translate(Vector3::RIGHT * MOVE_SPEED * timeStep);
  187. }
  188. if (input->GetKeyDown(KEY_Q))
  189. {
  190. SetFocus();
  191. cameraNode_->Translate(Vector3::UP * MOVE_SPEED * timeStep);
  192. }
  193. if (input->GetKeyDown(KEY_E))
  194. {
  195. SetFocus();
  196. cameraNode_->Translate(Vector3::DOWN * MOVE_SPEED * timeStep);
  197. }
  198. }
  199. else if (!superdown)
  200. {
  201. if (input->GetKeyPress(KEY_F))
  202. {
  203. FrameSelection();
  204. }
  205. }
  206. if (cameraMove_)
  207. {
  208. cameraMoveTime_ += timeStep * 3.0f;
  209. if (cameraMoveTime_ > 1.0f)
  210. {
  211. cameraMove_ = false;
  212. cameraMoveTime_ = 1.0f;
  213. }
  214. Vector3 pos = cameraMoveStart_.Lerp(cameraMoveTarget_, cameraMoveTime_);
  215. cameraNode_->SetWorldPosition(pos);
  216. }
  217. }
  218. Ray SceneView3D::GetCameraRay()
  219. {
  220. Ray camRay;
  221. Input* input = GetSubsystem<Input>();
  222. IntVector2 cpos = input->GetMousePosition();
  223. IntRect rect = GetRect();
  224. if (!rect.Width() || !rect.Height())
  225. return camRay;
  226. int x = rect.left_;
  227. int y = rect.top_;
  228. GetInternalWidget()->ConvertToRoot(x, y);
  229. return camera_->GetScreenRay(float(cpos.x_ - x) / rect.Width(),
  230. float(cpos.y_ - y) / rect.Height());
  231. }
  232. void SceneView3D::DrawNodeDebug(Node* node, DebugRenderer* debug, bool drawNode)
  233. {
  234. if (drawNode)
  235. debug->AddNode(node, 1.0, false);
  236. // Exception for the scene to avoid bringing the editor to its knees: drawing either the whole hierarchy or the subsystem-
  237. // components can have a large performance hit. Also do not draw terrain child nodes due to their large amount
  238. // (TerrainPatch component itself draws nothing as debug geometry)
  239. if (node != scene_ && !node->GetComponent<Terrain>())
  240. {
  241. const Vector<SharedPtr<Component> >& components = node->GetComponents();
  242. for (unsigned j = 0; j < components.Size(); ++j)
  243. components[j]->DrawDebugGeometry(debug, false);
  244. // To avoid cluttering the view, do not draw the node axes for child nodes
  245. for (unsigned k = 0; k < node->GetNumChildren(); ++k)
  246. DrawNodeDebug(node->GetChild(k), debug, false);
  247. }
  248. }
  249. bool SceneView3D::MouseInView()
  250. {
  251. if (!GetInternalWidget())
  252. return false;
  253. if (!TBWidget::hovered_widget || TBWidget::hovered_widget->GetDelegate() != this)
  254. return false;
  255. Input* input = GetSubsystem<Input>();
  256. IntVector2 pos = input->GetMousePosition();
  257. IntRect rect = GetRect();
  258. GetInternalWidget()->ConvertToRoot(rect.left_, rect.top_);
  259. GetInternalWidget()->ConvertToRoot(rect.right_, rect.bottom_);
  260. return rect.IsInside(pos);
  261. }
  262. void SceneView3D::HandleUIUnhandledShortcut(StringHash eventType, VariantMap& eventData)
  263. {
  264. if (!enabled_)
  265. return;
  266. unsigned id = eventData[UIUnhandledShortcut::P_REFID].GetUInt();
  267. if (id == TBIDC("undo"))
  268. sceneEditor_->Undo();
  269. else if (id == TBIDC("redo"))
  270. sceneEditor_->Redo();
  271. return;
  272. }
  273. void SceneView3D::HandleUIWidgetFocusEscaped(StringHash eventType, VariantMap& eventData)
  274. {
  275. if (!enabled_)
  276. return;
  277. SetFocus();
  278. }
  279. void SceneView3D::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
  280. {
  281. // Visualize the currently selected nodes
  282. if (selectedNode_.NotNull())
  283. {
  284. DrawNodeDebug(selectedNode_, debugRenderer_);
  285. }
  286. if (!MouseInView() || GetOrbitting())
  287. return;
  288. Input* input = GetSubsystem<Input>();
  289. mouseLeftDown_ = false;
  290. if (input->GetMouseButtonPress(MOUSEB_LEFT))
  291. {
  292. SetFocus();
  293. if (!mouseMoved_ && !sceneEditor_->GetGizmo()->Selected())
  294. {
  295. Ray camRay = GetCameraRay();
  296. PODVector<RayQueryResult> result;
  297. RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_GEOMETRY, 0x7fffffff);
  298. octree_->RaycastSingle(query);
  299. if (query.result_.Size())
  300. {
  301. const RayQueryResult& r = result[0];
  302. if (r.drawable_)
  303. {
  304. VariantMap neventData;
  305. Node* node = r.drawable_->GetNode();
  306. // if temporary, this is a prefab
  307. // TODO: if we use temporary for other stuff
  308. // fix this to look for prefab
  309. if (node->IsTemporary())
  310. node = node->GetParent();
  311. neventData[EditorActiveNodeChange::P_NODE] = node;
  312. SendEvent(E_EDITORACTIVENODECHANGE, neventData);
  313. }
  314. }
  315. }
  316. mouseMoved_ = false;
  317. }
  318. else if (!input->GetMouseButtonDown(MOUSEB_LEFT))
  319. {
  320. Ray camRay = GetCameraRay();
  321. PODVector<RayQueryResult> result;
  322. mouseMoved_ = false;
  323. /*
  324. Array<int> pickModeDrawableFlags = {
  325. DRAWABLE_GEOMETRY,
  326. DRAWABLE_LIGHT,
  327. DRAWABLE_ZONE
  328. };
  329. */
  330. RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_GEOMETRY, 0x7fffffff);
  331. octree_->RaycastSingle(query);
  332. if (query.result_.Size())
  333. {
  334. const RayQueryResult& r = result[0];
  335. if (r.drawable_)
  336. {
  337. debugRenderer_->AddNode(r.drawable_->GetNode(), 1.0, false);
  338. r.drawable_->DrawDebugGeometry(debugRenderer_, false);
  339. }
  340. }
  341. }
  342. else
  343. {
  344. mouseLeftDown_ = true;
  345. if (Abs(input->GetMouseMoveX() > 3 || input->GetMouseMoveY() > 3))
  346. {
  347. mouseMoved_ = true;
  348. }
  349. }
  350. }
  351. void SceneView3D::SelectNode(Node* node)
  352. {
  353. selectedNode_ = node;
  354. }
  355. bool SceneView3D::OnEvent(const TBWidgetEvent &ev)
  356. {
  357. if (ev.type == EVENT_TYPE_SHORTCUT)
  358. {
  359. if (ev.ref_id == TBIDC("close"))
  360. return false;
  361. }
  362. return sceneEditor_->OnEvent(ev);
  363. }
  364. void SceneView3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
  365. {
  366. // Timestep parameter is same no matter what event is being listened to
  367. float timeStep = eventData[Update::P_TIMESTEP].GetFloat();
  368. MoveCamera(timeStep);
  369. QueueUpdate();
  370. if (preloadResourceScene_.NotNull())
  371. {
  372. if (preloadResourceScene_->GetAsyncProgress() == 1.0f)
  373. {
  374. ResourceCache* cache = GetSubsystem<ResourceCache>();
  375. XMLFile* xml = cache->GetResource<XMLFile>(dragAssetGUID_);
  376. if (dragNode_.NotNull())
  377. {
  378. dragNode_->LoadXML(xml->GetRoot());
  379. UpdateDragNode(0, 0);
  380. AnimationController* controller = dragNode_->GetComponent<AnimationController>();
  381. if (controller)
  382. {
  383. controller->PlayExclusive("Idle", 0, true);
  384. dragNode_->GetScene()->SetUpdateEnabled(true);
  385. }
  386. }
  387. preloadResourceScene_ = 0;
  388. dragAssetGUID_ = "";
  389. }
  390. }
  391. }
  392. void SceneView3D::HandleEditorActiveNodeChange(StringHash eventType, VariantMap& eventData)
  393. {
  394. Node* node = (Node*) (eventData[EditorActiveNodeChange::P_NODE].GetPtr());
  395. SelectNode(node);
  396. }
  397. void SceneView3D::HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
  398. {
  399. Node* node = (Node*) (eventData[NodeRemoved::P_NODE].GetPtr());
  400. if (node == selectedNode_)
  401. SelectNode(0);
  402. }
  403. void SceneView3D::UpdateDragNode(int mouseX, int mouseY)
  404. {
  405. if (dragNode_.Null())
  406. return;
  407. Ray ray = GetCameraRay();
  408. Vector3 pos = ray.origin_;
  409. pos += ray.direction_ * 10;
  410. dragNode_->SetWorldPosition(pos);
  411. }
  412. void SceneView3D::HandleMouseMove(StringHash eventType, VariantMap& eventData)
  413. {
  414. if (dragNode_.Null())
  415. return;
  416. Input* input = GetSubsystem<Input>();
  417. if (!input->IsMouseVisible())
  418. return;
  419. using namespace MouseMove;
  420. int x = eventData[P_X].GetInt();
  421. int y = eventData[P_Y].GetInt();
  422. UpdateDragNode(x, y);
  423. }
  424. void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventData)
  425. {
  426. using namespace DragEnterWidget;
  427. UIWidget* widget = static_cast<UIWidget*>(eventData[P_WIDGET].GetPtr());
  428. if (widget != this)
  429. return;
  430. UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr());
  431. Object* object = dragObject->GetObject();
  432. if (!object)
  433. return;
  434. if (object->GetType() == Asset::GetTypeStatic())
  435. {
  436. Asset* asset = (Asset*) object;
  437. dragNode_ = asset->InstantiateNode(scene_, asset->GetName());
  438. if (dragNode_.NotNull())
  439. {
  440. Input* input = GetSubsystem<Input>();
  441. IntVector2 pos = input->GetMousePosition();
  442. UpdateDragNode(pos.x_, pos.y_);
  443. }
  444. //LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
  445. }
  446. }
  447. void SceneView3D::HandleDragExitWidget(StringHash eventType, VariantMap& eventData)
  448. {
  449. if (preloadResourceScene_.NotNull())
  450. {
  451. preloadResourceScene_->StopAsyncLoading();
  452. preloadResourceScene_ = 0;
  453. }
  454. if (dragNode_.NotNull())
  455. {
  456. scene_->RemoveChild(dragNode_);
  457. }
  458. dragAssetGUID_ = "";
  459. dragNode_ = 0;
  460. }
  461. void SceneView3D::HandleDragEnded(StringHash eventType, VariantMap& eventData)
  462. {
  463. using namespace DragEnded;
  464. UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr());
  465. if (dragNode_.NotNull())
  466. {
  467. VariantMap neventData;
  468. neventData[EditorActiveNodeChange::P_NODE] = dragNode_;
  469. SendEvent(E_EDITORACTIVENODECHANGE, neventData);
  470. VariantMap editData;
  471. editData[SceneEditNodeAddedRemoved::P_SCENE] = scene_;
  472. editData[SceneEditNodeAddedRemoved::P_NODE] = dragNode_;
  473. editData[SceneEditNodeAddedRemoved::P_ADDED] = true;
  474. scene_->SendEvent(E_SCENEEDITNODEADDEDREMOVED, editData);
  475. }
  476. if (dragObject && dragObject->GetObject()->GetType() == ToolCore::Asset::GetTypeStatic())
  477. {
  478. Asset* asset = (ToolCore::Asset*) dragObject->GetObject();
  479. if (asset->GetImporterTypeName() == "MaterialImporter") {
  480. Material* material = GetSubsystem<ResourceCache>()->GetResource<Material>(asset->GetPath());
  481. if (material) {
  482. material = material;
  483. Ray camRay = GetCameraRay();
  484. PODVector<RayQueryResult> result;
  485. RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_GEOMETRY, 0x7fffffff);
  486. octree_->RaycastSingle(query);
  487. if (query.result_.Size())
  488. {
  489. const RayQueryResult& r = result[0];
  490. if (r.drawable_ && (r.drawable_->GetType() == StaticModel::GetTypeStatic() || r.drawable_->GetType() == AnimatedModel::GetTypeStatic()))
  491. {
  492. ((StaticModel*)r.drawable_)->SetMaterial(material);
  493. }
  494. }
  495. }
  496. }
  497. }
  498. dragAssetGUID_ = "";
  499. dragNode_ = 0;
  500. }
  501. void SceneView3D::FrameSelection()
  502. {
  503. BoundingBox bbox;
  504. sceneEditor_->GetSelectionBoundingBox(bbox);
  505. if (!bbox.defined_)
  506. return;
  507. Sphere sphere(bbox);
  508. if (sphere.radius_ < .01f || sphere.radius_ > 512)
  509. return;
  510. framedNode_ = selectedNode_;
  511. cameraMoveStart_ = cameraNode_->GetWorldPosition();
  512. cameraMoveTarget_ = bbox.Center() - (cameraNode_->GetWorldDirection() * sphere.radius_ * 3);
  513. cameraMoveTime_ = 0.0f;
  514. cameraMove_ = true;
  515. }
  516. }