Fade¶
sceneplates/fade.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2#
3# Example to show how to change scene plate's transparency
4# This example is more complex as simple.py and create.py
5# Please study this first
6#
7# vrSceneplateService is used to create and query a scene plate
8# vrdSceneplateNode is used to change scene plate's transpacency
9#
10
11# We introduce this types to make the code more readable
12NodeType = vrSceneplateTypes.NodeType
13ContentType = vrSceneplateTypes.ContentType
14PositionType = vrSceneplateTypes.Position
15SizeType = vrSceneplateTypes.SizeType
16
17# Values used for fade animation
18theStep = 0.01;
19theTransparency = 0.0;
20
21# This function summarizes all necessary steps to create a scene plate and set its properties.
22# First we have to create a node using the scene plate service and convert this to an plate.
23# Then we set different properties of the new created plate.
24def createPlate(root, image):
25 theNode = vrSceneplateService.createNode(root, NodeType.Frontplate, "plate")
26 thePlate = vrdSceneplateNode(theNode)
27 thePlate.setContentType(ContentType.Image)
28 thePlate.setImage(image)
29 thePlate.setSizeMode(SizeType.Absolute)
30 thePlate.setSize(512)
31 thePlate.setPosition(PositionType.Center)
32
33# Load an image
34# Get the example directory
35# Dive in to the texture directory
36# Make path windows like with back slashes
37# Load image with help of image service
38def createVREDImage():
39 theDir = vrFileIO.getVREDExamplesDir()
40 theFile = theDir + "/textures/vred.png"
41 theFile = theFile.replace('\\', '/');
42 theImage = vrImageService.loadImage(theFile)
43 return theImage
44
45# Fade in and out the plate
46def nextStep():
47 global theStep
48 global theTransparency
49 theTransparency = theTransparency + theStep
50
51 if theTransparency >= 1.0:
52 theStep = -0.01
53
54 if theTransparency <= 0.0:
55 theStep = 0.01
56
57 theNode = vrSceneplateService.findNode("plate");
58 thePlate = vrdSceneplateNode(theNode)
59 thePlate.setTransparency(theTransparency)
60
61# Query parent object for all scene plate creation
62theRoot = vrSceneplateService.getRootNode()
63
64# Read an image
65theImage = createVREDImage()
66
67# Create image plate in the middle of the window
68createPlate(theRoot, theImage)
69
70# Start a timer and make each second the next step in this animation
71timer = vrTimer(0.1)
72timer.connect(nextStep)
73timer.setActive(true)