Blender Analytical Geometry -*NEW*BAG 0.0.5

Very nice script S68!

Springs image (Sorry, Geocities does not allow image hotlinking)

Bag file content spring.bag (Right click and select “Save target as…”)

<BAG version=“0.0.4”>
<Reference>Cylindrical</Reference>
<Label>
Spring
</Label>
<F1>
IR+SR*(1+cos(v))
</F1>
<F2>
2C/CLu
</F2>
<F3>
u/pi+SRsin(v)
</F3>
<ParU Min=“0” Max="CL
pi">
200
</ParU>
<ParV Min="-3.5" Max=“3.5”>
10
</ParV>
<UserPara Name=“SR” Value=“0.4” Index=“0”>
Section radius
</UserPara>
<UserPara Name=“IR” Value=“1.0” Index=“1”>
Internal radius
</UserPara>
<UserPara Name=“C” Value=“3.0” Index=“2”>
Number of coils
</UserPara>
<UserPara Name=“L” Value=“4.0” Index=“3”>
Length
</UserPara>
<Macro Name=“CL” Value="(L-2*SR)" Index=“0”>
Corrected length
</Macro>
</BAG>

wibauxl

Alright, I have a new bag:

The lumpy spiral torus bag

pics here: http://www.geocities.com/grunt5000/

Sorry about the geocities, hopefully it will be fixed soon.


&lt;BAG version="0.0.4"&gt;
&lt;Reference&gt;Cylindrical&lt;/Reference&gt;
&lt;Label&gt;
spiral torus with lumps
&lt;/Label&gt;
&lt;F1&gt;
trr+sin(v*pi*2)*tt+cos((u+off)*ln*2*pi)*lr+(sin(u*pi*nlump*2)*sin(v*2*pi)*slump)
&lt;/F1&gt;
&lt;F2&gt;
u*2*pi
&lt;/F2&gt;
&lt;F3&gt;
cos(v*pi*2)*tt+sin((u+off)*ln*2*pi)*lr+sin(u*pi*nlump*2)*cos(v*2*pi)*slump
&lt;/F3&gt;
&lt;ParU Min="0.0" Max="1.0"&gt;
70
&lt;/ParU&gt;
&lt;ParV Min="0.0" Max="1.0"&gt;
30
&lt;/ParV&gt;
&lt;UserPara Name="trr" Value="10.0" Index="0"&gt;
torus radius
&lt;/UserPara&gt;
&lt;UserPara Name="ln" Value="0.0" Index="1"&gt;
# of loops
&lt;/UserPara&gt;
&lt;UserPara Name="lr" Value="1.0" Index="2"&gt;
loop radius
&lt;/UserPara&gt;
&lt;UserPara Name="tt" Value="1.0" Index="3"&gt;
torus thickness
&lt;/UserPara&gt;
&lt;UserPara Name="off" Value="0.0" Index="4"&gt;
loop cycle offset(0-1)
&lt;/UserPara&gt;
&lt;UserPara Name="nlump" Value="10.0" Index="5"&gt;
# of lumps
&lt;/UserPara&gt;
&lt;UserPara Name="slump" Value="1.0" Index="6"&gt;
size of lumps
&lt;/UserPara&gt;
&lt;Macro Name="E" Value="exp(alpha0*2*pi*v)" Index="0"&gt;
Exponential behavior
&lt;/Macro&gt;
&lt;/BAG&gt;

It doesn’t have to be lumpy. Or spiral. it could just be a torus.

There’s a bug in the GUI, sometimes (often, but not always…) when removing macros, the script crashes.

flicks through code
Aha! Line 907 should be

TSMNumber = TSMNumber - 1

not

TSMNumber = TSUPNumber - 1

Also, sometimes weird things happen when removing either constants or macros when you have lots, which is fixed by putting a break command after each of the TSUPNumber = TSUPNumber - 1 and TSMNumber = TSMNumber - 1 lines (lines 891 and 907)

Oh,

one cannot get a 4 days off! I missed all these posts, thanx :slight_smile:

Actually I use Maple too, but Blender is much better a renderer…

I’m painfully aware of bad english, will fix that.

I also process all bug reports, probably replace Save/Load buttons but not today, nor tomorrow… I’m really buisy now!

