Example #1
0
 def OnInit( self ):
     """Scene set up and initial processing"""
     print 'Loading scene from embedded VRML97 file'
     self.sg = Loader.loads( scene, 'test.wrl' )
     self.tr = self.sg.getDEF( 'TR' )
     print 'press <b> to switch backgrounds'
     self.addEventHandler( "keypress", name="b", function = self.OnSwitch)
Example #2
0
 def OnInit(self):
     """Scene set up and initial processing"""
     print 'Loading scene from embedded VRML97 file'
     self.sg = Loader.loads(scene, 'test.wrl')
     self.tr = self.sg.getDEF('TR')
     print 'press <b> to switch backgrounds'
     self.addEventHandler("keypress", name="b", function=self.OnSwitch)
Example #3
0
    def OnInit( self ):
        """Load the image on initial load of the application"""
        print """This demo loads a VRML97 scenegraph and modifies
the rotation of the transform which contains one of the two boxes.
The ROUTE in the scene transmits this rotational change to the
transform which contains the other box."""
        self.sg = Loader.load( os.path.join("wrls","box.wrl") )
        self.trans = self.sg.getDEF( "Box01" )
        self.time = Timer( duration = 8.0, repeating = 1 )
        self.time.addEventHandler( "fraction", self.OnTimerFraction )
        self.time.register (self)
        self.time.start ()
Example #4
0
    def OnInit(self):
        """Load the image on initial load of the application"""
        print """This demo loads a VRML97 scenegraph and modifies
the rotation of the transform which contains one of the two boxes.
The ROUTE in the scene transmits this rotational change to the
transform which contains the other box."""
        self.sg = Loader.load(os.path.join("wrls", "box.wrl"))
        self.trans = self.sg.getDEF("Box01")
        self.time = Timer(duration=8.0, repeating=1)
        self.time.addEventHandler("fraction", self.OnTimerFraction)
        self.time.register(self)
        self.time.start()
Example #5
0
def saveSurfacePickle(fileName):
    """Extracts triangular faces from WRL file and saves them as a pickle."""
    in_sg = Loader.load(fileName + ".wrl")
    shapes, transforms = findShapes(in_sg)
    V, F = extractPolys(shapes, transforms)
    print(
        "Done vertices and faces extraction from WRL file (Connolly surface).")
    surfaceTrianglesWRL = []
    for i in range(0, len(F)):
        temp = []
        for j in F[i]:
            temp.append(tuple(V[j]))
        surfaceTrianglesWRL.append(temp)

    # Save pickle with data
    with open(fileName + ".pkl", "w") as f:
        pickle.dump(surfaceTrianglesWRL, f)
    print("Saved Connolly surface WRL triangular faces pickle.")
Example #6
0
    def loadBackground(self, url, contexts=()):
        """Load an image from the given url in the background

        url -- SF or MFString URL to load relative to the
            node's root's baseURL

        On success:
            Sets the resulting PIL image to the
            client's image property (triggering an un-caching
            and re-compile if there was a previous image).

            if contexts, iterate through the list calling
            context.triggerRedraw(1)
        """
        try:
            from OpenGLContext.loaders.loader import Loader
        except ImportError:
            pass
        else:
            for u in url:
                try:
                    baseNode = protofunctions.root(self)
                    if baseNode:
                        baseURI = baseNode.baseURI
                    else:
                        baseURI = None

                    result = Loader.load(u, baseURL=baseURI)
                except IOError:
                    pass
                else:
                    print 'loaded', u
                    self.scenegraph = result
                    for context in contexts:
                        c = context()
                        if c:
                            c.triggerRedraw(1)
                    return
        warnings.warn(
            """Unable to load any scene from the url %s for the node %s""" %
            (url, str(self)))
 def subLoad(self, client, urlFragment, i, overall):
     from OpenGLContext.loaders.loader import Loader
     try:
         baseNode = protofunctions.root(client)
         if baseNode:
             baseURI = baseNode.baseURI
         else:
             baseURI = None
         result = Loader(urlFragment, baseURL=baseURI)
     except IOError:
         pass
     else:
         if result:
             baseURL, filename, file, headers = result
             overall[i] = file.read()
             return True
     # should set client.image to something here to indicate
     # failure to the user.
     log.warn(
         """Unable to load any shader from the url %s for the node %s""",
         urlFragment, str(client))
Example #8
0
    def loadBackground( self, url, contexts=() ):
        """Load an image from the given url in the background

        url -- SF or MFString URL to load relative to the
            node's root's baseURL

        On success:
            Sets the resulting PIL image to the
            client's image property (triggering an un-caching
            and re-compile if there was a previous image).

            if contexts, iterate through the list calling
            context.triggerRedraw(1)
        """
        try:
            from OpenGLContext.loaders.loader import Loader
        except ImportError:
            pass
        else:
            for u in url:
                try:
                    baseNode = protofunctions.root(self)
                    if baseNode:
                        baseURI = baseNode.baseURI
                    else:
                        baseURI = None
                    
                    result = Loader.load( u, baseURL = baseURI )
                except IOError:
                    pass
                else:
                    print 'loaded', u
                    self.scenegraph = result
                    for context in contexts:
                        c = context()
                        if c:
                            c.triggerRedraw(1)
                    return
        warnings.warn( """Unable to load any scene from the url %s for the node %s"""%( url, str(self)))
        
Example #9
0
        def loadBackground( self, url, contexts=() ):
            """Load an image from the given url in the background

            url -- SF or MFString URL to load relative to the
                node's root's baseURL

            On success:
                Sets the resulting PIL image to the
                client's image property (triggering an un-caching
                and re-compile if there was a previous image).

                if contexts, iterate through the list calling
                context.triggerRedraw(1)
            """
            from OpenGLContext.loaders.loader import Loader
            try:
                baseNode = protofunctions.root(self)
                if baseNode:
                    baseURI = baseNode.baseURI
                else:
                    baseURI = None
                result = Loader( url, baseURL = baseURI )
            except IOError:
                pass
            else:
                if result:
                    
                    baseURL, filename, file, headers = result
                    image = Image.open( file )
                    image.info[ 'url' ] = baseURL
                    image.info[ 'filename' ] = filename
                        
                    if image:
                        return self.setImage( image, contexts )
            
            # should set client.image to something here to indicate
            # failure to the user.
            log.warn( """Unable to load any image from the url %s for the node %s""", url, str(self))
Example #10
0
 def load(self, filename):
     """Load given url, replacing current scenegraph"""
     self.sg = Loader.load(filename)
Example #11
0
 def OnInit( self ):
     """Load the image on initial load of the application"""
     self.sg = Loader.load( os.path.join("wrls","timesensor.wrl") )
Example #12
0
 def OnInit(self):
     """Load the image on initial load of the application"""
     self.sg = Loader.load(os.path.join("wrls", "timesensor.wrl"))
Example #13
0
 def load( self, filename ):
     """Load given url, replacing current scenegraph"""
     self.sg = Loader.load( filename )