コード例 #1
0
def zdepthchannel():
    '''Access the Z-Depth Channel'''
    prev_renderer = rt.renderers.current
    rt.renderers.current = rt.Default_Scanline_Renderer()
    voxelbox = re.compile("^VoxelBox")
    for tbd in filter(lambda o: voxelbox.match(o.name), list(rt.objects)):
        rt.delete(tbd)

    zdepth_name = rt.Name("zdepth")
    rbmp = rt.render(outputsize=rt.Point2(32, 32),
                     channels=[zdepth_name],
                     vfb=False)
    z_d = rt.getChannelAsMask(rbmp, zdepth_name)
    rt.progressStart("Rendering Voxels...")
    for y in range(1, rbmp.height):
        print("y =", y)
        if not rt.progressupdate(100.0 * y / rbmp.height):
            break
        pixel_line = rt.getPixels(rbmp, rt.Point2(0, y - 1), rbmp.width)
        z_line = rt.getPixels(z_d, rt.Point2(0, y - 1), rbmp.width)
        for x in range(1, rbmp.width):
            print("x =", x, z_line[x].value)
            box = rt.box(width=10, length=10, height=(z_line[x].value / 2))
            box.pos = rt.Point3(x * 10, -y * 10, 0)
            box.wirecolor = pixel_line[x]
            box.name = rt.uniqueName("VoxelBox")
    rt.progressEnd()
    rt.renderers.current = prev_renderer
コード例 #2
0
 def make_box():
     """Create a single node, a box of (10, 10, 10)."""
     box = rt.box()
     box.length = 10.0
     box.height = 10.0
     box.width = 10.0
     return box
コード例 #3
0
def create_box():
    """Create a box."""
    box = rt.box()
    box.Height = OBJECT_DIMENSION
    box.Width = OBJECT_DIMENSION
    box.Length = OBJECT_DIMENSION
    return box
コード例 #4
0
def main():
    """Create a box and display its vertices and normals."""
    box = rt.box()
    print(f"node name: {box.name}")
    trimesh = rt.convertTo(box, rt.TrimeshGeometry)
    print(f" verts: {trimesh.numVerts}")
    for vert in range(trimesh.numVerts):
        normal = rt.getNormal(trimesh, vert + 1)
        vertex = rt.getVert(trimesh, vert + 1)
        print(f"vertex: {vertex}")
        print(f"RNormal: {normal}")
コード例 #5
0
ファイル: rig.py プロジェクト: tpDcc/tpDcc-dccs-max
def create_end_bone(parent_bone,
                    name='newBone',
                    snap_to=None,
                    match_to=None,
                    parent=None,
                    **kwargs):
    """
    Creates and end bone
    :param parent_bone:
    :param snap_to:
    :param match_to:
    :param name:
    :param parent:
    :return:
    """

    length = kwargs.pop('length', 10)
    width = kwargs.pop('width', 10)
    height = kwargs.pop('height', 5)
    color = kwargs.pop('color', [7, 7, 11])
    main_axis = kwargs.pop('main_axis', 'z')
    extrude = kwargs.pop('extrude', True)
    freeze = kwargs.pop('freeze', False)

    parent_bone = node_utils.get_pymxs_node(parent_bone)
    snap_to = node_utils.get_pymxs_node(snap_to)
    match_to = node_utils.get_pymxs_node(match_to)
    parent = node_utils.get_pymxs_node(parent)

    if not parent_bone or not node_utils.node_exists(parent_bone.name):
        logger.error('Bone could not be created!')
        return False

    if color and rt.classOf(color) != rt.color:
        color = rt.color(*color)
    if not color:
        color = rt.color(7, 7, 11)

    bone_name = rt.uniquename(name)
    bone_box = rt.box(name=bone_name,
                      lengthsegs=1,
                      widthsegs=1,
                      heightsegs=1,
                      length=length,
                      width=width,
                      height=height,
                      mapcoords=True,
                      isSelected=True)
    bone_box.wirecolor = color
    bone_box.boneEnable = True
    bone_box.boneAxis = rt.Name(main_axis.lower())
    xform_utils.match_transforms(bone_box, parent_bone)

    rt.SetCommandPanelTaskMode(rt.Name('modify'))
    rt.convertTo(bone_box, rt.PolyMeshObject)
    rt.subobjectLevel = 1
    vertex_bitarray = rt.BitArray()
    vertex_indices = [1, 2, 3, 4]
    vertex_bitarray.count = len(vertex_indices)
    for i, index in enumerate(vertex_indices):
        vertex_bitarray[i] = index
    bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), vertex_bitarray)
    bone_box.EditablePoly.collapse(rt.Name('Vertex'))
    bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), rt.BitArray())
    if extrude:
        rt.subobjectLevel = 4
        vertex_bitarray = rt.BitArray()
        vertex_indices = [1]
        vertex_bitarray.count = len(vertex_indices)
        for i, index in enumerate(vertex_indices):
            vertex_bitarray[i] = index
        bone_box.EditablePoly.SetSelection(rt.Name('Face'), vertex_bitarray)
        bone_box.EditablePoly.extrudeFaces(height)
        bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), rt.BitArray())
    rt.subobjectLevel = 0

    if snap_to:
        xform_utils.match_position(bone_box, snap_to)
    if match_to:
        xform_utils.match_transforms(bone_box, match_to)

    if parent:
        bone_box.parent = parent

    if freeze:
        xform_utils.freeze_transform(bone_box)

    return bone_box
