コード例 #1
0
ファイル: json.py プロジェクト: jvail/plantgl
    def write(self, fname, scene):
        """ Write a JSON file from a plantGL scene graph.

        This method will convert a PlantGL scene graph into an JSON file.
        """
        with open(fname, 'w') as json_file:
            json.dump(jr.to_json_rep(scene), json_file)
コード例 #2
0
def jsonconversion(sceneobj, verbose=False):
    assert sceneobj.isValid()
    if verbose:
        print(sceneobj)
    res = jr.to_json_rep(sceneobj)
    if verbose:
        print(res)
    assert type(res) == dict
    sceneobj2 = jr.from_json_rep(res)
    assert type(sceneobj2) == type(sceneobj)
コード例 #3
0
ファイル: __init__.py プロジェクト: Mayssa-1195/lpy
    def generate_json_parameter_dict(self):
        import openalea.plantgl.algo.jsonrep as jrep

        parameters = OrderedDict()
        for category in self.categories.values():
            panel = category.info.copy()
            panel['name']
            panel.setdefault('enabled', True)
            panel['scalars'] = [
                scalar.todict() for scalar in category.scalars.values()
            ]
            items = []
            for manager, obj in category.items.values():
                items.append(manager.to_json(obj))
            panel['items'] = items
            parameters[panel['name']] = panel

        materials = []
        for i, cmat in self.color_list.items():
            if not isSimilarToDefaultTurtleMat(cmat, i):
                jmat = jrep.to_json_rep(cmat)
                jmat['index'] = i
                materials.append(jmat)

        if self.animation_timestep is None:
            options = self.execOptions
        else:
            options = self.execOptions.copy()
            options['animation_timestep'] = self.animation_timestep
            options['default_category'] = self.default_category_name

        result = dict(schema='lpy',
                      version=str(default_lpyjson_version),
                      options=options,
                      materials=materials,
                      parameters=list(parameters.values()),
                      credits=dict([(key, value)
                                    for key, value in self.credits.items()
                                    if value != '']))
        assert LsystemParameters.is_valid_schema(result)
        return result
コード例 #4
0
 def to_json(self, obj):
     import openalea.plantgl.algo.jsonrep  as jr
     res = jr.to_json_rep(obj)
     res['is_function'] = False
     return res
コード例 #5
0
 def to_json(self, obj):
     import openalea.plantgl.algo.jsonrep as jr
     return jr.to_json_rep(obj)