コード例 #1
0
ファイル: studioUsd.py プロジェクト: wandth/subins_tutorials
 def create_uv(self, data, stage=None):
     if not stage:
         stage = self.make_satge()
     if not stage:
         return
     geometries = common.sort_dictionary(data)
     for geometry in geometries:
         location = geometry.replace(':', '_')
         sdf_path = Sdf.Path(location.replace('|', '/'))
         current_data = data[geometry]
         for path in sdf_path.GetPrefixes():
             UsdGeom.Xform.Define(stage, path)
         mesh_define = UsdGeom.Mesh.Define(stage,
                                           sdf_path.GetPrefixes()[-1])
         uv_sets = common.sort_dictionary(current_data)
         for index, uv_set in enumerate(uv_sets):
             uv_d = current_data[uv_set]
             uv_points = []
             for x in range(len(uv_d['u_array'])):
                 uv_points.append((uv_d['u_array'][x], uv_d['u_array'][x]))
             current_set = 'st'
             if index > 0:
                 current_set = uv_set
             uv_data = [uv_points, uv_d['uv_ids']]
             self.make_uv_points_ids(mesh_define, current_set, uv_data)
     return stage
コード例 #2
0
ファイル: studioMaya.py プロジェクト: wandth/subins_tutorials
 def create_pipe_ids(self, mobject, id_data):
     attributes = common.sort_dictionary(id_data)
     self.remove_pipe_ids(mobject, id_data)
     data = {}
     hidden = {True: False, False: True}
     for attribute in attributes:
         short = id_data[attribute]['short']
         type_attribute = OpenMaya.MFnTypedAttribute()
         sample_mobject = OpenMaya.MObject()
         sample_mobject = type_attribute.create(attribute, short,
                                                OpenMaya.MFnData.kString)
         type_attribute.setKeyable(False)
         type_attribute.setReadable(True)
         type_attribute.setChannelBox(False)
         type_attribute.setWritable(id_data[attribute]['locked'])
         type_attribute.setHidden(hidden[id_data[attribute]['show']])
         mfn_dependency_node = OpenMaya.MFnDependencyNode()
         mfn_dependency_node.setObject(mobject)
         mfn_dependency_node.addAttribute(sample_mobject)
         mplug = mfn_dependency_node.findPlug(type_attribute.name())
         if not id_data[attribute]['value']:
             data.setdefault(attribute, 'no value updated')
         else:
             mplug.setString(id_data[attribute]['value'].encode())
             data.setdefault(attribute, id_data[attribute]['value'])
         mplug.setLocked(id_data[attribute]['locked'])
     return data
コード例 #3
0
ファイル: studioUsd.py プロジェクト: wandth/subins_tutorials
 def create_asset_ids(self, stage, root, data):
     define = UsdGeom.Xform.Define(stage, '/{}'.format(root))
     ids = common.sort_dictionary(data)
     for id in ids:
         primvar = define.CreatePrimvar(id, Sdf.ValueTypeNames.String)
         primvar.Set(data[id]['value'])
         primvar.SetInterpolation('constant')
     return stage
コード例 #4
0
def create_studio_model(studio_model_path, merge):
    from maya import OpenMaya
    from studio_usd_pipe.api import studioModel
    from studio_usd_pipe.api import studioNurbscurve
    # create polygon mesh
    studio_model = common.read_json(studio_model_path)
    model_data = studio_model['mesh']
    model_nodes = common.sort_dictionary(model_data)
    smodel = studioModel.Model()
    contents = {}
    for node in model_nodes:
        node_contents = model_data[node]
        mfn_mesh = smodel.create_model(node, node_contents, merge=merge)
        contents.setdefault(node.split('|')[-1], mfn_mesh.parent(0))
    # create nurbs curve
    scurve = studioNurbscurve.Nurbscurve()
    curve_data = studio_model['curve']
    curve_nodes = common.sort_dictionary(curve_data)
    for node in curve_nodes:
        node_contents = curve_data[node]
        mfn_curve = scurve.create_curve(node, node_contents, merge=merge)
        contents.setdefault(node.split('|')[-1], mfn_curve.parent(0))
    # create transform
    transform_data = studio_model['transform']
    for node, node_contents in transform_data.items():
        mfn_transform = smodel.create_transform(node,
                                                node_contents,
                                                merge=merge)
        contents.setdefault(node.split('|')[-1], mfn_transform.object())
    locations = model_nodes + curve_nodes + transform_data.keys()
    hierarchy = common.flatten_to_dictionary(locations, '|')
    stack = hierarchy.items()
    while stack:
        parent, children = stack.pop()
        if not children:
            continue
        if not isinstance(children, dict):
            continue
        mfndag_parent = OpenMaya.MFnDagNode(contents[parent])
        for child in children:
            mfndag_child = OpenMaya.MFnDagNode(contents[child])
            smodel.set_parent(mfndag_child, mfndag_parent)
        stack.extend(children.items())
    return True, studio_model_path, 'success'