Stefano

Blender is a better renderer and now (fingers crossed) that the
python API is a bit more stable I’ll start to make scripts again.
Blender meshes are also better because they carry normals,
and differentail geometry is normals :o

Your script is great but I think that if you could catch
the Python eval() errors and print them it would
be better. I spent five minutes with an example that
produced a mesh with single point because you set
the value of the expresion 0.0 when you capture the error.

I modified BAG0.0.1 to do a save before calculating
the surface. It crashed if the expression was not
well formed (missing paranthesis etc.) but at
least I got the Python stderror. And we all know
and love Python for its explicit error mssgs.

thanks anyhow

macbuse

A nice feature to add:

When making a curve rather than a surface, have the option to build it as a bezier rather than a mesh. Maybe have the option for a NURBS curve too.

And maybe while you’re at it have to option to build NURBS surfaces instead of meshes.

Of course, if you’re up to it :wink:

He is probably waiting for that lazy stiv guy to finish up work on the Curve module.

And maybe while you’re at it have to option to build NURBS surfaces instead of meshes.

The blender python interface does not support Surfaces. Yet. But it will.

Yeah

I wanted to do curves, but Python API can’t

Better error messages… yes…

BTW, the new API has dialogs?

TO show errors there rather than on console!

Stefano

Ok, no dialogs in API, so I’m making my owns

I’m trying to add uv coords like:

ve.uvco[0]=u
ve.uvco[1]=v

But I get wrong results. all verts have the same square UVs… what’s wrong?

Stefano

I had no problem in 0.0.1

I did the textured tori using BAG

http://picard.ups-tlse.fr/~mcshane/torus.htm

Did you remember?

SurfaceMesh.hasVertexUV(1)

--------------------here’s the rest of the code for reference----------------

#############################################################

Blender Analytic Geometry Tool

© May 2004 Stefano <S68> Selleri

Released under the Blender Artistic Licence (BAL)

See www.blender.org

#############################################################

History

V: 0.0.0 - 09-05-04 - The script starts to take shape, an

history is now deserved :slight_smile:

V: 0.0.1 - 14-05-04 - First public release

#############################################################

import Blender
from Blender import *
from math import *
import os
import re
import string

k = 1.75

rr = 0.0

#############################################################

GLOBALS

#############################################################
VERSION =‘0.0.0’

#############################################################

INTERFACE EVENTS

#############################################################
EXIT = 1
NOOP = 2
COMPUTE = 3
ACTION_SAVE = 4
ACTION_LOAD = 5
FILE_CHANGE = 6

CURVE_ON = 11
SURFACE_ON = 12

CART_ON = 21
CYL_ON = 22
SPH_ON = 23

CART_ONS = 25
CYL_ONS = 26
SPH_ONS = 27

SET_U_MIN = 101
SET_U_MAX = 102

SET_U_MINS = 105
SET_U_MAXS = 106
SET_V_MINS = 107
SET_V_MAXS = 108

TYPE_MESH = 201
TYPE_CURVE = 202

#############################################################

INTERFACE GLOBALS

#############################################################
TECurve = Draw.Create(1)
TESurface = Draw.Create(0)
#saveTo = Draw.Create(’’‘c:/bag.txt’’’)

#############################################################

GLOBAL Curves

#############################################################
TCRefCart = Draw.Create(1)
TCRefCyl = Draw.Create(0)
TCRefSph = Draw.Create(0)

TC1fun = Draw.Create(‘u’)
TC2fun = Draw.Create(‘0’)
TC3fun = Draw.Create(‘0’)

TCumin = Draw.Create(0.0)
TCumax = Draw.Create(1.0)
TCuN = Draw.Create(10)

TCmesh = Draw.Create(1)
TCcurve = Draw.Create(0)

#############################################################

FILE GLOBALS

#############################################################
MyFile = ‘’‘c:/bag.txt’’’
TempFile = ‘’’./bag.tmp’’’

#############################################################

SURFACE GLOBALS

#############################################################

TSRefCart = Draw.Create(1)
TSRefCyl = Draw.Create(0)
TSRefSph = Draw.Create(0)

TS1fun = Draw.Create(’(2+cos(u))*cos(v)’)
TS2fun = Draw.Create(’(2+cos(u))*sin(v)’)
TS3fun = Draw.Create(‘sin(u)’)

