/[gzz]/gzz/gfx/demo/paperbasis.py
ViewVC logotype

Diff of /gzz/gfx/demo/paperbasis.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by jvk, Tue Nov 26 18:46:35 2002 UTC revision 1.29 by tjl, Tue Nov 26 20:18:14 2002 UTC
# Line 1  Line 1 
1  from __future__ import nested_scopes  from __future__ import nested_scopes
2    
3  from gfx.libutil import nvcode  from gfx.libutil import nvcode
4    from gfx.libutil import saveanim
5    
6  from gzz.gfx.gl import GL,GLRen,Paper,PaperMill  from gzz.gfx.gl import GL,GLRen,Paper,PaperMill
7    
# Line 57  texcodes = { Line 58  texcodes = {
58          color = SPARE0          color = SPARE0
59          alpha = 1          alpha = 1
60      """),      """),
61        "BAND1_X" : nvcode.parseCombiner("""
62            SPARE0 = ((2*TEX0-1) . (2*TEX1-1)) * 4
63    
64            SPARE0 = ((+SPARE0)*(+SPARE0)) * 2
65    
66            color = SPARE0*COL0 + (1-SPARE0)*COL1
67            alpha = 1
68        """),
69    
70      "BAND2" : nvcode.parseCombiner("""      "BAND2" : nvcode.parseCombiner("""
71          SPARE0 = ((2*TEX0-1) . (2*TEX1-1)) * 4          SPARE0 = ((2*TEX0-1) . (2*TEX1-1)) * 4
72          SPARE1 = ((2*TEX0-1).(2*CONST0-1)) * 4          SPARE1 = ((2*TEX0-1).(2*CONST0-1)) * 4
73          SPARE1.a = ((TEX1.blue)*(TEX0.blue)) * 4          SPARE1.a = ((TEX1.a)+(.5-TEX0.a)) * 4
74    
75          SPARE0 = ((+SPARE0)*(+SPARE0)) * 2          SPARE0 = ((+SPARE0)*(+SPARE0)) * 2
76          SPARE1 = ((SPARE1) * (SPARE1.a)) * 2          SPARE1 = ((SPARE1.a) * (SPARE1.a)) * 2
77    
78          color = SPARE0 * SPARE1          color = SPARE0 * SPARE1
79          alpha = 1          alpha = 1
# Line 126  texcodes = { Line 136  texcodes = {
136  }  }
137    
138    
139  def getpaper(vecs, cols, t0, t1, tex0comb, isectcomb, tex1comb):  def getpaper(vecs, cols, x0, y0, x1, y1, t0, t1, tex0comb, isectcomb, tex1comb):
140      pap = Paper()      pap = Paper()
141      pap.setNPasses(1)      pap.setNPasses(1)
142      ppass = pap.getPass(0)      ppass = pap.getPass(0)
# Line 177  def getpaper(vecs, cols, t0, t1, tex0com Line 187  def getpaper(vecs, cols, t0, t1, tex0com
187          CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s          CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s
188      """ % locals()      """ % locals()
189    
190      return GLRen.createBasisPaperQuad(pap, 0, 0, 1, 1,      return GLRen.createBasisPaperQuad(pap, 0, 0, x0, y0,
191                                      3.0,                                  0, 0, x1, y1,
192                                        constcode + texcodes[tex0comb],                                        constcode + texcodes[tex0comb],
193                                        constcode + texcodes[tex1comb],                                        constcode + texcodes[tex1comb],
194                                        constcode + texcodes[isectcomb])                                        constcode + texcodes[isectcomb])
# Line 187  rng = java.util.Random() Line 197  rng = java.util.Random()
197    
198  class PaperTemplate:  class PaperTemplate:
199      def __init__(self):      def __init__(self):
200          self.deltac = .05          self.deltac = .01
201          self.vecseed0 = 0          self.vecseed0 = 0
202          self.vecseed1 = 1          self.vecseed1 = 1
203          self.colseed = 2          self.colseed = 2
# Line 195  class PaperTemplate: Line 205  class PaperTemplate:
205          self.initvecs()          self.initvecs()
206          self.initcols()          self.initcols()
207    
208          self.x0, self.y0 = 0, 0          self.x0, self.y0 = .12, .02
209          self.x1, self.y1 = 0, 0          self.x1, self.y1 = 0, 0
210          self.texgen0 = TexGenXYRepeatUnit(vecs = [[.5,0], [0,.5]])          self.texgen0 = TexGenXYRepeatUnit(vecs = [[.5,0], [0,.5]])
211          self.texgen1 = TexGenXYRepeatUnit(vecs = [[.25,.25], [.25,-.25]])          self.texgen1 = TexGenXYRepeatUnit(vecs = [[.25,.5], [.25,0]])
212    
213          self.frame = getDList("""          self.frame = getDList("""
214          Color 0 0 0          Color 0 0 0
215          Disable TEXTURE_2D          Disable TEXTURE_2D
216          Disable DEPTH_TEST          Disable DEPTH_TEST
217            LineWidth 2
218          Begin LINE_LOOP          Begin LINE_LOOP
219          Vertex 0 0          Vertex 0 0
220          Vertex 0 1          Vertex 0 1
# Line 251  class PaperTemplate: Line 262  class PaperTemplate:
262          elif k == "Right": self.x0 += self.deltac          elif k == "Right": self.x0 += self.deltac
263    
264      def place(self, vs, into, t1, c, t2):      def place(self, vs, into, t1, c, t2):
265            print self.x0,self.y0,self.x1,self.y1
266            sca = 1/3.0
267            x0s = 1 / sca
268            y0s = 1 / sca
269            x1s = 1 / sca
270            y1s = 2 / sca
271          pq = getpaper(self.vecs, self.cols,          pq = getpaper(self.vecs, self.cols,
272              "pyramid", "triangle",              x0s, y0s, x1s, y1s,
273                "cone", "triangle",
274              t1, c, t2)              t1, c, t2)
275    
276    
# Line 260  class PaperTemplate: Line 278  class PaperTemplate:
278          # [0,1] x [0,1] to vertex coords, cs1 is for the first texture unit          # [0,1] x [0,1] to vertex coords, cs1 is for the first texture unit
279          # and cs2 for the second          # and cs2 for the second
280    
281            sca = 2 * sca
282    
283          cs1 = vs.coords.affineCoordsys(into, 10, self.x0, self.y0,          cs1 = vs.coords.affineCoordsys(into, 10, self.x0, self.y0,
284                                         self.texgen0.vecs[0][0],                                         self.texgen0.vecs[0][0]*sca,
285                                         self.texgen0.vecs[1][0],                                         self.texgen0.vecs[1][0]*sca,
286                                         self.texgen0.vecs[0][1],                                         self.texgen0.vecs[0][1]*sca,
287                                         self.texgen0.vecs[1][1])                                         self.texgen0.vecs[1][1]*sca)
288          vs.matcher.add(cs1, "1")          vs.matcher.add(cs1, "1")
289          cs2 = vs.coords.affineCoordsys(into, 10, self.x1, self.y1,          cs2 = vs.coords.affineCoordsys(into, 10, self.x1, self.y1,
290                                         self.texgen1.vecs[0][0],                                         self.texgen1.vecs[0][0]*sca,
291                                         self.texgen1.vecs[1][0],                                         self.texgen1.vecs[1][0]*sca,
292                                         self.texgen1.vecs[0][1],                                         self.texgen1.vecs[0][1]*sca,
293                                         self.texgen1.vecs[1][1])                                         self.texgen1.vecs[1][1]*sca)
294          vs.matcher.add(cs2, "2")          vs.matcher.add(cs2, "2")
295    
296          vs.map.put(pq, cs1, cs2)          vs.map.put(pq, cs1, cs2)
297          vs.map.put(self.frame, cs1)          vs.map.put(self.frame, vs.scaleCS(cs1, "s", x0s, y0s))
298          vs.map.put(self.frame, cs2)          vs.map.put(self.frame, vs.scaleCS(cs2, "s", x1s, y1s))
299    
300  class PaperScene:  class PaperScene:
301      def __init__(self):      def __init__(self):
# Line 326  class PaperScene: Line 346  class PaperScene:
346              vs.map.put(cq, cs)              vs.map.put(cq, cs)
347              vs.map.put(self.pt.frame, cs)              vs.map.put(self.pt.frame, cs)
348    
349    def shootImages():
350        pt = PaperTemplate()
351        def frame(fileprefix, t0, c, t1):
352            vs = w.createVobScene()
353            vs.map.put(background((0.7, 0.8, 0.6)))
354            pt.place(vs, vs.orthoCS(0, "A", 0, 10, 10, 650, 650), t0, c, t1)
355            w.renderStill(vs, 0)
356            saveanim.saveframe("shots/%s.png" % fileprefix, w)
357    
358        frame("texcomb_a", "RGB0", "RGB0", "NONE")
359        frame("texcomb_b", "NONE", "RGB1", "RGB1")
360        frame("texcomb_c", "RGB0", "BAND0", "RGB1")
361        frame("texcomb_d", "RGB0", "BAND1", "RGB1")
362    
363  class PaperFlowScene(PaperTemplate):  class PaperFlowScene(PaperTemplate):
364      def __init__(self):      def __init__(self):
365          self.bgcolor = (0.7, 0.8, 0.6)          self.bgcolor = (0.7, 0.8, 0.6)
366          self.pt = PaperTemplate()          self.pt = PaperTemplate()
367      def key(self, k):      def key(self, k):
368          self.pt.key(k)          if k == "s":
369                shootImages()
370            else:
371                self.pt.key(k)
372    
373      def scene(self, vs):      def scene(self, vs):
374          putnoc(vs, background(self.bgcolor))          putnoc(vs, background(self.bgcolor))
375                    
376          self.pt.place(vs,          self.pt.place(vs,
377              vs.orthoCS(0, "S1", 0, 100, 100, 200, 200),              vs.orthoCS(0, "S1", 0, 10, 10, 100, 100),
378              "RGB0", "RGB0", "NONE")              "RGB0", "RGB0", "NONE")
379                    
380          self.pt.place(vs,          self.pt.place(vs,
381              vs.orthoCS(0, "S2", 0, 300, 100, 200, 200),              vs.orthoCS(0, "S2", 0, 300, 100, 100, 100),
382              "NONE", "RGB1", "RGB1")              "NONE", "RGB1", "RGB1")
383                    
384          self.pt.place(vs,          self.pt.place(vs,
385              vs.orthoCS(0, "S3", 0, 200, 250, 200, 200),              vs.orthoCS(0, "S3", 0, 200, 250, 100, 100),
386              "RGB0", "BAND0", "RGB1")              "RGB0", "BAND0", "RGB1")
387            
388          self.pt.place(vs,          self.pt.place(vs,
389              vs.orthoCS(0, "S4", 0, 200, 400, 200, 200),              vs.orthoCS(0, "S4", 0, 200, 400, 200, 200),
390              "RGB0", "BAND1", "RGB1")              "RGB0", "BAND1", "RGB1")
391                    
         self.pt.place(vs,  
             vs.orthoCS(0, "S5", 0, 200, 550, 200, 200),  
             "RGB0", "BAND2", "RGB1")  
           
         self.pt.place(vs,  
             vs.orthoCS(0, "S6", 0, 500, 550, 200, 200),  
             "RGB0", "BAND3", "RGB1")  
           
         self.pt.place(vs,  
             vs.orthoCS(0, "S8", 0, 500, 150, 400, 400),  
             "RGB0", "SHAPEX_2", "RGB1")  
392                    
393          self.pt.place(vs,          if 0:
394              vs.orthoCS(0, "S9", 0, 700, 200, 400, 400),              self.pt.place(vs,
395              "RGB0", "SHAPEX_3C", "RGB1")                  vs.orthoCS(0, "S5", 0, 400, 400, 200, 200),
396                    "RGB0", "BAND1_X", "RGB1")
397          self.pt.place(vs,  
398              vs.orthoCS(0, "S9S", 0, 700, 450, 400, 400),              self.pt.place(vs,
399              "RGB0", "SHAPEX_3B", "RGB1")                  vs.orthoCS(0, "S5", 0, 400, 550, 200, 200),
400                    "RGB0", "BAND2", "RGB1")
401                
402                self.pt.place(vs,
403                    vs.orthoCS(0, "S6", 0, 500, 550, 200, 200),
404                    "RGB0", "BAND3", "RGB1")
405                
406                self.pt.place(vs,
407                    vs.orthoCS(0, "S8", 0, 500, 150, 400, 400),
408                    "RGB0", "SHAPEX_2", "RGB1")
409                
410                self.pt.place(vs,
411                    vs.orthoCS(0, "S9", 0, 700, 200, 400, 400),
412                    "RGB0", "SHAPEX_3", "RGB1")
413    
414                self.pt.place(vs,
415                    vs.orthoCS(0, "S9S", 0, 700, 450, 400, 400),
416                    "RGB0", "SHAPEX_3B", "RGB1")
417    
418          print texcodes["SHAPEX_3"]          # print texcodes["SHAPEX_3"]
419    
420  currentScene = PaperFlowScene()          currentScene = PaperFlowScene()        
421    

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26