Custom Modules

How to build custom HTPK modules

The file Scripts/ModuleSkeleton.cs contains a skeleton code that you can use as a guide. Each module involves 4 main classes: Model, Handler, ViewModel (nested class in Handler) and Controller.

Model

Include those variables that are relevant to Your module. Make sure that these variables do not already exist in any HPTKModel. If the information domain for Your module involves an Avatar, ProxyHand or Interactable object, include a reference to AvatarModel, ProxyHandModel or InteractableModel respectively. Let’s assume that we want to build a Your module. Then we will need to create YourModel, YourHandler, YourViewModel (nested in YourHandler) and YourController. If you need to extend a HPTKModel and you can't include the new information in YourModel, create a class that extends the HPTKModel that YourModel is referring to and include the variables you need there, this way it will be easier to maintain and combine with other projects.

Controller

If YourModel includes a reference to an HPTKModel with a relatedHandler field and you want other modules to be able to access YourHandler, you must register YourHandler in the list of relatedHandlers of the HPTKModel that is referred in YourModel. The Awake function in YourController initializes the ViewModel by passing YourModel to the ViewModel builder. Only the Controllers can access their Models directly. Thus, by sharing Handlers instead of Controllers, the ViewModel can only be accessed from outside the module.

Handler

Handler has no functions, only events and ViewModel. The information that can be accessed from a Handler should be, whenever possible, read-only.

Code architecture

The following image depicts the code architecture of a HPTK module:

Example

If you want to generate sound feedback according to the friction of a slave hand, you can calculate and store a friction value for the whole hand to be read by the sound engine. To calculate the friction value, you will need to access the Rigidbodies of one or more bones in the slave hand so YourModel should contain a reference to a ProxyHandModel which contains the references to the Rigidbodies of that slave hand. In the Start function of YourController you must register YourHandler in the ProxyHandModel.relatedHandlers list so that YourHandler is accessible to other modules from ProxyHandModel. Once YourController has calculated the friction value, it stores the value in YourModel. If you want other modules to be able to read this value, make it accessible via YourViewModel.

Last updated