Exemplo n.º 1
0
def create_circle_control(name, init_pos=None, radius=10, color=None, axis='z'):
    """
    Creates a circle control
    :param name: str
    :param init_pos: list(float, float, float) or None
    :param radius: float
    :param color: list(float, float, float) or rt.Point3
    :param axis: str
    """

    pos = init_pos or [0, 0, 0]
    if rt.classOf(pos) != rt.Point3:
        pos = rt.Point3(*pos)
    if color and rt.classOf(color) != rt.color:
        color = rt.color(*color)
    if not color:
        color = rt.yellow

    rt.setCommandPanelTaskMode(rt.Name('modify'))
    ctrl_name = rt.uniquename(name)
    base_circle = rt.circle(name=ctrl_name, radius=radius, steps=6, pos=pos)
    if str(axis).lower() == 'x':
        xform_mod = rt.xform()
        rt.addModifier(base_circle, xform_mod)
        rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 90, 0))
    elif str(axis).lower() == 'y':
        xform_mod = rt.xform()
        rt.addModifier(base_circle, xform_mod)
        rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(90, 0, 0))
    base_circle.wirecolor = color
    rt.convertTo(base_circle, rt.SplineShape)

    return base_circle
Exemplo n.º 2
0
def create_box_control(name, init_pos=None, length=10, width=10, height=10, color=None):
    """
    Creates a box control
    :param name: str
    :param init_pos:
    :param length:
    :param width:
    :param height:
    :param color:
    :return:
    """

    pos = init_pos or [0, 0, 0]
    if rt.classOf(pos) != rt.Point3:
        pos = rt.Point3(*pos)
    if color and rt.classOf(color) != rt.color:
        color = rt.color(*color)
    if not color:
        color = rt.yellow

    rt.setCommandPanelTaskMode(rt.Name('modify'))
    base_box = rt.Box(
        lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height,
        mapcoords=True, pos=pos, isSelected=True)
    rt.select(base_box)
    rt.convertTo(base_box, rt.PolyMeshObject)
    rt.subobjectLevel = 2
    edge_bitarray = rt.BitArray()
    edge_indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    edge_bitarray.count = len(edge_indices)
    for i, index in enumerate(edge_indices):
        edge_bitarray[i] = index
    base_box.EditablePoly.SetSelection(rt.Name('Edge'), edge_bitarray)
    ctrl_name = rt.uniquename(name)
    base_box.EditablePoly.createShape(ctrl_name, False, base_box)
    rt.subobjectLevel = 0
    rt.delete(base_box)
    box_ctrl = rt.getNodeByName(ctrl_name)
    rt.convertTo(box_ctrl, rt.SplineShape)
    box_ctrl.wirecolor = color
    rt.CenterPivot(box_ctrl)
    transform.reset_xform_and_collapse(box_ctrl, freeze=True)

    return box_ctrl
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}")
Exemplo n.º 4
0
def create_rectangle_control(name, init_pos=None, length=10.0, width=10.0, corner_radius=0.0, color=None, axis='z'):
    """
    Creates a rectangle control
    :param name: str
    :param init_pos:
    :param length:
    :param width:
    :param corner_radius:
    :param color:
    :param axis:
    :return:
    """

    pos = init_pos or [0, 0, 0]
    if rt.classOf(pos) != rt.Point3:
        pos = rt.Point3(*pos)
    if color and rt.classOf(color) != rt.color:
        color = rt.color(*color)
    if not color:
        color = rt.yellow

    rt.setCommandPanelTaskMode(rt.Name('modify'))
    ctrl_name = rt.uniquename(name)
    base_rectangle = rt.rectangle(name=ctrl_name, length=length, width=width, cornerRadius=corner_radius, pos=pos)
    base_rectangle.wirecolor = color
    if str(axis).lower() == 'x':
        xform_mod = rt.xform()
        rt.addModifier(base_rectangle, xform_mod)
        rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 90, 0))
    elif str(axis).lower() == 'y':
        xform_mod = rt.xform()
        rt.addModifier(base_rectangle, xform_mod)
        rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(90, 0, 0))
    rt.convertTo(base_rectangle, rt.SplineShape)

    return base_rectangle
Exemplo n.º 5
0
    def convertToMesh(self):
        if not self.useAlpha_chb.isChecked() and not self.isValidTexture(
                self.texturePath):
            self.info_lbl = "Specified texture is missing or not found"
            return

        subdivideMod = rt.subdivide()
        volSel = rt.Vol__Select()
        for o in rt.selection:
            texturePath = self.texturePath
            if self.useAlpha_chb.isChecked():
                mat = o.material
                if rt.classOf(mat) == rt.FlightSim:
                    texturePath = mat.BaseColorTex
                elif rt.classOf(mat) == rt.Standardmaterial:
                    texturePath = mat.opacityMap.filename
                else:
                    self.info_lbl = "Currently only FlightSim material are supported"
                    continue

                if not os.path.isabs(texturePath):
                    texturePath = os.path.join(
                        rt.pathConfig.getCurrentProjectFolder(), texturePath)
                if not self.isValidTexture(texturePath):
                    continue

            p = rt.convertToPoly(o)
            rt.addModifier(o, subdivideMod)
            subdivideMod.size = 0.001
            rt.convertTo(o, rt.editable_poly)
            #hack adding the modifier only one time do not work for first object in iteration WTF?
            rt.addModifier(o, subdivideMod)
            subdivideMod.size = 0.001
            rt.convertTo(o, rt.editable_poly)
            rt.addModifier(p, volSel)
            volSel.level = 1
            volSel.invert = True
            bitmap = rt.Bitmaptexture(filename=texturePath)
            volSel.texture = bitmap
            volSel.method = 0
            volSel.volume = 4
            p = rt.convertToPoly(o)
            rt.subObjectLevel = 1
            p.delete(pymxs.runtime.Name("Vertex"))
            rt.convertTo(o, rt.editable_poly)
Exemplo n.º 6
0
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