Skip to content
Snippets Groups Projects
io_import_scene_unreal_psk.py 39.8 KiB
Newer Older
  • Learn to ignore specific revisions
  •             name="Align to View",
                default=False,
                )
        location = FloatVectorProperty(
                name="Location",
                subtype='TRANSLATION',
                )
        rotation = FloatVectorProperty(
                name="Rotation",
                subtype='EULER',
                )
        def execute(self, context):
            return {'FINISHED'}
            
        def invoke(self, context, event):
            me = bpy.data.meshes.new("test")
            obmade = bpy.data.objects.new("TestObject",me)
            print("Create Simple Mesh")
            bpy.data.scenes[0].objects.link(obmade)
            for i in bpy.context.scene.objects: i.select = False #deselect all objects
            obmade.select = True
            bpy.context.scene.objects.active = obmade
            
            #bpy.ops.object.mode_set(mode='EDIT')
            #me.from_pydata([(0,0,0),(2,0,0),(2,0,2)],[(1,2),(2,3),(3,1)],[(1,2,3)])
            #me.from_pydata([(0,0,0),(2,0,0),(2,0,2)],[(1,2),(2,3),(3,1)],[(1,2,3)])
            verts = [(0,0,0),(2,0,0),(2,0,2)]
            #faces = [([0, 1, 2])]
            
            faces = []
            #faces.extend([(1,2,3,0)])
            faces.extend([(0,1,2,0)])
            #print(faces[0][0])
            #print(dir(me.tessfaces))
            me.vertices.add(len(verts))
            me.vertices.foreach_set("co", unpack_list(verts))
            
            me.tessfaces.add(len(faces))
            #me.tessfaces.foreach_set("vertices_raw", unpack_list(faces))
            me.tessfaces.foreach_set("vertices", unpack_list(faces))
            #me.tessfaces.foreach_set("vertices_raw", (faces))
            print(len(me.tessfaces))
            me.tessface_uv_textures.new("uvtexture")
            for uv in me.tessface_uv_textures:
                print(len(uv.data))
                print(dir(uv.data[0]))
            bm = bmesh.new()
            bm.to_mesh(me)
            #for v_co in verts:
                #bm.verts.new(v_co)
            for f_idx in faces:
                bm.faces.new([bm.verts[i] for i in f_idx])
            #bm.to_mesh(me)
            #ob = bpy.data.objects.new("TestObject",me)
            #me.update()
            
            #print(dir(me))
            #me.uv_textures.new("uvtexture")
            #for uv in me.uv_textures:
                #print(len(uv.data))
            #from bpy_extras import object_utils
            #object_utils.object_data_add(context, me, operator=self)
            #ob = bpy.data.objects.new("TestObject",me)
            #bpy.context.scene.objects.link(ob) 
    
            return {'RUNNING_MODAL'}		
    """
    """
    class OBJECT_OT_Path(bpy.types.Operator):
        bl_idname = "object.path"
        bl_label = "PSA Path"
        __doc__ = ""
        # generic transform props
        view_align = BoolProperty(
                name="Align to View",
                default=False,
                )
        location = FloatVectorProperty(
                name="Location",
                subtype='TRANSLATION',
                )
        rotation = FloatVectorProperty(
                name="Rotation",
                subtype='EULER',
                )
        def execute(self, context):
            return {'FINISHED'}
            
        def invoke(self, context, event):
            me = bpy.data.meshes.new("test")
            #ob = bpy.data.objects.new("TestObject",me)
            print("Create Simple Mesh")
            #bpy.data.scenes[0].objects.link(ob)
            
            #me.from_pydata([(0,0,0),(2,0,0),(2,0,2)],[(1,2),(2,3),(3,1)],[(1,2,3)])
            #me.from_pydata([(0,0,0),(2,0,0),(2,0,2)],[(1,2),(2,3),(3,1)],[(1,2,3)])
            verts = [(0,0,0),(2,0,0),(2,0,2)]
            faces = [(0, 1, 2)]
            #faces = [([1,2,3])]
            
            
            bm = bmesh.new()
     
            for v_co in verts:
                bm.verts.new(v_co)
    
            for f_idx in faces:
                bm.faces.new([bm.verts[i] for i in f_idx])
    
            bm.to_mesh(me)
            ob = bpy.data.objects.new("TestObject",me)
            me.update()
            
            print(dir(me))
            me.uv_textures.new("uvtexture")
            for uv in me.uv_textures:
                print(len(uv.data))
            
            
            
            
            #from bpy_extras import object_utils
            #object_utils.object_data_add(context, me, operator=self)
            bpy.context.scene.objects.link(ob) 
    
            return {'RUNNING_MODAL'}
    """
    """		
    class OBJECT_OT_Path(bpy.types.Operator):
        bl_idname = "object.path"
        bl_label = "PSA Path"
        __doc__ = ""
        # generic transform props
        view_align = BoolProperty(
                name="Align to View",
                default=False,
                )
        location = FloatVectorProperty(
                name="Location",
                subtype='TRANSLATION',
                )
        rotation = FloatVectorProperty(
                name="Rotation",
                subtype='EULER',
                )
        #filepath = StringProperty(name="PSA File Path", description="Filepath used for importing the PSA file", maxlen= 1024, default= "")
        #filter_glob = StringProperty(
                #default="*.psa",
                #options={'HIDDEN'},
                #)
        def execute(self, context):
            #context.scene.importpsapath = self.properties.filepath
            return {'FINISHED'}
            
        def invoke(self, context, event):
            me = bpy.data.meshes.new("test")
            #ob = bpy.data.objects.new("TestObject",me)
            print("Create Simple Mesh")
            #bpy.data.scenes[0].objects.link(ob)
            
            #me.from_pydata([(0,0,0),(2,0,0),(2,0,2)],[(1,2),(2,3),(3,1)],[(1,2,3)])
            #me.from_pydata([(0,0,0),(2,0,0),(2,0,2)],[(1,2),(2,3),(3,1)],[(1,2,3)])
            verts = [(0,0,0),(2,0,0),(2,0,2)]
            faces = [(0, 1, 2, 3)]
            #faces = [([1,2,3])]
            
            
            bm = bmesh.new()
     
            for v_co in verts:
                bm.verts.new(v_co)
    
    John Phan's avatar
    John Phan committed
    
    
            #for f_idx in faces:
                #bm.faces.new([bm.verts[i] for i in f_idx])
            bm.to_mesh(me)
            me.update()
            from bpy_extras import object_utils
            object_utils.object_data_add(context, me, operator=self)
            
            #bpy.context.scene.objects.link(me) 
          
            #me.from_pydata(verts,[],faces)
            me.vertices.add(len(verts))
            me.tessfaces.add(len(faces))
            
            me.vertices.foreach_set("co", unpack_list(verts))
            me.tessfaces.foreach_set("vertices_raw", (faces))#not working
            
            me.update()
           
            #bpy.context.window_manager.fileselect_add(self)
            return {'RUNNING_MODAL'}		
    """
    
    John Phan's avatar
    John Phan committed
    #import menu panel tool bar
    class VIEW3D_PT_unrealimport_objectmode(bpy.types.Panel):
        bl_space_type = "VIEW_3D"
        bl_region_type = "TOOLS"
        bl_label = "Import PSK/PSA"
        
        @classmethod
        def poll(cls, context):
            return context.active_object
    
        def draw(self, context):
            layout = self.layout
            rd = context.scene
    
            row2 = layout.row(align=True)
            row2.operator(OBJECT_OT_PSKPath.bl_idname)                
            row2.operator(OBJECT_OT_PSAPath.bl_idname)        
            row2.operator(OBJECT_OT_Path.bl_idname)        
    #import panel
    
    def menu_func(self, context):
        self.layout.operator(IMPORT_OT_psk.bl_idname, text="Skeleton Mesh (.psk)")
    
    
    John Phan's avatar
    John Phan committed
        bpy.utils.register_module(__name__)
    
        bpy.types.INFO_MT_file_import.append(menu_func)
        
    def unregister():
    
    John Phan's avatar
    John Phan committed
        bpy.utils.unregister_module(__name__)
    
        bpy.types.INFO_MT_file_import.remove(menu_func)
    
    if __name__ == "__main__":
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        register()
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    #note this only read the data and will not be place in the scene    
    
    #getInputFilename('C:\\blenderfiles\\BotA.psk') 
    #getInputFilename('C:\\blenderfiles\\AA.PSK')
    
    John Phan's avatar
    John Phan committed
    #getInputFilename('C:\\blender26x\\blender-2.psk')