SceneAPI.cpp 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../AngelScript/APITemplates.h"
  24. #include "../Graphics/DebugRenderer.h"
  25. #include "../IO/PackageFile.h"
  26. #include "../Scene/ObjectAnimation.h"
  27. #include "../Scene/Scene.h"
  28. #include "../Scene/SmoothedTransform.h"
  29. #include "../Scene/SplinePath.h"
  30. #include "../Scene/ValueAnimation.h"
  31. namespace Urho3D
  32. {
  33. static void RegisterNode(asIScriptEngine* engine)
  34. {
  35. engine->RegisterGlobalFunction("Node@+ get_node()", asFUNCTION(GetScriptContextNode), asCALL_CDECL);
  36. }
  37. static CScriptArray* GetObjectCategories()
  38. {
  39. Vector<String> categories = GetScriptContext()->GetObjectCategories().Keys();
  40. Sort(categories.Begin(), categories.End());
  41. return VectorToArray<String>(categories, "Array<String>");
  42. }
  43. static CScriptArray* GetObjectsByCategory(const String& category)
  44. {
  45. const HashMap<String, Vector<StringHash> >& categories = GetScriptContext()->GetObjectCategories();
  46. Vector<String> components;
  47. HashMap<String, Vector<StringHash> >::ConstIterator i = categories.Find(category);
  48. if (i != categories.End())
  49. {
  50. const HashMap<StringHash, SharedPtr<ObjectFactory> >& factories = GetScriptContext()->GetObjectFactories();
  51. const Vector<StringHash>& factoryHashes = i->second_;
  52. components.Reserve(factoryHashes.Size());
  53. for (unsigned j = 0; j < factoryHashes.Size(); ++j)
  54. {
  55. HashMap<StringHash, SharedPtr<ObjectFactory> >::ConstIterator k = factories.Find(factoryHashes[j]);
  56. if (k != factories.End())
  57. components.Push(k->second_->GetTypeName());
  58. }
  59. }
  60. Sort(components.Begin(), components.End());
  61. return VectorToArray<String>(components, "Array<String>");
  62. }
  63. static CScriptArray* GetObjectAttributeInfos(const String& objectType)
  64. {
  65. const Vector<AttributeInfo>* attributes = GetScriptContext()->GetAttributes(Urho3D::StringHash(objectType));
  66. static Vector<AttributeInfo> emptyAttributes;
  67. return VectorToArray<AttributeInfo>(attributes ? *attributes : emptyAttributes, "Array<AttributeInfo>");
  68. }
  69. static void RegisterScene(asIScriptEngine* engine)
  70. {
  71. engine->RegisterGlobalFunction("Scene@+ get_scene()", asFUNCTION(GetScriptContextScene), asCALL_CDECL);
  72. engine->RegisterGlobalFunction("Array<String>@ GetObjectCategories()", asFUNCTION(GetObjectCategories), asCALL_CDECL);
  73. engine->RegisterGlobalFunction("Array<String>@ GetObjectsByCategory(const String&in)", asFUNCTION(GetObjectsByCategory), asCALL_CDECL);
  74. engine->RegisterGlobalFunction("Array<AttributeInfo>@ GetObjectAttributeInfos(const String&in)", asFUNCTION(GetObjectAttributeInfos), asCALL_CDECL);
  75. }
  76. void RegisterSceneAPI(asIScriptEngine* engine)
  77. {
  78. RegisterNode(engine);
  79. RegisterScene(engine);
  80. }
  81. }