コード例 #5
0
 def set_context_widgets(self, inputs, layout):
     sizepolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                        QtWidgets.QSizePolicy.Fixed)
     sorted_date = common.sort_dictionary(inputs)
     for index, each in enumerate(sorted_date):
         contents = inputs[each]
         label = QtWidgets.QLabel(self)
         label.setObjectName('label_%s' % each)
         label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
         label.setText(contents['label'])
         label.setSizePolicy(sizepolicy)
         layout.addWidget(label, index, 0, 1, 1)
         if contents['type'] in ['str', 'path', 'dirname', 'list']:
             lineedit = QtWidgets.QLineEdit(self)
             lineedit.setObjectName('lineedit_%s' % each)
             value = contents['value']
             if contents['type'] == 'list':
                 value = ', '.join(contents['value'])
             lineedit.setText(value)
             lineedit.setStatusTip('%s,%s,%s,%s' %
                                   (each, contents['env'], contents['type'],
                                    contents['order']))
             layout.addWidget(lineedit, index, 1, 1, 1)
         if contents['type'] in ['path', 'dirname']:
             button = QtWidgets.QPushButton(self)
             button.setObjectName('button_%s' % each)
             button.setText('...')
             button.setMinimumSize(QtCore.QSize(30, 0))
             button.setMaximumSize(QtCore.QSize(30, 16777215))
             layout.addWidget(button, index, 2, 1, 1)
             button.clicked.connect(
                 partial(self.find_directory, lineedit, contents))
         if contents['type'] in ['int']:
             spinbox = QtWidgets.QSpinBox(self)
             spinbox.setObjectName('spinbox_%s' % each)
             spinbox.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
             spinbox.setMinimum(0)
             value = 999999999
             if contents['type'] == 'bool':
                 value = 1
             spinbox.setMaximum(value)
             spinbox.setValue(contents['value'])
             spinbox.setStatusTip('%s,%s,%s,%s' %
                                  (each, contents['env'], contents['type'],
                                   contents['order']))
             layout.addWidget(spinbox, index, 1, 1, 1)
         if contents['type'] in ['bool']:
             combobox = QtWidgets.QComboBox(self)
             combobox.setObjectName('combobox_%s' % each)
             combobox.addItems(['False', 'True'])
             combobox.setCurrentIndex(contents['value'])
             combobox.setStatusTip('%s,%s,%s,%s' %
                                   (each, contents['env'], contents['type'],
                                    contents['order']))
             layout.addWidget(combobox, index, 1, 1, 1)
コード例 #6
0
    def set_default(self):
        inputs = self.shows.get_show_configure_data()
        order = self.shows.get_next_order()
        inputs['show']['order']['value'] = order
        self.set_widgets('current_show', 'show', inputs['show'], order)
        sorted_application = common.sort_dictionary(
            inputs['show_applications'])

        for index, application in enumerate(sorted_application):
            self.set_widgets('show_applications', application,
                             inputs['show_applications'][application], index)
コード例 #7
0
ファイル: studioPush.py プロジェクト: wandth/subins_tutorials
 def release(self):
     packing_data = sum(self.extracted_data.values(), [])
     valid = self.move_to_publish(packing_data)
     if not valid:
         print '#warnings', 'deployed to spublish failed!...'
         return False, 'deployed to spublish failed!...'
     release_inputs = self.make_release_inputs()
     dbs = database.DataBase(self.current_show, self.current_pipe)
     dbs.create(release_inputs)
     print '\n#header registered info'
     sorted_data = common.sort_dictionary(release_inputs)
     for each in sorted_data:
         print '%s: ' % each.rjust(15), release_inputs[each]['value']
     print 'successfully registered spublish'
     return True, 'successfully registered spublish'
