### BallController.cs - Setup method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_AR_Football.md Sets the start and end positions for the ball's movement. ```csharp public void Setup(Vector3 startPos, Vector3 endPos) { endPosition = endPos; startPosition = startPos; } ``` -------------------------------- ### Full PyNuitrack example with face and skeleton drawing Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Complete example covering all PyNuitrack features. Requires OpenCV installed via `pip3 install opencv-python`. Press space to switch between color/depth mode, press ESC to exit. Includes commented lines to enable face tracking and device activation. ```python from PyNuitrack import py_nuitrack import cv2 from itertools import cycle import numpy as np def draw_face(image): if not data_instance: return for instance in data_instance["Instances"]: line_color = (59, 164, 225) text_color = (59, 255, 255) if 'face' in instance.keys(): bbox = instance["face"]["rectangle"] else: return x1 = (round(bbox["left"]), round(bbox["top"])) x2 = (round(bbox["left"]) + round(bbox["width"]), round(bbox["top"])) x3 = (round(bbox["left"]), round(bbox["top"]) + round(bbox["height"])) x4 = (round(bbox["left"]) + round(bbox["width"]), round(bbox["top"]) + round(bbox["height"])) cv2.line(image, x1, x2, line_color, 3) cv2.line(image, x1, x3, line_color, 3) cv2.line(image, x2, x4, line_color, 3) cv2.line(image, x3, x4, line_color, 3) cv2.putText(image, "User {}".format(instance["id"]), x1, cv2.FONT_HERSHEY_SIMPLEX, 1, text_color, 2, cv2.LINE_AA) cv2.putText(image, "{} {}".format(instance["face"]["gender"],int(instance["face"]["age"]["years"])), x3, cv2.FONT_HERSHEY_SIMPLEX, 1, text_color, 2, cv2.LINE_AA) def draw_skeleton(image): point_color = (59, 164, 0) w, h, _ = image.shape for skel in data.skeletons: for el in skel[1:]: x = (round(el.projection[0] * h), round(el.projection[1] * w)) cv2.circle(image, x, 8, point_color, -1) nuitrack = py_nuitrack.Nuitrack() nuitrack.init() # ---enable if you want to use face tracking--- # nuitrack.set_config_value("Faces.ToUse", "true") # nuitrack.set_config_value("DepthProvider.Depth2ColorRegistration", "true") devices = nuitrack.get_device_list() for i, dev in enumerate(devices): print(dev.get_name(), dev.get_serial_number()) if i == 0: #dev.activate("ACTIVATION_KEY") #you can activate device using python api print(dev.get_activation()) nuitrack.set_device(dev) print(nuitrack.get_version()) print(nuitrack.get_license()) nuitrack.create_modules() nuitrack.run() modes = cycle(["depth", "color"]) mode = next(modes) while 1: key = cv2.waitKey(1) nuitrack.update() data = nuitrack.get_skeleton() data_instance=nuitrack.get_instance() img_depth = nuitrack.get_depth_data() if img_depth.size: cv2.normalize(img_depth, img_depth, 0, 255, cv2.NORM_MINMAX) img_depth = np.array(cv2.cvtColor(img_depth,cv2.COLOR_GRAY2RGB), dtype=np.uint8) img_color = nuitrack.get_color_data() draw_skeleton(img_depth) draw_skeleton(img_color) draw_face(img_depth) draw_face(img_color) if key == 32: mode = next(modes) if mode == "depth": cv2.imshow('Image', img_depth) if mode == "color": if img_color.size: cv2.imshow('Image', img_color) if key == 27: break nuitrack.release() ``` -------------------------------- ### NetworkController.cs - Start and client/server initialization Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_AR_Football.md Starts the server if not a client. StartClient initializes network discovery and starts as client. StartServer initializes discovery, starts host, and spawns the environment. ```csharp private void Start() { // If it's not a client, create a server. if (isClient == false) { StartServer(); } } public void StartClient() { FindObjectOfType().Initialize(); FindObjectOfType().StartAsClient(); } void StartServer() { FindObjectOfType().Initialize(); FindObjectOfType().StartAsServer(); NetworkManager.singleton.StartHost(); GameObject environment = (GameObject)Instantiate(environmentPrefab); NetworkServer.Spawn(environment); } ``` -------------------------------- ### BallController.cs - Start method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_AR_Football.md Initializes the ball's Rigidbody, sets parent to Environment, resets local transform, and gets NetworkController reference. Destroys the ball after 7 seconds. ```csharp [SerializeField] GameObject ball; Vector3 startPosition; Vector3 endPosition; float ballSpeed = 3; Rigidbody rb; bool inGame = true; NetworkController networkController; void Start() { // Get a reference to the RigidBody component. rb = GetComponentInChildren(); // Destroy the ball in 7 seconds after Start. Destroy(gameObject, 7.0f); transform.parent = FindObjectOfType().transform; transform.localScale = Vector3.one; transform.localPosition = Vector3.zero; transform.localEulerAngles = Vector3.zero; ball.transform.localPosition = startPosition; networkController = FindObjectOfType(); } ``` -------------------------------- ### Start recording with T-Pose calibration event Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Animation_Recording.md In the Start method, subscribe to the T-Pose calibration completion event and initialize the recorder based on the selected record mode. Currently only Generic mode is handled. ```csharp void Start() { poseCalibration.onSuccess += PoseCalibration_onSuccess; switch (recordMode) { case RecordMode.Generic: recordable = new GenericRecorder(); break; } } ``` -------------------------------- ### Install Ubuntu dependencies for Nuitrack C# Device API sample Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_csharp_device_api_sample/README.txt Install required packages for building and running the C# sample on Ubuntu. ```bash sudo apt-get install mono-utils monodevelop ``` -------------------------------- ### Single-sensor Nuitrack initialization example Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Multiple_Depth_Sensors.md Shows the standard single-sensor setup before adapting to multiple sensors. Initializes Nuitrack, creates DepthSensor, ColorSensor, and SkeletonTracker, connects callbacks, runs the main loop, and releases Nuitrack. ```cpp Nuitrack::init(); DepthSensor::Ptr depthSensor = DepthSensor::create(); depthSensor->connectOnNewFrame(depthCallback); ColorSensor::Ptr colorSensor = ColorSensor::create(); colorSensor->connectOnNewFrame(colorCallback); SkeletonTracker::Ptr skeletonTracker = SkeletonTracker::create(); skeletonTracker->connectOnUpdate(skeletonUpdateCallback); Nuitrack::run(); while(true) { Nuitrack::waitUpdate(skeletonTracker); } Nuitrack::release(); ``` -------------------------------- ### Start method to get Rigidbody component Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_VR_Box.md Gets the Rigidbody component attached to the capsule at the start of the game. ```csharp void Start() { rigidbody = GetComponent(); } ``` -------------------------------- ### Environment.cs Start(): Adjusting scale for client Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_AR_Football.md In the Start method of Environment.cs, the environment's local scale is set to clientSize when the object is not on the server. This keeps the environment size consistent on the client side. ```C# void Start() { if(FindObjectOfType().isServer == false) transform.localScale = clientSize; } ``` -------------------------------- ### Start method calling CreateSkeletonParts and getting parentRect Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_RGB_Skeletons.md In Start, calls CreateSkeletonParts() and retrieves the avatar's RectTransform component. ```csharp public class SimpleSkeletonAvatar : MonoBehaviour { ... void Start() { CreateSkeletonParts(); parentRect = GetComponent(); } } ``` -------------------------------- ### Install Python 3 on Ubuntu 18.04/20.04 Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Commands to install Python 3 on newer Ubuntu versions. Run these before installing PyNuitrack. ```bash sudo apt-get update sudo apt-get install -y python3 ``` -------------------------------- ### ZombieController.cs: Start method to initialize ragdoll and target Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Zombies_Oculus.md Gets references to all child Rigidbodies and Colliders and the main Rigidbody, then disables ragdoll at start. The target (player) is found later in the script. ```csharp void Start() { rigidbodyRagdoll = GetComponentsInChildren(); colliderRagdoll = GetComponentsInChildren(); rb = GetComponent(); SwitchRagdoll(false); // disable ragdoll } ``` -------------------------------- ### GalleryControl.cs - Start coroutine to fill gallery with images Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Gallery.md IEnumerator Start() that waits one frame, calculates page size and default image size, then instantiates image items from the prefab, positions them in a grid, and sets the content size. ```csharp IEnumerator Start() { // Skip the first frame when Unity updates the UI // (otherwise scrollRect.viewport.rect. size returns an invalid value) yield return null; pageSize = scrollRect.viewport.rect.size; // calculate the size of an image in the preview mode defaultSize = new Vector2(pageSize.x / colsNumber, pageSize.y / rowsNumber); Vector2 halfAdd = new Vector2(defaultSize.x / 2, -defaultSize.y / 2); int imagesOnPage = rowsNumber * colsNumber; // divide the total number of pictures by the number of pictures on one page and round it up numberOfPages = (int)Mathf.Ceil((float)spriteCollection.Length / imagesOnPage); int imageIndex = 0; for (int p = 0; p < numberOfPages; p++) // iterate over the pages { // set the number of images on a current page int imagesOnCurrentPage = Mathf.Min(spriteCollection.Length - p * imagesOnPage, imagesOnPage); for (int i = 0; i < imagesOnCurrentPage; i++) // fill the current page with images { // Create an image object from the prefab and make it child to the content GameObject currentItem = Instantiate(imageItemPrefab); currentItem.transform.SetParent(content.transform, false); // Calculate and specify the position on the content ImageItem currentImageItem = currentItem.GetComponent(); currentImageItem.Rect.sizeDelta = defaultSize; float X = pageSize.x * p + defaultSize.x * (i % colsNumber); float Y = defaultSize.y * (i / colsNumber); currentImageItem.Rect.anchoredPosition = new Vector2(X, -Y) + halfAdd; // Drag-and-drop to the sprite currentImageItem.image.sprite = spriteCollection[imageIndex]; imageIndex++; } } content.sizeDelta = new Vector2(pageSize.x * numberOfPages, pageSize.y); // set the content size } ``` -------------------------------- ### Install freeglut3-dev dependency Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_gl_sample/README.md Required dependency for Ubuntu. Install freeglut3-dev using apt-get. ```bash sudo apt-get install freeglut3-dev ``` -------------------------------- ### Example of setting up Multi-Sensor Daemon callbacks Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Nuitrack_Daemon.md Send a POST request to localhost:8080/endpoints with the specified JSON body to configure callback endpoints for the Multi-Sensor Daemon. ```http POST localhost:8080/endpoints { "NewHumanEndpoint": "localhost:8081/onNewHuman", "LostHumanEndpoint": "localhost:8081/onLostHuman" } ``` -------------------------------- ### Build Nuitrack C# sample on Ubuntu with CMake Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_csharp_sample/README.txt Creates a build directory, configures the project with CMake, and installs the built sample. ```bash cd /Examples/nuitrack_csharp_sample mkdir build cd build cmake .. make install ``` -------------------------------- ### Updated Start method with AddBoneScale calls Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Avatar_Animation.md The `Start` method should look like this after adding base distances between child and parent bones for direct mapping. ```csharp void Start() { for (int i = 0; i < modelJoints.Length; i++) { modelJoints[i].baseRotOffset = modelJoints[i].bone.rotation; jointsRigged.Add(modelJoints[i].jointType.TryGetMirrored(), modelJoints[i]); // adding base distances between the child bone and the parent bone if (modelJoints[i].parentJointType != nuitrack.JointType.None) AddBoneScale(modelJoints[i].jointType.TryGetMirrored(), modelJoints[i].parentJointType.TryGetMirrored()); } } ``` -------------------------------- ### Register Nuitrack dynamic module for OpenNI 1.5 (64-bit) Source: https://github.com/3divi/nuitrack-sdk/wiki/Windows Run this command to register the Nuitrack module for OpenNI 1.5 on 64-bit systems. Replace with the actual installation path. ```cmd "C:\Program Files\OpenNI\Bin64\niReg64.exe" -r \nuitrack\bin\libnuitrack_ni.dll \nuitrack\data ``` -------------------------------- ### FaceSwitcher Start method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Face_Tracking.md In Start, find the FaceController component in a parent object and assign it to the faceController variable. ```csharp public class FaceSwitcher : MonoBehaviour { ... void Start () { faceController = GetComponentInParent(); } } ``` -------------------------------- ### Instantiate joint prefabs in Start() Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Basic.md Creates joint visualization objects in Start() by instantiating the prefab for each joint type and setting them as children of the script's transform. After execution, the message 'Skeleton created' is set. ```csharp void Start() { CreatedJoint = new GameObject[typeJoint.Length]; for (int q = 0; q < typeJoint.Length; q++) { CreatedJoint[q] = Instantiate(PrefabJoint); CreatedJoint[q].transform.SetParent(transform); } message = "Skeleton created"; } ``` -------------------------------- ### FaceManager Start method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Face_Tracking.md Instantiates a FaceController for each detected skeleton and adds it to the faceControllers list. Called in Start to populate the scene with face emojis. ```csharp public class FaceManager : MonoBehaviour { ... void Start() { for (int i = 0; i < skeletonController.skeletonCount; i++) { faceControllers.Add(Instantiate(faceController, canvas.transform).GetComponent()); } } } ``` -------------------------------- ### Install libgl1-mesa-dri for Ubuntu 14.04 Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_gl_sample/README.md Additional dependency for Ubuntu 14.04. Install libgl1-mesa-dri using apt-get. ```bash sudo apt-get install libgl1-mesa-dri ``` -------------------------------- ### Register Nuitrack dynamic module for OpenNI 1.5 (32-bit) Source: https://github.com/3divi/nuitrack-sdk/wiki/Windows Run this command to register the Nuitrack module for OpenNI 1.5 on 32-bit systems. Replace with the actual installation path. ```cmd "C:\Program Files (x86)\OpenNI\Bin\niReg.exe" -r \nuitrack\bin\libnuitrack_ni.dll \nuitrack\data ``` -------------------------------- ### Start method for initialization Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Point_Cloud.md Calls Initialize() if not already initialized. ```csharp void Start() { if (!initialized) Initialize(); } ``` -------------------------------- ### Build Nuitrack C# Device API sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_csharp_device_api_sample/README.txt Create a build directory, configure with CMake, and install the sample. ```bash cd /Examples/nuitrack_csharp_device_api_sample mkdir build cd build cmake .. make install ``` -------------------------------- ### GET_INSTANCE Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Returns a dictionary containing information about faces of users with detected skeletons. The output can be converted to JSON format for further processing. ```APIDOC ## GET_INSTANCE ### Description Returns a dictionary containing information about faces of users with detected skeletons. The output can be converted to JSON format for further processing. ### Method GET_INSTANCE ### Response #### Success Response Returns a dictionary with the following structure: - **Timestamp** (integer) - Timestamp of the detection. - **Instances** (array) - List of detected instances, each containing: - **id** (integer) - Instance ID. - **class** (string) - Class of the instance (e.g., "human"). - **face** (object) - Face information: - **rectangle** (object) - Bounding box with left, top, width, height. - **landmark** (array) - Array of landmark points with x and y coordinates. - **left_eye** (object) - Left eye coordinates (x, y). - **right_eye** (object) - Right eye coordinates (x, y). - **angles** (object) - Head angles: yaw, pitch, roll. - **emotions** (object) - Emotion scores: angry, neutral, surprise, happy. - **age** (object) - Age information: type (e.g., "kid") and years. - **gender** (string) - Gender (e.g., "female"). - **quality** (number) - Quality score. - **recognizer** (object) - Recognizer data (e.g., angry score). #### Response Example ```json { "Timestamp":1636619547706618, "Instances":[ { "id":1, "class":"human", "face":{ "rectangle":{ "left":220.0, "top":55.0, "width":194.0, "height":194.0 }, "landmark":[ { "x":0.42078638076782227, "y":0.274656742811203 }, { "x":0.4336216449737549, "y":0.25765836238861084 }, { "x":0.45662862062454224, "y":0.25839850306510925 } ], "left_eye":{ "x":0.45123791694641113, "y":0.2969283163547516 }, "right_eye":{ "x":0.5217143297195435, "y":0.26434293389320374 }, "angles":{ "yaw":-22.729164123535156, "pitch":-7.3662333488464355, "roll":-20.351110458374023 }, "emotions":{ "angry":0.3902933895587921, "neutral":0.46033039689064026, "surprise":0.13632416725158691, "happy":0.013052115216851234 }, "age":{ "type":"kid", "years":14.538444519042969 }, "gender":"female", "quality":-1081.7933349609375, "recognizer":{ "angry":-1 } } } ] } ``` ``` -------------------------------- ### Install cmake dependency on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_device_api_sample/README.txt Installs the cmake build tool required to compile the Nuitrack device API sample on Ubuntu. ```bash sudo apt-get install cmake ``` -------------------------------- ### Install libcurl4-openssl-dev package Source: https://github.com/3divi/nuitrack-sdk/wiki/Linux Install the missing libcurl4-openssl-dev package to resolve the 'WARNING: Can not load library module' and 'ERROR: Empty factory for DepthProvider' errors. ```bash sudo apt-get install libcurl4-openssl-dev ``` -------------------------------- ### Enable face tracking with set_config_value Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Call these methods to enable face tracking. Must be called after `nuitrack.init()` and before `nuitrack.create_modules()`. ```python nuitrack.set_config_value("Faces.ToUse", "true") nuitrack.set_config_value("DepthProvider.Depth2ColorRegistration", "true") ``` -------------------------------- ### SkeletonController Start method to spawn and configure avatars Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_RGB_Skeletons.md In Start, instantiates skeleton avatars, disables autoProcessing for each, adds them to the list, and sets the number of active users via NuitrackManager.SkeletonTracker.SetNumActiveUsers. ```csharp public class SkeletonController : MonoBehaviour { ... void Start() { for (int i = 0; i < skeletonCount; i++) { GameObject newAvatar = Instantiate(skeletonAvatar.gameObject, transform, true); SimpleSkeletonAvatar simpleSkeleton = newAvatar.GetComponent(); simpleSkeleton.autoProcessing = false; avatars.Add(simpleSkeleton); } NuitrackManager.SkeletonTracker.SetNumActiveUsers(skeletonCount); } } ``` -------------------------------- ### QuickConnectNetworkDiscovery.cs - Auto-connect to server Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_AR_Football.md Inherits from NetworkDiscovery to automatically connect to the first server found. Overrides OnReceivedBroadcast to start the client if not already connected. ```csharp using UnityEngine.Networking; public class QuickConnectNetworkDiscovery : NetworkDiscovery { public override void OnReceivedBroadcast(string fromAddress, string data) { base.OnReceivedBroadcast(fromAddress, data); if(NetworkManager.singleton.IsClientConnected()) return; NetworkManager.singleton.networkAddress = fromAddress; // Found server IP is added to Network Manager. NetworkManager.singleton.StartClient(); // Connection. } } ``` -------------------------------- ### Handle gestures and start scroll animation Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Gallery.md In NuitrackManager_onNewGesture, checks the gallery mode and gesture type, updates the current page with clamping, and starts the scroll animation. Also defines StartScrollAnimation to set the start scroll value and disable the scrollbar. ```csharp private void NuitrackManager_onNewGesture(nuitrack.Gesture gesture) { switch (currentViewMode) { case ViewMode.Preview: currentPage = Mathf.RoundToInt(scrollRect.horizontalScrollbar.value * (1 / scrollStep)); if (gesture.Type == nuitrack.GestureType.GestureSwipeLeft) { currentPage = Mathf.Clamp(++currentPage, 0, numberOfPages - 1); StartScrollAnimation(); } if (gesture.Type == nuitrack.GestureType.GestureSwipeRight) { currentPage = Mathf.Clamp(--currentPage, 0, numberOfPages - 1); StartScrollAnimation(); } break; } } void StartScrollAnimation() { startScroll = scrollRect.horizontalScrollbar.value; scrollT = 0; scrollRect.horizontalScrollbar.interactable = false; } ``` -------------------------------- ### Nuitrack include and init Source: https://github.com/3divi/nuitrack-sdk/blob/master/iOS-beta/README.md Use these lines to verify the project can use Nuitrack. Set the source file extension to *.mm instead of *.m. ```Objective-C #include ``` ```Objective-C tdv::nuitrack::Nuitrack::init(); ``` -------------------------------- ### Android build commands for NuitrackGLSampleNI Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_ni_gl_sample/android/README.txt Command-line sequence to build and install the Nuitrack GL Sample NI Android app. Requires Android SDK and NDK >= r9d. The target must have API level greater than 14. Use arm64-v8a/jni for 64-bit ARM CPUs or armeabi-v7a/jni for 32-bit ARM-based CPUs. The final command installs the APK via adb. ```bash cd android/ ``` ```bash android update project -n NuitrackGLSampleNI -t -p . ``` ```bash cd arm64-v8a/jni (armeabi-v7a/jni for 32-bit ARM-based CPUs) ``` ```bash ndk-build ``` ```bash cd ../../ ``` ```bash ant debug ``` ```bash adb install -r bin/NuitrackGLSampleNI-debug.apk ``` -------------------------------- ### Start method passing parameters to ObjectSpawner Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Segment.md In the Start method of SegmentPaint, calls CreateColliders and then StartSpawn with the number of columns to begin spawning objects. ```csharp void Start() { ... gameColliders.CreateColliders(cols, rows); objectSpawner.StartSpawn(cols); } ... ``` -------------------------------- ### Initialize method with frameStep check Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Point_Cloud.md Gets camera output mode, computes frameStep, ensures it is > 0, and creates mesh instances. frameStep > 0 prevents division by zero crashes. ```csharp void Initialize() { initialized = true; var mode = NuitrackManager.DepthSensor.GetOutputMode(); frameStep = mode.Size.Width / hRes; if (frameStep <= 0) frameStep = 1; // frameStep must be > 0 hRes = mode.Size.Width / frameStep; // Define height and width, create mesh (cube) instances InitMeshes( (mode.Size.Width / frameStep), // Width (mode.Size.Height / frameStep), // Height mode.HFOV); } ``` -------------------------------- ### StartSpawn method to begin spawning objects Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Segment.md Public method that receives the image width, calculates halfWidth, and starts the SpawnObject coroutine with zero delay. ```csharp public void StartSpawn(float widthImage) { halfWidth = widthImage / 2; StartCoroutine(SpawnObject(0f)); } ``` -------------------------------- ### Start method with RecordMode.Generic switch Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Animation_Recording.md Initializes the recorder based on the selected record mode. In this snippet, only the Generic mode is handled, creating a GenericRecorder with the transforms and root. ```csharp void Start() { ... switch (recordMode) { case RecordMode.Generic: recordable = new GenericRecorder(transforms, root); break; } } ``` -------------------------------- ### Request camera access with AVFoundation Source: https://github.com/3divi/nuitrack-sdk/blob/master/iOS-beta/README.md Import AVFoundation and request camera access once. Logs the granted status to the console. ```objectivec #import ... // ask for access to camera once [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { NSLog(@"CameraAccess: %s \n", (granted?"true":"false")); } ]; ... ``` -------------------------------- ### Subscribe to user tracker update in Start method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Segment.md Subscribe to the NuitrackManager.onUserTrackerUpdate event in the Start method to receive user frame updates. ```csharp void Start() { NuitrackManager.onUserTrackerUpdate += ColorizeUser; } ``` -------------------------------- ### Enable mirroring in Start method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Segment.md Calls SetMirror(true) on the depth sensor to mirror the image received from the sensor. ```csharp void Start() { NuitrackManager.DepthSensor.SetMirror(true); } ``` -------------------------------- ### Spawn fox faces and set active user count in Start Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Animated_Emoji.md In the FaceAnimManager Start method, instantiate the number of fox faces specified by faceCount, place them apart, initialize each FaceAnimController, and set the number of active skeletons to faceCount. Faces are initially deactivated to avoid multiple faces being displayed for one user. ```csharp public class FaceAnimManager : MonoBehaviour { ... void Start() { for (int i = 0; i < faceCount; i++) { GameObject newFace = Instantiate(facePrefab.gameObject, new UnityEngine.Vector3(i * headsDistance, 0, 0), Quaternion.identity); newFace.SetActive(false); FaceAnimController faceAnimController = newFace.GetComponent(); faceAnimController.Init(canvas); faceAnimControllers.Add(faceAnimController); } NuitrackManager.SkeletonTracker.SetNumActiveUsers(faceCount); } } ``` -------------------------------- ### Environment.cs: Set Environment size at start Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_AR_Football.md Defines the Environment object's behavior, setting its scale to a serialized client size. The aim field references the Target object for the ball. ```csharp using UnityEngine; using UnityEngine.Networking; public class Environment : MonoBehaviour { public Transform aim; [SerializeField] Vector3 clientSize; void Start() { transform.localScale = clientSize; } } ``` -------------------------------- ### Create SkeletonTracker and connect callback in C# Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Person_Reidentification.md Create a SkeletonTracker module, subscribe to the OnSkeletonUpdateEvent, and start Nuitrack with Nuitrack.Run(). ```cs void onSkeletonUpdate(SkeletonData skeletonData) { /* your SkeletonData processing */ } ... SkeletonTracker skeletonTracker = SkeletonTracker.Create(); skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; Nuitrack.Run(); ``` -------------------------------- ### Start method to match Nuitrack and Unity joints Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Animation_Recording.md Loops over the joints list, converts each Nuitrack joint to a Unity bone, and retrieves the corresponding bone transform. Logs an error and disables the component if a bone is not found; otherwise stores the bone and its initial rotation as the offset. ```csharp void Start () { foreach (SimpleJoint item in joints) { HumanBodyBones unityBoneType = item.nuitrackJoint.ToUnityBones(); Transform bone = animator.GetBoneTransform(unityBoneType); if (bone == null) { Debug.LogError("The bone " + unityBoneType + " is not found (check configuration of the humanoid in the Rig tab)"); enabled = false; } else { item.Bone = bone; item.Offset = bone.rotation; } } } ``` -------------------------------- ### Create SkeletonTracker and connect callback in C++ Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Person_Reidentification.md Create a SkeletonTracker module, connect it to the onSkeletonUpdate callback, and start Nuitrack with Nuitrack::run(). ```cpp void onSkeletonUpdate(SkeletonData::Ptr userSkeletons) { /* your SkeletonData processing */ } ... auto skeletonTracker = SkeletonTracker::create(); skeletonTracker->connectOnUpdate(onSkeletonUpdate); Nuitrack::run(); ``` -------------------------------- ### Initialize joints in Start Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Avatar_Animation.md Loops over the modelJoints array, stores the base rotation offset, and adds each joint to the dictionary using the mirrored joint type (via TryGetMirrored) to handle mirror mode correctly. ```csharp void Start() { for (int i = 0; i < modelJoints.Length; i++) { modelJoints[i].baseRotOffset = modelJoints[i].bone.rotation; jointsRigged.Add(modelJoints[i].jointType.TryGetMirrored(), modelJoints[i]); } } ``` -------------------------------- ### Build sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_multisensor_sample/README.md Commands to build the Nuitrack Multi-Sensor sample on Ubuntu. Run from the sample directory. ```bash cd /Examples/nuitrack_multisensor_sample mkdir build cd build cmake .. make ``` -------------------------------- ### Call CreateColliders in Start Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Segment.md Invokes the CreateColliders method with the image columns and rows to create colliders at startup. ```csharp ... gameColliders.CreateColliders(cols, rows); ... ``` -------------------------------- ### Configure Nuitrack parameters after initialization Source: https://github.com/3divi/nuitrack-sdk/blob/master/iOS-beta/README.md Initialize Nuitrack with a config file and override parameters using Nuitrack::setConfigValue. Rotates frames, enables registration, and enables mirror mode. ```cpp ... //inintialize nuitrack Nuitrack::init(config_file); //rotate frames Nuitrack::setConfigValue("DepthProvider.RotateAngle", "90"); //turn registration mode on Nuitrack::setConfigValue("DepthProvider.Depth2ColorRegistration", "true"); //turn mirror mode on Nuitrack::setConfigValue("DepthProvider.Mirror", "true"); ... ``` -------------------------------- ### CMake configuration for nuitrack_csharp_device_api_sample Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_csharp_device_api_sample/CMakeLists.txt CMakeLists.txt for building the C# device API sample. It sets up the project, finds CSharp and Mono, compiles Program.cs with /unsafe, links required DLLs, installs the executable, and copies nuitrack.net.dll to the build directory on Windows. ```cmake cmake_minimum_required(VERSION 3.14) set(PROJECT_NAME nuitrack_csharp_device_api_sample) project(${PROJECT_NAME}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/../cmake) find_package(CSharp) include(${CMAKE_CURRENT_LIST_DIR}/../cmake/UseCSharp.cmake) include(${CMAKE_CURRENT_LIST_DIR}/../cmake/FindMono.cmake) set(SOURCES ${CMAKE_CURRENT_LIST_DIR}/Program.cs) CSHARP_ADD_EXECUTABLE(${PROJECT_NAME} ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_NAME} " " "/unsafe" "${SOURCES}" "System.Drawing.dll;System.Windows.Forms.dll;${CMAKE_CURRENT_LIST_DIR}/../../Nuitrack/lib/csharp/nuitrack.net.dll" ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.exe DESTINATION ${CMAKE_CURRENT_LIST_DIR}) # copying nuitrack.net.dll to the build directory if(WIN32) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/nuitrack.net.dll ${CMAKE_CURRENT_BINARY_DIR} ) endif() ``` -------------------------------- ### Run Nuitrack C# sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_csharp_sample/README.txt Makes the generated executable runnable and launches it from the sample directory. ```bash cd .. chmod +x nuitrack_csharp_sample.exe ./nuitrack_csharp_sample.exe ``` -------------------------------- ### Initialize Nuitrack and get device list Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Nuitrack_Integration.md After calling Nuitrack::init(), retrieve the list of connected sensors. This is the first step in the Device API activation workflow. ```cpp Nuitrack::init(); std::vector devices = Nuitrack::getDeviceList(); ``` -------------------------------- ### Check libcurl dependency for libNuitrackModule.so Source: https://github.com/3divi/nuitrack-sdk/wiki/Linux Use ldd to verify if libcurl is linked. If the output shows 'libcurl.so => not found', install the libcurl4-openssl-dev package. ```bash ldd /usr/etc/nuitrack/middleware/libNuitrackModule.so | grep curl ``` -------------------------------- ### Run sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_multisensor_sample/README.md Command to run the built sample executable on Ubuntu. ```bash ./nuitrack_multisensor_sample ``` -------------------------------- ### Install Python 3.6 on Ubuntu 14.04/16.04 Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Commands to install Python 3.6 on older Ubuntu versions using the deadsnakes PPA. Run these before installing PyNuitrack. ```bash sudo apt-get update sudo apt-get install -y software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install -y python3.6 ``` -------------------------------- ### Calculate scroll step in Start method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Gallery.md Calculates the scroll step based on the number of pages. The Scrollbar takes values from 0 to 1, so the step is 1/(n-1). ```csharp if (numberOfPages > 1) scrollStep = 1f / (numberOfPages - 1); // 1/(n-1) given that the Scrollbar takes values from 0 to 1 and one page is already displayed ``` -------------------------------- ### Run Nuitrack device API sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_device_api_sample/README.txt Executes the compiled sample binary. ```bash ./nuitrack_device_api_sample ``` -------------------------------- ### Fields of each joint Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Each joint field has these properties: type, confidence, real, projection, orientation. ```plaintext type confidence real projection orientation ``` -------------------------------- ### Build Nuitrack device API sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_device_api_sample/README.txt Creates a build directory, configures the project with CMake, and compiles the sample. Run these commands from the sample folder. ```bash cd /Examples/nuitrack_device_api_sample mkdir build cd build cmake .. make ``` -------------------------------- ### SpawnEnemy and calibration handlers Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Zombies_Oculus.md Handles calibration success to start spawning zombies. SpawnEnemy creates zombies at random spawn points with random sizes, stopping when maxEnemies is reached. Subscribes to CalibrationHandler events. ```csharp private void OnEnable() { if (CalibrationHandler.Instance != null) CalibrationHandler.Instance.onSuccess += OnSuccessCalib; } private void OnSuccessCalib(Quaternion rotation) { if (!gameStarted) { gameStarted = true; InvokeRepeating("SpawnEnemy", 3, 0.2f); } } void SpawnEnemy() { if (enemiesCount >= maxEnemies) return; float randomSize = Random.Range(0.2f, 0.3f); // zombie size enemies[Random.Range(0, enemies.Length)].transform.localScale = Vector3.one * randomSize; // set the zombie size Instantiate(enemies[Random.Range(0, enemies.Length)], spawnPoints[Random.Range(0, spawnPoints.Length)].position, Quaternion.identity); // spawn zombies enemiesCount++; } private void OnDisable() { if (CalibrationHandler.Instance != null) CalibrationHandler.Instance.onSuccess -= OnSuccessCalib; } ``` -------------------------------- ### Build sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_console_sample/README.txt Create a build directory, configure with CMake, and compile the sample. ```bash cd /Examples/nuitrack_console_sample mkdir build cd build cmake .. make ``` -------------------------------- ### Activate Nuitrack license using Device API Source: https://github.com/3divi/nuitrack-sdk/blob/master/iOS-beta/README.md Activate a Nuitrack license on a connected device. Requires internet access; set the proxy via "Network.ProxyUrl" immediately after Nuitrack::init(). Uses the activation key and checks the activation status. ```c++ using namespace tdv::nuitrack::device; ... // inintialize nuitrack Nuitrack::init(); // set proxy Nuitrack::setConfigValue("Network.ProxyUrl", "192.168.1.2:1234"); // activation key const std::string activationKey = "license_activation_key"; // find connected device vector devices = Nuitrack::getDeviceList(); if (!devices.empty()) { devices[0]->activate(activationKey); // get activation result ActivationStatus activationStatus = devices[0]->getActivationStatus(); ... auto depthSensor = DepthSensor::create(); ... } ``` -------------------------------- ### Grant write permissions to Nuitrack data directory after installation error Source: https://github.com/3divi/nuitrack-sdk/wiki/Windows Run this command in Windows PowerShell as Administrator after installation to grant full control to the current user on the Nuitrack data directory. This resolves the 'Execution failed (Unexpected exit code: 87)' error. If your username has two words, create a new account with just one. ```powershell cmd /C icacls "C:\\Program Files\\Nuitrack\\nuitrack\\nuitrack\\data" /grant %USERNAME%:F /T ``` -------------------------------- ### Iterate skeletons and access joints Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Loop through `data.skeletons` to retrieve skeleton joint and user id. Each skeleton has fields like `user_id`, `left_hand`, and `right_hand.projection`. ```python for skeleton in data.skeletons: print(skeleton.user_id) print(skeleton.left_hand) print(skeleton.right_hand.projection) ``` -------------------------------- ### Build sample with CMake and make Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_ni_gl_sample/README.txt Commands to configure and build the sample on Ubuntu. Requires the OPENNI_LIBRARY path to point to libOpenNI.so. ```bash cd /Examples/nuitrack_ni_gl_sample mkdir build cd build cmake .. -DOPENNI_LIBRARY=/usr/local/lib/nuitrack/libOpenNI.so make ``` -------------------------------- ### Get Unity app log with adb logcat Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Basic.md Run this command in the console to view the Unity app log from a mobile device. Requires Android Debug Bridge (adb) installed on your computer. ```bash adb logcat -s Unity ``` -------------------------------- ### Run sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_gl_sample/README.md Run the built sample on Ubuntu. Optionally specify a path to a nuitrack.config file. ```bash ./nuitrack_gl_sample [path/to/nuitrack.config] ``` -------------------------------- ### List of available skeleton joints Source: https://github.com/3divi/nuitrack-sdk/blob/master/PythonNuitrack-beta/README.MD Using `skeleton` you can access these joints: head, neck, torso, waist, left_collar, left_shoulder, left_elbow, left_wrist, left_hand, right_collar, right_shoulder, right_elbow, right_wrist, right_hand, left_hip, left_knee, left_ankle, right_hip, right_knee, right_ankle. ```plaintext head neck torso waist left_collar left_shoulder left_elbow left_wrist left_hand right_collar right_shoulder right_elbow right_wrist right_hand left_hip left_knee left_ankle right_hip right_knee right_ankle ``` -------------------------------- ### Run sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_console_sample/README.txt Execute the compiled sample, optionally passing a path to a nuitrack.config file. ```bash ./nuitrack_console_sample [path/to/nuitrack.config] ``` -------------------------------- ### Grant write permissions to Nuitrack data directory for another user Source: https://github.com/3divi/nuitrack-sdk/wiki/Windows Use this command to give write permissions to the Nuitrack data directory for a specific user, needed for activation via another user. Replace with the actual username. ```cmd icacls C:\Program Files\Nuitrack\nuitrack\nuitrack\data /grant :F /T ``` -------------------------------- ### Run Nuitrack C# Device API sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_csharp_device_api_sample/README.txt Make the generated executable runnable and launch it. ```bash cd .. chmod +x nuitrack_csharp_device_api_sample.exe ./nuitrack_csharp_device_api_sample.exe ``` -------------------------------- ### Build sample on Ubuntu Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_gl_sample/README.md Build the Nuitrack OpenGL sample on Ubuntu. Navigate to the sample directory, create a build directory, configure with CMake, and compile. ```bash cd /Examples/nuitrack_gl_sample mkdir build cd build cmake .. make ``` -------------------------------- ### Build Nuitrack GL Sample for Android from Command Line Source: https://github.com/3divi/nuitrack-sdk/blob/master/Examples/nuitrack_gl_sample/android/README.md Builds the Nuitrack GL sample for Android using the command line. Requires Android SDK and NDK >= r9d. The target must have API level greater than 14. ```bash cd android/ android update project -n NuitrackGLSample -t -p . # where is target Id from `android list targets` which have API level greater than 14 cd arm64-v8a/jni # (armeabi-v7a/jni for 32-bit ARM-based CPUs) ndk-build cd ../../ ant debug adb install -r bin/NuitrackGLSample-debug.apk ``` -------------------------------- ### FaceAnimController Init method Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Animated_Emoji.md Initializes the face display by instantiating the raw image as a child of the provided canvas, creating a render texture from the sample, assigning it to the camera and raw image, and scaling the image to screen height. The raw image is initially hidden. ```csharp public class FaceAnimController : MonoBehaviour { ... public void Init(Canvas canvas) { faceRaw = Instantiate(rawImage, canvas.transform).GetComponent(); // Spawn RawImage faceRaw.transform.localScale = Vector2.one * Screen.height; renderTexture = new RenderTexture(renderTextureSample); faceCamera.targetTexture = renderTexture; faceRaw.texture = renderTexture; faceRaw.gameObject.SetActive(false); } } ``` -------------------------------- ### Add click listener to gallery image items in Start Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Gallery.md In the GalleryControl script's Start coroutine, attach a click listener to each image item so that clicking it triggers CurrentImageItem_OnClick. The listener is added inside nested loops over pages and images on the current page. ```csharp IEnumerator Start() { ... for (int p = 0; p < numberOfPages; p++) { ... for (int i = 0; i < imagesOnCurrentPage; i++) { ... currentImageItem.onClick.AddListener(delegate { CurrentImageItem_OnClick(currentImageItem); }); } } } ``` -------------------------------- ### Instantiate point prefabs in InitMeshes Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_Point_Cloud.md Loop through the RGB texture dimensions and instantiate a point prefab for each pixel, parenting them to the transform. ```csharp int pointId = 0; for (int i = 0; i < rgbTexture.height; i++) { for (int j = 0; j < rgbTexture.width; j++) { points[pointId++] = Instantiate(pointMesh, transform); } } ``` -------------------------------- ### Create PunchSpeedSender.cs with OnCollisionEnter Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Unity_VR_Box.md Sends the relative collision speed to the PunchSpeedMeter when the dummy is punched. Uses relativeVelocity to get the correct collision speed. ```csharp public class PunchSpeedSender : MonoBehaviour { [SerializeField] PunchSpeedMeter punchSpeedMeter; private void OnCollisionEnter(Collision collision) { punchSpeedMeter.CalculateMaxPunchSpeed(collision.relativeVelocity.magnitude); } } ``` -------------------------------- ### Get Re-identification data in C# Source: https://github.com/3divi/nuitrack-sdk/blob/master/doc/Person_Reidentification.md Loop with Nuitrack.Update(skeletonTracker) and retrieve JSON data via Nuitrack.GetInstancesJson(). ```cs while (true) { Nuitrack.Update(skeletonTracker); string json = Nuitrack.GetInstancesJson(); } ```