Torque3D Documentation / _generateds / afxBillboard.cpp

afxBillboard.cpp

Engine/source/afx/ce/afxBillboard.cpp

More...

Public Defines

define
myOffset(field) (field, )

Public Functions

ConsoleDocClass(afxBillboard , "@brief A Billboard effect as defined by an <a href="/coding/class/classafxbillboarddata/">afxBillboardData</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "A Billboard effect is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> textured quadrangle which is always aligned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "face towards the camera. It is much like <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single static particle and is rendered " "in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> similar <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">fashion.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
ConsoleDocClass(afxBillboardData , "@brief A datablock that specifies <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Billboard <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "A Billboard effect is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> textured quadrangle which is always aligned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> face towards the camera. It is much like <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single " "static particle and is rendered in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> similar fashion." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
ImplementEnumType(afxBillboard_BlendStyle , "Possible blending <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxBillboard\n\n</a>" )

Detailed Description

Public Defines

myOffset(field) (field, )

Public Variables

EnumTable dstBlendFactorTable 
 EndImplementEnumType 
EnumTable srcBlendFactorTable 

Public Functions

ConsoleDocClass(afxBillboard , "@brief A Billboard effect as defined by an <a href="/coding/class/classafxbillboarddata/">afxBillboardData</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "A Billboard effect is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> textured quadrangle which is always aligned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "face towards the camera. It is much like <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single static particle and is rendered " "in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> similar <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">fashion.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )

ConsoleDocClass(afxBillboardData , "@brief A datablock that specifies <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Billboard <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "A Billboard effect is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> textured quadrangle which is always aligned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> face towards the camera. It is much like <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single " "static particle and is rendered in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> similar fashion." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(afxBillboardData )

IMPLEMENT_CO_NETOBJECT_V1(afxBillboard )

ImplementEnumType(afxBillboard_BlendStyle , "Possible blending <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxBillboard\n\n</a>" )

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include "afx/arcaneFX.h"
 28
 29#include "gfx/gfxAPI.h"
 30#include "math/mathIO.h"
 31
 32#include "afx/afxChoreographer.h"
 33#include "afx/ce/afxBillboard.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36// afxBillboardData
 37
 38IMPLEMENT_CO_DATABLOCK_V1(afxBillboardData);
 39
 40ConsoleDocClass( afxBillboardData,
 41   "@brief A datablock that specifies a Billboard effect.\n\n"
 42
 43   "A Billboard effect is a textured quadrangle which is always aligned to face towards the camera. It is much like a single "
 44   "static particle and is rendered in a similar fashion."
 45   "\n\n"
 46
 47   "@ingroup afxEffects\n"
 48   "@ingroup AFX\n"
 49   "@ingroup Datablocks\n"
 50);
 51
 52afxBillboardData::afxBillboardData()
 53{
 54  color.set(1.0f, 1.0f, 1.0f, 1.0f);
 55  txr_name = ST_NULLSTRING;
 56  dimensions.set(1.0f, 1.0f);
 57  texCoords[0].set(0.0f, 0.0f);
 58  texCoords[1].set(0.0f, 1.0f);
 59  texCoords[2].set(1.0f, 1.0f);
 60  texCoords[3].set(1.0f, 0.0f);
 61  blendStyle = BlendUndefined;
 62  srcBlendFactor = BLEND_UNDEFINED;
 63  dstBlendFactor = BLEND_UNDEFINED;
 64}
 65
 66afxBillboardData::afxBillboardData(const afxBillboardData& other, bool temp_clone)
 67  : GameBaseData(other, temp_clone)
 68{
 69  color = other.color;
 70  txr_name = other.txr_name;
 71  txr = other.txr;
 72  dimensions = other.dimensions;
 73  texCoords[0] = other.texCoords[0];
 74  texCoords[1] = other.texCoords[1];
 75  texCoords[2] = other.texCoords[2];
 76  texCoords[3] = other.texCoords[3];
 77  blendStyle = other.blendStyle;
 78  srcBlendFactor = other.srcBlendFactor;
 79  dstBlendFactor = other.dstBlendFactor;
 80}
 81
 82#define myOffset(field) Offset(field, afxBillboardData)
 83
 84extern EnumTable srcBlendFactorTable;
 85extern EnumTable dstBlendFactorTable;
 86
 87ImplementEnumType( afxBillboard_BlendStyle, "Possible blending types.\n" "@ingroup afxBillboard\n\n" )
 88    { afxBillboardData::BlendNormal,         "NORMAL",         "..." },
 89    { afxBillboardData::BlendAdditive,       "ADDITIVE",       "..." },
 90    { afxBillboardData::BlendSubtractive,    "SUBTRACTIVE",    "..." },
 91    { afxBillboardData::BlendPremultAlpha,   "PREMULTALPHA",   "..." },
 92EndImplementEnumType;
 93
 94void afxBillboardData::initPersistFields()
 95{
 96  addField("color",           TypeColorF,     myOffset(color),
 97    "The color assigned to the quadrangle geometry. The way it combines with the given "
 98    "texture varies according to the setting of the textureFunction field.");
 99  addField("texture",         TypeFilename,   myOffset(txr_name),
100    "An image to use as the billboard's texture.");
101  addField("dimensions",      TypePoint2F,    myOffset(dimensions),
102    "A value-pair that specifies the horizontal and vertical dimensions of the billboard "
103    "in scene units.");
104  addField("textureCoords",   TypePoint2F,    myOffset(texCoords),  4,
105    "An array of four value-pairs that specify the UV texture coordinates for the four "
106    "corners of the billboard's quadrangle.");
107
108  addField("blendStyle",      TYPEID<afxBillboardData::BlendStyle>(),   myOffset(blendStyle),
109    "Selects a common blend factor preset. When set to 'user', srcBlendFactor and "
110    "dstBlendFactor can be used to set additional blend factor combinations.\n"
111    "Possible values: normal, additive, subtractive, premultalpha, or user.");
112  addField("srcBlendFactor",  TYPEID<GFXBlend>(),   myOffset(srcBlendFactor),
113    "Specifies source blend factor when blendStyle is set to 'user'.\n"
114    "Possible values: GFXBlendZero, GFXBlendOne, GFXBlendDestColor, GFXBlendInvDestColor, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha, GFXBlendDestAlpha, GFXBlendInvDestAlpha, or GFXBlendSrcAlphaSat");
115  addField("dstBlendFactor",  TYPEID<GFXBlend>(),   myOffset(dstBlendFactor),
116    "Specifies destination blend factor when blendStyle is set to 'user'.\n"
117    "Possible values: GFXBlendZero, GFXBlendOne, GFXBlendSrcColor, GFXBlendInvSrcColor, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha, GFXBlendDestAlpha, or GFXBlendInvDestAlpha");
118
119  Parent::initPersistFields();
120}
121
122void afxBillboardData::packData(BitStream* stream)
123{
124   Parent::packData(stream);
125
126  stream->write(color);
127  stream->writeString(txr_name);
128  mathWrite(*stream, dimensions);
129  mathWrite(*stream, texCoords[0]);
130  mathWrite(*stream, texCoords[1]);
131  mathWrite(*stream, texCoords[2]);
132  mathWrite(*stream, texCoords[3]);
133
134  stream->writeInt(srcBlendFactor, 4);
135  stream->writeInt(dstBlendFactor, 4);
136}
137
138void afxBillboardData::unpackData(BitStream* stream)
139{
140  Parent::unpackData(stream);
141
142  stream->read(&color);
143  txr_name = stream->readSTString();
144  txr = GFXTexHandle();
145  mathRead(*stream, &dimensions);
146  mathRead(*stream, &texCoords[0]);
147  mathRead(*stream, &texCoords[1]);
148  mathRead(*stream, &texCoords[2]);
149  mathRead(*stream, &texCoords[3]);
150
151  srcBlendFactor = (GFXBlend) stream->readInt(4);
152  dstBlendFactor = (GFXBlend) stream->readInt(4);
153}
154
155bool afxBillboardData::preload(bool server, String &errorStr)
156{
157  if (!Parent::preload(server, errorStr))
158    return false;
159
160  if (!server)
161  {
162    if (txr_name && txr_name[0] != '\0')
163    {
164      txr.set(txr_name, &GFXStaticTextureSRGBProfile, "Billboard Texture");
165    }
166  }
167
168   // if blend-style is set to User, check for defined blend-factors
169   if (blendStyle == BlendUser && (srcBlendFactor == BLEND_UNDEFINED || dstBlendFactor == BLEND_UNDEFINED))
170   {
171      blendStyle = BlendUndefined;
172      Con::warnf(ConsoleLogEntry::General, "afxBillboardData(%s) incomplete blend factor specification.", getName());
173   }
174
175   // silently switch Undefined blend-style to User if blend factors are both defined
176   if (blendStyle == BlendUndefined && srcBlendFactor != BLEND_UNDEFINED && dstBlendFactor != BLEND_UNDEFINED)
177   {
178      blendStyle = BlendUser;
179   }
180
181   // set pre-defined blend-factors 
182   switch (blendStyle)
183   {
184   case BlendNormal:
185      srcBlendFactor = GFXBlendSrcAlpha;
186      dstBlendFactor = GFXBlendInvSrcAlpha;
187      break;
188   case BlendSubtractive:
189      srcBlendFactor = GFXBlendZero;
190      dstBlendFactor = GFXBlendInvSrcColor;
191      break;
192   case BlendPremultAlpha:
193      srcBlendFactor = GFXBlendOne;
194      dstBlendFactor = GFXBlendInvSrcAlpha;
195      break;
196   case BlendUser:
197      break;
198   case BlendAdditive:
199      srcBlendFactor = GFXBlendSrcAlpha;
200      dstBlendFactor = GFXBlendOne;
201      break;
202   case BlendUndefined:
203   default:
204      blendStyle = BlendNormal;
205      srcBlendFactor = GFXBlendSrcAlpha;
206      dstBlendFactor = GFXBlendInvSrcAlpha;
207      break;
208   }
209
210  return true;
211}
212
213//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
214//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
215// afxBillboard
216
217IMPLEMENT_CO_NETOBJECT_V1(afxBillboard);
218
219ConsoleDocClass( afxBillboard,
220   "@brief A Billboard effect as defined by an afxBillboardData datablock.\n\n"
221
222   "A Billboard effect is a textured quadrangle which is always aligned to "
223   "face towards the camera. It is much like a single static particle and is rendered "
224   "in a similar fashion.\n"
225
226   "@ingroup afxEffects\n"
227   "@ingroup AFX\n"
228);
229
230afxBillboard::afxBillboard()
231{
232  mNetFlags.clear();
233  mNetFlags.set(IsGhost);
234
235  mDataBlock = 0;
236  fade_amt = 1.0f;
237  is_visible = true;
238  sort_priority = 0;
239  live_color.set(1.0f, 1.0f, 1.0f, 1.0f);
240}
241
242afxBillboard::~afxBillboard()
243{
244}
245
246//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
247
248bool afxBillboard::onNewDataBlock(GameBaseData* dptr, bool reload)
249{
250  mDataBlock = dynamic_cast<afxBillboardData*>(dptr);
251  if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
252    return false;
253
254  live_color = mDataBlock->color;
255
256  return true;
257}
258
259bool afxBillboard::onAdd()
260{
261  if(!Parent::onAdd())
262    return false;
263
264  F32 width = mDataBlock->dimensions.x * 0.5f;
265  F32 height = mDataBlock->dimensions.y * 0.5f;
266  mObjBox = Box3F(Point3F(-width, -0.01f, -height), Point3F(width, 0.01f, height));
267  
268  addToScene();
269  
270  return true;
271}
272
273void afxBillboard::onRemove()
274{
275  removeFromScene();
276  
277  Parent::onRemove();
278}
279
280//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
281