EditorScene.as 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Urho3D editor scene handling
  2. Scene@ editorScene;
  3. string sceneResourcePath;
  4. void createScene()
  5. {
  6. // Create a scene with default values, these will be overridden when loading scenes
  7. @editorScene = engine.createScene("GraphicsTest", BoundingBox(-1000.0, 1000.0), 8, true);
  8. }
  9. void setResourcePath(string newPath)
  10. {
  11. if (newPath == sceneResourcePath)
  12. return;
  13. cache.releaseAllResources(false);
  14. // Remove the old scene resource path if any. However make sure that CoreData path never gets removed
  15. if ((!sceneResourcePath.empty()) && (sceneResourcePath.find("CoreData") < 0))
  16. cache.removeResourcePath(sceneResourcePath);
  17. cache.addResourcePath(newPath);
  18. sceneResourcePath = newPath;
  19. }
  20. void loadScene(string fileName)
  21. {
  22. // Always load the scene from the filesystem, not from resource paths
  23. if (!fileExists(fileName))
  24. {
  25. logError("No such scene " + fileName);
  26. return;
  27. }
  28. // Clear the old scene
  29. editorScene.removeAllEntities();
  30. // Add the new resource path
  31. setResourcePath(getPath(fileName));
  32. File file(fileName, FILE_READ);
  33. if (getExtension(fileName) == ".xml")
  34. editorScene.loadXML(file);
  35. else
  36. editorScene.load(file);
  37. }