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
vrml/vrml97/nodepath.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Node-paths for VRML97 incl. transform-matrix calculation
|
|
2
|
+
"""
|
|
3
|
+
from __future__ import generators
|
|
4
|
+
from vrml import nodepath
|
|
5
|
+
from vrml.cache import CACHE
|
|
6
|
+
from vrml.vrml97 import transformmatrix, nodetypes
|
|
7
|
+
from vrml.arrays import *
|
|
8
|
+
import weakref
|
|
9
|
+
try:
|
|
10
|
+
xrange
|
|
11
|
+
except NameError:
|
|
12
|
+
xrange = range
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _MatrixHolder( object ):
|
|
16
|
+
def __init__( self, matrix):
|
|
17
|
+
self.matrix = matrix
|
|
18
|
+
|
|
19
|
+
class _NodePath( object ):
|
|
20
|
+
"""Path within a VRML97 scenegraph from root to particular node
|
|
21
|
+
|
|
22
|
+
Adds transformation-matrix calculation functions
|
|
23
|
+
based on the nodetypes.Transforming node's
|
|
24
|
+
attributes.
|
|
25
|
+
"""
|
|
26
|
+
parent = None
|
|
27
|
+
children = None
|
|
28
|
+
active = True
|
|
29
|
+
broken = False
|
|
30
|
+
def isTransform( self, item ):
|
|
31
|
+
"""Customization Point: determine whether a node is a Transform"""
|
|
32
|
+
return isinstance(item, nodetypes.Transforming)
|
|
33
|
+
|
|
34
|
+
def transformMatrix( self, translate=True, scale=True, rotate=True, matrixHolder=False, inverse=False ):
|
|
35
|
+
"""Calculate (and cache) a transform matrix for this path
|
|
36
|
+
|
|
37
|
+
Calculates our transformMatrix from our parent's transform
|
|
38
|
+
and the set of nodes between our parent and ourself. Normally
|
|
39
|
+
that should be a *single* node or *none* in most cases.
|
|
40
|
+
|
|
41
|
+
translate -- if true, include translations in the matrix
|
|
42
|
+
scale -- if true, include scales in the matrix
|
|
43
|
+
rotate -- if true, include rotations in the matrix
|
|
44
|
+
|
|
45
|
+
Note: to apply these matrices to a particular coordinate,
|
|
46
|
+
you would do the following:
|
|
47
|
+
|
|
48
|
+
p = ones( 4 )
|
|
49
|
+
p[:3] = coordinate
|
|
50
|
+
return dot( p, matrix)
|
|
51
|
+
|
|
52
|
+
That is, you use the homogenous coordinate, and
|
|
53
|
+
make it the first item in the dot'ing.
|
|
54
|
+
"""
|
|
55
|
+
key=(['matrix','inverse_matrix'][int(bool(inverse))],translate,scale,rotate)
|
|
56
|
+
holder = CACHE.getHolder( self, key=key )
|
|
57
|
+
if holder is None:
|
|
58
|
+
doConnect = True
|
|
59
|
+
holder = CACHE.holder( self, None, key=key )
|
|
60
|
+
mHolder = None
|
|
61
|
+
else:
|
|
62
|
+
doConnect = False
|
|
63
|
+
mHolder = holder.data
|
|
64
|
+
if mHolder is not None:
|
|
65
|
+
return mHolder
|
|
66
|
+
def get_mat( item ):
|
|
67
|
+
child_holder = item.localMatrices(translate=translate,scale=scale,rotate=rotate)
|
|
68
|
+
if doConnect:
|
|
69
|
+
holder.depend( child_holder )
|
|
70
|
+
# TODO: assumes child is a Transform!
|
|
71
|
+
if translate:
|
|
72
|
+
holder.depend( item, 'translation' )
|
|
73
|
+
if scale:
|
|
74
|
+
holder.depend( item, 'scale' )
|
|
75
|
+
holder.depend( item, 'scaleOrientation' )
|
|
76
|
+
if rotate:
|
|
77
|
+
holder.depend( item, 'rotation' )
|
|
78
|
+
holder.depend( item, 'center' )
|
|
79
|
+
return child_holder.data[inverse]
|
|
80
|
+
matrix = transformmatrix.compressMatrices(
|
|
81
|
+
*[get_mat(item) for item in self.transformChildren(reverse=inverse)]
|
|
82
|
+
)
|
|
83
|
+
if matrix is None:
|
|
84
|
+
matrix = identity(4, dtype='f')
|
|
85
|
+
holder.data = matrix
|
|
86
|
+
return holder.data
|
|
87
|
+
def transformChildren( self, reverse=0 ):
|
|
88
|
+
"""Yield all transforming children"""
|
|
89
|
+
t = nodetypes.Transforming
|
|
90
|
+
if reverse:
|
|
91
|
+
for i in xrange(len(self)-1,-1, -1):
|
|
92
|
+
item = self[i]
|
|
93
|
+
if isinstance(item, t):
|
|
94
|
+
yield item
|
|
95
|
+
|
|
96
|
+
else: # forward...
|
|
97
|
+
for item in self:
|
|
98
|
+
if isinstance(item, t):
|
|
99
|
+
yield item
|
|
100
|
+
|
|
101
|
+
def __add__(self, other):
|
|
102
|
+
"""Add parent-matrix pre-caching support to nodepaths"""
|
|
103
|
+
base = super( _NodePath, self).__add__( other )
|
|
104
|
+
base.parent = self
|
|
105
|
+
if self.children is None:
|
|
106
|
+
self.children = []
|
|
107
|
+
self.children.append( weakref.ref( base ))
|
|
108
|
+
# watch for other sending events which say that
|
|
109
|
+
# this relationship is no longer active...
|
|
110
|
+
return base
|
|
111
|
+
def iterchildren( self ):
|
|
112
|
+
"""Iterate over child paths which are still live"""
|
|
113
|
+
if self.children is not None:
|
|
114
|
+
for childref in self.children[:]:
|
|
115
|
+
child = childref()
|
|
116
|
+
if child is not None:
|
|
117
|
+
yield child
|
|
118
|
+
else:
|
|
119
|
+
self.children.remove( childref )
|
|
120
|
+
def iterdescendents( self ):
|
|
121
|
+
"""Iterate over all descendent paths"""
|
|
122
|
+
for child in self.iterchildren():
|
|
123
|
+
yield child
|
|
124
|
+
for desc in child.iterchildren():
|
|
125
|
+
yield desc
|
|
126
|
+
def invalidate( self ):
|
|
127
|
+
"""Set this path to be invalid (and all children paths)"""
|
|
128
|
+
self.broken = True
|
|
129
|
+
for desc in self.iterdescendents( ):
|
|
130
|
+
desc.broken = True
|
|
131
|
+
|
|
132
|
+
class NodePath( _NodePath, nodepath.NodePath ):
|
|
133
|
+
"""Strong-reference version of VRML97 NodePath"""
|
|
134
|
+
class WeakNodePath( _NodePath, nodepath.WeakNodePath ):
|
|
135
|
+
"""Weak-reference version of VRML97 NodePath"""
|
vrml/vrml97/nodetypes.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""VRML97 semantic node-types"""
|
|
2
|
+
from vrml import node
|
|
3
|
+
|
|
4
|
+
class Traversable( object ):
|
|
5
|
+
"""Traversable nodes (Nodes which have node attributes)
|
|
6
|
+
"""
|
|
7
|
+
class Grouping( Traversable ):
|
|
8
|
+
"""Grouping nodes (Nodes which group children together)
|
|
9
|
+
"""
|
|
10
|
+
sensitive = 0
|
|
11
|
+
class Transforming( Grouping ):
|
|
12
|
+
"""Nodes which alter the transform matrix for children
|
|
13
|
+
|
|
14
|
+
This is a fairly small set of types:
|
|
15
|
+
|
|
16
|
+
Transform
|
|
17
|
+
Billboard
|
|
18
|
+
|
|
19
|
+
Billboard is not yet implemented, so there's
|
|
20
|
+
only the one functional node in the type-set
|
|
21
|
+
"""
|
|
22
|
+
def localMatrices( self, translate=True,scale=True,rotate=True ):
|
|
23
|
+
"""Calculate/lookup our local matrices
|
|
24
|
+
|
|
25
|
+
Certain operations want, e.g. just the rotation of an item,
|
|
26
|
+
so we actually can store 2**3 possible variations of the local
|
|
27
|
+
matrices. In practice we only see a very small number.
|
|
28
|
+
|
|
29
|
+
returns holder, where holder.data == (forward,inverse) matrix
|
|
30
|
+
for the local node, each of which can be None
|
|
31
|
+
"""
|
|
32
|
+
raise NotImplemented
|
|
33
|
+
|
|
34
|
+
class Children( object ):
|
|
35
|
+
"""Children nodes (Nodes which can belong to a Grouping)
|
|
36
|
+
"""
|
|
37
|
+
sensitive = 0
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Rendering( object ):
|
|
41
|
+
"""Rendering nodes (Shapes)
|
|
42
|
+
"""
|
|
43
|
+
class Geometry( object ):
|
|
44
|
+
"""Geometry nodes (Nodes which can appear in the geometry field of shapes)
|
|
45
|
+
"""
|
|
46
|
+
class Texture( object ):
|
|
47
|
+
"""Texture nodes
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Sensor( object ):
|
|
52
|
+
"""Sensor nodes
|
|
53
|
+
|
|
54
|
+
Note: All Sensors are also Children, though
|
|
55
|
+
that isn't represented here.
|
|
56
|
+
"""
|
|
57
|
+
class PointingSensor( Sensor ):
|
|
58
|
+
"""Pointing-Device Sensor nodes
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Bindable( object ):
|
|
63
|
+
"""Bindable nodes
|
|
64
|
+
|
|
65
|
+
Note: All Bindables are also Children, though
|
|
66
|
+
that isn't represented here.
|
|
67
|
+
"""
|
|
68
|
+
class Background( Bindable ):
|
|
69
|
+
"""Background nodes
|
|
70
|
+
"""
|
|
71
|
+
class Viewpoint( Bindable ):
|
|
72
|
+
"""Viewpoint nodes
|
|
73
|
+
"""
|
|
74
|
+
class NavigationInfo( Bindable ):
|
|
75
|
+
"""NavigationInfo nodes
|
|
76
|
+
"""
|
|
77
|
+
class Fog( Bindable ):
|
|
78
|
+
"""Fog nodes
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
class Light( object ):
|
|
82
|
+
"""Light nodes
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class Interpolator( object ):
|
|
87
|
+
"""Interpolator nodes
|
|
88
|
+
"""
|
|
89
|
+
class TimeDependent( object ):
|
|
90
|
+
"""TimeDependent nodes
|
|
91
|
+
"""
|
|
92
|
+
class Auditory( object ):
|
|
93
|
+
"""Auditory nodes (nodes with produce sound)
|
|
94
|
+
"""
|
|
95
|
+
|
vrml/vrml97/nurbs.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Node definitions for the VRML97 nurbs extension proposal
|
|
2
|
+
|
|
3
|
+
OpenGLContext only has the most rudimentary of NURBs support,
|
|
4
|
+
and still this module doesn't even define many of the NURBs-
|
|
5
|
+
related prototypes which you could run across. I've not
|
|
6
|
+
provided the more funky of the nodes, such as the interpolators
|
|
7
|
+
and the deformation matrices.
|
|
8
|
+
"""
|
|
9
|
+
from vrml.vrml97 import nodetypes
|
|
10
|
+
from vrml import field, node, fieldtypes
|
|
11
|
+
|
|
12
|
+
### Trimming curves
|
|
13
|
+
class Contour2D( node.Node ):
|
|
14
|
+
"""A 2D contour (collection of joined segments)
|
|
15
|
+
|
|
16
|
+
children -- a set of polylines and/or curves which are
|
|
17
|
+
joined to form the trimming contour
|
|
18
|
+
"""
|
|
19
|
+
PROTO = "Contour2D"
|
|
20
|
+
children = field.newField( 'children', 'MFNode', 1, list)
|
|
21
|
+
|
|
22
|
+
class Polyline2D( node.Node ):
|
|
23
|
+
"""A 2D piece-wise-linear polyline"""
|
|
24
|
+
PROTO = "Polyline2D"
|
|
25
|
+
point = field.newField( 'point', 'MFVec2f', 1, list)
|
|
26
|
+
class NurbsCurve2D( node.Node ):
|
|
27
|
+
"""A 2D nurbs curve normally used for trimming surfaces"""
|
|
28
|
+
PROTO = "NurbsCurve2D"
|
|
29
|
+
knot = field.newField( 'knot', 'MFFloat32', 1, list)
|
|
30
|
+
order = field.newField( 'order', 'SFInt32', 1, 3)
|
|
31
|
+
controlPoint = field.newField( 'controlPoint', 'MFVec2f', 1, list)
|
|
32
|
+
weight = field.newField( 'weight', 'MFFloat32', 1, list)
|
|
33
|
+
tessellation = field.newField( 'tessellation', 'SFInt32', 1, 0)
|
|
34
|
+
|
|
35
|
+
### Surfaces and Curves
|
|
36
|
+
class NurbsCurve( nodetypes.Geometry, node.Node ):
|
|
37
|
+
"""A 3D nurbs curve (a curvy line in 3D space)
|
|
38
|
+
"""
|
|
39
|
+
PROTO = "NurbsCurve"
|
|
40
|
+
knot = field.newField( 'knot', 'MFFloat32', 1, list)
|
|
41
|
+
order = field.newField( 'order', 'SFInt32', 1, 3)
|
|
42
|
+
controlPoint = field.newField( 'controlPoint', 'MFVec3f', 1, list)
|
|
43
|
+
color = field.newField( 'color', 'MFColor', 1, list)
|
|
44
|
+
weight = field.newField( 'weight', 'MFFloat32', 1, list)
|
|
45
|
+
tessellation = field.newField( 'tessellation', 'SFInt32', 1, 0)
|
|
46
|
+
|
|
47
|
+
class NurbsSurface( nodetypes.Geometry, node.Node ):
|
|
48
|
+
"""A Nurbs surface object"""
|
|
49
|
+
PROTO = "NurbsSurface"
|
|
50
|
+
uDimension = field.newField( 'uDimension', 'SFInt32', 1, 0)
|
|
51
|
+
vDimension = field.newField( 'vDimension', 'SFInt32', 1, 0)
|
|
52
|
+
uKnot = field.newField( 'uKnot', 'MFFloat32', 1, list)
|
|
53
|
+
vKnot = field.newField( 'vKnot', 'MFFloat32', 1, list)
|
|
54
|
+
uOrder = field.newField( 'uOrder', 'SFInt32', 1, 3)
|
|
55
|
+
vOrder = field.newField( 'vOrder', 'SFInt32', 1, 3)
|
|
56
|
+
controlPoint = field.newField( 'controlPoint', 'MFVec3f', 1, list)
|
|
57
|
+
color = field.newField( 'color', 'MFColor', 1, list)
|
|
58
|
+
weight = field.newField( 'weight', 'MFFloat32', 1, list)
|
|
59
|
+
uTessellation = field.newField( 'uTessellation', 'SFInt32', 1, 0)
|
|
60
|
+
vTessellation = field.newField( 'vTessellation', 'SFInt32', 1, 0)
|
|
61
|
+
texCoord = field.newField( 'texCoord', 'SFNode', 1, node.NULL)
|
|
62
|
+
solid = field.newField( 'solid', 'SFBool', 0, 1)
|
|
63
|
+
ccw = field.newField( 'ccw', 'SFBool', 0, 1)
|
|
64
|
+
|
|
65
|
+
class TrimmedSurface( nodetypes.Geometry, node.Node ):
|
|
66
|
+
"""A trimmed Nurbs surface object"""
|
|
67
|
+
PROTO = "TrimmedSurface"
|
|
68
|
+
trimmingContour = field.newField( 'trimmingContour', 'MFNode', 1, list)
|
|
69
|
+
surface = field.newField( 'surface', 'SFNode', 1, node.NULL)
|
|
70
|
+
|
|
71
|
+
### Unused...
|
|
72
|
+
class NurbsGroup( node.Node ):
|
|
73
|
+
"""(Unused) holder for multiple nurbs objects"""
|
|
74
|
+
PROTO = "NurbsGroup"
|
|
75
|
+
children = field.newField( 'children', 'MFNode', 1, list)
|
|
76
|
+
tessellationScale = field.newField( 'tessellationScale', 'SFFloat', 1, 1.0)
|
|
77
|
+
bboxSize = field.newField( 'bboxSize', 'SFVec3f', 0, [-1.0, -1.0, -1.0])
|
|
78
|
+
bboxCenter = field.newField( 'bboxCenter', 'SFVec3f', 0, [0.0, 0.0, 0.0])
|
|
79
|
+
|