Esempio n. 1
0
def exportWebGL(fn, createdby=50, **kargs):
    """Export the current scene to WebGL.

    Parameters:

    - `fn` : string: the (relative or absolute) filename of the .html, .js
      and .pgf files comprising the WebGL model. It can contain a directory
      path and an any extension. The latter is dropped and not used.
    - `createdby`: int: width in pixels of the 'Created by pyFormex' logo
      appearing on the page. If < 0, the logo is displayed at its natural
      width. If 0, the logo is suppressed.
    - `**kargs`: any other keyword parameteris passed to the
      :class:`WebGL` initialization. The `name` can not be specified: it
      is derived from the `fn` parameter.

    Returns the absolute pathname of the generated .html file.
    """
    from pyformex.plugins.webgl import WebGL
    print("Exporting current scene to %s" % fn)
    pf.GUI.setBusy()
    if os.path.isabs(fn):
        chdir(os.path.dirname(fn))
    fn = os.path.basename(fn)
    name = utils.projectName(fn)
    W = WebGL(name=name, **kargs)
    W.addScene(name)
    fn = W.export(createdby=createdby)
    pf.GUI.setBusy(False)
    return fn
Esempio n. 2
0
def show3ds(fn):
    """Import and show a 3ds file

    Import a 3ds file, render it, and export it to th GUI
    """
    from pyformex.plugins.vtk_itf import import3ds
    from pyformex.gui.draw import draw,export
    name = utils.projectName(fn)
    geom = import3ds(fn)
    draw(geom)
    export({name:geom})
Esempio n. 3
0
def multiWebGL(name=None,
               fn=None,
               title=None,
               description=None,
               keywords=None,
               author=None,
               createdby=50):
    """Export the current scene to WebGL.

    fn is the (relative or absolute) pathname of the .html and .js files to be
    created.

    When the export is finished, returns the absolute pathname of the
    generated .html file. Else, returns None.
    """
    global the_multiWebGL

    from pyformex.plugins.webgl import WebGL
    ret = None
    pf.GUI.setBusy()
    if fn is not None:
        if the_multiWebGL is not None:
            the_multiWebGL.export()
            the_multiWebGL = None

        print("OK", the_multiWebGL)

        if os.path.isabs(fn):
            chdir(os.path.dirname(fn))
        fn = os.path.basename(fn)
        proj = utils.projectName(fn)
        print("PROJECT %s" % proj)
        the_multiWebGL = WebGL(proj,
                               title=title,
                               description=description,
                               keywords=keywords,
                               author=author)

    if the_multiWebGL is not None:
        if name is not None:
            print("Exporting current scene to %s" % the_multiWebGL.name)
            the_multiWebGL.addScene(name)

        elif fn is None:  # No name, and not just starting
            print("Finishing export of %s" % the_multiWebGL.name)
            ret = the_multiWebGL.export(createdby=createdby)
            the_multiWebGL = None

    pf.GUI.setBusy(False)
    return ret
Esempio n. 4
0
def createMultiWebGL():
    """Creates a multimodel WebGL from single WebGL models"""
    from pyformex.gui.draw import askFilename, askNewFilename, ack, showHTML
    models = askFilename(filter=['html','js'],multi=True)
    if not models:
        return
    combined = askNewFilename(filter=['html','js'],caption="Enter name of the combined model")
    if not combined:
        return
    fout = open(utils.changeExt(combined,'js'),'w')

    print("""// Script generated by %s
var the_renderer;
var the_menu;
window.onload = function() {
show%s()
}
""" % (pf.fullVersion(),utils.projectName(models[0])),file=fout)

    body = createdBy()
    body += "<div style='position:absolute;top:150px;left:10px;'>"
    for model in models:
        name = utils.projectName(model)
        body += "<button onclick='show%s()'>Show %s</button><br />" % (name,name)
        print('',file=fout)
        print("show%s = function() {" % name,file=fout)
        fn = utils.changeExt(model,'js')
        f = open(fn,'r')
        s = f.readlines()
        f.close()
        while len(s) > 0:
            line = s.pop(0)
            if line.startswith("window.onload = function"):
                break
        line = s.pop(0)
        if line.startswith("var r = new X.renderer3D"):
            print("""if (the_menu != null) the_menu.destroy();
if (the_renderer != null) the_renderer.destroy();
the_renderer = new X.renderer3D();
var r = the_renderer;
""",file=fout)
        else:
            raise ValueError("Invalid WebGL script %s" % fn)

        while len(s) > 0:
            line = s.pop(0)
            print(line,file=fout)
            if line.startswith("var gui = new dat.GUI"):
                print("the_menu = gui;",file=fout)
    fout.close()
    body += "</div>"

    fn = createWebglHtml(
        utils.changeExt(combined,'html'),
        scripts=[
            pf.cfg['webgl/script'],
            pf.cfg['webgl/guiscript'],
            utils.changeExt(combined,'js')
            ],
        body=body
        )

    if ack("Show the scene in your browser?"):
        showHTML(fn)
Esempio n. 5
0
def charCurves(fontfile, character):
    l = charContours(fontfile, character)
    c = [ contourCurve(li) for li in l ]
    fontname = utils.projectName(fontfile)
    export({'%s-%s'%(fontname, character):c})
    return c
Esempio n. 6
0
 def autoname(self):
     if self._autoname is None:
         self._autoname = utils.NameSequence(utils.projectName(self.file.name)+'-0')
     return self._autoname