Пример #1
0
def profile(heightPeriph,
            heightTop,
            radius,
            shapeBot=2,
            shapeTop=2,
            stacks=20):
    radius = float(radius)
    points = [pgl.Vector2(0, 0)]
    rStep = radius / stacks
    rIter = 0
    for j in range(0, stacks - 1):
        rIter += rStep
        points.append(
            pgl.Vector2(rIter, heightPeriph * pow(rIter / radius, shapeBot)))
    rIter = radius
    heightTopPart = heightTop - heightPeriph
    points.append(pgl.Vector2(radius, heightPeriph))
    for j in range(0, stacks - 1):
        rIter -= rStep
        points.append(
            pgl.Vector2(
                rIter,
                heightTop - heightTopPart * pow(rIter / radius, shapeTop)))
    points.append(pgl.Vector2(0, heightTop))
    return points
Пример #2
0
    def NURBSCurve(self, ctrlpoints, dimension, **kwds):
        ctrlpoints = str(ctrlpoints)
        ctrlpoints = [float(num) for num in ctrlpoints.split(",")]
        dimension = int(dimension)
        items, chunk = ctrlpoints, dimension
        pointArray = zip(*[iter(items)] * chunk)

        if (dimension == 2):
            v4array = []
            for item in pointArray:
                v4array.append(pgl.Vector2(item))

            parray = pgl.Point3Array(0)
            for item in v4array:
                parray.append(Vector3(item,1))

            return (pgl.NurbsCurve2D(parray), None)
        elif (dimension == 3):
            v4array = []
            for item in pointArray:
                v4array.append(pgl.Vector3(item))

            parray = pgl.Point4Array(0)
            for item in v4array:
                parray.append(Vector4(item,1))
            return (pgl.NurbsCurve(parray), None)
Пример #3
0
    def to_geom_args(self, conversion=1.0, name=None):
        r"""Get arguments for creating a PlantGL geometry.

        Args:
            conversion (float, optional): Conversion factor that should be
                applied to the vertices. Defaults to 1.0.
            name (str, optional): Name that should be given to the created
                PlantGL symbol. Defaults to None and is ignored.

        Returns:
            tuple: Class, arguments and keyword arguments for PlantGL geometry.

        """
        import openalea.plantgl.all as pgl
        smb_class, args, kwargs = super(ObjDict, self).to_geom_args(
            conversion=conversion, name=name)
        index_class = pgl.Index3
        array_class = pgl.Index3Array
        # Texture coords
        if self.get('texcoords', []):
            obj_texcoords = []
            for t in self['texcoords']:
                obj_texcoords.append(pgl.Vector2(t[0], t[1]))
            kwargs['texCoordList'] = pgl.Point2Array(obj_texcoords)
            if self.get('face_texcoords', []):
                obj_ftexcoords = []
                for t in self['face_texcoords']:
                    if (t is not None) and (t[0] is not None):
                        entry = [int(_t) for _t in t]
                    else:
                        entry = [len(self['texcoords']) for _ in range(3)]
                    obj_ftexcoords.append(index_class(*entry))
                kwargs['texCoordIndexList'] = array_class(obj_ftexcoords)
        # Normals
        if self.get('normals', []):
            obj_normals = []
            for n in self['normals']:
                obj_normals.append(pgl.Vector3(n[0], n[1], n[2]))
            kwargs['normalList'] = pgl.Point3Array(obj_normals)
            if self.get('face_normals', []):
                obj_fnormals = []
                for n in self['face_normals']:
                    if (n is not None) and (n[0] is not None):
                        entry = [int(_n) for _n in n]
                    else:
                        entry = [len(self['normals']) for _ in range(3)]
                    obj_fnormals.append(index_class(*entry))
                kwargs['normalIndexList'] = array_class(obj_fnormals)
        return smb_class, args, kwargs
