2
0

notesObject.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include "T3D/notesObject.h"
  2. #include "math/mathIO.h"
  3. #include "scene/sceneRenderState.h"
  4. #include "core/stream/bitStream.h"
  5. #include "materials/sceneData.h"
  6. #include "gfx/gfxDebugEvent.h"
  7. #include "gfx/gfxTransformSaver.h"
  8. #include "renderInstance/renderPassManager.h"
  9. #include "math/mathUtils.h"
  10. #include "gfx/gfxDrawUtil.h"
  11. IMPLEMENT_CO_NETOBJECT_V1(NotesObject);
  12. extern bool gEditingMission;
  13. //-----------------------------------------------------------------------------
  14. // Object setup and teardown
  15. //-----------------------------------------------------------------------------
  16. NotesObject::NotesObject()
  17. {
  18. // Flag this object so that it will always
  19. // be sent across the network to clients
  20. mNetFlags.set(Ghostable | ScopeAlways);
  21. // Set it as a "static" object
  22. mTypeMask |= StaticObjectType | StaticShapeObjectType;
  23. mShowArrow = true;
  24. mArrowLength = 5;
  25. mArrowRadius = 0.25;
  26. }
  27. NotesObject::~NotesObject()
  28. {
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Object Editing
  32. //-----------------------------------------------------------------------------
  33. void NotesObject::initPersistFields()
  34. {
  35. docsURL;
  36. Parent::initPersistFields();
  37. addField("Note", TypeCommand, Offset(mNote, NotesObject), "");
  38. addField("showArrow", TypeBool, Offset(mShowArrow, NotesObject), "");
  39. addField("arrowColor", TypeColorF, Offset(mArrowColor, NotesObject), "");
  40. }
  41. void NotesObject::inspectPostApply()
  42. {
  43. // Apply any transformations set in the editor
  44. Parent::inspectPostApply();
  45. if (isServerObject())
  46. {
  47. setMaskBits(-1);
  48. }
  49. }
  50. bool NotesObject::onAdd()
  51. {
  52. if (!Parent::onAdd())
  53. return false;
  54. // Set up a 1x1x1 bounding box
  55. mObjBox.set(Point3F(-0.5f, -0.5f, -0.5f),
  56. Point3F(0.5f, 0.5f, 0.5f));
  57. resetWorldBox();
  58. // Add this object to the scene
  59. addToScene();
  60. return true;
  61. }
  62. void NotesObject::onRemove()
  63. {
  64. // Remove this object from the scene
  65. removeFromScene();
  66. Parent::onRemove();
  67. }
  68. void NotesObject::setTransform(const MatrixF& mat)
  69. {
  70. // Let SceneObject handle all of the matrix manipulation
  71. Parent::setTransform(mat);
  72. // Dirty our network mask so that the new transform gets
  73. // transmitted to the client object
  74. setMaskBits(TransformMask);
  75. }
  76. U32 NotesObject::packUpdate(NetConnection* conn, U32 mask, BitStream* stream)
  77. {
  78. // Allow the Parent to get a crack at writing its info
  79. U32 retMask = Parent::packUpdate(conn, mask, stream);
  80. // Write our transform information
  81. //if (stream->writeFlag(mask & TransformMask))
  82. {
  83. mathWrite(*stream, getTransform());
  84. mathWrite(*stream, getScale());
  85. stream->write(mShowArrow);
  86. stream->write(mArrowColor);
  87. }
  88. return retMask;
  89. }
  90. void NotesObject::unpackUpdate(NetConnection* conn, BitStream* stream)
  91. {
  92. // Let the Parent read any info it sent
  93. Parent::unpackUpdate(conn, stream);
  94. //if (stream->readFlag()) // TransformMask
  95. {
  96. mathRead(*stream, &mObjToWorld);
  97. mathRead(*stream, &mObjScale);
  98. setTransform(mObjToWorld);
  99. stream->read(&mShowArrow);
  100. stream->read(&mArrowColor);
  101. }
  102. }
  103. void NotesObject::prepRenderImage(SceneRenderState* state)
  104. {
  105. if (!gEditingMission)
  106. return;
  107. ObjectRenderInst* ri = state->getRenderPass()->allocInst<ObjectRenderInst>();
  108. ri->renderDelegate.bind(this, &NotesObject::_render);
  109. ri->type = RenderPassManager::RIT_Editor;
  110. state->getRenderPass()->addInst(ri);
  111. }
  112. void NotesObject::_render(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat)
  113. {
  114. if (showArrow())
  115. {
  116. GFXStateBlockDesc desc;
  117. desc.setBlend(true);
  118. desc.setZReadWrite(true, false);
  119. VectorF forwardVec = getTransform().getForwardVector();
  120. forwardVec.normalize();
  121. Point3F startPos = forwardVec * -(mArrowLength * 0.5) + getPosition();
  122. Point3F endPos = forwardVec * (mArrowLength * 0.5) + getPosition();
  123. ColorI arrowColor = mArrowColor.toColorI();
  124. arrowColor.alpha = 128;
  125. GFX->getDrawUtil()->drawArrow(desc, startPos, endPos, arrowColor, mArrowRadius);
  126. }
  127. }