Color¶
sceneplates/color.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2#
3# Example to show how to rotate a scene plate
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 HSB color
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# Current values for color animation
18theHue = 0.0;
19theContrast = 1.0;
20theBrightness = 1.0;
21theSaturation = 1.0;
22
23# This function summarizes all necessary steps to create a scene plate and set its properties.
24# First we have to create a node using the scene plate service and convert this to an plate.
25# Then we set different properties of the new created plate.
26def createPlate(root, image):
27 theNode = vrSceneplateService.createNode(root, NodeType.Frontplate, "plate")
28 thePlate = vrdSceneplateNode(theNode)
29 thePlate.setContentType(ContentType.Image)
30 thePlate.setImage(image)
31 thePlate.setSizeMode(SizeType.Absolute)
32 thePlate.setSize(512)
33 thePlate.setPosition(PositionType.Center)
34
35# Color correction for the plate
36def nextStep():
37 global theHue
38 global theContrast
39 global theBrightness
40 global theSaturation
41
42 theHue = theHue + 1.5
43 theContrast = theContrast + 0.01
44 theBrightness = theBrightness + 0.02
45 theSaturation = theSaturation + 0.03
46
47 if theHue > 360.0:
48 theHue = 0.0
49
50 if theContrast > 2.0:
51 theContrast = 0.0
52
53 if theBrightness > 2.0:
54 theBrightness = 0.0
55
56 if theSaturation > 2.0:
57 theSaturation = 0.0
58
59 theNode = vrSceneplateService.findNode("plate");
60 thePlate = vrdSceneplateNode(theNode)
61 thePlate.setHueShift(theHue)
62 thePlate.setContrast(theContrast)
63 thePlate.setBrightness(theBrightness)
64 thePlate.setSaturation(theSaturation)
65
66# Query parent object for all scene plate creation
67theRoot = vrSceneplateService.getRootNode()
68
69# Read an image
70theDir = vrFileIO.getVREDExamplesDir()
71theFile = theDir + "/textures/vred.png"
72theFile = theFile.replace('\\', '/');
73theImage = vrImageService.loadImage(theFile)
74
75# Create image back plates in the middle of the window
76createPlate(theRoot, theImage)
77
78# Start a timer and make each second the next step in this animation
79timer = vrTimer(0.1)
80timer.connect(nextStep)
81timer.setActive(true)