(Deprecated) Creating a local clipping plane

This example uses API v1. See Creating a local clipping plane for example with API v2.

deprecated/clipPlane.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3# Create sphere and move it up
 4sphere = createSphere(3, 500, 1, 1,1)
 5setTransformNodeTranslation(sphere, 0,0,500, true)
 6
 7# Create local clip plane
 8nodeType = "ClipPlane"
 9clipPlane = createNode(nodeType)
10setTransformNodeTranslation(clipPlane, 0,0,500, true)
11
12# Add sphere as child of clip plane. All children are clipped by the plane.
13clippedObjects = [sphere]
14addChilds(clipPlane, clippedObjects)
15
16# Function to activate and deactivate the clip plane
17def toggleClipPlane():
18    if clipPlane.isValid():
19        # The clip plane's boolean field "on" stores whether clipping is enabled.
20        # Use vrFieldAccess to get and set the current state.
21        isLocalClipPlaneEnabled = clipPlane.fields().getBool("on")
22        clipPlane.fields().setBool("on", not isLocalClipPlaneEnabled)
23
24# Connect toggle to key 'c'
25keyC = vrKey(Key_C)
26keyC.connect(toggleClipPlane)
27
28print("Press key 'c' to toggle the clip plane.")