Example #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()
Example #2
0
def testToPyString():
    t = n.ObjectTable()
    assert (t.pyStr() == "{}")
    t[0] = '1'
    t['1'] = 0.0
    t[2] = p.V3f(0, 1, 2)
    assert (t.pyStr() == '{"1": 0., 0: "1", 2: V3f(0, 1, 2)}')
Example #3
0
def MakeLookAt(pos,la,up=pimath.V3f(0,1,0)):
    f = (pos - la).normalized()
    r = up.cross(f).normalized()
    u = f.cross(r).normalized() # re-cross it to make 99.999% orthogonal
    m = pimath.M44f(r.x, u.x, f.x, 0.0,
                    r.y, u.y, f.y, 0.0,
                    r.z, u.z, f.z, 0.0,
                    -r.dot(pos), -u.dot(pos), -f.dot(pos), 1.0 )
    return m
Example #4
0
def testToTupleString():
    t = n.ObjectTable()
    assert (t.tupStr() == "{}")
    t[0] = '1'
    t['1'] = 0.0
    t[2] = p.V3f(0, 1, 2)
    assert (t.tupStr() == '{"1": 0., 0: "1", 2: (0, 1, 2)}')
    exec("m=" + t.tupStr())
    assert (m == {"1": 0., 0: "1", 2: (0, 1, 2)})
Example #5
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)
Example #6
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
Example #7
0
def testTable():
    t = n.ObjectTable()
    assert (len(t) == 0)

    fail = False
    try:
        t["foo"]
    except KeyError:
        fail = True
    assert (fail)

    t[1] = 1.111
    t["two"] = 68
    t[3] = p.V3f(5, 6, 7)
    t["four"] = 'Q'

    assert (len(t) == 4)
    assert ("two" in t)
    assert ("blah" not in t)
    assert (t["two"] == 68)
    assert (t["four"] == 'Q')
    vdiff = t[3] - p.V3f(5, 6, 7)
    assert (vdiff.length() < 0.0001)

    t["buf"] = n.IntBuffer(100)
    t["buf"][50] = 50
    assert (t["buf"][50] == 50)

    del t["four"]
    del t[3]
    assert (len(t) == 3)
    assert (3 not in t)

    keys = t.keys()
    keys2 = []
    for k in t:
        keys2.append(k)
    assert (keys == keys2)
    def render(self, detailSize):

        # form a table from our buffers with required renderman info
        t = n.ObjectTable()
        t['radius'] = self.radius
        t['zmin'] = -self.radius
        t['zmax'] = self.radius
        t['thetamax'] = 360.0

        # constant colour
        t['Cs'] = n.AttribTable()
        t['Cs']['value'] = pimath.V3f(1, 0.5, 0)
        t['Cs']['token'] = 'constant color Cs'

        # render
        ri.TransformBegin()
        ri.Translate(self.centre[0], self.centre[1], self.centre[2])
        nd.sphere(t)
        ri.TransformEnd()
Example #9
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
Example #10
0
    def testPrecision(self):
        x = pimath.V3f(0.1, 0.0, 0.8)
        x.normalize()

        assert x.length() - 1.0 < 0.00000000000000001
Example #11
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()