コード例 #8
0
 def setup_applications(self, application_type, application_contents, listwidget):
     if not application_contents:
         return
     sorted_contents = common.sort_dictionary(application_contents)
     for each in sorted_contents:            
         if each == 'show':
             continue
         contents = application_contents[each]
         print '%s|%s' % (application_type, each)
         swidgets.add_listwidget_item(
             listwidget,
             contents['version'][1],
             key='%s|%s' % (application_type, each),
             icon_path=contents['icon'][1]
             )
         print 'version: '.rjust(15), contents['version'][1]
         print 'source: '.rjust(15), contents['exe'][1]
         print 'path: '.rjust(15), contents['path'][1], '\n'
コード例 #9
0
def show_applications(current_show, verbose=False):
    show = studioShow.Show()
    data = show.get_show_preset_data(current_show)
    if not data:
        return None
    versions = []
    for application in show.application_types:
        if application not in data:
            continue
        if not data[application]:
            continue
        applications = common.sort_dictionary(data[application])
        for each in applications:
            name = [each, data[application][each]['version'][1]]
            versions.append(name)
            if verbose:
                print application.rjust(25), name
    return versions
コード例 #10
0
 def create_kuv(self, mobject, data):
     mfn_mesh = OpenMaya.MFnMesh(mobject)
     self.delete_uv_sets(mfn_mesh, set_names=None)
     default_set_name = self.get_default_uvset(mfn_mesh)     
     sorted_data = common.sort_dictionary(data)        
     for index, set_name in enumerate(sorted_data):
         contents = data[set_name]
         u_array = self.create_float_array(contents['u_array'])
         v_array = self.create_float_array(contents['v_array'])
         uv_counts = self.create_int_array(contents['uv_counts'])
         uv_ids = self.create_int_array(contents['uv_ids']) 
         if index == 0:
             mfn_mesh.clearUVs(default_set_name)
             if default_set_name != set_name:
                 mfn_mesh.renameUVSet(default_set_name, set_name)
         else:
             set_name = mfn_mesh.createUVSetWithName(set_name)                
         mfn_mesh.setUVs(u_array, v_array, set_name)
         mfn_mesh.assignUVs(uv_counts, uv_ids, set_name)
     mfn_mesh.updateSurface()
     return mfn_mesh              
コード例 #11
0
ファイル: studioUsd.py プロジェクト: wandth/subins_tutorials
 def create_model(self, data, stage=None):
     if not stage:
         stage = self.make_satge()
     if not stage:
         return
     geometries = common.sort_dictionary(data)
     for geometry in geometries:
         location = geometry.replace(':', '_')
         sdf_path = Sdf.Path(location.replace('|', '/'))
         current_data = data[geometry]
         for path in sdf_path.GetPrefixes():
             UsdGeom.Xform.Define(stage, path)
         mesh_define = UsdGeom.Mesh.Define(stage,
                                           sdf_path.GetPrefixes()[-1])
         self.make_m_subdivision(mesh_define, current_data['subdmesh'])
         self.make_m_doublesided(mesh_define, current_data['double_sided'])
         self.make_m_extent(mesh_define, current_data['bounding'])
         self.make_m_face_vertex_counts(mesh_define,
                                        current_data['vertex_count'])
         self.make_m_face_vertex_indices(mesh_define,
                                         current_data['vertex_list'])
         self.make_m_points(mesh_define, current_data['vertices'])
     return stage
コード例 #12
0
ファイル: studioUsd.py プロジェクト: wandth/subins_tutorials
    def create_curve(self, data, stage=None):
        if not stage:
            stage = self.make_satge()
        if not stage:
            return
        geometries = common.sort_dictionary(data)
        for geometry in geometries:
            location = geometry.replace(':', '_')
            sdf_path = Sdf.Path(location.replace('|', '/'))
            current_data = data[geometry]
            for path in sdf_path.GetPrefixes():
                UsdGeom.Xform.Define(stage, path)
            curev_define = UsdGeom.NurbsCurves.Define(
                stage,
                sdf_path.GetPrefixes()[-1])
            self.make_c_vertex_counts(curev_define, [11])
            self.make_c_extent(curev_define, current_data['bounding'])
            self.make_c_knots(curev_define, current_data['knots'])
            self.make_c_order(curev_define, [4])
            self.make_c_points(curev_define, current_data['points'])
            self.make_c_ranges(curev_define, (0, 8))
            self.make_c_widths(curev_define, [1])

        return stage
