File: example.iv

package info (click to toggle)
pivy 0.6.10-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,232 kB
  • sloc: python: 36,331; cpp: 787; ansic: 733; makefile: 30; sh: 27; objc: 5
file content (113 lines) | stat: -rw-r--r-- 3,163 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#Inventor V2.0 ascii

DEF root Separator {
   DEF shuttle SoShuttle {
      translation0 0 0 0
      translation1 -1 0.5 -1
   }
   Material { diffuseColor 1.0 0.0 0.0 }
   DEF Glow SoPyScript {
      fields [ SoSFColor color, SoSFFloat brightness, SoSFFloat transparency ]
      color 1 0 0 = USE shuttle.translation
      brightness 0.5
      transparency 0.3
      script "
# make the handler of the color field to call chicken_mcnuggets()
# instead of the default set handle_color() function
handler_registry['color'] = 'chicken_mcnuggets'

def chicken_mcnuggets():
  # print color.getValue().getValue()
  pass

# Initialize the color Packer (required of any property node that
# uses an SoColorPacker to set diffuse color or transparency:
colorPacker = SoColorPacker()
transpValue = floatp()

def doAction(action):
    global transpValue

    if not brightness.isIgnored() and not SoOverrideElement.getEmissiveColorOverride(action.getState()):
        emissiveColor = color.getValue() * brightness.getValue()
        # print 'doAction():', color.getValue().getValue()

        # Use the Lazy element to set emissive color. 
        # Note that this will not actually send the color to GL.       
        SoLazyElement.setEmissive(action.getState(), emissiveColor)

    # To send transparency we again check ignore flag and override element.
    if not transparency.isIgnored() and not SoOverrideElement.getTransparencyOverride(action.getState()):
        # keep a copy of the transparency that we are putting in the state:
        transpValue.assign(transparency.getValue())
     
        # The color packer must be provided when the transparency is set,
        # so that the transparency will be merged with current diffuse color
        # in the state:
        SoLazyElement.setTransparency(action.getState(), self, 1, transpValue, colorPacker)

def GLRender(action):
    action.setTransparencyType(SoGLRenderAction.SORTED_OBJECT_BLEND)
    doAction(action)

def callback(action):
    doAction(action)

wa = SoWriteAction()
wa.apply(self)

print handler_registry

print '== Glow script loaded =='
"
   }
   Cone {}
   Material { diffuseColor 0 0 1 }
   Sphere{}
   SoTranslation { translation 0 1.2 0 }
   SoFont {
      name "Times New Roman"
      size 24.0
   }
   DEF TextScroller SoPyScript {
      fields [ SoSFString string, SoSFColor color ]
      string "I am Pivy powered!"
      color 0 1 0
      script "
# example that shows a scrolling text using a timer sensor
idx = 0
text = string.getValue().getString()
text_length = len(text)

interval = 0.15

def changeStringSensorCallback(data, sensor):
  global idx
  string.setValue(text[:idx])

  if idx == text_length:
    sensor.setInterval(5.0)
  else:
    sensor.setInterval(interval)

  idx %= text_length
  idx += 1

timersensor = SoTimerSensor(changeStringSensorCallback, None)
timersensor.setInterval(interval)
timersensor.schedule()

wa = SoWriteAction()
wa.apply(self)

string.setValue(text[:idx])

print '== TextScroller script loaded =='
"
   }
   Material { diffuseColor = USE TextScroller.color }
   SoText2 {
      string = USE TextScroller.string
      justification CENTER
   }
}