Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


adp001 posted Sat, 16 May 2020 at 3:10 PM

The function to save the figure is pretty slow, because a whole lot of function calls to Poser are needed when collecting the indices. Use the following and it is pretty fast:

        vsets = poser_geom.Sets()
        tsets = poser_geom.TexSets()
        geom = MyGeom(
                verts=NP.array([[v.X(), v.Y(), v.Z()] for v in poser_geom.Vertices()], NP_PRECISION),
                tverts=NP.array([[v.U(), v.V()] for v in poser_geom.TexVertices()], NP_PRECISION),
                polys=NP.array([f_forcequad([[v.X(), v.Y(), v.Z()] for v in p.Vertices()])
                                for p in poser_geom.Polygons()], NP_PRECISION),
                polysets=NP.array([f_forcequad(vsets[p.Start():p.Start() + p.NumVertices()])
                                   for p in poser_geom.Polygons()], NP.int32),
                tpolys=NP.array([f_forcequad([[v.U(), v.V()]
                                              for v in p.TexVertices()]) for p in poser_geom.TexPolygons()],
                                NP_PRECISION),
                tpolysets=NP.array([f_forcequad(tsets[p.Start():p.Start() + p.NumTexVertices()])
                                    for p in poser_geom.TexPolygons()], NP.int32),
                matindex=NP.array([p.MaterialIndex() for p in poser_geom.Polygons()], NP.int32),
                matnames=[m.Name() for m in poser_geom.Materials()]
        )