BsScriptLight.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsScriptLight.h"
  4. #include "BsScriptSceneObject.h"
  5. #include "BsSceneObject.h"
  6. #include "BsSceneManager.h"
  7. namespace BansheeEngine
  8. {
  9. ScriptLight::ScriptLight(MonoObject* managedInstance, const HSceneObject& parentSO)
  10. :ScriptObject(managedInstance), mLight(nullptr), mLastUpdateHash(0)
  11. {
  12. mLight = Light::create();
  13. gSceneManager()._registerLight(mLight, parentSO);
  14. }
  15. ScriptLight::~ScriptLight()
  16. { }
  17. void ScriptLight::initRuntimeData()
  18. {
  19. metaData.scriptClass->addInternalCall("Internal_Create", &ScriptLight::internal_create);
  20. metaData.scriptClass->addInternalCall("Internal_GetType", &ScriptLight::internal_getType);
  21. metaData.scriptClass->addInternalCall("Internal_SetType", &ScriptLight::internal_setType);
  22. metaData.scriptClass->addInternalCall("Internal_GetCastsShadow", &ScriptLight::internal_getCastsShadow);
  23. metaData.scriptClass->addInternalCall("Internal_SetCastsShadow", &ScriptLight::internal_setCastsShadow);
  24. metaData.scriptClass->addInternalCall("Internal_GetPhysicallyBasedAttenuation",
  25. &ScriptLight::internal_getPhysicallyBasedAttenuation);
  26. metaData.scriptClass->addInternalCall("Internal_SetPhysicallyBasedAttenuation",
  27. &ScriptLight::internal_setPhysicallyBasedAttenuation);
  28. metaData.scriptClass->addInternalCall("Internal_GetColor", &ScriptLight::internal_getColor);
  29. metaData.scriptClass->addInternalCall("Internal_SetColor", &ScriptLight::internal_setColor);
  30. metaData.scriptClass->addInternalCall("Internal_GetRange", &ScriptLight::internal_getRange);
  31. metaData.scriptClass->addInternalCall("Internal_SetRange", &ScriptLight::internal_setRange);
  32. metaData.scriptClass->addInternalCall("Internal_GetIntensity", &ScriptLight::internal_getIntensity);
  33. metaData.scriptClass->addInternalCall("Internal_SetIntensity", &ScriptLight::internal_setIntensity);
  34. metaData.scriptClass->addInternalCall("Internal_GetSpotAngle", &ScriptLight::internal_getSpotAngle);
  35. metaData.scriptClass->addInternalCall("Internal_SetSpotAngle", &ScriptLight::internal_setSpotAngle);
  36. metaData.scriptClass->addInternalCall("Internal_GetSpotFalloffAngle", &ScriptLight::internal_getSpotFalloffAngle);
  37. metaData.scriptClass->addInternalCall("Internal_SetSpotFalloffAngle", &ScriptLight::internal_setSpotFalloffAngle);
  38. metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptLight::internal_getBounds);
  39. metaData.scriptClass->addInternalCall("Internal_UpdateTransform", &ScriptLight::internal_updateTransform);
  40. metaData.scriptClass->addInternalCall("Internal_OnDestroy", &ScriptLight::internal_onDestroy);
  41. }
  42. void ScriptLight::internal_create(MonoObject* managedInstance, ScriptSceneObject* parentSO)
  43. {
  44. HSceneObject so;
  45. if (parentSO != nullptr)
  46. so = parentSO->getNativeHandle();
  47. new (bs_alloc<ScriptLight>()) ScriptLight(managedInstance, so);
  48. }
  49. LightType ScriptLight::internal_getType(ScriptLight* thisPtr)
  50. {
  51. return thisPtr->getInternal()->getType();
  52. }
  53. void ScriptLight::internal_setType(ScriptLight* thisPtr, LightType type)
  54. {
  55. thisPtr->getInternal()->setType(type);
  56. }
  57. bool ScriptLight::internal_getCastsShadow(ScriptLight* thisPtr)
  58. {
  59. return thisPtr->getInternal()->getCastsShadow();
  60. }
  61. void ScriptLight::internal_setCastsShadow(ScriptLight* thisPtr, bool castsShadow)
  62. {
  63. thisPtr->getInternal()->setCastsShadow(castsShadow);
  64. }
  65. bool ScriptLight::internal_getPhysicallyBasedAttenuation(ScriptLight* thisPtr)
  66. {
  67. return thisPtr->getInternal()->getPhysicallyBasedAttenuation();
  68. }
  69. void ScriptLight::internal_setPhysicallyBasedAttenuation(ScriptLight* thisPtr, bool value)
  70. {
  71. thisPtr->getInternal()->setPhysicallyBasedAttenuation(value);
  72. }
  73. void ScriptLight::internal_getColor(ScriptLight* thisPtr, Color* color)
  74. {
  75. *color = thisPtr->getInternal()->getColor();
  76. }
  77. void ScriptLight::internal_setColor(ScriptLight* thisPtr, Color color)
  78. {
  79. thisPtr->getInternal()->setColor(color);
  80. }
  81. float ScriptLight::internal_getRange(ScriptLight* thisPtr)
  82. {
  83. return thisPtr->getInternal()->getRange();
  84. }
  85. void ScriptLight::internal_setRange(ScriptLight* thisPtr, float range)
  86. {
  87. thisPtr->getInternal()->setRange(range);
  88. }
  89. float ScriptLight::internal_getIntensity(ScriptLight* thisPtr)
  90. {
  91. return thisPtr->getInternal()->getIntensity();
  92. }
  93. void ScriptLight::internal_setIntensity(ScriptLight* thisPtr, float intensity)
  94. {
  95. thisPtr->getInternal()->setIntensity(intensity);
  96. }
  97. float ScriptLight::internal_getSpotAngle(ScriptLight* thisPtr)
  98. {
  99. return thisPtr->getInternal()->getSpotAngle().valueDegrees();
  100. }
  101. void ScriptLight::internal_setSpotAngle(ScriptLight* thisPtr, float spotAngle)
  102. {
  103. thisPtr->getInternal()->setSpotAngle(Degree(spotAngle));
  104. }
  105. float ScriptLight::internal_getSpotFalloffAngle(ScriptLight* thisPtr)
  106. {
  107. return thisPtr->getInternal()->getSpotFalloffAngle().valueDegrees();
  108. }
  109. void ScriptLight::internal_setSpotFalloffAngle(ScriptLight* thisPtr, float spotFalloffAngle)
  110. {
  111. thisPtr->getInternal()->setSpotFalloffAngle(Degree(spotFalloffAngle));
  112. }
  113. void ScriptLight::internal_getBounds(ScriptLight* thisPtr, Sphere* bounds)
  114. {
  115. *bounds = thisPtr->getInternal()->getBounds();
  116. }
  117. void ScriptLight::internal_updateTransform(ScriptLight* thisPtr, ScriptSceneObject* parent)
  118. {
  119. HSceneObject parentSO = parent->getNativeSceneObject();
  120. if (!parentSO.isDestroyed())
  121. {
  122. thisPtr->getInternal()->_updateTransform(parentSO);
  123. if (parentSO->getActive() != thisPtr->getInternal()->getIsActive())
  124. {
  125. thisPtr->getInternal()->setIsActive(parentSO->getActive());
  126. }
  127. }
  128. }
  129. void ScriptLight::internal_onDestroy(ScriptLight* instance)
  130. {
  131. instance->destroy();
  132. }
  133. void ScriptLight::destroy()
  134. {
  135. if (mLight->isDestroyed())
  136. return;
  137. gSceneManager()._unregisterLight(mLight);
  138. mLight->destroy();
  139. }
  140. void ScriptLight::_onManagedInstanceDeleted()
  141. {
  142. destroy();
  143. ScriptObject::_onManagedInstanceDeleted();
  144. }
  145. }