00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __POP_ContextData_h__
00015 #define __POP_ContextData_h__
00016
00017 #include "POP_API.h"
00018 #include <SYS/SYS_Math.h>
00019 #include <UT/UT_IntArray.h>
00020 #include <UT/UT_PtrArray.h>
00021 #include <UT/UT_RefArray.h>
00022 #include <GU/GU_DetailHandle.h>
00023 #include <OP/OP_Context.h>
00024 #include "POP_Guide.h"
00025 #include "POP_ParticleList.h"
00026
00027
00028 #define POP_USER_VARIABLE 600
00029 #define POP_TIMEDELTA 0.01
00030 #define MAX_INPUT_GEOS 4
00031
00032 class GEO_PrimParticle;
00033 class UT_SymbolTable;
00034 class UT_HashTable;
00035 class GU_Detail;
00036 class POP_Node;
00037 class OP_Network;
00038 class CH_LocalVariable;
00039 class PHYS_Constraint;
00040 class POP_BlindData;
00041 class POP_ContextDataHandle;
00042 class pop_ContextDataHandleRef;
00043
00044
00045 typedef UT_RefArray<GU_DetailHandle> POP_GuideHandleList;
00046
00047
00048
00049
00050
00051
00052 class POP_API POP_ContextData
00053 {
00054 public:
00055 POP_ContextData (const char *owner);
00056 virtual ~POP_ContextData (void);
00057
00058 const char * getName() const { return myName; }
00059
00060
00061
00062
00063
00064
00065
00066 void copyFrom (const POP_ContextData &data,
00067 GU_Detail* gdp = NULL);
00068
00069
00070
00071 void cook (OP_Context& context);
00072
00073
00074
00075 void cookGuide (OP_Context& context);
00076
00077
00078
00079 void reset (POP_Node *pop,
00080 GU_Detail *gdp,
00081 const char *init,
00082 bool keepgeo,
00083 unsigned seed,
00084 bool solveimmediately);
00085
00086
00087
00088
00089
00090 void frameReset (void);
00091
00092
00093 void offsetReset (void);
00094
00095
00096 void recacheOffset (void);
00097
00098
00099
00100 GU_Detail* getDisplayDetail (void) { return(myDisplayGdp); }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 POP_BlindData *getBlindData(const POP_Node *pop) const;
00115 int addBlindData(POP_BlindData *data);
00116 POP_BlindData *stealBlindData(const POP_Node *pop);
00117
00118
00119
00120
00121
00122
00123
00124 float random (void);
00125
00126
00127
00128
00129
00130 float randomSample (void);
00131
00132 unsigned getRandomSeed() const { return myFastRandomSeed; }
00133
00134
00135
00136
00137 GEO_PrimParticle* getPrimPart (POP_Node* node);
00138
00139
00140
00141 GEO_PrimParticle* hasPrimPart (POP_Node* node);
00142
00143
00144
00145 POP_Node* getGenerator (GEO_PrimParticle* part) const;
00146
00147
00148
00149 GU_Detail* getDetail (void) const { return(myGdp); }
00150
00151
00152 GB_Attribute* getEventAttr (void);
00153
00154
00155 void addEvent (UT_String& events, float t);
00156
00157
00158 void removeEvent (UT_String& events);
00159
00160
00161 void clearAllEvents (void);
00162
00163
00164 void cacheDetail (POP_Node* node);
00165
00166
00167
00168
00169 void addToParticleList (GEO_PrimParticle* part,
00170 POP_Node* pop, int idx);
00171
00172
00173
00174
00175 void incRef()
00176 {
00177 myRefCount++;
00178 }
00179 void decRef()
00180 {
00181 myRefCount--;
00182 if (!myRefCount)
00183 {
00184 delete myGdp;
00185 delete this;
00186 }
00187 }
00188
00189
00190
00191
00192 void setRefDetail(GU_Detail *gdp) { myGdp = gdp; }
00193
00194
00195
00196
00197 bool shouldDoReap() const { return myDoReap; }
00198 void setDoReap(bool v) { myDoReap = v; }
00199 bool shouldDoPrep() const { return myDoPrep; }
00200 void setDoPrep(bool v) { myDoPrep = v; }
00201 bool shouldDoApplyRules() const { return myDoApplyRules; }
00202 void setDoApplyRules(bool v) { myDoApplyRules = v; }
00203 bool shouldDoCook() const { return myDoCook; }
00204 void setDoCook(bool v) { myDoCook = v; }
00205 bool shouldDoCookFirst() const { return myDoCookFirst; }
00206 void setDoCookFirst(bool v) { myDoCookFirst = v; }
00207
00208
00209
00210
00211 int getRuleSuppression() { return myRuleSuppression; }
00212 void setRuleSuppression(int suppress) { myRuleSuppression = suppress; }
00213
00214
00215 POP_ParticleList* getParticleList (void) { return(&myParticleList); };
00216
00217 int getStateOffset (void) const { return(myStateOffset); }
00218 int getLifeOffset (void) const { return(myLifeOffset); }
00219 int getVelocityOffset (void) const { return(myVelocityOffset); }
00220 int getAccelOffset (void) const { return(myAccelOffset); }
00221 int getBacktrackOffset (void) const { return(myBacktrackOffset); }
00222
00223 int getBornOffset (void) const { return(myBornOffset); }
00224 int getSourceOffset (void) const { return(mySourceOffset); }
00225
00226 int getAlphaOffset (void) const { return(myAlphaOffset); }
00227 int getAngVelOffset (void) const { return(myAngVelOffset); }
00228 int getAttractOffset (void) const { return(myAttractOffset); }
00229 int getBounceOffset (void) const { return(myBounceOffset); }
00230 int getChargeOffset (void) const { return(myChargeOffset); }
00231 int getClingOffset (void) const { return(myClingOffset); }
00232 int getComOffset (void) const { return(myComOffset); }
00233 int getDiffuseOffset (void) const { return(myDiffuseOffset); }
00234 int getDistanceOffset (void) const { return(myDistanceOffset); }
00235 int getDragOffset (void) const { return(myDragOffset); }
00236 int getFollowOffset (void) const { return(myFollowOffset); }
00237 int getFDynamicOffset (void) const { return(myFDynamicOffset); }
00238 int getFStaticOffset (void) const { return(myFStaticOffset); }
00239 int getGenOffset (void) const { return(myGenOffset); }
00240 int getHitDiffuseOffset (void) const { return(myHitDiffuseOffset); }
00241 int getHitIDOffset (void) const { return(myHitIDOffset); }
00242 int getHitForceOffset (void) const { return(myHitForceOffset); }
00243 int getHitNormalOffset (void) const { return(myHitNormalOffset); }
00244 int getHitPosOffset (void) const { return(myHitPosOffset); }
00245 int getHitPosUVOffset (void) const { return(myHitPosUVOffset); }
00246 int getHitTimeOffset (void) const { return(myHitTimeOffset); }
00247 int getHitUVOffset (void) const { return(myHitUVOffset); }
00248 int getIDOffset (void) const { return(myIDOffset); }
00249 int getInstanceOffset (void) const { return(myInstanceOffset); }
00250 int getMassOffset (void) const { return(myMassOffset); }
00251 int getNearestOffset (void) const { return(myNearestOffset); }
00252 int getNearestDistOffset (void) const { return(myNearestDistOffset); }
00253 int getNormalOffset (void) const { return(myNormalOffset); }
00254 int getNumHitOffset (void) const { return(myNumHitOffset); }
00255 int getNumProximityOffset(void) const { return(myNumProximityOffset);}
00256 int getOrbitAxisOffset (void) const { return(myOrbitAxisOffset); }
00257 int getOrbitCenterOffset (void) const { return(myOrbitCenterOffset); }
00258 int getOrbitOffset (void) const { return(myOrbitOffset); }
00259 int getOrbitRadiusOffset (void) const { return(myOrbitRadiusOffset); }
00260 int getOrbitSpeedOffset (void) const { return(myOrbitSpeedOffset); }
00261 int getOrientOffset (void) const { return(myOrientOffset); }
00262 int getOriginOffset (void) const { return(myOriginOffset); }
00263 int getParentOffset (void) const { return(myParentOffset); }
00264 int getPosPathOffset (void) const { return(myPosPathOffset); }
00265
00266 int getPosPrimOffset (void) const { return(myPosPrimOffset); }
00267 int getPosUVOffset (void) const { return(myPosUVOffset); }
00268 int getPrevVelOffset (void) const { return(myPrevVelOffset); }
00269 int getRestOffset (void) const { return(myRestOffset); }
00270 int getRotOffset (void) const { return(myRotOffset); }
00271 int getScaleOffset (void) const { return(myScaleOffset); }
00272 int getScale3Offset (void) const { return(myScale3Offset); }
00273 int getSpeedOffset (void) const { return(mySpeedOffset); }
00274 int getSpeedLimitOffset (void) const { return(mySpeedLimitOffset); }
00275 int getSpringKOffset (void) const { return(mySpringKOffset); }
00276 int getSpriteRotOffset (void) const { return(mySpriteRotOffset); }
00277 int getSpriteScaleOffset (void) const { return(mySpriteScaleOffset); }
00278 int getSpriteShopOffset (void) const { return(mySpriteShopOffset); }
00279 int getSpriteUVOffset (void) const { return(mySpriteUVOffset); }
00280 int getTensionOffset (void) const { return(myTensionOffset); }
00281 int getTextureOffset (void) const { return(myTextureOffset); }
00282 int getTransOffset (void) const { return(myTransOffset); }
00283 int getTorqueOffset (void) const { return(myTorqueOffset); }
00284 int getUpOffset (void) const { return(myUpOffset); }
00285
00286 void setAlphaOffset (int offset) { myAlphaOffset = offset; }
00287 void setAngVelOffset (int offset) { myAngVelOffset = offset; }
00288 void setAttractOffset (int offset) { myAttractOffset = offset; }
00289 void setBounceOffset (int offset) { myBounceOffset = offset; }
00290 void setChargeOffset (int offset) { myChargeOffset = offset; }
00291 void setClingOffset (int offset) { myClingOffset = offset; }
00292 void setComOffset (int offset) { myComOffset = offset; }
00293 void setDiffuseOffset (int offset) { myDiffuseOffset = offset; }
00294 void setDistanceOffset (int offset) { myDistanceOffset = offset; }
00295 void setDragOffset (int offset) { myDragOffset = offset; }
00296 void setFollowOffset (int offset) { myFollowOffset = offset; }
00297 void setFDynamicOffset (int offset) { myFDynamicOffset = offset; }
00298 void setFStaticOffset (int offset) { myFStaticOffset = offset; }
00299 void setGenOffset (int offset) { myGenOffset = offset; }
00300 void setHitDiffuseOffset (int offset) { myHitDiffuseOffset = offset; }
00301 void setHitForceOffset (int offset) { myHitForceOffset = offset; }
00302 void setHitIDOffset (int offset) { myHitIDOffset = offset; }
00303 void setHitNormalOffset (int offset) { myHitNormalOffset = offset; }
00304 void setHitPosOffset (int offset) { myHitPosOffset = offset; }
00305 void setHitPosUVOffset (int offset) { myHitPosUVOffset = offset; }
00306 void setHitTimeOffset (int offset) { myHitTimeOffset = offset; }
00307 void setHitUVOffset (int offset) { myHitUVOffset = offset; }
00308 void setIDOffset (int offset) { myIDOffset = offset; }
00309 void setInstanceOffset (int offset) { myInstanceOffset = offset; }
00310 void setMassOffset (int offset) { myMassOffset = offset; }
00311 void setNearestOffset (int offset) { myNearestOffset = offset; }
00312 void setNearestDistOffset (int offset) { myNearestDistOffset = offset; }
00313 void setNormalOffset (int offset) { myNormalOffset = offset; }
00314 void setNumHitOffset (int offset) { myNumHitOffset = offset; }
00315 void setNumProximityOffset(int offset){ myNumProximityOffset=offset;}
00316 void setOrbitAxisOffset (int offset) { myOrbitAxisOffset = offset; }
00317 void setOrbitCenterOffset (int offset) { myOrbitCenterOffset = offset; }
00318 void setOrbitOffset (int offset) { myOrbitOffset = offset; }
00319 void setOrbitRadiusOffset (int offset) { myOrbitRadiusOffset = offset; }
00320 void setOrbitSpeedOffset (int offset) { myOrbitSpeedOffset = offset; }
00321 void setOrientOffset (int offset) { myOrientOffset = offset; }
00322 void setOriginOffset (int offset) { myOriginOffset = offset; }
00323 void setParentOffset (int offset) { myParentOffset = offset; }
00324
00325 void setPosPathOffset (int offset) { myPosPathOffset = offset; }
00326 void setPosPrimOffset (int offset) { myPosPrimOffset = offset; }
00327 void setPosUVOffset (int offset) { myPosUVOffset = offset; }
00328 void setPrevVelOffset (int offset) { myPrevVelOffset = offset; }
00329 void setRestOffset (int offset) { myRestOffset = offset; }
00330 void setRotOffset (int offset) { myRotOffset = offset; }
00331 void setScaleOffset (int offset) { myScaleOffset = offset; }
00332 void setScale3Offset (int offset) { myScale3Offset = offset; }
00333 void setSpeedOffset (int offset) { mySpeedOffset = offset; }
00334 void setSpeedLimitOffset (int offset) { mySpeedLimitOffset = offset; }
00335 void setSpringKOffset (int offset) { mySpringKOffset = offset; }
00336 void setSpriteRotOffset (int offset) { mySpriteRotOffset = offset; }
00337 void setSpriteScaleOffset (int offset) { mySpriteScaleOffset = offset; }
00338 void setSpriteShopOffset (int offset) { mySpriteShopOffset = offset; }
00339 void setSpriteUVOffset (int offset) { mySpriteUVOffset = offset; }
00340 void setTensionOffset (int offset) { myTensionOffset = offset; }
00341 void setTextureOffset (int offset) { myTextureOffset = offset; }
00342 void setTransOffset (int offset) { myTransOffset = offset; }
00343 void setTorqueOffset (int offset) { myTorqueOffset = offset; }
00344 void setUpOffset (int offset) { myUpOffset = offset; }
00345
00346 CH_LocalVariable *getUserVariables (void) { return myUserVars; }
00347 const CH_LocalVariable *getUserVariables(void) const
00348 { return myUserVars; }
00349
00350 int addUserVariable (const char* name, int size,
00351 GB_AttribType type,
00352 const void* def, const char* local = 0);
00353
00354 int isUserVariable (int index)
00355 { return (index >= POP_USER_VARIABLE); }
00356
00357 float getUserVariableValue (GEO_Point* ppt, int index, int thread);
00358
00359 uint64 getUserVariableSerial() const { return myUserVarSerial; }
00360
00361
00362 int isGuideOnly (void) const { return myGuideOnly; }
00363
00364
00365 int nextID (void);
00366
00367
00368 void bumpNumParticles (int delta) { myNumParticles += delta; }
00369
00370
00371 int allowBirth (void);
00372
00373
00374 void getInputGeo(UT_String &path, int index) const;
00375 void setInputGeo(const UT_String &path, int index);
00376
00377
00378
00379 void appendGuide(POP_Node *, const GU_DetailHandle &);
00380
00381
00382
00383
00384 void setInstanceGuide(POP_Node *, const GU_DetailHandle &);
00385
00386
00387
00388 bool getSelectionChanged() const
00389 { return mySelectionChanged; }
00390 void setSelectionChanged() { mySelectionChanged = true; }
00391
00392
00393
00394
00395
00396
00397 static POP_ContextData *getExpressionData(int thread);
00398
00399
00400
00401
00402 float myTime;
00403 float myTimeInc;
00404 void* myUserData;
00405 int myRemoveUnused;
00406 OP_Network* myXformObj;
00407 POP_Node* myCookPOP;
00408 POP_Node* myDisplayPOP;
00409 int myDoInfoButton;
00410 int myDoUpdateViewport;
00411 int myMaxParticles;
00412
00413
00414
00415
00416
00417 POP_GuideHandleList myOPGuides;
00418 UT_IntArray myGuidePOPs;
00419
00420 UT_PtrArray<GEO_Point*> myInstancePoints;
00421 GU_DetailHandle myInstanceOPGuide;
00422 int myInstanceGuidePOP;
00423
00424 int myNotifyCache;
00425
00426 private:
00427 void recacheUserOffset (void);
00428
00429 void setupAttributes(GU_Detail *gdp);
00430 void setupInitialState(GU_Detail *gdp);
00431
00432 pop_ContextDataHandleRef *getIndirectHandle();
00433
00434 UT_String myName;
00435
00436
00437 int myGuideOnly;
00438 #ifdef INTEL_COMPILER
00439
00440
00441
00442
00443 std::vector<UT_String> myInputPaths;
00444 #else
00445 UT_String myInputPaths[MAX_INPUT_GEOS];
00446 #endif
00447
00448
00449 GU_Detail myCacheGdp;
00450 GU_Detail* myDisplayGdp;
00451
00452
00453 unsigned myFastRandomSeed;
00454 UT_SymbolTable* myPrimParts;
00455 UT_SymbolTable* myGenerators;
00456 UT_SymbolTable* myInitPrims;
00457 GU_Detail* myGdp;
00458 POP_ParticleList myParticleList;
00459 POP_ParticleList myInitParticleList;
00460 float myPrevTimeInc;
00461 bool mySolveImmediately;
00462 bool mySelectionChanged;
00463 int myNumParticles;
00464
00465
00466 int myAlphaOffset;
00467 int myAngVelOffset;
00468 int myAttractOffset;
00469 int myBounceOffset;
00470 int myChargeOffset;
00471 int myClingOffset;
00472 int myComOffset;
00473 int myDiffuseOffset;
00474 int myDistanceOffset;
00475 int myDragOffset;
00476 int myFollowOffset;
00477 int myFDynamicOffset;
00478 int myFStaticOffset;
00479 int myGenOffset;
00480 int myHitDiffuseOffset;
00481 int myHitForceOffset;
00482 int myHitIDOffset;
00483 int myHitNormalOffset;
00484 int myHitPosOffset;
00485 int myHitPosUVOffset;
00486 int myHitTimeOffset;
00487 int myHitUVOffset;
00488 int myIDOffset;
00489 int myInstanceOffset;
00490 int myMassOffset;
00491 int myNearestOffset;
00492 int myNearestDistOffset;
00493 int myNormalOffset;
00494 int myNumHitOffset;
00495 int myNumProximityOffset;
00496 int myOrbitAxisOffset;
00497 int myOrbitCenterOffset;
00498 int myOrbitOffset;
00499 int myOrbitRadiusOffset;
00500 int myOrbitSpeedOffset;
00501 int myOrientOffset;
00502 int myOriginOffset;
00503 int myParentOffset;
00504
00505
00506
00507 int myPosPathOffset;
00508
00509 int myPosPrimOffset;
00510 int myPosUVOffset;
00511 int myPrevVelOffset;
00512 int myRestOffset;
00513 int myRotOffset;
00514 int myScaleOffset;
00515 int myScale3Offset;
00516 int mySpeedOffset;
00517 int mySpeedLimitOffset;
00518 int mySpringKOffset;
00519 int mySpriteRotOffset;
00520 int mySpriteScaleOffset;
00521 int mySpriteShopOffset;
00522 int mySpriteUVOffset;
00523 int myTensionOffset;
00524 int myTextureOffset;
00525 int myTransOffset;
00526 int myTorqueOffset;
00527 int myUpOffset;
00528
00529
00530 int myVelocityOffset;
00531 int myAccelOffset;
00532 int myStateOffset;
00533 int myLifeOffset;
00534 int myBacktrackOffset;
00535
00536
00537 int myBornOffset;
00538 int mySourceOffset;
00539 int myGeneratorOffset;
00540
00541
00542
00543 bool myDoPrep;
00544 bool myDoReap;
00545 bool myDoApplyRules;
00546 bool myDoCook;
00547 bool myDoCookFirst;
00548
00549
00550
00551 int myRuleSuppression;
00552
00553
00554
00555
00556 CH_LocalVariable* getLocalVariable (const char* symbol);
00557
00558 void resetUserVariables();
00559
00560
00561
00562
00563 void resetBlindData(int forced);
00564
00565 int myUserVarSize;
00566 int myUserVarEntries;
00567 CH_LocalVariable* myUserVars;
00568 UT_SymbolTable* myUserVarSymbols;
00569 UT_SymbolTable* myUserVarIDs;
00570 uint64 myUserVarSerial;
00571 UT_HashTable *myBlindData;
00572
00573 int myRefCount;
00574
00575 pop_ContextDataHandleRef *myIndirectHandle;
00576
00577 friend class POP_ContextDataHandle;
00578 };
00579
00580 inline float
00581 POP_ContextData::random (void)
00582 {
00583 return SYSfastRandom(myFastRandomSeed);
00584 }
00585
00586 inline float
00587 POP_ContextData::randomSample (void)
00588 {
00589 return SYSrandom(myFastRandomSeed);
00590 }
00591
00592
00593
00594
00595
00596
00597
00598
00599 class POP_API POP_ContextDataHandle
00600 {
00601 public:
00602 POP_ContextDataHandle();
00603 POP_ContextDataHandle(const POP_ContextDataHandle &handle);
00604 ~POP_ContextDataHandle();
00605
00606 void clear();
00607 const POP_ContextDataHandle &operator=(const POP_ContextDataHandle &handle);
00608 POP_ContextData *getContextData() const;
00609 void bind(POP_ContextData *data);
00610 private:
00611 void setHandleRef(pop_ContextDataHandleRef *handle);
00612 pop_ContextDataHandleRef *myHandle;
00613 };
00614
00615
00616
00617
00618 class POP_API POP_UserVarResolveInfo
00619 {
00620 public:
00621 POP_UserVarResolveInfo() : mySerial(0) {}
00622
00623
00624
00625 bool update(POP_ContextData *data);
00626
00627 private:
00628 POP_ContextDataHandle myContextData;
00629 uint64 mySerial;
00630 };
00631
00632 #endif