コード例 #13
0
ファイル: studioUsd.py プロジェクト: wandth/subins_tutorials
    def create_surface(self, root, data, stage=None):
        if not stage:
            stage = self.make_satge()
        if not stage:
            return
        # make geomery hierarchy
        for material in data:
            for geometry in data[material]['geometries']:
                location = geometry.replace(':', '_')
                sdf_path = Sdf.Path(location.replace('|', '/'))
                for path in sdf_path.GetPrefixes():
                    UsdGeom.Xform.Define(stage, path)
                mesh_define = UsdGeom.Mesh.Define(stage,
                                                  sdf_path.GetPrefixes()[-1])

        look_path = Sdf.Path('/{}/Looks'.format(root))
        UsdGeom.Scope.Define(stage, look_path)
        materials = common.sort_dictionary(data)
        for material in materials:  # make materials
            contents = data[material]
            material_path = look_path.AppendPath(material)
            UsdShade.Material.Define(stage, material_path)
            # make shader and attributes
            for node, node_contents in contents['nodes'].items():
                shader_path = material_path.AppendPath(node)
                shader_define = UsdShade.Shader.Define(stage, shader_path)
                shader_define.CreateIdAttr(node_contents['type'])
                if 'parameters' not in node_contents:
                    continue
                for parameter, parameter_contents in node_contents[
                        'parameters'].items():
                    current_type, current_value = self.get_prameter_values(
                        parameter_contents['type'],
                        parameter_contents['value'])
                    if not current_type or current_value == 'null':
                        print '#need to update attribute configure'
                        print '\tmaterial', material, node, parameter
                        print '\t', parameter, parameter_contents[
                            'type'], parameter_contents['value']
                        print '\t', current_type, current_value
                        print '\t', type(current_type)
                        # raise Exception('function get_prameter_values need to update')
                    # print '\t\t>>>>>', current_type, parameter_contents['value']
                    shader_define.CreateInput(parameter,
                                              current_type).Set(current_value)
        # shader connections
        for material, contents in data.items():
            for node, node_contents in contents['nodes'].items():
                if 'connections' not in node_contents:
                    continue
                for parameter, connection_contents in node_contents[
                        'connections'].items():
                    source_attribute, source_node = connection_contents[
                        'value'].split('@')
                    shader_path = look_path.AppendPath('%s/%s' %
                                                       (material, node))
                    source_path = look_path.AppendPath('%s/%s' %
                                                       (material, source_node))
                    shader_define = UsdShade.Shader.Define(stage, shader_path)
                    source_define = UsdShade.Shader.Define(stage, source_path)
                    current_type, current_value = self.get_prameter_values(
                        connection_contents['type'], None)
                    shader_input = shader_define.CreateInput(
                        parameter, current_type)
                    shader_input.ConnectToSource(source_define,
                                                 source_attribute)
        for material in data:
            # material assignments
            material_path = look_path.AppendPath(material)
            material_define = UsdShade.Material.Define(stage, material_path)
            for geometry in data[material]['geometries']:
                location = geometry.replace(':', '_')
                sdf_path = Sdf.Path(location.replace('|', '/'))
                mesh_define = UsdGeom.Mesh.Define(stage, sdf_path)
                UsdShade.MaterialBindingAPI(mesh_define).Bind(material_define)
            # material to shader connection
            shader = data[material]['surface']['shader']
            attribute = data[material]['surface']['attribute']
            shader_path = look_path.AppendPath('%s/%s' % (material, shader))
            material_define = UsdShade.Material.Define(stage, material_path)
            shader_define = UsdShade.Shader.Define(stage, shader_path)
            shader_output = material_define.CreateOutput(
                'ri:surface', Sdf.ValueTypeNames.Token)
            shader_output.ConnectToSource(shader_define, attribute)
        return stage