Пример #4
0
            def fn(change):
                if 'new' in change:
                    value = change['new']
                    if isinstance(param, BaseScalar):
                        param.value = value
                    elif isinstance(param, tuple):
                        if isinstance(param[1],
                                      (pgl.NurbsCurve2D, pgl.BezierCurve2D)):
                            param[1].ctrlPointList = pgl.Point3Array(
                                [pgl.Vector3(p[0], p[1], 1) for p in value])
                        elif isinstance(param[1], pgl.Polyline2D):
                            param[1].pointList = pgl.Point2Array(
                                [pgl.Vector2(p[0], p[1]) for p in value])

                    lsw.set_parameters(lp.dumps())
Пример #5
0
 def on_param_changed(change):
     if 'new' in change:
         value = change['new']
         name = change['name']
         if isinstance(param, BaseScalar):
             if name == 'name':
                 param.name = value
             else:
                 param.value = value
         elif isinstance(param, tuple):
             if name == 'value':
                 if isinstance(param[1],
                               (pgl.NurbsCurve2D, pgl.BezierCurve2D)):
                     param[1].ctrlPointList = pgl.Point3Array(
                         [pgl.Vector3(p[0], p[1], 1) for p in value])
                 elif isinstance(param[1], pgl.Polyline2D):
                     param[1].pointList = pgl.Point2Array(
                         [pgl.Vector2(p[0], p[1]) for p in value])
             else:
                 param[1].name = value
         if self.__auto_apply:
             self.on_lpy_context_change(self.__lp.dumps())
         if self.__auto_save:
             self.__save()
Пример #6
0
    def to_geom_args(self, conversion=1.0, name=None):  # pragma: lpy
        r"""Get arguments for creating a PlantGL geometry.

        Args:
            conversion (float, optional): Conversion factor that should be
                applied to the vertices. Defaults to 1.0.
            name (str, optional): Name that should be given to the created
                PlantGL symbol. Defaults to None and is ignored.

        Returns:
            tuple: Class, arguments and keyword arguments for PlantGL geometry.

        """
        import openalea.plantgl.all as pgl
        smb_class, args, kwargs = super(ObjDict, self).to_geom_args(
            conversion=conversion, name=name, _as_obj=True)
        index_class = pgl.Index
        array_class = pgl.IndexArray
        # Texture coords
        if self.get('texcoords', []):
            obj_texcoords = []
            for t in self['texcoords']:
                obj_texcoords.append(
                    pgl.Vector2(np.float64(t['u']), np.float64(t.get('v',
                                                                     0.0))))
            kwargs['texCoordList'] = pgl.Point2Array(obj_texcoords)
            obj_ftexcoords = []
            for i, f in enumerate(self['faces']):
                entry = []
                for _f in f:
                    if 'texcoord_index' not in _f:
                        if i > 0:
                            warnings.warn(
                                ("'texcoord_index' missing from face" +
                                 "%d, texcoord indices will be " + "ignored.")
                                % i)
                        obj_ftexcoords = []
                        entry = []
                        break
                    entry.append(int(_f['texcoord_index']))
                if not entry:
                    break
                obj_ftexcoords.append(index_class(*entry))
            if obj_ftexcoords:
                kwargs['texCoordIndexList'] = array_class(obj_ftexcoords)
        # Normals
        if self.get('normals', []):
            obj_normals = []
            for n in self['normals']:
                obj_normals.append(
                    pgl.Vector3(np.float64(n['i']), np.float64(n['j']),
                                np.float64(n['k'])))
            kwargs['normalList'] = pgl.Point3Array(obj_normals)
            obj_fnormals = []
            for i, f in enumerate(self['faces']):
                entry = []
                for _f in f:
                    if 'normal_index' not in _f:
                        if i > 0:
                            warnings.warn(
                                ("'normal_index' missing from face" +
                                 "%d, normal indices will be " + "ignored.") %
                                i)
                        obj_fnormals = []
                        entry = []
                        break
                    entry.append(int(_f['normal_index']))
                if not entry:
                    break
                obj_fnormals.append(index_class(*entry))
            if obj_fnormals:
                kwargs['normalIndexList'] = array_class(obj_fnormals)
        return smb_class, args, kwargs