コード例 #1
0
def build_camera(json_file):

    with open(json_file, 'r') as f:
        json_data = json.load(f)
    obj_node = hou.node('/obj')
    cam_node = obj_node.createNode('cam', node_name=json_data['name'])

    logging.info('Building %s camera', json_data['name'])

    eye = hou.Vector3(json_data['eye'])
    up = hou.Vector3(json_data['up'])
    look = hou.Vector3(json_data['look'])

    cam_node.parmTuple('t').set(json_data['eye'])

    z = look - eye
    x = up.cross(z)
    y = z.cross(x)
    # x axis is flipped from houdini
    x = -x.normalized()
    y = y.normalized()
    z = z.normalized()
    mat3 = hou.Matrix3((x, y, z))
    cam_node.parmTuple('r').set(mat3.extractRotates())
    cam_node.parmTuple('res').set((2048, int(2048 * 1.0 / json_data['ratio'])))
    focal = json_data['focalLength']
    cam_node.parm('focal').set(focal)
    fov_rad = math.radians(json_data['fov'])
    fov_ratio = (1.0 / math.tan(fov_rad * 0.5)) * 0.5
    cam_node.parm('aperture').set(focal / fov_ratio)
    cam_node.parm('focus').set(json_data['centerOfInterest'])
    cam_node.parm('fstop').set(focal / (json_data['lensRadius'] * 2.0))
    cam_node.parm('far').set(1.0e6)

    create_rop(cam_node)
コード例 #2
0
def extractBoxTransform(geo):
    # Extrects Box Transforms from the geo
    p = []
    for prim in geo.prims():
        p += [prim.positionAtInterior(0.5, 0.5)]

    center = (p[4] + p[5]) * 0.5
    dx = (p[1] - p[3]).length()
    dy = (p[5] - p[4]).length()
    dz = (p[2] - p[0]).length()
    size = hou.Vector3(dx, dy, dz)

    yax = (p[5] - p[4]).normalized()
    xax = (p[1] - p[3]).normalized()
    zax = (p[2] - p[0]).normalized()
    m = hou.Matrix3([
        xax.x(),
        xax.y(),
        xax.z(),
        yax.x(),
        yax.y(),
        yax.z(),
        zax.x(),
        zax.y(),
        zax.z()
    ])
    rotates = m.extractRotates()
    return [center, size, rotates]
コード例 #3
0
def prim_transform(prim):
    """Return a tuple representing the Matrix4 of the transform intrinsic"""
    rot_mat = hou.Matrix3(prim.intrinsicValue("transform"))
    vtx = prim.vertex(0)
    pt = vtx.point()
    pos = pt.position()
    xlate = hou.hmath.buildTranslate(pos)
    return (hou.Matrix4(rot_mat) * xlate).asTuple()
コード例 #4
0
    def test_buildLookat(self):
        TARGET = hou.Matrix3(
            ((0.70710678118654746, -0.0, 0.70710678118654746), (0.0, 1.0, 0.0),
             (-0.70710678118654746, 0.0, 0.70710678118654746)))

        lookAt = hou.hmath.buildLookat(hou.Vector3(0, 0, 1),
                                       hou.Vector3(1, 0, 0),
                                       hou.Vector3(0, 1, 0))

        self.assertEqual(lookAt, TARGET)
コード例 #5
0
 def getTransform(self):
     self.update()
     if (self.__transmat is None):
         rangle = radians(self.__localangle)
         co = cos(rangle)
         si = sin(rangle)
         pos = self.__localposition
         localmat = hou.Matrix3(
             ((co, si, 0.0), (-si, co, 0.0), (pos[0], pos[1], 1.0)))
         if (self.__parent is not None):
             self.__transmat = localmat * self.__parent.getTransform()
         else:
             self.__transmat = localmat
     return self.__transmat
コード例 #6
0
    def test_m3ZeroIsNotIdentity(self):
        m3 = hou.Matrix3()

        self.assertFalse(m3.isIdentity())
コード例 #7
0
    def test_m3IdentIsIdentity(self):
        m3 = hou.Matrix3()
        m3.setToIdentity()

        self.assertTrue(m3.isIdentity())
コード例 #8
0
    def test_getDual(self):
        TARGET = hou.Matrix3(((0, -3, 2), (3, 0, -1), (-2, 1, 0)))

        v3 = hou.Vector3(1, 2, 3)

        self.assertEqual(v3.getDual(), TARGET)