示例#1
0
    def import_file(my,
                    node_name,
                    path,
                    instantiation='import',
                    use_namespace=True):

        naming = XSINodeNaming(node_name)

        # if there is no node_name name, then just import without namespaces
        if not naming.has_instance():
            # import file into namespace
            if instantiation == 'reference':
                created_node = my.app.import_reference(path)
            else:
                created_node = my.app.import_file(path)

        else:
            # import file into namespace
            if instantiation == 'reference':
                created_node = my.app.import_reference(path, node_name)
            else:
                created_node = my.app.import_file(path, node_name)

        # FIXME: created node name is not always node_name
        # select newly created node
        my.app.select(created_node)

        return created_node
示例#2
0
    def import_file(self, node_name, path, instantiation='import', use_namespace=True):

        naming = XSINodeNaming(node_name)

        # if there is no node_name name, then just import without namespaces
        if not naming.has_instance():
            # import file into namespace
            if instantiation == 'reference':
                created_node = self.app.import_reference(path)
            else:
                created_node = self.app.import_file(path)

        else:
            # import file into namespace
            if instantiation == 'reference':
                created_node = self.app.import_reference(path,node_name)
            else:
                created_node = self.app.import_file(path,node_name)

        # FIXME: created node name is not always node_name
        # select newly created node
        self.app.select(created_node)

        return created_node
示例#3
0
    def _get_texture_node_dict(self, node_name):
        '''get the texture node dict and add prefix(asset_code) to the texture first
            if nececssary'''
        root = self.app.xsi.ActiveProject.ActiveScene.Root
        # extract asset_code
        naming = XSINodeNaming(node_name)
        asset_code = naming.get_asset_code()
        node = root.FindChild(node_name)
        info = {}
        children = node.FindChildren('', '', ['Mesh Geometries', 'Clusters'],
                                     True)
        image_attr = "AllImageClips"
        if self.app.xsi.Version() < "7":
            image_attr = "ImageClips"
        clip_dict = {}
        for i in children:
            clips = eval('i.Material.%s' % image_attr)

            for clip in clips:
                if self._is_light_map(clip):
                    continue
                if self._is_clip_referenced(clip):
                    continue
                clip_name = str(clip.Name)

                # add prefix if it does not exist
                if not clip_name.startswith(asset_code):
                    clip_name = '%s_%s' % (asset_code, clip_name)
                    clip.Name = clip_name
                path = clip.Parameters('SourceFileName').Value
                clip_dict[clip_name] = clip.FullName, path

            #listing clusters for each mesh along with their material
            for j in i.ActivePrimitive.Geometry.Clusters:
                if (j.type == "poly"):
                    clips = eval('j.Material.%s' % image_attr)
                    nested_clips=filter(lambda nest:\
                        nest.Type=='ImageClip', j.Material.NestedObjects)
                    all_clips = []
                    all_clips.extend(clips)
                    if nested_clips:
                        all_clips.extend(nested_clips)
                    for clip in all_clips:
                        if self._is_light_map(clip):
                            continue
                        if self._is_clip_referenced(clip):
                            continue
                        clip_name = str(clip.Name)
                        # add prefix if it does not exist
                        if not clip_name.startswith(asset_code):
                            clip_name = '%s_%s' % (asset_code, clip_name)
                            clip.Name = clip_name
                        path = clip.Parameters('SourceFileName').Value
                        clip_dict[clip_name] = clip.FullName, path

        for key, value in clip_dict.items():
            full_name, path = value
            current_list = info.get(path)
            if current_list:
                current_list.append(full_name)
            else:
                info[path] = [full_name]
        ''' # this only works if the Shader name is Material
        import win32com.client
        o = win32com.client.Dispatch( "XSI.Collection" )
        o.Items = '%s.*.Material, %s.*.*.cls.*.Material' %(node_name, node_name) 
        o.Unique = True
        LogMessage( o.Count )
        for i in o:
            clips = i.ImageClips
            for clip in clips:
                path = clip.Parameters('SourceFileName').Value
                info[path] = clip.FullName
           
        '''

        return info
示例#4
0
文件: xsi_impl.py 项目: 0-T-0/TACTIC
    def _get_texture_node_dict(my, node_name):
        '''get the texture node dict and add prefix(asset_code) to the texture first
            if nececssary'''
        root = my.app.xsi.ActiveProject.ActiveScene.Root
        # extract asset_code
        naming = XSINodeNaming(node_name)
        asset_code = naming.get_asset_code()
        node = root.FindChild(node_name)
        info = {}
        children = node.FindChildren('','', ['Mesh Geometries','Clusters'], True)
        image_attr = "AllImageClips"
        if my.app.xsi.Version() < "7":
            image_attr = "ImageClips"
        clip_dict = {} 
        for i in children:
            clips = eval('i.Material.%s' % image_attr)
            
            for clip in clips:
                if my._is_light_map(clip):
                    continue
                if my._is_clip_referenced(clip):
                    continue
                clip_name = str(clip.Name)
                
                # add prefix if it does not exist
                if not clip_name.startswith(asset_code):
                    clip_name = '%s_%s' %(asset_code, clip_name) 
                    clip.Name = clip_name
                path = clip.Parameters('SourceFileName').Value
                clip_dict[clip_name] = clip.FullName, path
            

            #listing clusters for each mesh along with their material
            for j in i.ActivePrimitive.Geometry.Clusters:
                if (j.type=="poly"):
                    clips = eval('j.Material.%s' % image_attr)
                    nested_clips=filter(lambda nest:\
                        nest.Type=='ImageClip', j.Material.NestedObjects)
                    all_clips = []
                    all_clips.extend(clips)
                    if nested_clips:
                        all_clips.extend(nested_clips)
                    for clip in all_clips:
                        if my._is_light_map(clip):
                            continue
                        if my._is_clip_referenced(clip):
                            continue
                        clip_name = str(clip.Name)
                        # add prefix if it does not exist
                        if not clip_name.startswith(asset_code):
                            clip_name = '%s_%s' %(asset_code, clip_name) 
                            clip.Name = clip_name
                        path = clip.Parameters('SourceFileName').Value
                        clip_dict[clip_name] = clip.FullName, path
                
        for key, value in clip_dict.items():
            full_name, path = value
            current_list = info.get(path)
            if current_list:
                current_list.append(full_name)
            else:
                info[path] = [full_name]
        ''' # this only works if the Shader name is Material
        import win32com.client
        o = win32com.client.Dispatch( "XSI.Collection" )
        o.Items = '%s.*.Material, %s.*.*.cls.*.Material' %(node_name, node_name) 
        o.Unique = True
        LogMessage( o.Count )
        for i in o:
            clips = i.ImageClips
            for clip in clips:
                path = clip.Parameters('SourceFileName').Value
                info[path] = clip.FullName
           
        '''

        return info