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.
@@ -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
+