├── .gitignore ├── CHOP_CPlusPlusBase.h ├── CPlusPlusCHOPExample.vcxproj ├── CPlusPlusCHOPExample.vcxproj.user ├── CPlusPlusCHOPExample.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── CPlusPlus_Common.h ├── GL_Extensions.h ├── Info.plist ├── LICENSE ├── PhaserCHOP.cpp ├── PhaserCHOP.h ├── PhaserCHOP.sln ├── PhaserCHOP.toe ├── Plugins └── .gitignore └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | #*.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /CHOP_CPlusPlusBase.h: -------------------------------------------------------------------------------- 1 | /* Shared Use License: This file is owned by Derivative Inc. (Derivative) 2 | * and can only be used, and/or modified for use, in conjunction with 3 | * Derivative's TouchDesigner software, and only if you are a licensee who has 4 | * accepted Derivative's TouchDesigner license or assignment agreement 5 | * (which also govern the use of this file). You may share or redistribute 6 | * a modified version of this file provided the following conditions are met: 7 | * 8 | * 1. The shared file or redistribution must retain the information set out 9 | * above and this list of conditions. 10 | * 2. Derivative's name (Derivative Inc.) or its trademarks may not be used 11 | * to endorse or promote products derived from this file without specific 12 | * prior written permission from Derivative. 13 | */ 14 | 15 | /* 16 | * Produced by: 17 | * 18 | * Derivative Inc 19 | * 401 Richmond Street West, Unit 386 20 | * Toronto, Ontario 21 | * Canada M5V 3A8 22 | * 416-591-3555 23 | * 24 | * NAME: CHOP_CPlusPlusBase.h 25 | * 26 | * 27 | * Do not edit this file directly! 28 | * Make a subclass of CHOP_CPlusPlusBase instead, and add your own 29 | * data/functions. 30 | 31 | * Derivative Developers:: Make sure the virtual function order 32 | * stays the same, otherwise changes won't be backwards compatible 33 | */ 34 | 35 | #ifndef __CHOP_CPlusPlusBase__ 36 | #define __CHOP_CPlusPlusBase__ 37 | 38 | #include "CPlusPlus_Common.h" 39 | 40 | 41 | class CHOP_CPlusPlusBase; 42 | 43 | // Define for the current API version that this sample code is made for. 44 | // To upgrade to a newer version, replace the files 45 | // CHOP_CPlusPlusBase.h 46 | // CPlusPlus_Common.h 47 | // from the samples folder in a newer TouchDesigner installation. 48 | // You may need to upgrade your plugin code in that case, to match 49 | // the new API requirements 50 | const int CHOPCPlusPlusAPIVersion = 8; 51 | 52 | struct CHOP_PluginInfo 53 | { 54 | public: 55 | 56 | // Must be set to CHOPCPlusPlusAPIVersion in FillCHOPPluginInfo 57 | int32_t apiVersion = 0; 58 | 59 | int32_t reserved[100]; 60 | 61 | 62 | // Information used to describe this plugin as a custom OP. 63 | OP_CustomOPInfo customOPInfo; 64 | 65 | 66 | int32_t reserved2[20]; 67 | 68 | }; 69 | 70 | 71 | 72 | // These are the definitions for the C-functions that are used to 73 | // load the library and create instances of the object you define 74 | typedef void (__cdecl *FILLCHOPPLUGININFO)(CHOP_PluginInfo *info); 75 | typedef CHOP_CPlusPlusBase* (__cdecl *CREATECHOPINSTANCE)(const OP_NodeInfo*); 76 | typedef void (__cdecl *DESTROYCHOPINSTANCE)(CHOP_CPlusPlusBase*); 77 | 78 | 79 | class CHOP_GeneralInfo 80 | { 81 | public: 82 | // Set this to true if you want the CHOP to cook every frame, even 83 | // if none of it's inputs/parameters are changing 84 | // DEFAULT: false 85 | 86 | bool cookEveryFrame; 87 | 88 | // Set this to true if you want the CHOP to cook every frame, but only 89 | // if someone asks for it to cook. So if nobody is using the output from 90 | // the CHOP, it won't cook. This is difereent from 'cookEveryFrame' 91 | // since that will cause it to cook every frame no matter what. 92 | 93 | bool cookEveryFrameIfAsked; 94 | 95 | // Set this to true if you will be outputting a timeslice 96 | // Outputting a timeslice means the number of samples in the CHOP will 97 | // be determined by the number of frames that have elapsed since the last 98 | // time TouchDesigner cooked (it will be more than one in cases where it's 99 | // running slower than the target cook rate), the playbar framerate and 100 | // the sample rate of the CHOP. 101 | // For example if you are outputting the CHOP 120hz sample rate, 102 | // TouchDesigner is running at 60 hz cookrate, and you missed a frame last cook 103 | // then on this cook the number of sampels of the output of this CHOP will 104 | // be 4 samples. I.e (120 / 60) * number of playbar frames to output. 105 | // If this isn't set then you specify the number of sample in the CHOP using 106 | // the getOutputInfo() function 107 | // DEFAULT: false 108 | 109 | bool timeslice; 110 | 111 | // If you are returning 'false' from getOutputInfo, this index will 112 | // specify the CHOP input whos attribues you will match 113 | // (channel names, length, sample rate etc.) 114 | // DEFAULT : 0 115 | 116 | int32_t inputMatchIndex; 117 | 118 | 119 | int32_t reserved[20]; 120 | }; 121 | 122 | 123 | 124 | class CHOP_OutputInfo 125 | { 126 | public: 127 | 128 | // The number of channels you want to output 129 | 130 | int32_t numChannels; 131 | 132 | 133 | // If you arn't outputting a timeslice, specify the number of samples here 134 | 135 | int32_t numSamples; 136 | 137 | 138 | // if you arn't outputting a timeslice, specify the start index 139 | // of the channels here. This is the 'Start' you see when you 140 | // middle click on a CHOP 141 | 142 | uint32_t startIndex; 143 | 144 | 145 | // Specify the sample rate of the channel data 146 | // DEFAULT : whatever the timeline FPS is ($FPS) 147 | 148 | float sampleRate; 149 | 150 | 151 | void* reserved1; 152 | 153 | 154 | int32_t reserved[20]; 155 | 156 | }; 157 | 158 | 159 | 160 | 161 | 162 | class CHOP_Output 163 | { 164 | public: 165 | CHOP_Output(int32_t nc, int32_t l, float s, uint32_t st, 166 | float **cs, const char** ns): 167 | numChannels(nc), 168 | numSamples(l), 169 | sampleRate(s), 170 | startIndex(st), 171 | channels(cs), 172 | names(ns) 173 | { 174 | } 175 | 176 | // Info about what you are expected to output 177 | const int32_t numChannels; 178 | const int32_t numSamples; 179 | const float sampleRate; 180 | const uint32_t startIndex; 181 | 182 | // This is an array of const char* that tells you the channel names 183 | // of the channels you are providing values for. It's 'numChannels' long. 184 | // E.g names[3] is the name of the 4th channel 185 | const char** const names; 186 | 187 | // This is an array of float arrays that is already allocated for you. 188 | // Fill it with the data you want outputted for this CHOP. 189 | // The length of the array is 'numChannels', 190 | // While the length of each of the array entries is 'numSamples'. 191 | // For example channels[1][10] will point to the 11th sample in the 2nd 192 | // channel 193 | float** const channels; 194 | 195 | 196 | 197 | int32_t reserved[20]; 198 | }; 199 | 200 | 201 | 202 | /***** FUNCTION CALL ORDER DURING INITIALIZATION ******/ 203 | /* 204 | When the TOP loads the dll the functions will be called in this order 205 | 206 | setupParameters(OP_ParameterManager* m); 207 | 208 | */ 209 | 210 | /***** FUNCTION CALL ORDER DURING A COOK ******/ 211 | /* 212 | 213 | When the CHOP cooks the functions will be called in this order 214 | 215 | getGeneralInfo() 216 | getOutputInfo() 217 | if getOutputInfo() returns true 218 | { 219 | getChannelName() once for each channel needed 220 | } 221 | execute() 222 | getNumInfoCHOPChans() 223 | for the number of chans returned getNumInfoCHOPChans() 224 | { 225 | getInfoCHOPChan() 226 | } 227 | getInfoDATSize() 228 | for the number of rows/cols returned by getInfoDATSize() 229 | { 230 | getInfoDATEntries() 231 | } 232 | getInfoPopupString() 233 | getWarningString() 234 | getErrorString() 235 | */ 236 | 237 | /*** DO NOT EDIT THIS CLASS, MAKE A SUBCLASS OF IT INSTEAD ***/ 238 | class CHOP_CPlusPlusBase 239 | { 240 | protected: 241 | CHOP_CPlusPlusBase() 242 | { 243 | } 244 | 245 | virtual ~CHOP_CPlusPlusBase() 246 | { 247 | } 248 | 249 | public: 250 | 251 | 252 | // BEGIN PUBLIC INTERFACE 253 | 254 | // Some general settings can be assigned here (if you override it) 255 | virtual void 256 | getGeneralInfo(CHOP_GeneralInfo*, const OP_Inputs *inputs, void* reserved1) 257 | { 258 | } 259 | 260 | 261 | // This function is called so the class can tell the CHOP how many 262 | // channels it wants to output, how many samples etc. 263 | // Return true if you specify the output here. 264 | // Return false if you want the output to be set by matching 265 | // the channel names, numSamples, sample rate etc. of one of your inputs 266 | // The input that is used is chosen by setting the 'inputMatchIndex' 267 | // memeber in CHOP_OutputInfo 268 | // The CHOP_OutputInfo class is pre-filled with what the CHOP would 269 | // output if you return false, so you can just tweak a few settings 270 | // and return true if you want 271 | virtual bool 272 | getOutputInfo(CHOP_OutputInfo*, const OP_Inputs *inputs, void *reserved1) 273 | { 274 | return false; 275 | } 276 | 277 | 278 | // This function will be called after getOutputInfo() asking for 279 | // the channel names. It will get called once for each channel name 280 | // you need to specify. If you returned 'false' from getOutputInfo() 281 | // it won't be called. 282 | virtual void 283 | getChannelName(int32_t index, OP_String *name, 284 | const OP_Inputs *inputs, void* reserved1) 285 | { 286 | name->setString("chan1"); 287 | } 288 | 289 | 290 | // In this function you do whatever you want to fill the output channels 291 | // which are already allocated for you in 'outputs' 292 | virtual void execute(CHOP_Output* outputs, 293 | const OP_Inputs* inputs, 294 | void* reserved1) = 0; 295 | 296 | 297 | // Override these methods if you want to output values to the Info CHOP/DAT 298 | // returning 0 means you dont plan to output any Info CHOP channels 299 | virtual int32_t 300 | getNumInfoCHOPChans(void *reserved1) 301 | { 302 | return 0; 303 | } 304 | 305 | // Specify the name and value for Info CHOP channel 'index', 306 | // by assigning something to 'name' and 'value' members of the 307 | // OP_InfoCHOPChan class pointer that is passed in. 308 | virtual void 309 | getInfoCHOPChan(int32_t index, OP_InfoCHOPChan* chan, void* reserved1) 310 | { 311 | } 312 | 313 | 314 | // Return false if you arn't returning data for an Info DAT 315 | // Return true if you are. 316 | // Set the members of the CHOP_InfoDATSize class to specify 317 | // the dimensions of the Info DAT 318 | virtual bool 319 | getInfoDATSize(OP_InfoDATSize* infoSize, void *reserved1) 320 | { 321 | return false; 322 | } 323 | 324 | // You are asked to assign values to the Info DAT 1 row or column at a time 325 | // The 'byColumn' variable in 'getInfoDATSize' is how you specify 326 | // if it is by column or by row. 327 | // 'index' is the row/column index 328 | // 'nEntries' is the number of entries in the row/column 329 | // Strings should be UTF-8 encoded. 330 | virtual void 331 | getInfoDATEntries(int32_t index, int32_t nEntries, 332 | OP_InfoDATEntries* entries, 333 | void *reserved1) 334 | { 335 | } 336 | 337 | // You can use this function to put the node into a warning state 338 | // by calling setSting() on 'warning' with a non empty string. 339 | // Leave 'warning' unchanged to not go into warning state. 340 | virtual void 341 | getWarningString(OP_String *warning, void *reserved1) 342 | { 343 | } 344 | 345 | // You can use this function to put the node into a error state 346 | // by calling setSting() on 'error' with a non empty string. 347 | // Leave 'error' unchanged to not go into error state. 348 | virtual void 349 | getErrorString(OP_String *error, void *reserved1) 350 | { 351 | } 352 | 353 | // Use this function to return some text that will show up in the 354 | // info popup (when you middle click on a node) 355 | // call setString() on info and give it some info if desired. 356 | virtual void 357 | getInfoPopupString(OP_String *info, void *reserved1) 358 | { 359 | } 360 | 361 | 362 | // Override these methods if you want to define specfic parameters 363 | virtual void 364 | setupParameters(OP_ParameterManager* manager, void* reserved1) 365 | { 366 | } 367 | 368 | 369 | // This is called whenever a pulse parameter is pressed 370 | virtual void 371 | pulsePressed(const char* name, void* reserved1) 372 | { 373 | } 374 | 375 | // END PUBLIC INTERFACE 376 | 377 | 378 | private: 379 | 380 | // Reserved for future features 381 | virtual int32_t reservedFunc6() { return 0; } 382 | virtual int32_t reservedFunc7() { return 0; } 383 | virtual int32_t reservedFunc8() { return 0; } 384 | virtual int32_t reservedFunc9() { return 0; } 385 | virtual int32_t reservedFunc10() { return 0; } 386 | virtual int32_t reservedFunc11() { return 0; } 387 | virtual int32_t reservedFunc12() { return 0; } 388 | virtual int32_t reservedFunc13() { return 0; } 389 | virtual int32_t reservedFunc14() { return 0; } 390 | virtual int32_t reservedFunc15() { return 0; } 391 | virtual int32_t reservedFunc16() { return 0; } 392 | virtual int32_t reservedFunc17() { return 0; } 393 | virtual int32_t reservedFunc18() { return 0; } 394 | virtual int32_t reservedFunc19() { return 0; } 395 | virtual int32_t reservedFunc20() { return 0; } 396 | 397 | int32_t reserved[400]; 398 | 399 | }; 400 | 401 | static_assert(offsetof(CHOP_PluginInfo, apiVersion) == 0, "Incorrect Alignment"); 402 | static_assert(offsetof(CHOP_PluginInfo, customOPInfo) == 408, "Incorrect Alignment"); 403 | static_assert(sizeof(CHOP_PluginInfo) == 944, "Incorrect Size"); 404 | 405 | static_assert(offsetof(CHOP_GeneralInfo, cookEveryFrame) == 0, "Incorrect Alignment"); 406 | static_assert(offsetof(CHOP_GeneralInfo, cookEveryFrameIfAsked) == 1, "Incorrect Alignment"); 407 | static_assert(offsetof(CHOP_GeneralInfo, timeslice) == 2, "Incorrect Alignment"); 408 | static_assert(offsetof(CHOP_GeneralInfo, inputMatchIndex) == 4, "Incorrect Alignment"); 409 | static_assert(sizeof(CHOP_GeneralInfo) == 88, "Incorrect Size"); 410 | 411 | static_assert(offsetof(CHOP_OutputInfo, numChannels) == 0, "Incorrect Alignment"); 412 | static_assert(offsetof(CHOP_OutputInfo, numSamples) == 4, "Incorrect Alignment"); 413 | static_assert(offsetof(CHOP_OutputInfo, startIndex) == 8, "Incorrect Alignment"); 414 | static_assert(offsetof(CHOP_OutputInfo, sampleRate) == 12, "Incorrect Alignment"); 415 | static_assert(offsetof(CHOP_OutputInfo, reserved1) == 16, "Incorrect Alignment"); 416 | static_assert(sizeof(CHOP_OutputInfo) == 104, "Incorrect Size"); 417 | 418 | static_assert(offsetof(CHOP_Output, numChannels) == 0, "Incorrect Alignment"); 419 | static_assert(offsetof(CHOP_Output, numSamples) == 4, "Incorrect Alignment"); 420 | static_assert(offsetof(CHOP_Output, sampleRate) == 8, "Incorrect Alignment"); 421 | static_assert(offsetof(CHOP_Output, startIndex) == 12, "Incorrect Alignment"); 422 | static_assert(offsetof(CHOP_Output, names) == 16, "Incorrect Alignment"); 423 | static_assert(offsetof(CHOP_Output, channels) == 24, "Incorrect Alignment"); 424 | static_assert(sizeof(CHOP_Output) == 112, "Incorrect Size"); 425 | #endif 426 | -------------------------------------------------------------------------------- /CPlusPlusCHOPExample.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {3F5BEECD-FA36-459F-91B8-BB481A67EF44} 23 | CPlusPlusCHOPExample 24 | Win32Proj 25 | PhaserCHOP 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | NotSet 32 | true 33 | v142 34 | 35 | 36 | DynamicLibrary 37 | NotSet 38 | true 39 | v142 40 | 41 | 42 | DynamicLibrary 43 | NotSet 44 | v142 45 | 46 | 47 | DynamicLibrary 48 | NotSet 49 | v142 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | <_ProjectFileVersion>10.0.40219.1 69 | $(SolutionDir)$(Configuration)\ 70 | $(SolutionDir)$(Configuration)\$(Platform) 71 | $(Configuration)\ 72 | $(SolutionDir)$(Configuration)\$(Platform) 73 | false 74 | false 75 | $(SolutionDir)$(Configuration)\ 76 | $(SolutionDir)$(Configuration)\$(Platform) 77 | $(Configuration)\ 78 | $(SolutionDir)$(Configuration)\$(Platform) 79 | false 80 | false 81 | 82 | 83 | 84 | Disabled 85 | WIN32;_DEBUG;_WINDOWS;_USRDLL;CPLUSPLUSCHOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions) 86 | true 87 | EnableFastChecks 88 | MultiThreadedDebugDLL 89 | 90 | 91 | Level3 92 | ProgramDatabase 93 | 94 | 95 | true 96 | Windows 97 | MachineX86 98 | 99 | 100 | 101 | 102 | Disabled 103 | WIN32;_DEBUG;_WINDOWS;_USRDLL;CPLUSPLUSCHOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions) 104 | EnableFastChecks 105 | MultiThreadedDebugDLL 106 | 107 | 108 | Level3 109 | ProgramDatabase 110 | 111 | 112 | true 113 | Windows 114 | 115 | 116 | cp $(TargetPath) Plugins/ 117 | 118 | 119 | 120 | 121 | WIN32;NDEBUG;_WINDOWS;_USRDLL;CPLUSPLUSCHOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions) 122 | MultiThreadedDLL 123 | 124 | 125 | Level3 126 | ProgramDatabase 127 | 128 | 129 | true 130 | Windows 131 | true 132 | true 133 | MachineX86 134 | 135 | 136 | 137 | 138 | WIN32;NDEBUG;_WINDOWS;_USRDLL;CPLUSPLUSCHOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions) 139 | MultiThreadedDLL 140 | 141 | 142 | Level3 143 | ProgramDatabase 144 | 145 | 146 | true 147 | Windows 148 | true 149 | true 150 | 151 | 152 | cp $(TargetPath) Plugins/ 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /CPlusPlusCHOPExample.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | C:\Program Files\Derivative\TouchDesigner\bin\TouchDesigner.exe 5 | WindowsLocalDebugger 6 | $(ProjectName).toe 7 | 8 | 9 | C:\Program Files\Derivative\TouchDesigner\bin\TouchDesigner.exe 10 | $(ProjectName).toe 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /CPlusPlusCHOPExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E23329E31DF092C90002B4FE /* CPlusPlusCHOPExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E23329E11DF092C90002B4FE /* CPlusPlusCHOPExample.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXFileReference section */ 14 | E23329D61DF092AD0002B4FE /* CPlusPlusCHOPExample.plugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CPlusPlusCHOPExample.plugin; sourceTree = BUILT_PRODUCTS_DIR; }; 15 | E23329D91DF092AD0002B4FE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; 16 | E23329DF1DF092C90002B4FE /* CHOP_CPlusPlusBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHOP_CPlusPlusBase.h; sourceTree = SOURCE_ROOT; }; 17 | E23329E01DF092C90002B4FE /* CPlusPlus_Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPlusPlus_Common.h; sourceTree = SOURCE_ROOT; }; 18 | E23329E11DF092C90002B4FE /* CPlusPlusCHOPExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPlusPlusCHOPExample.cpp; sourceTree = SOURCE_ROOT; }; 19 | E23329E21DF092C90002B4FE /* CPlusPlusCHOPExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPlusPlusCHOPExample.h; sourceTree = SOURCE_ROOT; }; 20 | /* End PBXFileReference section */ 21 | 22 | /* Begin PBXFrameworksBuildPhase section */ 23 | E23329D31DF092AD0002B4FE /* Frameworks */ = { 24 | isa = PBXFrameworksBuildPhase; 25 | buildActionMask = 2147483647; 26 | files = ( 27 | ); 28 | runOnlyForDeploymentPostprocessing = 0; 29 | }; 30 | /* End PBXFrameworksBuildPhase section */ 31 | 32 | /* Begin PBXGroup section */ 33 | E23329CD1DF092AD0002B4FE = { 34 | isa = PBXGroup; 35 | children = ( 36 | E23329F11DF1D64A0002B4FE /* CHOP */, 37 | E23329D71DF092AD0002B4FE /* Products */, 38 | ); 39 | sourceTree = ""; 40 | }; 41 | E23329D71DF092AD0002B4FE /* Products */ = { 42 | isa = PBXGroup; 43 | children = ( 44 | E23329D61DF092AD0002B4FE /* CPlusPlusCHOPExample.plugin */, 45 | ); 46 | name = Products; 47 | sourceTree = ""; 48 | }; 49 | E23329F11DF1D64A0002B4FE /* CHOP */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | E23329DF1DF092C90002B4FE /* CHOP_CPlusPlusBase.h */, 53 | E23329E01DF092C90002B4FE /* CPlusPlus_Common.h */, 54 | E23329E11DF092C90002B4FE /* CPlusPlusCHOPExample.cpp */, 55 | E23329E21DF092C90002B4FE /* CPlusPlusCHOPExample.h */, 56 | E23329D91DF092AD0002B4FE /* Info.plist */, 57 | ); 58 | name = CHOP; 59 | sourceTree = ""; 60 | }; 61 | /* End PBXGroup section */ 62 | 63 | /* Begin PBXNativeTarget section */ 64 | E23329D51DF092AD0002B4FE /* CPlusPlusCHOPExample */ = { 65 | isa = PBXNativeTarget; 66 | buildConfigurationList = E23329DC1DF092AD0002B4FE /* Build configuration list for PBXNativeTarget "CPlusPlusCHOPExample" */; 67 | buildPhases = ( 68 | E23329D21DF092AD0002B4FE /* Sources */, 69 | E23329D31DF092AD0002B4FE /* Frameworks */, 70 | E23329D41DF092AD0002B4FE /* Resources */, 71 | ); 72 | buildRules = ( 73 | ); 74 | dependencies = ( 75 | ); 76 | name = CPlusPlusCHOPExample; 77 | productName = CPlusPlusCHOPExample; 78 | productReference = E23329D61DF092AD0002B4FE /* CPlusPlusCHOPExample.plugin */; 79 | productType = "com.apple.product-type.bundle"; 80 | }; 81 | /* End PBXNativeTarget section */ 82 | 83 | /* Begin PBXProject section */ 84 | E23329CE1DF092AD0002B4FE /* Project object */ = { 85 | isa = PBXProject; 86 | attributes = { 87 | LastUpgradeCheck = 0820; 88 | ORGANIZATIONNAME = Derivative; 89 | TargetAttributes = { 90 | E23329D51DF092AD0002B4FE = { 91 | CreatedOnToolsVersion = 8.0; 92 | ProvisioningStyle = Automatic; 93 | }; 94 | }; 95 | }; 96 | buildConfigurationList = E23329D11DF092AD0002B4FE /* Build configuration list for PBXProject "CPlusPlusCHOPExample" */; 97 | compatibilityVersion = "Xcode 3.2"; 98 | developmentRegion = English; 99 | hasScannedForEncodings = 0; 100 | knownRegions = ( 101 | en, 102 | ); 103 | mainGroup = E23329CD1DF092AD0002B4FE; 104 | productRefGroup = E23329D71DF092AD0002B4FE /* Products */; 105 | projectDirPath = ""; 106 | projectRoot = ""; 107 | targets = ( 108 | E23329D51DF092AD0002B4FE /* CPlusPlusCHOPExample */, 109 | ); 110 | }; 111 | /* End PBXProject section */ 112 | 113 | /* Begin PBXResourcesBuildPhase section */ 114 | E23329D41DF092AD0002B4FE /* Resources */ = { 115 | isa = PBXResourcesBuildPhase; 116 | buildActionMask = 2147483647; 117 | files = ( 118 | ); 119 | runOnlyForDeploymentPostprocessing = 0; 120 | }; 121 | /* End PBXResourcesBuildPhase section */ 122 | 123 | /* Begin PBXSourcesBuildPhase section */ 124 | E23329D21DF092AD0002B4FE /* Sources */ = { 125 | isa = PBXSourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | E23329E31DF092C90002B4FE /* CPlusPlusCHOPExample.cpp in Sources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXSourcesBuildPhase section */ 133 | 134 | /* Begin XCBuildConfiguration section */ 135 | E23329DA1DF092AD0002B4FE /* Debug */ = { 136 | isa = XCBuildConfiguration; 137 | buildSettings = { 138 | ALWAYS_SEARCH_USER_PATHS = NO; 139 | CLANG_ANALYZER_NONNULL = YES; 140 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 141 | CLANG_CXX_LIBRARY = "libc++"; 142 | CLANG_ENABLE_MODULES = YES; 143 | CLANG_ENABLE_OBJC_ARC = YES; 144 | CLANG_WARN_BOOL_CONVERSION = YES; 145 | CLANG_WARN_CONSTANT_CONVERSION = YES; 146 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 147 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 148 | CLANG_WARN_EMPTY_BODY = YES; 149 | CLANG_WARN_ENUM_CONVERSION = YES; 150 | CLANG_WARN_INFINITE_RECURSION = YES; 151 | CLANG_WARN_INT_CONVERSION = YES; 152 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 153 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 154 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 155 | CLANG_WARN_UNREACHABLE_CODE = YES; 156 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 157 | CODE_SIGN_IDENTITY = "-"; 158 | COPY_PHASE_STRIP = NO; 159 | DEBUG_INFORMATION_FORMAT = dwarf; 160 | ENABLE_STRICT_OBJC_MSGSEND = YES; 161 | ENABLE_TESTABILITY = YES; 162 | GCC_C_LANGUAGE_STANDARD = gnu99; 163 | GCC_DYNAMIC_NO_PIC = NO; 164 | GCC_NO_COMMON_BLOCKS = YES; 165 | GCC_OPTIMIZATION_LEVEL = 0; 166 | GCC_PREPROCESSOR_DEFINITIONS = ( 167 | "DEBUG=1", 168 | "$(inherited)", 169 | ); 170 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 171 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 172 | GCC_WARN_UNDECLARED_SELECTOR = YES; 173 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 174 | GCC_WARN_UNUSED_FUNCTION = YES; 175 | GCC_WARN_UNUSED_VARIABLE = YES; 176 | MACOSX_DEPLOYMENT_TARGET = 10.11; 177 | MTL_ENABLE_DEBUG_INFO = YES; 178 | ONLY_ACTIVE_ARCH = YES; 179 | SDKROOT = macosx; 180 | }; 181 | name = Debug; 182 | }; 183 | E23329DB1DF092AD0002B4FE /* Release */ = { 184 | isa = XCBuildConfiguration; 185 | buildSettings = { 186 | ALWAYS_SEARCH_USER_PATHS = NO; 187 | CLANG_ANALYZER_NONNULL = YES; 188 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 189 | CLANG_CXX_LIBRARY = "libc++"; 190 | CLANG_ENABLE_MODULES = YES; 191 | CLANG_ENABLE_OBJC_ARC = YES; 192 | CLANG_WARN_BOOL_CONVERSION = YES; 193 | CLANG_WARN_CONSTANT_CONVERSION = YES; 194 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 195 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 196 | CLANG_WARN_EMPTY_BODY = YES; 197 | CLANG_WARN_ENUM_CONVERSION = YES; 198 | CLANG_WARN_INFINITE_RECURSION = YES; 199 | CLANG_WARN_INT_CONVERSION = YES; 200 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | CODE_SIGN_IDENTITY = "-"; 206 | COPY_PHASE_STRIP = NO; 207 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 208 | ENABLE_NS_ASSERTIONS = NO; 209 | ENABLE_STRICT_OBJC_MSGSEND = YES; 210 | GCC_C_LANGUAGE_STANDARD = gnu99; 211 | GCC_NO_COMMON_BLOCKS = YES; 212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 214 | GCC_WARN_UNDECLARED_SELECTOR = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 216 | GCC_WARN_UNUSED_FUNCTION = YES; 217 | GCC_WARN_UNUSED_VARIABLE = YES; 218 | MACOSX_DEPLOYMENT_TARGET = 10.11; 219 | MTL_ENABLE_DEBUG_INFO = NO; 220 | SDKROOT = macosx; 221 | }; 222 | name = Release; 223 | }; 224 | E23329DD1DF092AD0002B4FE /* Debug */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | COMBINE_HIDPI_IMAGES = YES; 228 | INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; 229 | INSTALL_PATH = /; 230 | PRODUCT_BUNDLE_IDENTIFIER = ca.derivative.cpp.CPlusPlusCHOPExample; 231 | PRODUCT_NAME = "$(TARGET_NAME)"; 232 | WRAPPER_EXTENSION = plugin; 233 | }; 234 | name = Debug; 235 | }; 236 | E23329DE1DF092AD0002B4FE /* Release */ = { 237 | isa = XCBuildConfiguration; 238 | buildSettings = { 239 | COMBINE_HIDPI_IMAGES = YES; 240 | INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; 241 | INSTALL_PATH = /; 242 | PRODUCT_BUNDLE_IDENTIFIER = ca.derivative.cpp.CPlusPlusCHOPExample; 243 | PRODUCT_NAME = "$(TARGET_NAME)"; 244 | WRAPPER_EXTENSION = plugin; 245 | }; 246 | name = Release; 247 | }; 248 | /* End XCBuildConfiguration section */ 249 | 250 | /* Begin XCConfigurationList section */ 251 | E23329D11DF092AD0002B4FE /* Build configuration list for PBXProject "CPlusPlusCHOPExample" */ = { 252 | isa = XCConfigurationList; 253 | buildConfigurations = ( 254 | E23329DA1DF092AD0002B4FE /* Debug */, 255 | E23329DB1DF092AD0002B4FE /* Release */, 256 | ); 257 | defaultConfigurationIsVisible = 0; 258 | defaultConfigurationName = Release; 259 | }; 260 | E23329DC1DF092AD0002B4FE /* Build configuration list for PBXNativeTarget "CPlusPlusCHOPExample" */ = { 261 | isa = XCConfigurationList; 262 | buildConfigurations = ( 263 | E23329DD1DF092AD0002B4FE /* Debug */, 264 | E23329DE1DF092AD0002B4FE /* Release */, 265 | ); 266 | defaultConfigurationIsVisible = 0; 267 | defaultConfigurationName = Release; 268 | }; 269 | /* End XCConfigurationList section */ 270 | }; 271 | rootObject = E23329CE1DF092AD0002B4FE /* Project object */; 272 | } 273 | -------------------------------------------------------------------------------- /CPlusPlusCHOPExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CPlusPlus_Common.h: -------------------------------------------------------------------------------- 1 | /* Shared Use License: This file is owned by Derivative Inc. (Derivative) 2 | * and can only be used, and/or modified for use, in conjunction with 3 | * Derivative's TouchDesigner software, and only if you are a licensee who has 4 | * accepted Derivative's TouchDesigner license or assignment agreement 5 | * (which also govern the use of this file). You may share or redistribute 6 | * a modified version of this file provided the following conditions are met: 7 | * 8 | * 1. The shared file or redistribution must retain the information set out 9 | * above and this list of conditions. 10 | * 2. Derivative's name (Derivative Inc.) or its trademarks may not be used 11 | * to endorse or promote products derived from this file without specific 12 | * prior written permission from Derivative. 13 | */ 14 | 15 | /******* 16 | Derivative Developers: Make sure the virtual function order 17 | stays the same, otherwise changes won't be backwards compatible 18 | ********/ 19 | 20 | 21 | #ifndef __CPlusPlus_Common 22 | #define __CPlusPlus_Common 23 | 24 | 25 | #ifdef _WIN32 26 | #define NOMINMAX 27 | #include 28 | #include 29 | #include "GL_Extensions.h" 30 | #define DLLEXPORT __declspec (dllexport) 31 | #else 32 | #include 33 | #define DLLEXPORT 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifndef PyObject_HEAD 41 | struct _object; 42 | typedef _object PyObject; 43 | #endif 44 | 45 | struct cudaArray; 46 | 47 | enum class OP_CPUMemPixelType : int32_t 48 | { 49 | // 8-bit per color, BGRA pixels. This is preferred for 4 channel 8-bit data 50 | BGRA8Fixed = 0, 51 | // 8-bit per color, RGBA pixels. Only use this one if absolutely nesseary. 52 | RGBA8Fixed, 53 | // 32-bit float per color, RGBA pixels 54 | RGBA32Float, 55 | 56 | // A few single and two channel versions of the above 57 | R8Fixed, 58 | RG8Fixed, 59 | R32Float, 60 | RG32Float, 61 | 62 | R16Fixed = 100, 63 | RG16Fixed, 64 | RGBA16Fixed, 65 | 66 | R16Float = 200, 67 | RG16Float, 68 | RGBA16Float, 69 | }; 70 | 71 | class OP_String; 72 | 73 | // Used to describe this Plugin so it can be used as a custom OP. 74 | // Can be filled in as part of the Fill*PluginInfo() callback 75 | class OP_CustomOPInfo 76 | { 77 | public: 78 | // For this plugin to be treated as a Custom OP, all of the below fields 79 | // must be filled in correctly. Otherwise the .dll can only be used 80 | // when manually loaded into the C++ TOP 81 | 82 | // The type name of the node, this needs to be unique from all the other 83 | // TOP plugins loaded on the system. The name must start with an upper case 84 | // character (A-Z), and the rest should be lower case 85 | // Only the characters a-z and 0-9 are allowed in the opType. 86 | // Spaces are not allowed 87 | OP_String* opType; 88 | 89 | // The english readable label for the node. This is what is shown in the 90 | // OP Create Menu dialog. 91 | // Spaces and other special characters are allowed. 92 | // This can be a UTF-8 encoded string for non-english langauge label 93 | OP_String* opLabel; 94 | 95 | // This should be three letters (upper or lower case), or numbers, which 96 | // are used to create an icon for this Custom OP. 97 | OP_String* opIcon; 98 | 99 | // The minimum number of wired inputs required for this OP to function. 100 | int32_t minInputs = 0; 101 | 102 | // The maximum number of connected inputs allowed for this OP. If this plugin 103 | // always requires 1 input, then set both min and max to 1. 104 | int32_t maxInputs = 0; 105 | 106 | // The name of the author 107 | OP_String* authorName; 108 | 109 | // The email of the author 110 | OP_String* authorEmail; 111 | 112 | // Major version should be used to differentiate between drastically different 113 | // versions of this Custom OP. In particular changes that arn't backwards 114 | // compatible. 115 | // A project file will compare the major version of OPs saved in it with the 116 | // major version of the plugin installed on the system, and expect them to be 117 | // the same. 118 | int32_t majorVersion = 0; 119 | 120 | // Minor version is used to denote upgrades to a plugin. It should be increased 121 | // when new features are added to a plugin that would cause loading up a project 122 | // with an older version of the plguin to behavior incorrectly. For example 123 | // if new parameters are added to the plugin. 124 | // A project file will expect the plugin installed on the system to be greater than 125 | // or equal to the plugin version the project was created with. Assuming 126 | // the majorVersion is the same. 127 | int32_t minorVersion = 1; 128 | 129 | // If this Custom OP is using CPython objects (PyObject* etc.) obtained via 130 | // getParPython() calls, this needs to be set to the Python 131 | // version this plugin is compiled against. 132 | // 133 | // This ensures when TD's Python version is upgraded the plugins will 134 | // error cleanly. This should be set to PY_VERSION as defined in 135 | // patchlevel.h from the Python include folder. (E.g, "3.5.1") 136 | // It should be left unchanged if CPython isn't being used in this plugin. 137 | OP_String* pythonVersion; 138 | 139 | int32_t reserved[98]; 140 | }; 141 | 142 | 143 | class OP_NodeInfo 144 | { 145 | public: 146 | 147 | // The full path to the operator 148 | const char* opPath; 149 | 150 | // A unique ID representing the operator, no two operators will ever 151 | // have the same ID in a single TouchDesigner instance. 152 | uint32_t opId; 153 | 154 | // This is the handle to the main TouchDesigner window. 155 | // It's possible this will be 0 the first few times the operator cooks, 156 | // incase it cooks while TouchDesigner is still loading up 157 | #ifdef _WIN32 158 | HWND mainWindowHandle; 159 | #endif 160 | 161 | // The path to where the plugin's binary is located on this machine. 162 | // UTF8-8 encoded. 163 | const char* pluginPath; 164 | 165 | int32_t reserved[17]; 166 | }; 167 | 168 | 169 | class OP_DATInput 170 | { 171 | public: 172 | const char* opPath; 173 | uint32_t opId; 174 | 175 | int32_t numRows; 176 | int32_t numCols; 177 | bool isTable; 178 | 179 | // data, referenced by (row,col), which will be a const char* for the 180 | // contents of the cell 181 | // E.g getCell(1,2) will be the contents of the cell located at (1,2) 182 | // The string will be in UTF-8 encoding. 183 | const char* 184 | getCell(int32_t row, int32_t col) const 185 | { 186 | return cellData[row * numCols + col]; 187 | } 188 | 189 | const char** cellData; 190 | 191 | // The number of times this node has cooked 192 | int64_t totalCooks; 193 | 194 | int32_t reserved[18]; 195 | }; 196 | 197 | 198 | class OP_TOPInput 199 | { 200 | public: 201 | const char* opPath; 202 | uint32_t opId; 203 | 204 | int32_t width; 205 | int32_t height; 206 | 207 | // You can use OP_Inputs::getTOPDataInCPUMemory() to download the 208 | // data from a TOP input into CPU memory easily. 209 | 210 | // The OpenGL Texture index for this TOP. 211 | // This is only valid when accessed from C++ TOPs. 212 | // Other C++ OPs will have this value set to 0 (invalid). 213 | GLuint textureIndex; 214 | 215 | // The OpenGL Texture target for this TOP. 216 | // E.g GL_TEXTURE_2D, GL_TEXTURE_CUBE, 217 | // GL_TEXTURE_2D_ARRAY 218 | GLenum textureType; 219 | 220 | // Depth for 3D and 2D_ARRAY textures, undefined 221 | // for other texture types 222 | uint32_t depth; 223 | 224 | // contains the internalFormat for the texture 225 | // such as GL_RGBA8, GL_RGBA32F, GL_R16 226 | GLint pixelFormat; 227 | 228 | int32_t reserved1; 229 | 230 | // When the TOP_ExecuteMode is CUDA, this will be filled in 231 | cudaArray* cudaInput; 232 | 233 | // The number of times this node has cooked 234 | int64_t totalCooks; 235 | 236 | int32_t reserved[14]; 237 | }; 238 | 239 | class OP_String 240 | { 241 | protected: 242 | OP_String() 243 | { 244 | } 245 | 246 | virtual ~OP_String() 247 | { 248 | } 249 | 250 | public: 251 | 252 | // val is expected to be UTF-8 encoded 253 | virtual void setString(const char* val) = 0; 254 | 255 | 256 | int32_t reserved[20]; 257 | 258 | }; 259 | 260 | 261 | class OP_CHOPInput 262 | { 263 | public: 264 | 265 | const char* opPath; 266 | uint32_t opId; 267 | 268 | int32_t numChannels; 269 | int32_t numSamples; 270 | double sampleRate; 271 | double startIndex; 272 | 273 | 274 | 275 | // Retrieve a float array for a specific channel. 276 | // 'i' ranges from 0 to numChannels-1 277 | // The returned arrray contains 'numSamples' samples. 278 | // e.g: getChannelData(1)[10] will refer to the 11th sample in the 2nd channel 279 | 280 | const float* 281 | getChannelData(int32_t i) const 282 | { 283 | return channelData[i]; 284 | } 285 | 286 | 287 | // Retrieve the name of a specific channel. 288 | // 'i' ranges from 0 to numChannels-1 289 | // For example getChannelName(1) is the name of the 2nd channel 290 | 291 | const char* 292 | getChannelName(int32_t i) const 293 | { 294 | return nameData[i]; 295 | } 296 | 297 | const float** channelData; 298 | const char** nameData; 299 | 300 | // The number of times this node has cooked 301 | int64_t totalCooks; 302 | 303 | int32_t reserved[18]; 304 | }; 305 | 306 | 307 | class OP_ObjectInput 308 | { 309 | public: 310 | 311 | const char* opPath; 312 | uint32_t opId; 313 | 314 | // Use these methods to calculate object transforms 315 | double worldTransform[4][4]; 316 | double localTransform[4][4]; 317 | 318 | // The number of times this node has cooked 319 | int64_t totalCooks; 320 | 321 | int32_t reserved[18]; 322 | }; 323 | 324 | 325 | // The type of data the attribute holds 326 | enum class AttribType : int32_t 327 | { 328 | // One or more floats 329 | Float = 0, 330 | 331 | // One or more integers 332 | Int, 333 | }; 334 | 335 | // Right now we only support point attributes. 336 | enum class AttribSet : int32_t 337 | { 338 | Invalid, 339 | Point = 0, 340 | }; 341 | 342 | // The type of the primitives, currently only Polygon type 343 | // is supported 344 | enum class PrimitiveType : int32_t 345 | { 346 | Invalid, 347 | Polygon = 0, 348 | }; 349 | 350 | 351 | class Vector 352 | { 353 | public: 354 | Vector() 355 | { 356 | x = 0.0f; 357 | y = 0.0f; 358 | z = 0.0f; 359 | } 360 | 361 | Vector(float xx, float yy, float zz) 362 | { 363 | x = xx; 364 | y = yy; 365 | z = zz; 366 | } 367 | 368 | // inplace operators 369 | inline Vector& 370 | operator*=(const float scalar) 371 | { 372 | x *= scalar; 373 | y *= scalar; 374 | z *= scalar; 375 | return *this; 376 | } 377 | 378 | inline Vector& 379 | operator/=(const float scalar) 380 | { 381 | x /= scalar; 382 | y /= scalar; 383 | z /= scalar; 384 | return *this; 385 | } 386 | 387 | inline Vector& 388 | operator-=(const Vector& trans) 389 | { 390 | x -= trans.x; 391 | y -= trans.y; 392 | z -= trans.z; 393 | return *this; 394 | } 395 | 396 | inline Vector& 397 | operator+=(const Vector& trans) 398 | { 399 | x += trans.x; 400 | y += trans.y; 401 | z += trans.z; 402 | return *this; 403 | } 404 | 405 | // non-inplace operations: 406 | inline Vector 407 | operator*(const float scalar) 408 | { 409 | Vector temp(*this); 410 | temp.x *= scalar; 411 | temp.y *= scalar; 412 | temp.z *= scalar; 413 | return temp; 414 | } 415 | 416 | inline Vector 417 | operator/(const float scalar) 418 | { 419 | Vector temp(*this); 420 | temp.x /= scalar; 421 | temp.y /= scalar; 422 | temp.z /= scalar; 423 | return temp; 424 | } 425 | 426 | inline Vector 427 | operator-(const Vector& trans) 428 | { 429 | Vector temp(*this); 430 | temp.x -= trans.x; 431 | temp.y -= trans.y; 432 | temp.z -= trans.z; 433 | return temp; 434 | } 435 | 436 | inline Vector 437 | operator+(const Vector& trans) 438 | { 439 | Vector temp(*this); 440 | temp.x += trans.x; 441 | temp.y += trans.y; 442 | temp.z += trans.z; 443 | return temp; 444 | } 445 | 446 | //------ 447 | float 448 | dot(const Vector &v) const 449 | { 450 | return x * v.x + y * v.y + z * v.z; 451 | } 452 | 453 | inline float 454 | length() 455 | { 456 | return sqrtf(dot(*this)); 457 | } 458 | 459 | inline float 460 | normalize() 461 | { 462 | float dn = x * x + y * y + z * z; 463 | if (dn > FLT_MIN && dn != 1.0F) 464 | { 465 | dn = sqrtf(dn); 466 | (*this) /= dn; 467 | } 468 | return dn; 469 | } 470 | 471 | float x; 472 | float y; 473 | float z; 474 | }; 475 | 476 | class Position 477 | { 478 | public: 479 | Position() 480 | { 481 | x = 0.0f; 482 | y = 0.0f; 483 | z = 0.0f; 484 | } 485 | 486 | Position(float xx, float yy, float zz) 487 | { 488 | x = xx; 489 | y = yy; 490 | z = zz; 491 | } 492 | 493 | // in-place operators 494 | inline Position& operator*=(const float scalar) 495 | { 496 | x *= scalar; 497 | y *= scalar; 498 | z *= scalar; 499 | return *this; 500 | } 501 | 502 | inline Position& operator/=(const float scalar) 503 | { 504 | x /= scalar; 505 | y /= scalar; 506 | z /= scalar; 507 | return *this; 508 | } 509 | 510 | inline Position& operator-=(const Vector& trans) 511 | { 512 | x -= trans.x; 513 | y -= trans.y; 514 | z -= trans.z; 515 | return *this; 516 | } 517 | 518 | inline Position& operator+=(const Vector& trans) 519 | { 520 | x += trans.x; 521 | y += trans.y; 522 | z += trans.z; 523 | return *this; 524 | } 525 | 526 | // non-inplace operators 527 | inline Position operator*(const float scalar) 528 | { 529 | Position temp(*this); 530 | temp.x *= scalar; 531 | temp.y *= scalar; 532 | temp.z *= scalar; 533 | return temp; 534 | } 535 | 536 | inline Position operator/(const float scalar) 537 | { 538 | Position temp(*this); 539 | temp.x /= scalar; 540 | temp.y /= scalar; 541 | temp.z /= scalar; 542 | return temp; 543 | } 544 | 545 | inline Position operator+(const Vector& trans) 546 | { 547 | Position temp(*this); 548 | temp.x += trans.x; 549 | temp.y += trans.y; 550 | temp.z += trans.z; 551 | return temp; 552 | } 553 | 554 | inline Position operator-(const Vector& trans) 555 | { 556 | Position temp(*this); 557 | temp.x -= trans.x; 558 | temp.y -= trans.y; 559 | temp.z -= trans.z; 560 | return temp; 561 | } 562 | 563 | float x; 564 | float y; 565 | float z; 566 | }; 567 | 568 | 569 | class Color 570 | { 571 | public: 572 | Color () 573 | { 574 | r = 1.0f; 575 | g = 1.0f; 576 | b = 1.0f; 577 | a = 1.0f; 578 | } 579 | 580 | Color (float rr, float gg, float bb, float aa) 581 | { 582 | r = rr; 583 | g = gg; 584 | b = bb; 585 | a = aa; 586 | } 587 | 588 | float r; 589 | float g; 590 | float b; 591 | float a; 592 | }; 593 | 594 | 595 | class TexCoord 596 | { 597 | public: 598 | TexCoord() 599 | { 600 | u = 0.0f; 601 | v = 0.0f; 602 | w = 0.0f; 603 | } 604 | 605 | TexCoord(float uu, float vv, float ww) 606 | { 607 | u = uu; 608 | v = vv; 609 | w = ww; 610 | } 611 | 612 | float u; 613 | float v; 614 | float w; 615 | }; 616 | 617 | class BoundingBox 618 | { 619 | public: 620 | BoundingBox(float minx, float miny, float minz, 621 | float maxx, float maxy, float maxz) : 622 | minX(minx), minY(miny), minZ(minz), maxX(maxx), maxY(maxy), maxZ(maxz) 623 | { 624 | } 625 | 626 | BoundingBox(const Position& min, const Position& max) 627 | { 628 | minX = min.x; 629 | maxX = max.x; 630 | minY = min.y; 631 | maxY = max.y; 632 | minZ = min.z; 633 | maxZ = max.z; 634 | } 635 | 636 | BoundingBox(const Position& center, float x, float y, float z) 637 | { 638 | minX = center.x - x; 639 | maxX = center.x + x; 640 | minY = center.y - y; 641 | maxY = center.y + y; 642 | minZ = center.z - z; 643 | maxZ = center.z + z; 644 | } 645 | 646 | // enlarge the bounding box by the input point Position 647 | void 648 | enlargeBounds(const Position& pos) 649 | { 650 | if (pos.x < minX) 651 | minX = pos.x; 652 | if (pos.x > maxX) 653 | maxX = pos.x; 654 | if (pos.y < minY) 655 | minY = pos.y; 656 | if (pos.y > maxY) 657 | maxY = pos.y; 658 | if (pos.z < minZ) 659 | minZ = pos.z; 660 | if (pos.z > maxZ) 661 | maxZ = pos.z; 662 | } 663 | 664 | // enlarge the bounding box by the input bounding box: 665 | void 666 | enlargeBounds(const BoundingBox &box) 667 | { 668 | if (box.minX < minX) 669 | minX = box.minX; 670 | if (box.maxX > maxX) 671 | maxX = box.maxX; 672 | if (box.minY < minY) 673 | minY = box.minY; 674 | if (box.maxY > maxY) 675 | maxY = box.maxY; 676 | if (box.minZ < minZ) 677 | minZ = box.minZ; 678 | if (box.maxZ > maxZ) 679 | maxZ = box.maxZ; 680 | } 681 | 682 | // returns the bounding box length in x axis: 683 | float 684 | sizeX() 685 | { 686 | return maxX - minX; 687 | } 688 | 689 | // returns the bounding box length in y axis: 690 | float 691 | sizeY() 692 | { 693 | return maxY - minY; 694 | } 695 | 696 | // returns the bounding box length in z axis: 697 | float 698 | sizeZ() 699 | { 700 | return maxZ - minZ; 701 | } 702 | 703 | bool 704 | getCenter(Position* pos) 705 | { 706 | if (!pos) 707 | return false; 708 | pos->x = (minX + maxX) / 2.0f; 709 | pos->y = (minY + maxY) / 2.0f; 710 | pos->z = (minZ + maxZ) / 2.0f; 711 | return true; 712 | } 713 | 714 | // verifies if the input position (pos) is inside the current bounding box or not: 715 | bool 716 | isInside(const Position& pos) 717 | { 718 | if (pos.x >= minX && pos.x <= maxX && 719 | pos.y >= minY && pos.y <= maxY && 720 | pos.z >= minZ && pos.z <= maxZ) 721 | return true; 722 | else 723 | return false; 724 | } 725 | 726 | 727 | float minX; 728 | float minY; 729 | float minZ; 730 | 731 | float maxX; 732 | float maxY; 733 | float maxZ; 734 | 735 | }; 736 | 737 | 738 | class SOP_NormalInfo 739 | { 740 | public: 741 | 742 | SOP_NormalInfo() 743 | { 744 | numNormals = 0; 745 | attribSet = AttribSet::Point; 746 | normals = nullptr; 747 | } 748 | 749 | int32_t numNormals; 750 | AttribSet attribSet; 751 | const Vector* normals; 752 | }; 753 | 754 | class SOP_ColorInfo 755 | { 756 | public: 757 | 758 | SOP_ColorInfo() 759 | { 760 | numColors = 0; 761 | attribSet = AttribSet::Point; 762 | colors = nullptr; 763 | } 764 | 765 | int32_t numColors; 766 | AttribSet attribSet; 767 | const Color* colors; 768 | }; 769 | 770 | class SOP_TextureInfo 771 | { 772 | public: 773 | 774 | SOP_TextureInfo() 775 | { 776 | numTextures = 0; 777 | attribSet = AttribSet::Point; 778 | textures = nullptr; 779 | numTextureLayers = 0; 780 | } 781 | 782 | int32_t numTextures; 783 | AttribSet attribSet; 784 | const TexCoord* textures; 785 | int32_t numTextureLayers; 786 | }; 787 | 788 | 789 | 790 | // CustomAttribInfo, all the required data for each custom attribute 791 | // this info can be queried by calling getCustomAttribute() which accepts 792 | // two types of argument: 793 | // 1) a valid index of a custom attribute 794 | // 2) a valid name of a custom attribute 795 | class SOP_CustomAttribInfo 796 | { 797 | public: 798 | 799 | SOP_CustomAttribInfo() 800 | { 801 | name = nullptr; 802 | numComponents = 0; 803 | attribType = AttribType::Float; 804 | } 805 | 806 | SOP_CustomAttribInfo(const char* n, int32_t numComp, AttribType type) 807 | { 808 | name = n; 809 | numComponents = numComp; 810 | attribType = type; 811 | } 812 | 813 | const char* name; 814 | int32_t numComponents; 815 | AttribType attribType; 816 | }; 817 | 818 | // SOP_CustomAttribData, all the required data for each custom attribute 819 | // this info can be queried by calling getCustomAttribute() which accepts 820 | // a valid name of a custom attribute 821 | class SOP_CustomAttribData : public SOP_CustomAttribInfo 822 | { 823 | public: 824 | 825 | SOP_CustomAttribData() 826 | { 827 | floatData = nullptr; 828 | intData = nullptr; 829 | } 830 | 831 | SOP_CustomAttribData(const char* n, int32_t numComp, AttribType type) : 832 | SOP_CustomAttribInfo(n, numComp, type) 833 | { 834 | floatData = nullptr; 835 | intData = nullptr; 836 | } 837 | 838 | const float* floatData; 839 | const int32_t* intData; 840 | 841 | }; 842 | 843 | // SOP_PrimitiveInfo, all the required data for each primitive 844 | // this info can be queried by calling getPrimitive() which accepts 845 | // a valid index of a primitive as an input argument 846 | class SOP_PrimitiveInfo 847 | { 848 | public: 849 | 850 | SOP_PrimitiveInfo() 851 | { 852 | pointIndices = nullptr; 853 | numVertices = 0; 854 | type = PrimitiveType::Invalid; 855 | pointIndicesOffset = 0; 856 | } 857 | 858 | // number of vertices of this prim 859 | int32_t numVertices; 860 | 861 | // all the indices of the vertices of the primitive. This array has 862 | // numVertices entries in it 863 | const int32_t* pointIndices; 864 | 865 | // The type of this primitive 866 | PrimitiveType type; 867 | 868 | // the offset of the this primitive's point indices in the index array 869 | // returned from getAllPrimPointIndices() 870 | int32_t pointIndicesOffset; 871 | 872 | }; 873 | 874 | 875 | 876 | 877 | class OP_SOPInput 878 | { 879 | public: 880 | 881 | virtual ~OP_SOPInput() 882 | { 883 | } 884 | 885 | 886 | 887 | const char* opPath; 888 | uint32_t opId; 889 | 890 | 891 | // Returns the total number of points 892 | virtual int32_t getNumPoints() const = 0; 893 | 894 | // The total number of vertices, across all primitives. 895 | virtual int32_t getNumVertices() const = 0; 896 | 897 | // The total number of primitives 898 | virtual int32_t getNumPrimitives() const = 0; 899 | 900 | // The total number of custom attributes 901 | virtual int32_t getNumCustomAttributes() const = 0; 902 | 903 | // Returns an array of point positions. This array is getNumPoints() long. 904 | virtual const Position* getPointPositions() const = 0; 905 | 906 | // Returns an array of normals. 907 | // 908 | // Returns nullptr if no normals are present 909 | virtual const SOP_NormalInfo* getNormals() const = 0; 910 | 911 | // Returns an array of colors. 912 | // Returns nullptr if no colors are present 913 | virtual const SOP_ColorInfo* getColors() const = 0; 914 | 915 | // Returns an array of texture coordinates. 916 | // If multiple texture coordinate layers are present, they will be placed 917 | // interleaved back-to-back. 918 | // E.g layer0 followed by layer1 followed by layer0 etc. 919 | // 920 | // Returns nullptr if no texture layers are present 921 | virtual const SOP_TextureInfo* getTextures() const = 0; 922 | 923 | // Returns the custom attribute data with an input index 924 | virtual const SOP_CustomAttribData* getCustomAttribute(int32_t customAttribIndex) const = 0; 925 | 926 | // Returns the custom attribute data with its name 927 | virtual const SOP_CustomAttribData* getCustomAttribute(const char* customAttribName) const = 0; 928 | 929 | // Returns true if the SOP has a normal attribute of the given source 930 | // attribute 'N' 931 | virtual bool hasNormals() const = 0; 932 | 933 | // Returns true if the SOP has a color the given source 934 | // attribute 'Cd' 935 | virtual bool hasColors() const = 0; 936 | 937 | // Returns the SOP_PrimitiveInfo with primIndex 938 | const SOP_PrimitiveInfo 939 | getPrimitive(int32_t primIndex) const 940 | { 941 | return myPrimsInfo[primIndex]; 942 | } 943 | 944 | // Returns the full list of all the point indices for all primitives. 945 | // The primitives are stored back to back in this array. 946 | const int32_t* 947 | getAllPrimPointIndices() 948 | { 949 | return myPrimPointIndices; 950 | } 951 | 952 | SOP_PrimitiveInfo* myPrimsInfo; 953 | const int32_t* myPrimPointIndices; 954 | 955 | // The number of times this node has cooked 956 | int64_t totalCooks; 957 | 958 | int32_t reserved[98]; 959 | }; 960 | 961 | 962 | 963 | enum class OP_TOPInputDownloadType : int32_t 964 | { 965 | // The texture data will be downloaded and and available on the next frame. 966 | // Except for the first time this is used, getTOPDataInCPUMemory() 967 | // will return the texture data on the CPU from the previous frame. 968 | // The first getTOPDataInCPUMemory() is called it will be nullptr. 969 | // ** This mode should be used is most cases for performance reasons ** 970 | Delayed = 0, 971 | 972 | // The texture data will be downloaded immediately and be available 973 | // this frame. This can cause a large stall though and should be avoided 974 | // in most cases 975 | Instant, 976 | }; 977 | 978 | class OP_TOPInputDownloadOptions 979 | { 980 | public: 981 | OP_TOPInputDownloadOptions() 982 | { 983 | downloadType = OP_TOPInputDownloadType::Delayed; 984 | verticalFlip = false; 985 | cpuMemPixelType = OP_CPUMemPixelType::BGRA8Fixed; 986 | } 987 | 988 | OP_TOPInputDownloadType downloadType; 989 | 990 | // Set this to true if you want the image vertically flipped in the 991 | // downloaded data 992 | bool verticalFlip; 993 | 994 | // Set this to how you want the pixel data to be give to you in CPU 995 | // memory. BGRA8Fixed should be used for 4 channel 8-bit data if possible 996 | OP_CPUMemPixelType cpuMemPixelType; 997 | 998 | }; 999 | 1000 | class OP_TimeInfo 1001 | { 1002 | public: 1003 | 1004 | // same as global Python value absTime.frame. Counts up forever 1005 | // since the application started. In rootFPS units. 1006 | int64_t absFrame; 1007 | 1008 | // The timeline frame number for this cook 1009 | double frame; 1010 | 1011 | // The timeline FPS/rate this node is cooking at. 1012 | // If the component this node is located in has Component Time, it's FPS 1013 | // may be different than the Root FPS 1014 | double rate; 1015 | 1016 | // The frame number for the root timeline. Different than frame 1017 | // if the node is in a component that has component time. 1018 | double rootFrame; 1019 | 1020 | // The Root FPS/Rate the file is running at. 1021 | double rootRate; 1022 | 1023 | // The number of frames that have elapsed since the last cook occured. 1024 | // This can be more than one if frames were dropped. 1025 | // If this is the first time this node is cooking, this will be 0.0 1026 | // This is in 'rate' units, not 'rootRate' units. 1027 | double deltaFrames; 1028 | 1029 | // The number of milliseconds that have elapsed since the last cook. 1030 | // Note that this isn't done via CPU timers, but is instead 1031 | // simply deltaFrames * milliSecondsPerFrame 1032 | double deltaMS; 1033 | 1034 | 1035 | 1036 | int32_t reserved[40]; 1037 | }; 1038 | 1039 | 1040 | class OP_Inputs 1041 | { 1042 | public: 1043 | // NOTE: When writting a TOP, none of these functions should 1044 | // be called inside a beginGLCommands()/endGLCommands() section 1045 | // as they may require GL themselves to complete execution. 1046 | 1047 | // Inputs that are wired into the node. Note that since some inputs 1048 | // may not be connected this number doesn't mean that that the first N 1049 | // inputs are connected. For example on a 3 input node if the 3rd input 1050 | // is only one connected, this will return 1, and getInput*(0) and (1) 1051 | // will return nullptr. 1052 | virtual int32_t getNumInputs() const = 0; 1053 | 1054 | // Will return nullptr when the input has nothing connected to it. 1055 | // only valid for C++ TOP operators 1056 | virtual const OP_TOPInput* getInputTOP(int32_t index) const = 0; 1057 | // Only valid for C++ CHOP operators 1058 | virtual const OP_CHOPInput* getInputCHOP(int32_t index) const = 0; 1059 | // getInputSOP() declared later on in the class 1060 | // getInputDAT() declared later on in the class 1061 | 1062 | // these are defined by parameters. 1063 | // may return nullptr when invalid input 1064 | // this value is valid until the parameters are rebuilt or it is called with the same parameter name. 1065 | virtual const OP_DATInput* getParDAT(const char *name) const = 0; 1066 | virtual const OP_TOPInput* getParTOP(const char *name) const = 0; 1067 | virtual const OP_CHOPInput* getParCHOP(const char *name) const = 0; 1068 | virtual const OP_ObjectInput* getParObject(const char *name) const = 0; 1069 | // getParSOP() declared later on in the class 1070 | 1071 | // these work on any type of parameter and can be interchanged 1072 | // for menu types, int returns the menu selection index, string returns the item 1073 | 1074 | // returns the requested value, index may be 0 to 4. 1075 | virtual double getParDouble(const char* name, int32_t index = 0) const = 0; 1076 | 1077 | // for multiple values: returns True on success/false otherwise 1078 | virtual bool getParDouble2(const char* name, double &v0, double &v1) const = 0; 1079 | virtual bool getParDouble3(const char* name, double &v0, double &v1, double &v2) const = 0; 1080 | virtual bool getParDouble4(const char* name, double &v0, double &v1, double &v2, double &v3) const = 0; 1081 | 1082 | 1083 | // returns the requested value 1084 | virtual int32_t getParInt(const char* name, int32_t index = 0) const = 0; 1085 | 1086 | // for multiple values: returns True on success/false otherwise 1087 | virtual bool getParInt2(const char* name, int32_t &v0, int32_t &v1) const = 0; 1088 | virtual bool getParInt3(const char* name, int32_t &v0, int32_t &v1, int32_t &v2) const = 0; 1089 | virtual bool getParInt4(const char* name, int32_t &v0, int32_t &v1, int32_t &v2, int32_t &v3) const = 0; 1090 | 1091 | // returns the requested value 1092 | // this value is valid until the parameters are rebuilt or it is called with the same parameter name. 1093 | // return value usable for life of parameter 1094 | // The returned string will be in UTF-8 encoding. 1095 | virtual const char* getParString(const char* name) const = 0; 1096 | 1097 | 1098 | // this is similar to getParString, but will return an absolute path if it exists, with 1099 | // slash direction consistent with O/S requirements. 1100 | // to get the original parameter value, use getParString 1101 | // return value usable for life of parameter 1102 | // The returned string will be in UTF-8 encoding. 1103 | virtual const char* getParFilePath(const char* name) const = 0; 1104 | 1105 | // returns true on success 1106 | // from_name and to_name must be Object parameters 1107 | virtual bool getRelativeTransform(const char* from_name, const char* to_name, double matrix[4][4]) const = 0; 1108 | 1109 | 1110 | // disable or enable updating of the parameter 1111 | virtual void enablePar(const char* name, bool onoff) const = 0; 1112 | 1113 | 1114 | // these are defined by paths. 1115 | // may return nullptr when invalid input 1116 | // this value is valid until the parameters are rebuilt or it is called with the same parameter name. 1117 | virtual const OP_DATInput* getDAT(const char *path) const = 0; 1118 | virtual const OP_TOPInput* getTOP(const char *path) const = 0; 1119 | virtual const OP_CHOPInput* getCHOP(const char *path) const = 0; 1120 | virtual const OP_ObjectInput* getObject(const char *path) const = 0; 1121 | 1122 | 1123 | // This function can be used to retrieve the TOPs texture data in CPU 1124 | // memory. You must pass the OP_TOPInput object you get from 1125 | // getParTOP/getInputTOP into this, not a copy you've made 1126 | // 1127 | // Fill in a OP_TOPIputDownloadOptions class with the desired options set 1128 | // 1129 | // Returns the data, which will be valid until the end of execute() 1130 | // Returned value may be nullptr in some cases, such as the first call 1131 | // to this with options->downloadType == OP_TOP_DOWNLOAD_DELAYED. 1132 | virtual void* getTOPDataInCPUMemory(const OP_TOPInput *top, 1133 | const OP_TOPInputDownloadOptions *options) const = 0; 1134 | 1135 | 1136 | virtual const OP_SOPInput* getParSOP(const char *name) const = 0; 1137 | // only valid for C++ SOP operators 1138 | virtual const OP_SOPInput* getInputSOP(int32_t index) const = 0; 1139 | virtual const OP_SOPInput* getSOP(const char *path) const = 0; 1140 | 1141 | // only valid for C++ DAT operators 1142 | virtual const OP_DATInput* getInputDAT(int32_t index) const = 0; 1143 | 1144 | // To use Python in your Plugin you need to fill the 1145 | // customOPInfo.pythonVersion member in Fill*PluginInfo. 1146 | // 1147 | // The returned object, if not null should have its reference count decremented 1148 | // or else a memorky leak will occur. 1149 | virtual PyObject* getParPython(const char* name) const = 0; 1150 | 1151 | 1152 | // Returns a class whose members gives you information about timing 1153 | // such as FPS and delta-time since the last cook. 1154 | // See OP_TimeInfo for more information 1155 | virtual const OP_TimeInfo* getTimeInfo() const = 0; 1156 | 1157 | }; 1158 | 1159 | class OP_InfoCHOPChan 1160 | { 1161 | public: 1162 | OP_String* name; 1163 | float value; 1164 | 1165 | int32_t reserved[10]; 1166 | }; 1167 | 1168 | 1169 | class OP_InfoDATSize 1170 | { 1171 | public: 1172 | 1173 | // Set this to the size you want the table to be 1174 | 1175 | int32_t rows; 1176 | int32_t cols; 1177 | 1178 | // Set this to true if you want to return DAT entries on a column 1179 | // by column basis. 1180 | // Otherwise set to false, and you'll be expected to set them on 1181 | // a row by row basis. 1182 | // DEFAULT : false 1183 | 1184 | bool byColumn; 1185 | 1186 | int32_t reserved[10]; 1187 | }; 1188 | 1189 | 1190 | class OP_InfoDATEntries 1191 | { 1192 | public: 1193 | 1194 | // This is an array of OP_String* pointers which you are expected to assign 1195 | // values to. 1196 | // e.g values[1]->setString("myColumnName"); 1197 | // The string should be in UTF-8 encoding. 1198 | OP_String** values; 1199 | 1200 | int32_t reserved[10]; 1201 | }; 1202 | 1203 | 1204 | class OP_NumericParameter 1205 | { 1206 | public: 1207 | 1208 | OP_NumericParameter(const char* iname = nullptr) 1209 | { 1210 | name = iname; 1211 | label = page = nullptr; 1212 | 1213 | for (int i = 0; i<4; i++) 1214 | { 1215 | defaultValues[i] = 0.0; 1216 | 1217 | minSliders[i] = 0.0; 1218 | maxSliders[i] = 1.0; 1219 | 1220 | minValues[i] = 0.0; 1221 | maxValues[i] = 1.0; 1222 | 1223 | clampMins[i] = false; 1224 | clampMaxes[i] = false; 1225 | } 1226 | } 1227 | 1228 | // Any char* values passed are copied immediately by the append parameter functions, 1229 | // and do not need to be retained by the calling function. 1230 | // Must begin with capital letter, and contain no spaces 1231 | const char* name; 1232 | const char* label; 1233 | const char* page; 1234 | 1235 | double defaultValues[4]; 1236 | double minValues[4]; 1237 | double maxValues[4]; 1238 | 1239 | bool clampMins[4]; 1240 | bool clampMaxes[4]; 1241 | 1242 | double minSliders[4]; 1243 | double maxSliders[4]; 1244 | 1245 | int32_t reserved[20]; 1246 | 1247 | }; 1248 | 1249 | 1250 | class OP_StringParameter 1251 | { 1252 | public: 1253 | 1254 | OP_StringParameter(const char* iname = nullptr) 1255 | { 1256 | name = iname; 1257 | label = page = nullptr; 1258 | defaultValue = nullptr; 1259 | } 1260 | 1261 | // Any char* values passed are copied immediately by the append parameter functions, 1262 | // and do not need to be retained by the calling function. 1263 | 1264 | // Must begin with capital letter, and contain no spaces 1265 | const char* name; 1266 | const char* label; 1267 | const char* page; 1268 | 1269 | // This should be in UTF-8 encoding. 1270 | const char* defaultValue; 1271 | 1272 | int32_t reserved[20]; 1273 | }; 1274 | 1275 | 1276 | enum class OP_ParAppendResult : int32_t 1277 | { 1278 | Success = 0, 1279 | InvalidName, // invalid or duplicate name 1280 | InvalidSize, // size out of range 1281 | }; 1282 | 1283 | 1284 | class OP_ParameterManager 1285 | { 1286 | 1287 | public: 1288 | 1289 | // Returns PARAMETER_APPEND_SUCCESS on succesful 1290 | 1291 | virtual OP_ParAppendResult appendFloat(const OP_NumericParameter &np, int32_t size = 1) = 0; 1292 | virtual OP_ParAppendResult appendInt(const OP_NumericParameter &np, int32_t size = 1) = 0; 1293 | 1294 | virtual OP_ParAppendResult appendXY(const OP_NumericParameter &np) = 0; 1295 | virtual OP_ParAppendResult appendXYZ(const OP_NumericParameter &np) = 0; 1296 | 1297 | virtual OP_ParAppendResult appendUV(const OP_NumericParameter &np) = 0; 1298 | virtual OP_ParAppendResult appendUVW(const OP_NumericParameter &np) = 0; 1299 | 1300 | virtual OP_ParAppendResult appendRGB(const OP_NumericParameter &np) = 0; 1301 | virtual OP_ParAppendResult appendRGBA(const OP_NumericParameter &np) = 0; 1302 | 1303 | virtual OP_ParAppendResult appendToggle(const OP_NumericParameter &np) = 0; 1304 | virtual OP_ParAppendResult appendPulse(const OP_NumericParameter &np) = 0; 1305 | 1306 | virtual OP_ParAppendResult appendString(const OP_StringParameter &sp) = 0; 1307 | virtual OP_ParAppendResult appendFile(const OP_StringParameter &sp) = 0; 1308 | virtual OP_ParAppendResult appendFolder(const OP_StringParameter &sp) = 0; 1309 | 1310 | virtual OP_ParAppendResult appendDAT(const OP_StringParameter &sp) = 0; 1311 | virtual OP_ParAppendResult appendCHOP(const OP_StringParameter &sp) = 0; 1312 | virtual OP_ParAppendResult appendTOP(const OP_StringParameter &sp) = 0; 1313 | virtual OP_ParAppendResult appendObject(const OP_StringParameter &sp) = 0; 1314 | // appendSOP() located further down in the class 1315 | 1316 | 1317 | // Any char* values passed are copied immediately by the append parameter functions, 1318 | // and do not need to be retained by the calling function. 1319 | virtual OP_ParAppendResult appendMenu(const OP_StringParameter &sp, 1320 | int32_t nitems, const char **names, 1321 | const char **labels) = 0; 1322 | 1323 | // Any char* values passed are copied immediately by the append parameter functions, 1324 | // and do not need to be retained by the calling function. 1325 | virtual OP_ParAppendResult appendStringMenu(const OP_StringParameter &sp, 1326 | int32_t nitems, const char **names, 1327 | const char **labels) = 0; 1328 | 1329 | virtual OP_ParAppendResult appendSOP(const OP_StringParameter &sp) = 0; 1330 | 1331 | // To use Python in your Plugin you need to fill the 1332 | // customOPInfo.pythonVersion member in Fill*PluginInfo. 1333 | virtual OP_ParAppendResult appendPython(const OP_StringParameter &sp) = 0; 1334 | 1335 | 1336 | }; 1337 | 1338 | static_assert(offsetof(OP_CustomOPInfo, opType) == 0, "Incorrect Alignment"); 1339 | static_assert(offsetof(OP_CustomOPInfo, opLabel) == 8, "Incorrect Alignment"); 1340 | static_assert(offsetof(OP_CustomOPInfo, opIcon) == 16, "Incorrect Alignment"); 1341 | static_assert(offsetof(OP_CustomOPInfo, minInputs) == 24, "Incorrect Alignment"); 1342 | static_assert(offsetof(OP_CustomOPInfo, maxInputs) == 28, "Incorrect Alignment"); 1343 | static_assert(offsetof(OP_CustomOPInfo, authorName) == 32, "Incorrect Alignment"); 1344 | static_assert(offsetof(OP_CustomOPInfo, authorEmail) == 40, "Incorrect Alignment"); 1345 | static_assert(offsetof(OP_CustomOPInfo, majorVersion) == 48, "Incorrect Alignment"); 1346 | static_assert(offsetof(OP_CustomOPInfo, minorVersion) == 52, "Incorrect Alignment"); 1347 | static_assert(sizeof(OP_CustomOPInfo) == 456, "Incorrect Size"); 1348 | 1349 | static_assert(offsetof(OP_NodeInfo, opPath) == 0, "Incorrect Alignment"); 1350 | static_assert(offsetof(OP_NodeInfo, opId) == 8, "Incorrect Alignment"); 1351 | #ifdef _WIN32 1352 | static_assert(offsetof(OP_NodeInfo, mainWindowHandle) == 16, "Incorrect Alignment"); 1353 | static_assert(sizeof(OP_NodeInfo) == 104, "Incorrect Size"); 1354 | #else 1355 | static_assert(sizeof(OP_NodeInfo) == 96, "Incorrect Size"); 1356 | #endif 1357 | 1358 | static_assert(offsetof(OP_DATInput, opPath) == 0, "Incorrect Alignment"); 1359 | static_assert(offsetof(OP_DATInput, opId) == 8, "Incorrect Alignment"); 1360 | static_assert(offsetof(OP_DATInput, numRows) == 12, "Incorrect Alignment"); 1361 | static_assert(offsetof(OP_DATInput, numCols) == 16, "Incorrect Alignment"); 1362 | static_assert(offsetof(OP_DATInput, isTable) == 20, "Incorrect Alignment"); 1363 | static_assert(offsetof(OP_DATInput, cellData) == 24, "Incorrect Alignment"); 1364 | static_assert(offsetof(OP_DATInput, totalCooks) == 32, "Incorrect Alignment"); 1365 | static_assert(sizeof(OP_DATInput) == 112, "Incorrect Size"); 1366 | 1367 | static_assert(offsetof(OP_TOPInput, opPath) == 0, "Incorrect Alignment"); 1368 | static_assert(offsetof(OP_TOPInput, opId) == 8, "Incorrect Alignment"); 1369 | static_assert(offsetof(OP_TOPInput, width) == 12, "Incorrect Alignment"); 1370 | static_assert(offsetof(OP_TOPInput, height) == 16, "Incorrect Alignment"); 1371 | static_assert(offsetof(OP_TOPInput, textureIndex) == 20, "Incorrect Alignment"); 1372 | static_assert(offsetof(OP_TOPInput, textureType) == 24, "Incorrect Alignment"); 1373 | static_assert(offsetof(OP_TOPInput, depth) == 28, "Incorrect Alignment"); 1374 | static_assert(offsetof(OP_TOPInput, pixelFormat) == 32, "Incorrect Alignment"); 1375 | static_assert(offsetof(OP_TOPInput, cudaInput) == 40, "Incorrect Alignment"); 1376 | static_assert(offsetof(OP_TOPInput, totalCooks) == 48, "Incorrect Alignment"); 1377 | static_assert(sizeof(OP_TOPInput) == 112, "Incorrect Size"); 1378 | 1379 | static_assert(offsetof(OP_CHOPInput, opPath) == 0, "Incorrect Alignment"); 1380 | static_assert(offsetof(OP_CHOPInput, opId) == 8, "Incorrect Alignment"); 1381 | static_assert(offsetof(OP_CHOPInput, numChannels) == 12, "Incorrect Alignment"); 1382 | static_assert(offsetof(OP_CHOPInput, numSamples) == 16, "Incorrect Alignment"); 1383 | static_assert(offsetof(OP_CHOPInput, sampleRate) == 24, "Incorrect Alignment"); 1384 | static_assert(offsetof(OP_CHOPInput, startIndex) == 32, "Incorrect Alignment"); 1385 | static_assert(offsetof(OP_CHOPInput, channelData) == 40, "Incorrect Alignment"); 1386 | static_assert(offsetof(OP_CHOPInput, nameData) == 48, "Incorrect Alignment"); 1387 | static_assert(offsetof(OP_CHOPInput, totalCooks) == 56, "Incorrect Alignment"); 1388 | static_assert(sizeof(OP_CHOPInput) == 136, "Incorrect Size"); 1389 | 1390 | static_assert(offsetof(OP_ObjectInput, opPath) == 0, "Incorrect Alignment"); 1391 | static_assert(offsetof(OP_ObjectInput, opId) == 8, "Incorrect Alignment"); 1392 | static_assert(offsetof(OP_ObjectInput, worldTransform) == 16, "Incorrect Alignment"); 1393 | static_assert(offsetof(OP_ObjectInput, localTransform) == 144, "Incorrect Alignment"); 1394 | static_assert(offsetof(OP_ObjectInput, totalCooks) == 272, "Incorrect Alignment"); 1395 | static_assert(sizeof(OP_ObjectInput) == 352, "Incorrect Size"); 1396 | 1397 | static_assert(offsetof(Position, x) == 0, "Incorrect Alignment"); 1398 | static_assert(offsetof(Position, y) == 4, "Incorrect Alignment"); 1399 | static_assert(offsetof(Position, z) == 8, "Incorrect Alignment"); 1400 | static_assert(sizeof(Position) == 12, "Incorrect Size"); 1401 | 1402 | static_assert(offsetof(Vector, x) == 0, "Incorrect Alignment"); 1403 | static_assert(offsetof(Vector, y) == 4, "Incorrect Alignment"); 1404 | static_assert(offsetof(Vector, z) == 8, "Incorrect Alignment"); 1405 | static_assert(sizeof(Vector) == 12, "Incorrect Size"); 1406 | 1407 | static_assert(offsetof(Color, r) == 0, "Incorrect Alignment"); 1408 | static_assert(offsetof(Color, g) == 4, "Incorrect Alignment"); 1409 | static_assert(offsetof(Color, b) == 8, "Incorrect Alignment"); 1410 | static_assert(offsetof(Color, a) == 12, "Incorrect Alignment"); 1411 | static_assert(sizeof(Color) == 16, "Incorrect Size"); 1412 | 1413 | static_assert(offsetof(TexCoord, u) == 0, "Incorrect Alignment"); 1414 | static_assert(offsetof(TexCoord, v) == 4, "Incorrect Alignment"); 1415 | static_assert(offsetof(TexCoord, w) == 8, "Incorrect Alignment"); 1416 | static_assert(sizeof(TexCoord) == 12, "Incorrect Size"); 1417 | 1418 | static_assert(offsetof(SOP_NormalInfo, numNormals) == 0, "Incorrect Alignment"); 1419 | static_assert(offsetof(SOP_NormalInfo, attribSet) == 4, "Incorrect Alignment"); 1420 | static_assert(offsetof(SOP_NormalInfo, normals) == 8, "Incorrect Alignment"); 1421 | static_assert(sizeof(SOP_NormalInfo) == 16, "Incorrect Size"); 1422 | 1423 | static_assert(offsetof(SOP_ColorInfo, numColors) == 0, "Incorrect Alignment"); 1424 | static_assert(offsetof(SOP_ColorInfo, attribSet) == 4, "Incorrect Alignment"); 1425 | static_assert(offsetof(SOP_ColorInfo, colors) == 8, "Incorrect Alignment"); 1426 | static_assert(sizeof(SOP_ColorInfo) == 16, "Incorrect Size"); 1427 | 1428 | static_assert(offsetof(SOP_TextureInfo, numTextures) == 0, "Incorrect Alignment"); 1429 | static_assert(offsetof(SOP_TextureInfo, attribSet) == 4, "Incorrect Alignment"); 1430 | static_assert(offsetof(SOP_TextureInfo, textures) == 8, "Incorrect Alignment"); 1431 | static_assert(offsetof(SOP_TextureInfo, numTextureLayers) == 16, "Incorrect Alignment"); 1432 | static_assert(sizeof(SOP_TextureInfo) == 24, "Incorrect Size"); 1433 | 1434 | static_assert(offsetof(SOP_CustomAttribData, name) == 0, "Incorrect Alignment"); 1435 | static_assert(offsetof(SOP_CustomAttribData, numComponents) == 8, "Incorrect Alignment"); 1436 | static_assert(offsetof(SOP_CustomAttribData, attribType) == 12, "Incorrect Alignment"); 1437 | static_assert(offsetof(SOP_CustomAttribData, floatData) == 16, "Incorrect Alignment"); 1438 | static_assert(offsetof(SOP_CustomAttribData, intData) == 24, "Incorrect Alignment"); 1439 | static_assert(sizeof(SOP_CustomAttribData) == 32, "Incorrect Size"); 1440 | 1441 | static_assert(offsetof(SOP_PrimitiveInfo, numVertices) == 0, "Incorrect Alignment"); 1442 | static_assert(offsetof(SOP_PrimitiveInfo, pointIndices) == 8, "Incorrect Alignment"); 1443 | static_assert(offsetof(SOP_PrimitiveInfo, type) == 16, "Incorrect Alignment"); 1444 | static_assert(offsetof(SOP_PrimitiveInfo, pointIndicesOffset) == 20, "Incorrect Alignment"); 1445 | static_assert(sizeof(SOP_PrimitiveInfo) == 24, "Incorrect Size"); 1446 | 1447 | static_assert(sizeof(OP_SOPInput) == 440, "Incorrect Size"); 1448 | 1449 | static_assert(offsetof(OP_TOPInputDownloadOptions, downloadType) == 0, "Incorrect Alignment"); 1450 | static_assert(offsetof(OP_TOPInputDownloadOptions, verticalFlip) == 4, "Incorrect Alignment"); 1451 | static_assert(offsetof(OP_TOPInputDownloadOptions, cpuMemPixelType) == 8, "Incorrect Alignment"); 1452 | static_assert(sizeof(OP_TOPInputDownloadOptions) == 12, "Incorrect Size"); 1453 | 1454 | static_assert(offsetof(OP_InfoCHOPChan, name) == 0, "Incorrect Alignment"); 1455 | static_assert(offsetof(OP_InfoCHOPChan, value) == 8, "Incorrect Alignment"); 1456 | static_assert(sizeof(OP_InfoCHOPChan) == 56, "Incorrect Size"); 1457 | 1458 | static_assert(offsetof(OP_InfoDATSize, rows) == 0, "Incorrect Alignment"); 1459 | static_assert(offsetof(OP_InfoDATSize, cols) == 4, "Incorrect Alignment"); 1460 | static_assert(offsetof(OP_InfoDATSize, byColumn) == 8, "Incorrect Alignment"); 1461 | static_assert(sizeof(OP_InfoDATSize) == 52, "Incorrect Size"); 1462 | 1463 | static_assert(offsetof(OP_InfoDATEntries, values) == 0, "Incorrect Alignment"); 1464 | static_assert(sizeof(OP_InfoDATEntries) == 48, "Incorrect Size"); 1465 | 1466 | static_assert(offsetof(OP_NumericParameter, name) == 0, "Incorrect Alignment"); 1467 | static_assert(offsetof(OP_NumericParameter, label) == 8, "Incorrect Alignment"); 1468 | static_assert(offsetof(OP_NumericParameter, page) == 16, "Incorrect Alignment"); 1469 | static_assert(offsetof(OP_NumericParameter, defaultValues) == 24, "Incorrect Alignment"); 1470 | static_assert(offsetof(OP_NumericParameter, minValues) == 56, "Incorrect Alignment"); 1471 | static_assert(offsetof(OP_NumericParameter, maxValues) == 88, "Incorrect Alignment"); 1472 | static_assert(offsetof(OP_NumericParameter, clampMins) == 120, "Incorrect Alignment"); 1473 | static_assert(offsetof(OP_NumericParameter, clampMaxes) == 124, "Incorrect Alignment"); 1474 | static_assert(offsetof(OP_NumericParameter, minSliders) == 128, "Incorrect Alignment"); 1475 | static_assert(offsetof(OP_NumericParameter, maxSliders) == 160, "Incorrect Alignment"); 1476 | static_assert(sizeof(OP_NumericParameter) == 272, "Incorrect Size"); 1477 | 1478 | static_assert(offsetof(OP_StringParameter, name) == 0, "Incorrect Alignment"); 1479 | static_assert(offsetof(OP_StringParameter, label) == 8, "Incorrect Alignment"); 1480 | static_assert(offsetof(OP_StringParameter, page) == 16, "Incorrect Alignment"); 1481 | static_assert(offsetof(OP_StringParameter, defaultValue) == 24, "Incorrect Alignment"); 1482 | static_assert(sizeof(OP_StringParameter) == 112, "Incorrect Size"); 1483 | static_assert(sizeof(OP_TimeInfo) == 216, "Incorrect Size"); 1484 | #endif 1485 | -------------------------------------------------------------------------------- /GL_Extensions.h: -------------------------------------------------------------------------------- 1 | // Stub file for simpler CHOP usage than an OpenGLTOP 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | NSHumanReadableCopyright 22 | Copyright © 2016 Derivative. All rights reserved. 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 David Braun 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PhaserCHOP.cpp: -------------------------------------------------------------------------------- 1 | /* Shared Use License: This file is owned by Derivative Inc. (Derivative) and 2 | * can only be used, and/or modified for use, in conjunction with 3 | * Derivative's TouchDesigner software, and only if you are a licensee who has 4 | * accepted Derivative's TouchDesigner license or assignment agreement (which 5 | * also govern the use of this file). You may share a modified version of this 6 | * file with another authorized licensee of Derivative's TouchDesigner software. 7 | * Otherwise, no redistribution or sharing of this file, with or without 8 | * modification, is permitted. 9 | */ 10 | 11 | #include "PhaserCHOP.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include // std::max 20 | 21 | 22 | // These functions are basic C function, which the DLL loader can find 23 | // much easier than finding a C++ Class. 24 | // The DLLEXPORT prefix is needed so the compile exports these functions from the .dll 25 | // you are creating 26 | extern "C" 27 | { 28 | 29 | DLLEXPORT 30 | void 31 | FillCHOPPluginInfo(CHOP_PluginInfo* info) 32 | { 33 | // Always set this to CHOPCPlusPlusAPIVersion. 34 | info->apiVersion = CHOPCPlusPlusAPIVersion; 35 | 36 | // The opType is the unique name for this CHOP. It must start with a 37 | // capital A-Z character, and all the following characters must lower case 38 | // or numbers (a-z, 0-9) 39 | info->customOPInfo.opType->setString("Phaser"); 40 | 41 | // The opLabel is the text that will show up in the OP Create Dialog 42 | info->customOPInfo.opLabel->setString("Phaser CHOP"); 43 | 44 | // Information about the author of this OP 45 | info->customOPInfo.authorName->setString("David Braun"); 46 | info->customOPInfo.authorEmail->setString("github.com/DBraun"); 47 | 48 | // This CHOP can work with 0 inputs. 49 | info->customOPInfo.minInputs = 0; 50 | 51 | // It can accept up to 3 inputs. Each is optional. 52 | info->customOPInfo.maxInputs = 3; 53 | } 54 | 55 | DLLEXPORT 56 | CHOP_CPlusPlusBase* 57 | CreateCHOPInstance(const OP_NodeInfo* info) 58 | { 59 | // Return a new instance of your class every time this is called. 60 | // It will be called once per CHOP that is using the .dll 61 | return new PhaserCHOP(info); 62 | } 63 | 64 | DLLEXPORT 65 | void 66 | DestroyCHOPInstance(CHOP_CPlusPlusBase* instance) 67 | { 68 | // Delete the instance here, this will be called when 69 | // Touch is shutting down, when the CHOP using that instance is deleted, or 70 | // if the CHOP loads a different DLL 71 | delete (PhaserCHOP*)instance; 72 | } 73 | 74 | }; 75 | 76 | 77 | PhaserCHOP::PhaserCHOP(const OP_NodeInfo* info) : myNodeInfo(info), myRamp(0.) 78 | { 79 | } 80 | 81 | PhaserCHOP::~PhaserCHOP() 82 | { 83 | } 84 | 85 | void 86 | PhaserCHOP::getGeneralInfo(CHOP_GeneralInfo* ginfo, const OP_Inputs* inputs, void* reserved1) 87 | { 88 | ginfo->cookEveryFrameIfAsked = true; 89 | ginfo->timeslice = false; 90 | ginfo->inputMatchIndex = 1; 91 | } 92 | 93 | bool 94 | PhaserCHOP::getOutputInfo(CHOP_OutputInfo* info, const OP_Inputs* inputs, void* reserved1) 95 | { 96 | const OP_CHOPInput* phaseInput = inputs->getInputCHOP(1); 97 | 98 | PHASER_OutputFormat myOutputFormat = (PHASER_OutputFormat)inputs->getParDouble("Outputformat"); 99 | 100 | switch (myOutputFormat) 101 | { 102 | case PHASER_OutputFormat::Invalid: 103 | myError = "Invalid Output Format"; 104 | return false; 105 | break; 106 | case PHASER_OutputFormat::Onechannel: 107 | if (phaseInput) { 108 | // return false and copy the samples/channels of the phaseInput 109 | return false; 110 | } 111 | else { 112 | info->numChannels = 1; 113 | info->numSamples = inputs->getParDouble("Nsamples"); 114 | info->startIndex = 0; 115 | //info->sampleRate = 60.f; // todo sample rate 116 | return true; 117 | } 118 | break; 119 | case PHASER_OutputFormat::Multichannels: 120 | // swap samples to channels and channels to samples 121 | if (phaseInput) { 122 | info->numChannels = phaseInput->numSamples; 123 | info->numSamples = phaseInput->numChannels; 124 | info->startIndex = phaseInput->startIndex; 125 | } 126 | else { 127 | // swap samples to channels and channels to samples 128 | info->numChannels = inputs->getParDouble("Nsamples"); 129 | info->numSamples = 1; 130 | info->startIndex = 0; 131 | //info->sampleRate = 60.f; // todo sample rate 132 | } 133 | return true; 134 | break; 135 | default: 136 | myError = "Unexpected Output Format"; 137 | return false; 138 | break; 139 | } 140 | } 141 | 142 | void 143 | PhaserCHOP::getChannelName(int32_t index, OP_String* name, const OP_Inputs* inputs, void* reserved1) 144 | { 145 | name->setString("chan1"); 146 | } 147 | 148 | float 149 | PhaserCHOP::clamp(double val, double lower, double upper) 150 | { 151 | return val <= lower ? lower : val >= upper ? upper : val; 152 | // return std::max(std::min(val, upper), lower); // alternative equivalent version 153 | } 154 | 155 | // An alternative easing function. 156 | // A typical easing function called "ease" takes a value "t" from [0,1] and returns another value [0,1] 157 | // where ease(0)=0, ease(1)=1. 158 | // Imagine we have multiple unique objects that are being animated from 0 to 1 and then processed through "ease". 159 | // We may want to stagger the way in which these objects go through "ease", and this is why we use the "phaser" function. 160 | // Phaser takes an additional argument called "phase", which is from [0,1]. A value of 1 corresponds to an animated object that 161 | // "ahead of the pack"; It will start animating before others. A value of 0 for phase corresponds to an object that is late; It 162 | // will be the last to start moving. The "edge" parameter describes the cohesiveness of the pack of animated objects; A small value 163 | // will cause the objects to go through the animation very differently, or very sharply. A small value is a sharper edge. 164 | // The output of the phaser function will be [0,1], so these values can then be passed to any other easing function, perhaps "smoothstep", 165 | // or "ease-in-out". 166 | float 167 | PhaserCHOP::phaser(double t, double _phase, double edge) 168 | { 169 | // safety checks because phase must be [0-1]. 170 | float phase = clamp(_phase, 0., 1.); 171 | // but we will assume t has been clamped to [0,1] before entering this function. 172 | // We will also assume edge is greater than and not equal to 0. 173 | 174 | // smaller edge corresponds to sharper separation according 175 | // to differences in phase 176 | return clamp((-1. + phase + t*(1. + edge)) / edge, 0., 1.); 177 | } 178 | 179 | void 180 | PhaserCHOP::execute(CHOP_Output* output, 181 | const OP_Inputs* inputs, 182 | void* reserved) 183 | { 184 | // remove errors 185 | myError = ""; 186 | 187 | myRamp = fmod(myRamp + (1. / 60.)/4., 1.); // basic LFO ramp over 4 seconds 188 | 189 | // Edge can't be zero. We'll rely on the Parameter settings to prevent this. 190 | double Edge = inputs->getParDouble("Edge"); 191 | Edge = std::max(smallestDouble, Edge); 192 | int numInputs = inputs->getNumInputs(); 193 | 194 | const OP_CHOPInput* timeInput = inputs->getInputCHOP(0); 195 | const OP_CHOPInput* phaseInput = inputs->getInputCHOP(1); 196 | const OP_CHOPInput* edgeInput = inputs->getInputCHOP(2); 197 | 198 | bool canGetEdge = false; 199 | if (edgeInput && edgeInput->numSamples > 0 && edgeInput->numChannels > 0) 200 | { 201 | canGetEdge = true; 202 | } 203 | 204 | double t = 0.; 205 | if (timeInput && timeInput->numChannels > 0 && timeInput->numSamples > 0) 206 | { 207 | // Get the latest sample in the time input because PhaserCHOP doesn't 208 | // yet support timeslicing. 209 | t = timeInput->getChannelData(0)[timeInput->numSamples - 1]; 210 | t = clamp(t, 0., 1.); 211 | } 212 | else 213 | { 214 | t = myRamp; 215 | } 216 | 217 | PHASER_OutputFormat myOutputFormat = (PHASER_OutputFormat)inputs->getParDouble("Outputformat"); 218 | 219 | int numChannels, numSamples; 220 | 221 | if (phaseInput) { 222 | numChannels = phaseInput->numChannels; 223 | numSamples = phaseInput->numSamples; 224 | } 225 | else { 226 | numChannels = 1; 227 | numSamples = inputs->getParDouble("Nsamples"); 228 | } 229 | 230 | float phase = 0.f; 231 | float result = 0.f; 232 | 233 | for (int j = 0; j < numSamples; j++) 234 | { 235 | for (int i = 0; i < numChannels; i++) 236 | { 237 | if (canGetEdge) 238 | { 239 | Edge = edgeInput->getChannelData(std::min(i, edgeInput->numChannels-1))[std::min(j, edgeInput->numSamples - 1)]; 240 | 241 | // Edge must be greater than zero. 242 | Edge = std::max(smallestDouble, Edge); 243 | } 244 | 245 | if (phaseInput) 246 | { 247 | phase = phaseInput->getChannelData(i)[j]; 248 | } 249 | else 250 | { 251 | // Rely on the N samples parameter and make a descending ramp of phase samples. 252 | // Question: what if the ramp is only 1 sample? Then pick 0.5 rather than 0 or 1. 253 | phase = numSamples > 1 ? 1. - (double)j / (double)(numSamples - 1) : 0.5; 254 | } 255 | 256 | result = phaser(t, phase, Edge); 257 | 258 | switch (myOutputFormat) 259 | { 260 | case PHASER_OutputFormat::Invalid: 261 | // don't write to output. 262 | break; 263 | case PHASER_OutputFormat::Onechannel: 264 | output->channels[i][j] = result; 265 | break; 266 | case PHASER_OutputFormat::Multichannels: 267 | // swap samples to channels and channels to samples 268 | output->channels[j][i] = result; 269 | break; 270 | default: 271 | // don't write to output. 272 | break; 273 | } 274 | } 275 | } 276 | } 277 | 278 | int32_t 279 | PhaserCHOP::getNumInfoCHOPChans(void* reserved1) 280 | { 281 | return 0; 282 | } 283 | 284 | void 285 | PhaserCHOP::getInfoCHOPChan(int32_t index, 286 | OP_InfoCHOPChan* chan, 287 | void* reserved1) 288 | { 289 | } 290 | 291 | bool 292 | PhaserCHOP::getInfoDATSize(OP_InfoDATSize* infoSize, void* reserved1) 293 | { 294 | infoSize->rows = 0; 295 | infoSize->cols = 0; 296 | // Setting this to false means we'll be assigning values to the table 297 | // one row at a time. True means we'll do it one column at a time. 298 | infoSize->byColumn = false; 299 | return true; 300 | } 301 | 302 | void 303 | PhaserCHOP::getInfoDATEntries(int32_t index, 304 | int32_t nEntries, 305 | OP_InfoDATEntries* entries, 306 | void* reserved1) 307 | { 308 | } 309 | 310 | void 311 | PhaserCHOP::setupParameters(OP_ParameterManager* manager, void* reserved1) 312 | { 313 | // Edge 314 | { 315 | OP_NumericParameter np; 316 | 317 | np.name = "Edge"; 318 | np.label = "Edge"; 319 | np.defaultValues[0] = 1.0; 320 | np.minSliders[0] = smallestDouble; 321 | np.maxSliders[0] = 10.0; 322 | 323 | np.clampMins[0] = true; 324 | np.minValues[0] = smallestDouble; 325 | 326 | OP_ParAppendResult res = manager->appendFloat(np); 327 | assert(res == OP_ParAppendResult::Success); 328 | } 329 | 330 | // Number of samples: 331 | // This parameter only matters when phase samples isn't wired in. 332 | { 333 | OP_NumericParameter np; 334 | 335 | np.name = "Nsamples"; 336 | np.label = "N Samples"; 337 | np.defaultValues[0] = 10.0; 338 | np.minSliders[0] = 0; 339 | np.maxSliders[0] = 10.; 340 | 341 | np.clampMins[0] = true; 342 | np.minValues[0] = 0; 343 | 344 | OP_ParAppendResult res = manager->appendInt(np); 345 | assert(res == OP_ParAppendResult::Success); 346 | } 347 | 348 | // Output Format: 349 | // First option is do nothing and copy info of phase samples input. 350 | // Second option is equivalent to shuffle chop swap channels and samples. 351 | { 352 | OP_StringParameter sp; 353 | 354 | sp.name = "Outputformat"; 355 | sp.label = "Output Format"; 356 | 357 | sp.defaultValue = "Onechannel"; 358 | 359 | const char* names[] = { "Onechannel", "Multichannels" }; 360 | const char* labels[] = { "One Channel", "Multi-Channels" }; 361 | 362 | OP_ParAppendResult res = manager->appendMenu(sp, 2, names, labels); 363 | assert(res == OP_ParAppendResult::Success); 364 | } 365 | } 366 | 367 | void 368 | PhaserCHOP::pulsePressed(const char* name, void* reserved1) 369 | { 370 | } 371 | 372 | -------------------------------------------------------------------------------- /PhaserCHOP.h: -------------------------------------------------------------------------------- 1 | /* Shared Use License: This file is owned by Derivative Inc. (Derivative) and 2 | * can only be used, and/or modified for use, in conjunction with 3 | * Derivative's TouchDesigner software, and only if you are a licensee who has 4 | * accepted Derivative's TouchDesigner license or assignment agreement (which 5 | * also govern the use of this file). You may share a modified version of this 6 | * file with another authorized licensee of Derivative's TouchDesigner software. 7 | * Otherwise, no redistribution or sharing of this file, with or without 8 | * modification, is permitted. 9 | */ 10 | 11 | #include "CHOP_CPlusPlusBase.h" 12 | #include 13 | /* 14 | 15 | This example file implements a class that does 2 different things depending on 16 | if a CHOP is connected to the CPlusPlus CHOPs input or not. 17 | The example is timesliced, which is the more complex way of working. 18 | 19 | If an input is connected the node will output the same number of channels as the 20 | input and divide the first 'N' samples in the input channel by 2. 'N' being the current 21 | timeslice size. This is noteworthy because if the input isn't changing then the output 22 | will look wierd since depending on the timeslice size some number of the first samples 23 | of the input will get used. 24 | 25 | If no input is connected then the node will output a smooth sine wave at 120hz. 26 | */ 27 | 28 | 29 | // To get more help about these functions, look at CHOP_CPlusPlusBase.h 30 | class PhaserCHOP : public CHOP_CPlusPlusBase 31 | { 32 | public: 33 | PhaserCHOP(const OP_NodeInfo* info); 34 | virtual ~PhaserCHOP(); 35 | 36 | virtual void getGeneralInfo(CHOP_GeneralInfo*, const OP_Inputs*, void*) override; 37 | virtual bool getOutputInfo(CHOP_OutputInfo*, const OP_Inputs*, void*) override; 38 | virtual void getChannelName(int32_t index, OP_String* name, const OP_Inputs*, void* reserved) override; 39 | 40 | virtual void execute(CHOP_Output*, 41 | const OP_Inputs*, 42 | void* reserved) override; 43 | 44 | 45 | virtual int32_t getNumInfoCHOPChans(void* reserved1) override; 46 | virtual void getInfoCHOPChan(int32_t index, 47 | OP_InfoCHOPChan* chan, 48 | void* reserved1) override; 49 | 50 | virtual bool getInfoDATSize(OP_InfoDATSize* infoSize, void* resereved1) override; 51 | virtual void getInfoDATEntries(int32_t index, 52 | int32_t nEntries, 53 | OP_InfoDATEntries* entries, 54 | void* reserved1) override; 55 | 56 | virtual void setupParameters(OP_ParameterManager* manager, void* reserved1) override; 57 | virtual void pulsePressed(const char* name, void* reserved1) override; 58 | 59 | private: 60 | 61 | // We don't need to store this pointer, but we do for the example. 62 | // The OP_NodeInfo class store information about the node that's using 63 | // this instance of the class (like its name). 64 | const OP_NodeInfo* myNodeInfo; 65 | 66 | float clamp(double a, double theMin, double theMax); 67 | float phaser(double t, double phase, double theEdge); 68 | 69 | char* myError; 70 | 71 | const double smallestDouble = pow(2, -16); 72 | 73 | double myRamp = 0.; 74 | 75 | }; 76 | 77 | enum class PHASER_OutputFormat 78 | { 79 | Invalid = -1, 80 | Onechannel, 81 | Multichannels 82 | }; 83 | -------------------------------------------------------------------------------- /PhaserCHOP.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29102.190 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PhaserCHOP", "CPlusPlusCHOPExample.vcxproj", "{3F5BEECD-FA36-459F-91B8-BB481A67EF44}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3F5BEECD-FA36-459F-91B8-BB481A67EF44}.Debug|x64.ActiveCfg = Debug|x64 15 | {3F5BEECD-FA36-459F-91B8-BB481A67EF44}.Debug|x64.Build.0 = Debug|x64 16 | {3F5BEECD-FA36-459F-91B8-BB481A67EF44}.Release|x64.ActiveCfg = Release|x64 17 | {3F5BEECD-FA36-459F-91B8-BB481A67EF44}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {5026231E-B5A1-4FB4-BA2F-DA1DF2127D38} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /PhaserCHOP.toe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DBraun/PhaserCHOP/5f06605f0ac357a50269c0cb3d232de5ee48c5c0/PhaserCHOP.toe -------------------------------------------------------------------------------- /Plugins/.gitignore: -------------------------------------------------------------------------------- 1 | *.dll 2 | *.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [//]: # (For development of this README.md, use http://markdownlivepreview.com/) 2 | 3 | # PhaserCHOP 4 | 5 | ## Background 6 | 7 | Let's review a basic easing function often called "ease-in". 8 | ```glsl 9 | float easeIn(float pct) { 10 | return pct * pct; 11 | } 12 | ``` 13 | Note that `easeIn(0)==0` and `easeIn(1)==1`. This is a normal requirement of easing functions. You give it 0; you get 0. You give it 1; you get 1. All of the animation in between is up to you, either through keyframing or designing more [complex](https://github.com/glslify/glsl-easings/blob/master/bounce-out.glsl) [equations](https://en.wikipedia.org/wiki/Smoothstep#Generalization_to_higher-order_equations). 14 | 15 | What if we had a more generalized approach to easing where multiple items could go through the same easing animation but with staggered offsets or phases? This function should be easy to use and formatted like `easeIn`. The first input should be like `pct`. When this argument is 0, the function should return 0 no matter what, and when the argument is 1, it should return 1 no matter what. The next argument should represent the phase of an item as well as an overall "phase-separation-amount". And now... 16 | 17 | ## The Phaser GLSL Function 18 | ```glsl 19 | float phaser(float pct, float phase, float edge) { 20 | return clamp( (phase-1.+pct*(1.+edge))/edge, 0., 1.); 21 | } 22 | ``` 23 | 24 | * `pct`: [0,1] 25 | * `phase`: [0,1] 26 | * `edge`: (0, infinity] 27 | 28 | The properties of `phaser` can also be summed up like this: 29 | 30 | * When `pct` is 0, phaser returns 0, regardless of the other variables. 31 | * When `pct` is 1, phaser returns 1, regardless of the other variables. 32 | * All else equal, a larger `phase` causes phaser to return 1 sooner. 33 | * All else equal, a larger edge causes differences in phase to matter less. 34 | * All else equal, a smaller edge causes differences in phase to matter more. (Corollary to previous) 35 | * An infinitely large `edge` makes `phaser` equivalent to `clamp(pct, 0., 1.)` (a linear easing function with a clamp). However, the point of `phaser` is to *not* use an infinitely large edge. 36 | 37 | More thoroughly: 38 | 39 | * `pct` (short for "percent") is like the `pct` in `easeIn`. It should be between 0 and 1 inclusive. 40 | * For `phase`, imagine an animation function `f(pct)` and another `f(pct+phase)`. If `phase` is larger, the sample is further down the animation timeline. 41 | * For `edge`, imagine two different phase values `A` and `B` where `A`<`B`. Our `phaser` function will be called in parallel for both a phase `A` and a phase `B` for a shared time `pct`. These parallel output values of A and B will go from 0 to 1 but at different start times and end times. Imagine neither output of `A` or `B` has become non-zero. Because `B` has the larger phase, its output can move from 0 to 1 over a duration `D`. At exactly the moment `B` finishes by reaching 1, `A`'s output can begin to animate over the same duration `D`. Because `B` finishes at exactly the moment `A` begins, the difference between `A` and `B` is defined as the `edge` size. The trick of the phaser function is that we get to play with the constant `edge` parameter and the constant `phase` values rather than think about the `D` duration value. Instead of `D`, our timeline's overall duration comes from how long we take to animate `pct` from 0 to 1. 42 | 43 | ## How To Use PhaserCHOP in TouchDesigner 44 | 45 | The first input to PhaserCHOP is the `pct` from the GLSL function. **This is different from the first version of PhaserCHOP.** It should be one sample and one channel. Channels other than the first and samples other than the last will be ignored. When `pct` is 0, PhaserCHOP will return `0` for all input phase samples. When `pct` is 1, it will return `1` for all phase samples. Typically, you linearly bring `pct` from 0 to 1, but you could do it at different speeds or directions. 46 | 47 | The second input to the PhaserCHOP works as an N-channel list of S `phase` samples. N is often 1 but doesn't need to be. S can be very large. Although S can be as small as 1, you probably don't need the PhaserCHOP to animate only one sample. Most importantly, **the `phase` input typically does not need to animate/cook every frame.** You can swap it out an opportune times for different phases, like when `pct` is 0 or 1, but you probably shouldn't be animating it in a complicated way. 48 | 49 | The third input to PhaserCHOP is the `edge` parameter from the GLSL function. Typically you don't connect anything here. Instead you use the Custom Parameter `Edge` on the node itself. If you do want to wire into this third input, it should match the channels and samples of the phase input. If it doesn't exactly match, it will use as many samples/channels as possible before reusing the last channel or last sample. 50 | 51 | The first custom parameter is `Edge`, as explained earlier. It only matters if you don't wire a third input. 52 | 53 | The second custom parameter is `Nsamples`. If you don't provide a `phase` input, then the phase will automatically be a ramp from 1 to 0 with `Nsamples`-many samples. 54 | 55 | The third custom parameter is `Outputformat`, currently either "One Channel" or "Multi-Channel". One-channel is the default behavior, and Multi-Channel is like using a ShuffleCHOP to swap channels and samples. 56 | 57 | ## Instructions 58 | 59 | The PhaserCHOP is now a built-in operator: [https://docs.derivative.ca/Phaser_CHOP](https://docs.derivative.ca/Phaser_CHOP). Be sure to check out the examples in the [Op Snippets](https://docs.derivative.ca/OP_Snippets). 60 | 61 | To build the file yourself, open `PhaserCHOP.sln` and press `F5` in either Debug mode or Release Mode. A post-build event will copy the newly built DLL into `Plugins`. 62 | 63 | The `PhaserCHOP.toe` in this repo is mainly meant to be a unit test. For more interesting examples, check out [https://github.com/DBraun/PhaserCHOP-TD-Summit-Talk](https://github.com/DBraun/PhaserCHOP-TD-Summit-Talk) and David Braun's ["Quantitative Easing" 2019 TouchDesigner Summit Talk](https://www.youtube.com/watch?v=S4PQW4f34c8). 64 | 65 | ## Changelog 66 | * 2020-08-21 v2.0 **Breaking change: Phase and Time inputs have been swapped.** 67 | * 2020-06-15 More flexibility in using the third wired "edge" input. Better test cases in `.toe` file for extremely small `edge` values. Follow C++ style guide. 68 | * 2020-06-01 Better unit test `SmoothstepCHOP.toe` for Custom Operator. Build with `TouchDesigner 2020.22080`. Cleanup repo by removing non-custom operator. All releases are now on the [Releases](https://github.com/DBraun/PhaserCHOP/releases) page. 69 | * 2019-08-07 create a Custom Operator version for TD 2019.17550. 70 | * 2019-07-04 working version. 71 | 72 | ## Thanks 73 | * [Derivative, makers of TouchDesigner](http://derivative.ca) 74 | --------------------------------------------------------------------------------