TSumin = Draw.Create(0.0)
TSumax = Draw.Create(3.141)
TSuN = Draw.Create(10)

TSvmin = Draw.Create(0.0)
TSvmax = Draw.Create(3.141)
TSvN = Draw.Create(10)

#############################################################

XML Parser

#############################################################

#############################################################

FILE FUNCTIONS

#############################################################

#############################################################

Curves

#############################################################
def ComputeCurve():
global TCRefCart, TCRefCyl,TCRefSph
global TC1fun, TC2fun, TC3fun
global TCumin, TCumax, TCuN, TCmesh, TCcurve

CurveMesh = NMesh.GetRaw()




for i in range(TCuN.val):
    u = (TCumax.val-TCumin.val)*i/(TCuN.val-1)+TCumin.val

    c1 = TC1fun.val
    c1 = re.sub(r'\bu\b',str(u),c1)
    c1 = eval(c1)
    
    c2 = TC2fun.val
    c2 = re.sub(r'\bu\b',str(u),c2)
    c2 = eval(c2)

    c3 = TC3fun.val
    c3 = re.sub(r'\bu\b',str(u),c3)
    c3 = eval(c3)

    if (TCRefCart.val==1):
        x = c1
        y = c2
        z = c3
    elif (TCRefCyl.val==1):
        x = c1 * cos(c2)
        y = c1 * sin(c2)
        z = c3
    else:
        x = c1 * sin(c2) * cos(c3)
        y = c1 * sin(c2) * sin(c3)
        z = c1 * cos(c2)

    CurveMesh.verts.append(NMesh.Vert(x,y,z))
    if (i&gt;0):
        nf = NMesh.Face()
    nf.v.append(CurveMesh.verts[i-1])
    nf.v.append(CurveMesh.verts[i])
        CurveMesh.faces.append(nf)
        
NMesh.PutRaw(CurveMesh)

#############################################################

Change File

#############################################################

def changeFile(fn):
global MyFile
MyFile = fn

#############################################################

Save

#############################################################

def BAGsave(fn):

fp = open(fn,'w')

