Exemplo n.º 1
0
    def render(self, detailSize):

        # set up some buffers
        count = 20000

        P = []
        Cs = []
        w = []

        random.seed(997)
        for i in range(count):
            P.append(
                pimath.V3f(random.uniform(-self.dim, self.dim),
                           random.uniform(-self.dim, self.dim),
                           random.uniform(-self.dim, self.dim)))
            Cs.append(
                pimath.V3f(random.uniform(0.05, 1), random.uniform(0.05, 1),
                           random.uniform(0.05, 1)))
            w.append(random.uniform(0.5 * self.point_radius,
                                    self.point_radius))

        # form a table from our buffers with required renderman info
        t = n.ObjectTable()
        t['P'] = n.V3fBuffer(count, pimath.V3f(0, 0, 0))
        t['P'].contents = P
        t['P'].attribs['token'] = 'P'

        if 1:
            # colour per point
            t['Cs'] = n.V3fBuffer(count, pimath.V3f(0, 0, 0))
            t['Cs'].contents = Cs
            t['Cs'].attribs['token'] = 'vertex color Cs'
        else:
            # constant colour across all points
            t['Cs'] = n.AttribTable()
            t['Cs']['value'] = pimath.V3f(1, 0, 0)
            t['Cs']['token'] = 'constant color Cs'

        if 0:
            # varying width
            t['width'] = n.FloatBuffer(count, 0.0)
            t['width'].contents = w
            t['width'].attribs['token'] = 'varying float width'
        else:
            if 1:
                # constants either as attrib table
                t['width'] = n.AttribTable()
                t['width']['value'] = 0.05
                t['width']['token'] = 'constant float constantwidth'
            else:
                # or buffer of length 1
                t['width'] = n.FloatBuffer(1, 0.03)
                t['width'].attribs['token'] = 'constant float constantwidth'

        # render
        ri.TransformBegin()
        ri.Translate(self.centre[0], self.centre[1], self.centre[2])
        nd.points(t)
        ri.TransformEnd()
Exemplo n.º 2
0
def testV3fBufSerialize(ext):
    # create test data on disk
    filepath = "/tmp/v3fbuf." + ext
    b = n.V3fBuffer(100)
    b[50] = p.V3f(3.3, 4.4, 5.5)
    n.save(b, filepath)

    b2 = n.load(filepath)
    assert (type(b) == type(b2))
    assert (len(b) == len(b2))
    vdiff = b[50] - b2[50]
    assert (vdiff.length() < 0.001)
Exemplo n.º 3
0
def createImage():
    w = 320
    h = 240
    b = n.V3fBuffer(w * h, p.V3f(0, 0, 0))

    print '# creating pixel data'
    for y in range(h):
        for x in range(w):
            s = float(x) / w
            t = float(y) / h
            b[y * w + x] = p.V3f(s, t, 0)

    img = n.ObjectTable()
    img['xres'] = w
    img['yres'] = h
    img['pixels'] = b

    # check that this is a valid napalm image
    assert ni.isValid(img, True)

    return img
Exemplo n.º 4
0
def createUberTable():
    t = n.ObjectTable()
    t[1] = 1  # this is interpreted as an int
    t[2] = 2.2  # this is interpreted as a float
    t[3] = n.Double(3.333)
    t[4] = "hello"
    t[5] = n.Char(-10)  # in napalm, a char is interpreted as a number
    t[6] = n.UChar(200)  # as is an unsigned char
    t[7] = n.Short(-30000)
    t[8] = n.UShort(60000)
    t[9] = n.UInt(2000000000)

    # todo add the new imath types inc half
    t[10] = p.V3f()
    t[11] = p.V3d()
    t[12] = p.M33f()
    t[13] = p.M33d()
    t[14] = p.M44f()
    t[15] = p.M44d()

    sz = 100
    t[16] = n.CharBuffer(sz)
    t[17] = n.FloatBuffer(sz)
    t[18] = n.DoubleBuffer(sz)
    t[19] = n.IntBuffer(sz)
    t[20] = n.V3fBuffer(sz)
    t[21] = n.V3dBuffer(sz)
    t[22] = n.M33fBuffer(sz)
    t[23] = n.M33dBuffer(sz)
    t[24] = n.M44fBuffer(sz)
    t[25] = n.M44dBuffer(sz)

    t[16].attribs["a1"] = "aaa1"
    t["hey"] = "ho"

    return t
Exemplo n.º 5
0
    def render(self, detailSize):

        # set up some buffers
        count = 200

        P = []
        Cs = []
        w = []
        nvertices = []

        random.seed(997)
        for i in range(count):
            cv_count = random.randint(5, 20)
            nvertices.append(cv_count)
            p0 = pimath.V3f(random.uniform(-self.dim, self.dim),
                            random.uniform(-self.dim, self.dim),
                            random.uniform(-self.dim, self.dim))
            for cv in range(cv_count):
                p0 = p0 + pimath.V3f(random.uniform(-self.dim, self.dim),
                                     random.uniform(-self.dim, self.dim),
                                     random.uniform(-self.dim, self.dim)) * 0.1
                P.append(p0)
                Cs.append(
                    pimath.V3f(random.uniform(0.05,
                                              1), random.uniform(0.05, 1),
                               random.uniform(0.05, 1)))
                w.append(
                    random.uniform(0.1 * self.curve_width, self.curve_width))

        # form a table from our buffers with required renderman info
        t = n.ObjectTable()

        #t['type'] = 'linear'
        t['type'] = 'cubic'
        #t['wrap'] = 'periodic'
        t['wrap'] = 'nonperiodic'

        t['nvertices'] = n.IntBuffer(count, len(nvertices))
        t['nvertices'].contents = nvertices
        #        t['nvertices'].attribs['to]

        t['P'] = n.V3fBuffer(count, pimath.V3f(0, 0, 0))
        t['P'].contents = P
        t['P'].attribs['token'] = 'P'

        if 1:
            # colour per point
            t['Cs'] = n.V3fBuffer(count, pimath.V3f(0, 0, 0))
            t['Cs'].contents = Cs
            t['Cs'].attribs['token'] = 'vertex color Cs'
        else:
            # constant colour across all points
            t['Cs'] = n.AttribTable()
            t['Cs']['value'] = pimath.V3f(1, 0, 0)
            t['Cs']['token'] = 'constant color Cs'

        if 1:
            # varying width
            t['width'] = n.FloatBuffer(count, 0.0)
            t['width'].contents = w
            t['width'].attribs['token'] = 'vertex float width'
        else:
            if 1:
                # constants either as attrib table
                t['width'] = n.AttribTable()
                t['width']['value'] = 0.05
                t['width']['token'] = 'constant float constantwidth'
            else:
                # or buffer of length 1
                t['width'] = n.FloatBuffer(1, 0.03)
                t['width'].attribs['token'] = 'constant float constantwidth'

        # render
        ri.TransformBegin()
        ri.Translate(self.centre[0], self.centre[1], self.centre[2])
        nd.curves(t)
        ri.TransformEnd()