コード例 #6
0
ファイル: rig.py プロジェクト: tpDcc/tpDcc-dccs-max
def create_bone(root_node,
                name='new_bone',
                target_node=None,
                parent=None,
                **kwargs):

    length = kwargs.pop('length', 10)
    width = kwargs.pop('width', 10)
    height = kwargs.pop('height', 10)
    color = kwargs.pop('color', [7, 7, 11])
    main_axis = kwargs.pop('main_axis', 'z')
    flip_main_axis = kwargs.pop('flip_main_axis', False)
    main_rot_axis = kwargs.pop('main_rot_axis', 'y')
    flip_main_rot_axis = kwargs.pop('flip_main_rot_axis', False)
    freeze = kwargs.pop('freeze', False)

    root_node = node_utils.get_pymxs_node(root_node)
    target_node = node_utils.get_pymxs_node(target_node)
    parent = node_utils.get_pymxs_node(parent)

    if not root_node or not node_utils.node_exists(root_node.name):
        logger.error('Bone could not be created!')
        return False

    if color and rt.classOf(color) != rt.color:
        color = rt.color(*color)
    if not color:
        color = rt.color(7, 7, 11)

    bone_name = rt.uniquename(name)
    bone_box = rt.box(name=bone_name,
                      lengthsegs=1,
                      widthsegs=1,
                      heightsegs=1,
                      length=length,
                      width=width,
                      height=height,
                      mapcoords=True,
                      isSelected=True)
    bone_box.wirecolor = color
    bone_box.boneEnable = True
    bone_box.boneAxis = rt.Name(main_axis.lower())

    main_axis_index = 0
    main_rot_index = 0
    if main_axis.lower() == 'y':
        main_axis_index = 1
    elif main_axis.lower() == 'z':
        main_axis_index = 2
    if main_rot_axis.lower() == 'y':
        main_rot_index = 1
    elif main_rot_axis.lower() == 'z':
        main_rot_index = 2

    xform_utils.match_transforms(bone_box, root_node)
    if target_node and node_utils.node_exists(target_node.name):
        temp_helper = rt.Point(pos=rt.Point3(0, 0, 0))
        xform_utils.match_position(temp_helper, bone_box)
        look_at_controller = rt.LookAt_Constraint()
        rt.setPropertyController(temp_helper.controller, 'Rotation',
                                 look_at_controller)
        look_at_controller.appendTarget(target_node, 1)
        look_at_controller.target_axis = main_axis_index
        look_at_controller.upnode_axis = 1
        look_at_controller.StoUP_axis = main_rot_index
        look_at_controller.target_axisFlip = flip_main_axis
        look_at_controller.StoUP_axisFlip = flip_main_rot_axis
        xform_utils.match_transforms(bone_box, temp_helper)
        rt.delete(temp_helper)
        bone_box.height = rt.distance(root_node, target_node)

    if parent:
        bone_box.parent = parent

    if freeze:
        xform_utils.freeze_transform(bone_box)

    return bone_box