fp.write("%d

“%TECurve.val)
fp.write(”%d
"%TESurface.val)

fp.write("%d

“%TSRefCart.val)
fp.write(”%d
“%TSRefCyl.val)
fp.write(”%d
"%TSRefSph.val)

fp.write(TS1fun.val+"

“)
fp.write(TS2fun.val+”
“)
fp.write(TS3fun.val+”
")

fp.write("%f

“%TSumin.val)
fp.write(”%f
“%TSumax.val)
fp.write(”%f
“%TSvmin.val)
fp.write(”%f
"%TSvmax.val)

fp.write("%d

“%TCRefCart.val)
fp.write(”%d
“%TCRefCyl.val)
fp.write(”%d
"%TCRefSph.val)

fp.write(TC1fun.val+"

“)
fp.write(TC2fun.val+”
“)
fp.write(TC3fun.val+”
")

fp.write("%f

“%TCumin.val)
fp.write(”%f
"%TCumax.val)

fp.write("%d

“%TSuN.val)
fp.write(”%d
"%TSvN.val)

fp.close()
print "BAG saved %s"%fn 

#############################################################

Load

#############################################################
def BAGload(fn):
try:
fp = open(fn,‘r’)
except:
print “bad file name: %s”%fn
return

if 1:	
	TECurve.val = int(fp.readline()[:-1])
	TESurface.val = int(fp.readline()[:-1])

	TSRefCart.val = int(fp.readline()[:-1])
	TSRefCyl.val = int(fp.readline()[:-1])
	TSRefSph.val = int(fp.readline()[:-1])

	TS1fun.val = fp.readline()[:-1]
	TS2fun.val = fp.readline()[:-1]
	TS3fun.val = fp.readline()[:-1]

	TSumin.val = float(fp.readline()[:-1])
	TSumax.val = float(fp.readline()[:-1])
	TSvmin.val = float(fp.readline()[:-1])
	TSvmax.val = float(fp.readline()[:-1])


	TCRefCart.val = int(fp.readline()[:-1])
	TCRefCyl.val = int(fp.readline()[:-1])
	TCRefSph.val = int(fp.readline()[:-1])

	TC1fun.val = fp.readline()[:-1]
	TC2fun.val = fp.readline()[:-1]
	TC3fun.val = fp.readline()[:-1]

	TCumin.val = float(fp.readline()[:-1])
	TCumax.val = float(fp.readline()[:-1])

	TSuN.val = int(fp.readline()[:-1])
	TSvN.val = int(fp.readline()[:-1])
	
else:
	print "bad data  file: %s"%fn
	fp.close()
	return

fp.close()
Draw.Redraw()
print "BAG loaded %s"%fn 

#############################################################

Surfaces

#############################################################
def ComputeSurface():
global TSRefCart, TSRefCyl,TSRefSph
global TS1fun, TS2fun, TS3fun
global TSumin, TSumax, TSuN, TSvmin, TSvmax, TSvN

SurfaceMesh = NMesh.GetRaw()
SurfaceMesh.hasVertexUV(1)

print k

for i in range(TSuN.val):
    for j in range(TSvN.val):

        u = (TSumax.val-TSumin.val)*i/(TSuN.val-1)+TSumin.val
        v = (TSvmax.val-TSvmin.val)*j/(TSvN.val-1)+TSvmin.val

        c1 = TS1fun.val
        c1 = re.sub(r'\bu\b',str(u),c1)
        c1 = re.sub(r'\bv\b',str(v),c1)
        c1 = eval(c1)
    
        c2 = TS2fun.val
        c2 = re.sub(r'\bu\b',str(u),c2)
        c2 = re.sub(r'\bu\b',str(v),c2)
        c2 = eval(c2)

        c3 = TS3fun.val
        c3 = re.sub(r'\bu\b',str(u),c3)
        c3 = re.sub(r'\bv\b',str(v),c3)
        c3 = eval(c3)

        if (TSRefCart.val==1):
            x = c1
            y = c2
            z = c3
        elif (TSRefCyl.val==1):
            x = c1 * cos(c2)
            y = c1 * sin(c2)
            z = c3
        else:
            x = c1 * sin(c2) * cos(c3)
            y = c1 * sin(c2) * sin(c3)
            z = c1 * cos(c2)
		
        pp = NMesh.Vert(x,y,z)
        #print (1.0*i/TSuN.val,1.0*j/TSvN.val)
        pp.uvco = (2.0*i/TSuN.val,2.0*j/TSvN.val)
        SurfaceMesh.verts.append(pp)

        if (i&gt;0):
            if (j&gt;0):
                nf = NMesh.Face()
                idx = i*TSvN.val + j
                nf.v.append(SurfaceMesh.verts[idx])
                nf.v.append(SurfaceMesh.verts[idx-1])
                nf.v.append(SurfaceMesh.verts[idx-TSvN.val-1])
                nf.v.append(SurfaceMesh.verts[idx-TSvN.val])
                SurfaceMesh.faces.append(nf)
        
NMesh.PutRaw(SurfaceMesh)

#############################################################

Graphics

#############################################################
def draw():
global EXIT, NOOP, COMPUTE, ACTION_SAVE, ACTION_LOAD
global CURVE_ON, SURFACE_ON
global CART_ON,CYL_ON,SPH_ON
global SET_U_MIN, SET_U_MAX
global SET_U_MINS, SET_U_MAXS, SET_V_MINS, SET_V_MAXS
global TYPE_MESH, TYPE_CURVE

global TECurve, TESurface
global TCRefCart, TCRefCyl,TCRefSph
global TC1fun, TC2fun, TC3fun
global TCumin, TCumax, TCuN, TCmesh, TCcurve

global TSRefCart, TSRefCyl,TSRefSph
global TS1fun, TS2fun, TS3fun
global TSumin, TSumax, TSuN, TSvmin, TSvmax, TSvN

global myFile

#############################################################
# Backgrounds                                               #
#############################################################

BGL.glClearColor(0.5, 0.5, 0.5, 0.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glColor3f(0, 0, 0) 			# Black
BGL.glRectf(2, 2, 482, 520)
BGL.glColor3f(0.48, 0.4, 0.57) 		# Light Purple
BGL.glRectf(4, 479, 480, 510)
BGL.glRectf(4, 34, 480, 450)
BGL.glColor3f(0.3, 0.27, 0.35) 		# Dark purple
BGL.glRectf(4, 451,480, 478)
BGL.glColor3f(0.6, 0.6, 0.35) 		# Dark purple
BGL.glRectf(4, 170, 480, 33)

#############################################################
# Common Header                                             #
#############################################################

BGL.glColor3f(0.9, 0.8, 1)
BGL.glRasterPos2d(10, 500)
Draw.Text("Blender Analytic Geometry v. "+VERSION)
BGL.glRasterPos2d(10, 484)
Draw.Text("(C) May 2004 Stefano Selleri &lt;a.k.a. S68&gt;")
Draw.Button("Save", ACTION_SAVE, 4, 150, 60, 12,"Save currents settings to a file")
Draw.Button("Load", ACTION_LOAD, 145, 150, 60, 12,"Loads Previously saved Settings form a file")
Draw.Button("Exit", EXIT, 367, 130, 110, 24)

Draw.Button("File:" + MyFile, FILE_CHANGE, 5, 120, 200, 18)

TECurve     = Draw.Toggle("Curve",CURVE_ON,7,454,110,20,TECurve.val,
                          "Curve: 1 parameter item")
TESurface   = Draw.Toggle("Surface",SURFACE_ON,127,454,110,20,TESurface.val,
                          "Surface: 2 parameter item")


Draw.Button("GENERATE", COMPUTE, 7, 200, 470, 24)
BGL.glColor3f(0.9, 0.9, 0.9)

if (TECurve.val==1):
#############################################################
# Screen 1                                                  #
#############################################################

    BGL.glRasterPos2d(8, 425)
    Draw.Text("Parametric curve:")
    
TCRefCart = Draw.Toggle("Cartesian",CART_ON,160,420,76,18,TCRefCart.val,
           	                "Uses Cartesian Coordinates")
TCRefCyl  = Draw.Toggle("Cylindrical",CYL_ON,240,420,76,18,TCRefCyl.val,
           	                "Uses Cylindrical Coordinates")
TCRefSph  = Draw.Toggle("Spherical",SPH_ON,320,420,76,18,TCRefSph.val,
           	                "Uses Spherical Coordinates")

BGL.glRasterPos2d(8, 385)
Draw.Text("Parametric laws (parameter 'u'):")

if (TCRefCart.val == 1):
####################################################
# CartLabels                                       #
####################################################
        TC1fun    = Draw.String("x(u) = ", NOOP, 50, 360, 360, 18, TC1fun.val, 2048 , 
        		    "X coordinate parametric (u) law")
        TC2fun    = Draw.String("y(u) = ", NOOP, 50, 340, 360, 18, TC2fun.val, 2048 , 
        		    "Y coordinate parametric (u) law")
        TC3fun    = Draw.String("z(u) = ", NOOP, 50, 320, 360, 18, TC3fun.val, 2048 ,
        		    "Z coordinate parametric (u) law")
elif (TCRefCyl.val == 1):
####################################################
# CartLabels                                       #
####################################################
        TC1fun    = Draw.String("rho(u) = ", NOOP, 50, 360, 360, 18, TC1fun.val, 2048 , 
        		    "RHO coordinate parametric (u) law")
        TC2fun    = Draw.String("phi(u) = ", NOOP, 50, 340, 360, 18, TC2fun.val, 2048 , 
        		    "PHI coordinate parametric (u) law")
        TC3fun    = Draw.String("z(u) = ", NOOP, 50, 320, 360, 18, TC3fun.val, 2048 ,
        		    "Z coordinate parametric (u) law")	 

else:
####################################################
# CartLabels                                       #
####################################################
        TC1fun    = Draw.String("r(u) = ", NOOP, 50, 360, 360, 18, TC1fun.val, 2048 , 
        		    "R coordinate parametric (u) law")
        TC2fun    = Draw.String("theta(u) = ", NOOP, 50, 340, 360, 18, TC2fun.val, 2048 , 
        		    "THETA coordinate parametric (u) law")
        TC3fun    = Draw.String("phi(u) = ", NOOP, 50, 320, 360, 18, TC3fun.val, 2048 ,
        		    "PHI coordinate parametric (u) law")	 


BGL.glRasterPos2d(8, 285)
Draw.Text("Parameter u values:")
   	TCumin = Draw.Number("u min: ", SET_U_MIN, 50, 260, 120, 18, TCumin.val, -10000.0, 10000.0, 
            	                "Minimum (starting) value for parameter u")
   	TCumax = Draw.Number("u max: ", SET_U_MAX, 175, 260, 120, 18, TCumax.val, -10000.0, 10000.0, 
            	                "Maximum (starting) value for parameter u")
   	TCuN   = Draw.Number("N: ", NOOP, 300, 260, 120, 18, TCuN.val, 2, 10000, 
            	                "Number of points")

BGL.glRasterPos2d(8, 205)
Draw.Text("Create What?:")

TCmesh = Draw.Toggle(“Mesh”,TYPE_MESH,160,200,76,18,TCmesh.val,

“Make a Mesh”)

TCcurve = Draw.Toggle(“Curve”,TYPE_CURVE,240,200,76,18,TCcurve.val,

“Make a Curve”)

else:
#############################################################
# Screen 2                                                  #
#############################################################

    BGL.glRasterPos2d(8, 425)
    Draw.Text("Parametric surface:")
    
TSRefCart = Draw.Toggle("Cartesian",CART_ONS,160,420,76,18,TSRefCart.val,
           	                "Uses Cartesian Coordinates")
TSRefCyl  = Draw.Toggle("Cylindrical",CYL_ONS,240,420,76,18,TSRefCyl.val,
           	                "Uses Cylindrical Coordinates")
TSRefSph  = Draw.Toggle("Spherical",SPH_ONS,320,420,76,18,TSRefSph.val,
           	                "Uses Spherical Coordinates")

BGL.glRasterPos2d(8, 385)
Draw.Text("Parametric laws (parameters 'u,v'):")

if (TSRefCart.val == 1):
####################################################
# CartLabels                                       #
####################################################
        TS1fun    = Draw.String("x(u,v) = ", NOOP, 50, 360, 360, 18, TS1fun.val, 2048 , 
        		    "X coordinate parametric (u,v) law")
        TS2fun    = Draw.String("y(u,v) = ", NOOP, 50, 340, 360, 18, TS2fun.val, 2048 , 
        		    "Y coordinate parametric (u,v) law")
        TS3fun    = Draw.String("z(u,v) = ", NOOP, 50, 320, 360, 18, TS3fun.val, 2048 ,
        		    "Z coordinate parametric (u,v) law")
elif (TSRefCyl.val == 1):
####################################################
# CartLabels                                       #
####################################################
        TS1fun    = Draw.String("rho(u,v) = ", NOOP, 50, 360, 360, 18, TS1fun.val, 2048 , 
        		    "RHO coordinate parametric (u,v) law")
        TS2fun    = Draw.String("phi(u,v) = ", NOOP, 50, 340, 360, 18, TS2fun.val, 2048 , 
        		    "PHI coordinate parametric (u,v) law")
        TS3fun    = Draw.String("z(u,v) = ", NOOP, 50, 320, 360, 18, TS3fun.val, 2048 ,
        		    "Z coordinate parametric (u,v) law")	 

else:
####################################################
# CartLabels                                       #
####################################################
        TS1fun    = Draw.String("r(u,v) = ", NOOP, 50, 360, 360, 18, TS1fun.val, 2048 , 
        		    "R coordinate parametric (u,v) law")
        TS2fun    = Draw.String("theta(u,v) = ", NOOP, 50, 340, 360, 18, TS2fun.val, 2048 , 
        		    "THETA coordinate parametric (u,v) law")
        TS3fun    = Draw.String("phi(u,v) = ", NOOP, 50, 320, 360, 18, TS3fun.val, 2048 ,
        		    "PHI coordinate parametric (u,v) law")	 


BGL.glRasterPos2d(8, 285)
Draw.Text("Parameter u,v values:")
   	TSumin = Draw.Number("u min: ", SET_U_MIN, 50, 260, 120, 18, TSumin.val, -10000.0, 10000.0, 
            	                "Minimum (starting) value for parameter u")
   	TSumax = Draw.Number("u max: ", SET_U_MAX, 175, 260, 120, 18, TSumax.val, -10000.0, 10000.0, 
            	                "Maximum (starting) value for parameter u")
   	TSuN   = Draw.Number("N: ", NOOP, 300, 260, 120, 18, TSuN.val, 2, 10000, 
            	                "Number of points")

   	TSvmin = Draw.Number("v min: ", SET_U_MIN, 50, 240, 120, 18, TSvmin.val, -10000.0, 10000.0, 
            	                "Minimum (starting) value for parameter u")
   	TSvmax = Draw.Number("v max: ", SET_U_MAX, 175, 240, 120, 18, TSvmax.val, -10000.0, 10000.0, 
            	                "Maximum (starting) value for parameter u")
   	TSvN   = Draw.Number("M: ", NOOP, 300, 240, 120, 18, TSvN.val, 2, 10000, 
            	                "Number of points")

def event(evt, val):
if (evt== Draw.QKEY and not val):
Draw.Exit()

def bevent(evt):
global EXIT, NOOP, COMPUTE, ACTION_SAVE, ACTION_LOAD,FILE_CHANGE
global CURVE_ON, SURFACE_ON
global CART_ON,CYL_ON,SPH_ON
global CART_ONS,CYL_ONS,SPH_ONS
global SET_U_MIN, SET_U_MAX
global SET_U_MINS, SET_U_MAXS, SET_V_MINS, SET_V_MAXS
global TYPE_MESH, TYPE_CURVE

global TECurve, TESurface
global TCRefCart, TCRefCyl,TCRefSph
global TC1fun, TC2fun, TC3fun
global TCumin, TCumax, TCuN, TCmesh, TCcurve

global TSRefCart, TSRefCyl,TSRefSph
global TS1fun, TS2fun, TS3fun
global TSumin, TSumax, TSuN, TSvmin, TSvmax, TSvN

if   (evt == EXIT):
    # EXIT
    Draw.Exit()
    # 2 = NOOP
elif (evt == COMPUTE):
    #save data before the crash
    BAGsave(TempFile)
    # CALCULATE CURVE	
    if (TECurve.val==1):
        ComputeCurve()
    else:
        ComputeSurface()
Draw.Redraw()
elif (evt == ACTION_SAVE):
    BAGsave(MyFile)
elif (evt == ACTION_LOAD):
    BAGload(MyFile)
elif (evt == FILE_CHANGE):
	Blender.Window.FileSelector(changeFile,"Pick a file")
    
#############################################################
# Interface Panel Swapping                                  #
#############################################################
elif (evt == CURVE_ON):
TECurve.val     = 1
TESurface.val   = 0
    # REDRAW INTERFACE
Draw.Redraw()
elif (evt == SURFACE_ON):
TECurve.val     = 0
TESurface.val   = 1
    # REDRAW INTERFACE
Draw.Redraw()

#############################################################
# COORDINATE SWAPPING                                       #
#############################################################
elif (evt == CART_ON):
TCRefCart.val  = 1
TCRefCyl.val   = 0
TCRefSph.val   = 0
    # REDRAW INTERFACE
Draw.Redraw()
elif (evt == CYL_ON):
TCRefCart.val  = 0
TCRefCyl.val   = 1
TCRefSph.val   = 0
    # REDRAW INTERFACE
Draw.Redraw()
elif (evt == SPH_ON):
TCRefCart.val  = 0
TCRefCyl.val   = 0
TCRefSph.val   = 1
    # REDRAW INTERFACE
Draw.Redraw()
    
elif (evt == CART_ONS):
TSRefCart.val  = 1
TSRefCyl.val   = 0
TSRefSph.val   = 0
    # REDRAW INTERFACE
Draw.Redraw()
elif (evt == CYL_ONS):
TSRefCart.val  = 0
TSRefCyl.val   = 1
TSRefSph.val   = 0
    # REDRAW INTERFACE
Draw.Redraw()
elif (evt == SPH_ONS):
TSRefCart.val  = 0
TSRefCyl.val   = 0
TSRefSph.val   = 1
    # REDRAW INTERFACE
Draw.Redraw()

elif (evt == SET_U_MIN):
if (TCumax.val &lt; TCumin.val):
        TCumax.val = TCumin.val
        Draw.Redraw()
elif (evt == SET_U_MAX):
if (TCumax.val &lt; TCumin.val):
        TCumin.val = TCumax.val
        Draw.Redraw()

elif (evt == SET_U_MINS):
if (TSumax.val &lt; TSumin.val):
        TSumax.val = TSumin.val
        Draw.Redraw()
elif (evt == SET_U_MAXS):
if (TSumax.val &lt; TSumin.val):
        TSumin.val = TSumax.val
        Draw.Redraw()
elif (evt == SET_V_MINS):
if (TSvmax.val &lt; TSvmin.val):
        TSvmax.val = TSvmin.val
        Draw.Redraw()
elif (evt == SET_V_MAXS):
if (TSvmax.val &lt; TSvmin.val):
        TSvmin.val = TSvmax.val
        Draw.Redraw()
        
elif (evt == TYPE_MESH):
TCmesh.val    = 1
TCcurve.val   = 0
    # REDRAW INTERFACE
Draw.Redraw()
elif (evt == TYPE_CURVE):
TCmesh.val    = 0
TCcurve.val   = 1
    # REDRAW INTERFACE
Draw.Redraw()

#############################################################

Registering all functions

#############################################################

try:
BAGload(TempFile)
except:
print “BAG no saved session”

Draw.Register(draw, event, bevent)

Oh, thanx :slight_smile:

I’ll try again

Stefano

Hrm,

You did what I was trying…

But you don’t need to do 2.0*i/TSuN.val since ‘u’ is available .

BTW, why 2.0* ?

Anyway it does not work.

If I select the surface and hit FKEY Image window shows that each
face has the same UV coords

[(0,0),(256,0),(256,256),(0,256)]

:frowning:

Stefano

OK! Vers. 0.0.5 is out!

http://www.selleri.org/Blender/scripts/bag-0.0.5.zip

CHANGELOG

  • bigger Save & Load Buttons (but still on header, sorry…

  • N and M are now parametric too!

  • GUI bug solved

  • UV coords are created

  • Error messages are more clear (?) and on GUI

Stefano

this is awesome! so useful.

thanks stefano!

Loop over the vertices they are there

for p in mesh.verts:
print p.uvco

I was only interested in sticky (vertex uv) co ords
so the texture shouldhave the sticky flag set in the map tab
to see the mapping.

They don’t show up in the face.uv list which is used
when the uv flag is activated in the texture.

I haven’t really figured how face uvs work as they weren’t
available the last time (<Blender 2.25) that I wrote scripts.

As for 2.0 I don’t know why it works but it does.

Oh, Ok, I see :slight_smile:

But I believe face UV are mosre useful, since you can edit them on the image window!

Stefano

This works for me

first comment out

#SurfaceMesh.hasVertexUV(1)

then modify your loop to modify nf.uv.

I’m sorry I like list comprehensions %

            square = [[0,0],[0,-1],[-1,-1],[-1,0]]

            if (i&gt;0):
                if (j&gt;0):
                    nf = NMesh.Face()
                    nf.v = [ SurfaceMesh.verts[i + x[0]*TSuN.val + j + x[1] ] for x in square ]
                    nf.uv =[ (1.0)/TSuN.val* (x[0] + i, 1.0/TSvN.val*(x[1] + j) ) for x in square]
                    SurfaceMesh.faces.append(nf)

Sorry I screwed up its:


            square = [[0,0],[0,-1],[-1,-1],[-1,0]]

            if (i&gt;0):
                if (j&gt;0):
                    nf = NMesh.Face()
                    nf.v = [ SurfaceMesh.verts[i + x[0]*TSuN.val + j + x[1] ] for x in square ]
                    nf.uv =[ (2.0/TSuN.val* (x[0] + i), 2.0/TSvN.val*(x[1] + j) ) for x in square]
                    SurfaceMesh.faces.append(nf)

I’m sorry I like list comprehensions

hahahaha - me too - they look soo damn good in my Sc1 (the baby scite :slight_smile: ) in fact they look good in scite|flash too

Anyhow, it works! Thanx for all suggestions!

http://www.selleri.org/Blender/buffer/uvtest.jpg

Stefano

P.S. In 0.0.5 there is a print in the face creation loop which you might want to eliminate!