aboutsummaryrefslogtreecommitdiff
path: root/demo/sgi/gl_panel/nurbs
diff options
context:
space:
mode:
authorSkip Montanaro <[email protected]>2021-02-16 14:40:46 -0600
committerSkip Montanaro <[email protected]>2021-02-16 14:40:46 -0600
commita19a216bc60160c162e616145ef091dd18ce4e61 (patch)
treefa4bdff21f9b04a125c84a2bfab8a1c738359e15 /demo/sgi/gl_panel/nurbs
downloadpython-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.tar.xz
python-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.zip
Python 0.9.1 as posted in alt.sources
Diffstat (limited to 'demo/sgi/gl_panel/nurbs')
-rwxr-xr-xdemo/sgi/gl_panel/nurbs/nurbs.py196
-rw-r--r--demo/sgi/gl_panel/nurbs/nurbs.s81
-rw-r--r--demo/sgi/gl_panel/nurbs/nurbsdata.py82
3 files changed, 359 insertions, 0 deletions
diff --git a/demo/sgi/gl_panel/nurbs/nurbs.py b/demo/sgi/gl_panel/nurbs/nurbs.py
new file mode 100755
index 0000000..686c3bd
--- /dev/null
+++ b/demo/sgi/gl_panel/nurbs/nurbs.py
@@ -0,0 +1,196 @@
+#! /ufs/guido/bin/sgi/python
+
+# Fancy NURBS demo. Require Z buffer and Panel Library.
+
+from gl import *
+from GL import *
+from DEVICE import *
+from nurbsdata import *
+import panel
+
+#
+# flags = trim_f, invis_f, cpvis_f, tpvis_f, axvis_f, freeze_f
+#
+TRIM = 0
+VIS = 1
+CPVIS = 2
+TPVIS = 3
+AXVIS = 4
+FREEZE = 5
+flags = [0, 1, 0, 0, 0, 0]
+
+def draw_axis () :
+ cpack (0x0)
+ zero = (0.0, 0.0, 0.0)
+ #
+ one = (1.0, 0.0, 0.0)
+ smallline (zero, one)
+ cmov (1.0, 0.0, 0.0)
+ charstr ('x')
+ #
+ one = (0.0, 1.0, 0.0)
+ smallline (zero, one)
+ cmov (0.0, 1.0, 0.0)
+ charstr ('y')
+ #
+ one = (0.0, 0.0, 1.0)
+ smallline (zero, one)
+ cmov (0.0, 0.0, 1.0)
+ charstr ('z')
+
+DELTA = 0.1
+
+def cross (p) :
+ p0 = [p[0], p[1], p[2]]
+ p1 = [p[0], p[1], p[2]]
+ for i in range (0, 3) :
+ p0[i] = p0[i] + DELTA
+ p1[i] = p1[i] - DELTA
+ smallline (p0, p1)
+ p0[i] = p0[i] - DELTA
+ p1[i] = p1[i] + DELTA
+
+def smallline (p0, p1) :
+ bgnline ()
+ v3f (p0)
+ v3f (p1)
+ endline ()
+
+def draw_pts (pnts, color) :
+ linewidth (2)
+ cpack (color)
+ for i in pnts :
+ cross (i)
+
+def init_windows():
+ foreground()
+ wid = winopen('nurbs')
+ wintitle('NURBS Surface')
+ doublebuffer()
+ RGBmode()
+ gconfig()
+ lsetdepth(0x000, 0x7fffff)
+ zbuffer( TRUE )
+
+def init_view():
+ mmode(MPROJECTION)
+ ortho( -5., 5., -5., 5., -5., 5. )
+ #
+ mmode(MVIEWING)
+ loadmatrix(idmat)
+ #
+ lmbind(MATERIAL, 1)
+
+def set_scene(flags):
+ #
+ lmbind(MATERIAL, 0)
+ RGBcolor(150,150,150)
+ lmbind(MATERIAL, 1)
+ clear()
+ zclear()
+ #
+ if not flags[FREEZE] :
+ rotate( 100, 'y' )
+ rotate( 100, 'z' )
+
+def draw_trim_surface(flags):
+ pnts = ctlpoints
+ if flags[VIS] :
+ bgnsurface()
+ nurbssurface(surfknots,surfknots,pnts,ORDER,ORDER,N_XYZ)
+ if flags[TRIM]:
+ bgntrim()
+ nurbscurve(trimknots,trimpoints,ORDER-1,N_STW)
+ endtrim()
+ endsurface()
+ #
+ if flags[CPVIS] :
+ for i in pnts :
+ draw_pts (i, RED)
+ #
+ if flags[TPVIS] :
+ tpts = trimpoints
+ draw_pts (tpts, YELLOW)
+ #
+ if flags[AXVIS] :
+ draw_axis ()
+ #
+ swapbuffers()
+
+def make_lights():
+ lmdef(DEFLMODEL,1,[])
+ lmdef(DEFLIGHT,1,[])
+ #
+ # define material #1
+ #
+ a = []
+ a = a + [EMISSION, 0.0, 0.0, 0.0]
+ a = a + [AMBIENT, 0.1, 0.1, 0.1]
+ a = a + [DIFFUSE, 0.6, 0.3, 0.3]
+ a = a + [SPECULAR, 0.0, 0.6, 0.0]
+ a = a + [SHININESS, 2.0]
+ a = a + [LMNULL]
+ lmdef(DEFMATERIAL, 1, a)
+ #
+ # turn on lighting
+ #
+ lmbind(LIGHT0, 1)
+ lmbind(LMODEL, 1)
+
+def main():
+ init_windows()
+ make_lights()
+ init_view()
+ #
+ panel.needredraw()
+ panels = panel.defpanellist('nurbs.s')
+ p = panels[0]
+ #
+ def cbtrim (a) :
+ flags[TRIM:TRIM+1] = [int (a.val)]
+ p.trim.upfunc = cbtrim
+ #
+ def cbquit (a) :
+ import sys
+ sys.exit (1)
+ p.quit.upfunc = cbquit
+ #
+ def cbmotion (a) :
+ flags[FREEZE:FREEZE+1] = [int (a.val)]
+ p.motion.upfunc = cbmotion
+ #
+ def cbxyzaxis (a) :
+ flags[AXVIS:AXVIS+1] = [int (a.val)]
+ p.xyzaxis.upfunc = cbxyzaxis
+ #
+ def cbtrimpnts (a) :
+ flags[TPVIS:TPVIS+1] = [int (a.val)]
+ p.trimpnts.upfunc = cbtrimpnts
+ #
+ def cbcntlpnts (a) :
+ flags[CPVIS:CPVIS+1] = [int (a.val)]
+ p.cntlpnts.upfunc = cbcntlpnts
+ #
+ def cbnurb (a) :
+ flags[VIS:VIS+1] = [int (a.val)]
+ p.nurb.upfunc = cbnurb
+ #
+ set_scene(flags)
+ setnurbsproperty( N_ERRORCHECKING, 1.0 )
+ setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 )
+ draw_trim_surface(flags)
+ #
+ while 1:
+ act = panel.dopanel()
+ #
+ wid = panel.userredraw ()
+ if wid :
+ winset (wid)
+ reshapeviewport()
+ set_scene(flags)
+ draw_trim_surface(flags)
+ #
+ set_scene(flags)
+ draw_trim_surface(flags)
+
+main()
diff --git a/demo/sgi/gl_panel/nurbs/nurbs.s b/demo/sgi/gl_panel/nurbs/nurbs.s
new file mode 100644
index 0000000..05fb514
--- /dev/null
+++ b/demo/sgi/gl_panel/nurbs/nurbs.s
@@ -0,0 +1,81 @@
+;;; This file was automatically generated by the panel editor.
+;;; If you read it into gnu emacs, it will automagically format itself.
+
+(panel (prop help creator:user-panel-help)
+(prop user-panel #t)
+(label "NURB controls")
+(x 815)
+(y 22)
+(al (pnl_toggle_button (name "trim")
+(prop help creator:user-act-help)
+(label "trim on/off")
+(x 4)
+(y 4.5)
+(w 0.45)
+(h 0.4)
+(downfunc move-then-resize)
+)
+(pnl_toggle_button (name "motion")
+(prop help creator:user-act-help)
+(label "motion on/off")
+(y 1)
+(downfunc move-then-resize)
+)
+(pnl_toggle_button (name "xyzaxis")
+(prop help creator:user-act-help)
+(label "xyz-axis")
+(y 3)
+(downfunc move-then-resize)
+)
+(pnl_toggle_button (name "trimpnts")
+(prop help creator:user-act-help)
+(label "trimming pnts")
+(y 3.5)
+(downfunc move-then-resize)
+)
+(pnl_toggle_button (name "cntlpnts")
+(prop help creator:user-act-help)
+(label "control pnts")
+(y 4)
+(downfunc move-then-resize)
+)
+(pnl_toggle_button (name "nurb")
+(prop help creator:user-act-help)
+(label "nurb")
+(y 4.5)
+(val 1)
+(downfunc move-then-resize)
+)
+(pnl_button (name "quit")
+(prop help creator:user-act-help)
+(label "quit")
+(x 4)
+(y 1)
+(labeltype 1)
+(downfunc move-then-resize)
+)
+(pnl_label (prop help creator:user-act-help)
+(label "TRIMMING")
+(x 4)
+(y 5)
+(downfunc move-then-resize)
+)
+(pnl_label (prop help creator:user-act-help)
+(label "MOTION")
+(y 1.5)
+(downfunc move-then-resize)
+)
+(pnl_label (prop help creator:user-act-help)
+(label "VISIBILITY")
+(y 5)
+(downfunc move-then-resize)
+)
+)
+)
+;;; Local Variables:
+;;; mode: scheme
+;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3))
+;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")"))
+;;; eval: (indent-region (point-min) (point-max) nil)
+;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer))
+;;; End:
diff --git a/demo/sgi/gl_panel/nurbs/nurbsdata.py b/demo/sgi/gl_panel/nurbs/nurbsdata.py
new file mode 100644
index 0000000..ed7e705
--- /dev/null
+++ b/demo/sgi/gl_panel/nurbs/nurbsdata.py
@@ -0,0 +1,82 @@
+# Data used by fancy nurbs demo.
+
+TRUE = 1
+FALSE = 0
+
+RED = 0xff
+YELLOW = 0xffff
+
+#
+# nurb order
+#
+ORDER = 4
+
+#
+# identity matrix
+#
+idmat = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
+
+#
+# s and t knots
+#
+surfknots = [-1, -1, -1, -1, 1, 1, 1, 1]
+
+#
+# list of list of control points
+#
+def make_ctlpoints():
+ c = []
+ #
+ ci = []
+ ci.append(-2.5, -3.7, 1.0)
+ ci.append(-1.5, -3.7, 3.0)
+ ci.append(1.5, -3.7, -2.5)
+ ci.append(2.5, -3.7, -0.75)
+ c.append(ci)
+ #
+ ci = []
+ ci.append(-2.5, -2.0, 3.0)
+ ci.append(-1.5, -2.0, 4.0)
+ ci.append(1.5, -2.0, -3.0)
+ ci.append(2.5, -2.0, 0.0)
+ c.append(ci)
+ #
+ ci = []
+ ci.append(-2.5, 2.0, 1.0)
+ ci.append(-1.5, 2.0, 0.0)
+ ci.append(1.5, 2.0, -1.0)
+ ci.append(2.5, 2.0, 2.0)
+ c.append(ci)
+ #
+ ci = []
+ ci.append(-2.5, 2.7, 1.25)
+ ci.append(-1.5, 2.7, 0.1)
+ ci.append(1.5, 2.7, -0.6)
+ ci.append(2.5, 2.7, 0.2)
+ c.append(ci)
+ #
+ return c
+
+ctlpoints = make_ctlpoints ()
+
+#
+# trim knots
+#
+trimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.]
+
+def make_trimpoints():
+ c = []
+ #
+ c.append(1.0, 0.0, 1.0)
+ c.append(1.0, 1.0, 1.0)
+ c.append(0.0, 2.0, 2.0)
+ c.append(-1.0, 1.0, 1.0)
+ c.append(-1.0, 0.0, 1.0)
+ c.append(-1.0, -1.0, 1.0)
+ c.append(0.0, -2.0, 2.0)
+ c.append(1.0, -1.0, 1.0)
+ c.append(1.0, 0.0, 1.0)
+ #
+ return c
+
+trimpoints = make_trimpoints()