PyVRML97 2.3.4b3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyvrml97-2.3.4b3.dist-info/METADATA +65 -0
- pyvrml97-2.3.4b3.dist-info/RECORD +39 -0
- pyvrml97-2.3.4b3.dist-info/WHEEL +5 -0
- pyvrml97-2.3.4b3.dist-info/top_level.txt +1 -0
- vrml/__init__.py +22 -0
- vrml/_bytes.py +85 -0
- vrml/arrays.py +86 -0
- vrml/cache.py +250 -0
- vrml/copier.py +27 -0
- vrml/csscolors.py +177 -0
- vrml/event.py +24 -0
- vrml/field.py +476 -0
- vrml/fieldtypes.py +1491 -0
- vrml/node.py +569 -0
- vrml/nodepath.py +70 -0
- vrml/olist.py +126 -0
- vrml/protofunctions.py +233 -0
- vrml/protonamespace.py +13 -0
- vrml/route.py +167 -0
- vrml/vrml200x/__init__.py +0 -0
- vrml/vrml200x/parser.py +87 -0
- vrml/vrml97/__init__.py +6 -0
- vrml/vrml97/_transformmatrix.py +133 -0
- vrml/vrml97/_transformmatrix_accel.py +63 -0
- vrml/vrml97/basenamespaces.py +28 -0
- vrml/vrml97/basenodes.py +648 -0
- vrml/vrml97/linearise.py +579 -0
- vrml/vrml97/nodepath.py +135 -0
- vrml/vrml97/nodetypes.py +95 -0
- vrml/vrml97/nurbs.py +79 -0
- vrml/vrml97/parseprocessor.py +452 -0
- vrml/vrml97/parser.py +72 -0
- vrml/vrml97/scenegraph.py +181 -0
- vrml/vrml97/script.py +25 -0
- vrml/vrml97/shaders.py +123 -0
- vrml/vrml97/transformmatrix.py +193 -0
- vrml/weakkeydictfix.py +36 -0
- vrml/weaklist.py +163 -0
- vrml/weaktuple.py +138 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""transformmatrix forward/backward calculation without accelerate support"""
|
|
2
|
+
from math import pi
|
|
3
|
+
from vrml.arrays import array, cos, sin, tan
|
|
4
|
+
# used to determine whether angles are non-null
|
|
5
|
+
TWOPI = pi * 2.0
|
|
6
|
+
# used to determine the center point of a transform
|
|
7
|
+
VERY_SMALL = 1e-300
|
|
8
|
+
|
|
9
|
+
def rotMatrix( source=None ):
|
|
10
|
+
"""Convert a VRML rotation to rotation matrices
|
|
11
|
+
|
|
12
|
+
Returns (R, R') (R and the inverse of R), with both
|
|
13
|
+
being 4x4 transformation matrices.
|
|
14
|
+
or
|
|
15
|
+
None,None if the angle is an exact multiple of 2pi
|
|
16
|
+
|
|
17
|
+
x,y,z -- (normalised) rotational vector
|
|
18
|
+
a -- angle in radians
|
|
19
|
+
"""
|
|
20
|
+
if source is None:
|
|
21
|
+
return None,None
|
|
22
|
+
else:
|
|
23
|
+
(x,y,z, a) = source
|
|
24
|
+
if a % TWOPI:
|
|
25
|
+
# normalize the rotation vector!
|
|
26
|
+
squared = x*x + y*y + z*z
|
|
27
|
+
if squared != 1.0:
|
|
28
|
+
length = squared ** .5
|
|
29
|
+
x /= length
|
|
30
|
+
y /= length
|
|
31
|
+
z /= length
|
|
32
|
+
c = cos( a )
|
|
33
|
+
c1 = cos( -a )
|
|
34
|
+
s = sin( a )
|
|
35
|
+
s1 = sin( -a )
|
|
36
|
+
t = 1-c
|
|
37
|
+
R = array( [
|
|
38
|
+
[ t*x*x+c, t*x*y+s*z, t*x*z-s*y, 0],
|
|
39
|
+
[ t*x*y-s*z, t*y*y+c, t*y*z+s*x, 0],
|
|
40
|
+
[ t*x*z+s*y, t*y*z-s*x, t*z*z+c, 0],
|
|
41
|
+
[ 0, 0, 0, 1]
|
|
42
|
+
] )
|
|
43
|
+
R1 = array( [
|
|
44
|
+
[ t*x*x+c1, t*x*y+s1*z, t*x*z-s1*y, 0],
|
|
45
|
+
[ t*x*y-s1*z, t*y*y+c1, t*y*z+s1*x, 0],
|
|
46
|
+
[ t*x*z+s1*y, t*y*z-s1*x, t*z*z+c1, 0],
|
|
47
|
+
[ 0, 0, 0, 1]
|
|
48
|
+
] )
|
|
49
|
+
return R, R1
|
|
50
|
+
else:
|
|
51
|
+
return None, None
|
|
52
|
+
|
|
53
|
+
def scaleMatrix( source=None ):
|
|
54
|
+
"""Convert a VRML scale to scale matrices
|
|
55
|
+
|
|
56
|
+
Returns (S, S') (S and the inverse of S), with both
|
|
57
|
+
being 4x4 transformation matrices.
|
|
58
|
+
or
|
|
59
|
+
None,None if x == y == z == 1.0
|
|
60
|
+
|
|
61
|
+
x,y,z -- scale vector
|
|
62
|
+
"""
|
|
63
|
+
if source is None:
|
|
64
|
+
return None,None
|
|
65
|
+
else:
|
|
66
|
+
(x,y,z) = source[:3]
|
|
67
|
+
if x == y == z == 1.0:
|
|
68
|
+
return None, None
|
|
69
|
+
S = array( [ [x,0,0,0], [0,y,0,0], [0,0,z,0], [0,0,0,1] ], 'f' )
|
|
70
|
+
S1 = array( [
|
|
71
|
+
[1./(x or VERY_SMALL),0,0,0],
|
|
72
|
+
[0,1./(y or VERY_SMALL),0,0],
|
|
73
|
+
[0,0,1./(z or VERY_SMALL),0],
|
|
74
|
+
[0,0,0,1] ], 'f'
|
|
75
|
+
)
|
|
76
|
+
return S, S1
|
|
77
|
+
|
|
78
|
+
def transMatrix( source=None ):
|
|
79
|
+
"""Convert a VRML translation to translation matrices
|
|
80
|
+
|
|
81
|
+
Returns (T, T') (T and the inverse of T), with both
|
|
82
|
+
being 4x4 transformation matrices.
|
|
83
|
+
or
|
|
84
|
+
None,None if x == y == z == 0.0
|
|
85
|
+
|
|
86
|
+
x,y,z -- scale vector
|
|
87
|
+
"""
|
|
88
|
+
if source is None:
|
|
89
|
+
return None,None
|
|
90
|
+
else:
|
|
91
|
+
(x,y,z) = source[:3]
|
|
92
|
+
if x == y == z == 0.0:
|
|
93
|
+
return None, None
|
|
94
|
+
T = array( [ [1,0,0,0], [0,1,0,0], [0,0,1,0], [x,y,z,1] ], 'f' )
|
|
95
|
+
T1 = array( [ [1,0,0,0], [0,1,0,0], [0,0,1,0], [-x,-y,-z,1] ], 'f' )
|
|
96
|
+
return T, T1
|
|
97
|
+
|
|
98
|
+
def perspectiveMatrix( fovy, aspect, zNear, zFar, inverse=False ):
|
|
99
|
+
"""Create a perspective matrix from given parameters
|
|
100
|
+
|
|
101
|
+
Note that this is the same matrix as for gluPerspective,
|
|
102
|
+
save that we are using radians...
|
|
103
|
+
"""
|
|
104
|
+
f = 1.0/tan( (fovy/2.0) ) # cotangent( fovy/2.0 )
|
|
105
|
+
zDelta = zNear-zFar
|
|
106
|
+
if inverse:
|
|
107
|
+
return array([
|
|
108
|
+
[aspect/f,0,0,0],
|
|
109
|
+
[0,1/(f or VERY_SMALL),0,0],
|
|
110
|
+
[0,0,0,zDelta/(2*zFar*zNear)],
|
|
111
|
+
[0,0,-1,(zFar+zNear)/(2*zFar*zNear)],
|
|
112
|
+
],'f')
|
|
113
|
+
else:
|
|
114
|
+
return array([
|
|
115
|
+
[f/aspect,0,0,0],
|
|
116
|
+
[0,f,0,0],
|
|
117
|
+
[0,0,(zFar+zNear)/zDelta,-1],
|
|
118
|
+
[0,0,(2*zFar*zNear)/zDelta,0]
|
|
119
|
+
],'f')
|
|
120
|
+
def orthoMatrix( left=-1.0, right=1.0, bottom=-1.0, top=1.0, zNear=-1.0, zFar=1.0 ):
|
|
121
|
+
"""Calculate an orthographic projection matrix
|
|
122
|
+
|
|
123
|
+
Similar to glOrtho
|
|
124
|
+
"""
|
|
125
|
+
tx = - ( right + left ) / float( right-left )
|
|
126
|
+
ty = - ( top + bottom ) / float( top-bottom )
|
|
127
|
+
tz = - ( zFar + zNear ) / float( zFar-zNear )
|
|
128
|
+
return array([
|
|
129
|
+
[2/(right-left), 0, 0, tx],
|
|
130
|
+
[0, 2/(top-bottom), 0, ty],
|
|
131
|
+
[0, 0, -2/(zFar-zNear), tz],
|
|
132
|
+
[0, 0, 0, 1],
|
|
133
|
+
], dtype='f')
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""transformmatrix forward/backward calculation with accelerate support"""
|
|
2
|
+
from vrml_accelerate import tmatrixaccel
|
|
3
|
+
from math import pi
|
|
4
|
+
# used to determine whether angles are non-null
|
|
5
|
+
TWOPI = pi * 2.0
|
|
6
|
+
VERY_SMALL = 1e-300
|
|
7
|
+
|
|
8
|
+
def rotMatrix( source = None ):
|
|
9
|
+
"""Convert a VRML rotation to rotation matrices
|
|
10
|
+
|
|
11
|
+
Returns (R, R') (R and the inverse of R), with both
|
|
12
|
+
being 4x4 transformation matrices.
|
|
13
|
+
or
|
|
14
|
+
None,None if the angle is an exact multiple of 2pi
|
|
15
|
+
|
|
16
|
+
x,y,z -- (normalised) rotational vector
|
|
17
|
+
a -- angle in radians
|
|
18
|
+
"""
|
|
19
|
+
if source is None:
|
|
20
|
+
return None,None
|
|
21
|
+
else:
|
|
22
|
+
(x,y,z, a) = source
|
|
23
|
+
if a % TWOPI:
|
|
24
|
+
return tmatrixaccel.rotMatrix( x,y,z,a ),tmatrixaccel.rotMatrix( x,y,z,-a )
|
|
25
|
+
return None,None
|
|
26
|
+
def scaleMatrix( source=None ):
|
|
27
|
+
"""Convert a VRML scale to scale matrices
|
|
28
|
+
|
|
29
|
+
Returns (S, S') (S and the inverse of S), with both
|
|
30
|
+
being 4x4 transformation matrices.
|
|
31
|
+
or
|
|
32
|
+
None,None if x == y == z == 1.0
|
|
33
|
+
|
|
34
|
+
x,y,z -- scale vector
|
|
35
|
+
"""
|
|
36
|
+
if source is None:
|
|
37
|
+
return None,None
|
|
38
|
+
else:
|
|
39
|
+
(x,y,z) = source[:3]
|
|
40
|
+
if x == y == z == 1.0:
|
|
41
|
+
return None, None
|
|
42
|
+
forward = tmatrixaccel.scaleMatrix( x,y,z )
|
|
43
|
+
backward = tmatrixaccel.scaleMatrix( 1.0/(x or VERY_SMALL),1.0/(y or VERY_SMALL), 1.0/(z or VERY_SMALL) )
|
|
44
|
+
return forward, backward
|
|
45
|
+
def transMatrix( source=None ):
|
|
46
|
+
"""Convert a VRML translation to translation matrices
|
|
47
|
+
|
|
48
|
+
Returns (T, T') (T and the inverse of T), with both
|
|
49
|
+
being 4x4 transformation matrices.
|
|
50
|
+
or
|
|
51
|
+
None,None if x == y == z == 0.0
|
|
52
|
+
|
|
53
|
+
x,y,z -- scale vector
|
|
54
|
+
"""
|
|
55
|
+
if source is None:
|
|
56
|
+
return None,None
|
|
57
|
+
else:
|
|
58
|
+
(x,y,z) = source[:3]
|
|
59
|
+
if x == y == z == 0.0:
|
|
60
|
+
return None, None
|
|
61
|
+
return tmatrixaccel.transMatrix( x,y,z ),tmatrixaccel.transMatrix( -x, -y, -z )
|
|
62
|
+
perspectiveMatrix = tmatrixaccel.perspectiveMatrix
|
|
63
|
+
orthoMatrix = tmatrixaccel.orthoMatrix
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Base namespace for VRML97
|
|
2
|
+
|
|
3
|
+
The basePrototypes object holds a protonamespace object
|
|
4
|
+
which contains a mapping from canonical node name to
|
|
5
|
+
node representation.
|
|
6
|
+
|
|
7
|
+
See vrml.vrml97.basenodes for most of the actual
|
|
8
|
+
node definitions.
|
|
9
|
+
"""
|
|
10
|
+
from vrml import node, protonamespace, fieldtypes, route
|
|
11
|
+
from vrml.vrml97 import script, basenodes, scenegraph
|
|
12
|
+
|
|
13
|
+
basePrototypes = protonamespace.ProtoNamespace(
|
|
14
|
+
{
|
|
15
|
+
'PROTO': node.prototype,
|
|
16
|
+
'sceneGraph': scenegraph.SceneGraph,
|
|
17
|
+
'ROUTE': route.ROUTE,
|
|
18
|
+
'NULL': node.NULL,
|
|
19
|
+
'Script': script.Script,
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
for key,value in basenodes.__dict__.items():
|
|
23
|
+
try:
|
|
24
|
+
if issubclass( value, node.Node ):
|
|
25
|
+
basePrototypes[key] = value
|
|
26
|
+
except:
|
|
27
|
+
pass
|
|
28
|
+
|