Skip to content
Snippets Groups Projects
export_x3d.py 48.3 KiB
Newer Older
  • Learn to ignore specific revisions
  •                 elif namemat == "right":
    
                    elif namemat == "top":
    
    
    ##########################################################
    # export routine
    ##########################################################
    
            world = scene.world
    
    
            # tag un-exported IDs
            bpy.data.meshes.tag(False)
            bpy.data.materials.tag(False)
            bpy.data.images.tag(False)
    
    
            print("Info: starting X3D export to %r..." % file.name)
    
            ident = writeHeader(ident)
    
            writeNavigationInfo(ident, scene)
            writeBackground(ident, world)
            writeFog(ident, world)
    
            if use_selection:
                objects = (o for o in scene.objects if o.is_visible(scene) and o.select)
            else:
                objects = (o for o in scene.objects if o.is_visible(scene))
    
            for ob_main in objects:
    
    
                free, derived = create_derived_objects(scene, ob_main)
    
                if derived is None:
                    continue
    
                for ob, ob_mat in derived:
                    objType = ob.type
                    objName = ob.name
    
                    ob_mat = global_matrix * ob_mat
    
                        writeViewpoint(ident, ob, ob_mat, scene)
    
                    elif objType in ('MESH', 'CURVE', 'SURF', 'FONT'):
    
                        if (objType != 'MESH') or (use_apply_modifiers and ob.is_modified(scene, 'PREVIEW')):
    
                                me = ob.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
    
                            writeIndexedFaceSet(ident, ob, me, ob_mat, world)
    
                            # free mesh created with create_mesh()
                            if me != ob.data:
                                bpy.data.meshes.remove(me)
    
    
                    elif objType == 'LAMP':
                        data = ob.data
                        datatype = data.type
                        if datatype == 'POINT':
    
                            writePointLight(ident, ob, ob_mat, data, world)
    
                            writeSpotLight(ident, ob, ob_mat, data, world)
    
                            writeDirectionalLight(ident, ob, ob_mat, data, world)
    
                            writeDirectionalLight(ident, ob, ob_mat, data, world)
    
                    else:
                        #print "Info: Ignoring [%s], object type [%s] not handle yet" % (object.name,object.getType)
                        pass
    
                if free:
                    free_derived_objects(ob_main)
    
    
            ident = writeFooter(ident)
    
        export_main()
        file.close()
        print("Info: finished X3D export to %r" % file.name)
    
    
    
    ##########################################################
    # Callbacks, needed before Main
    ##########################################################
    
    
    def save(operator, context, filepath="",
    
             use_selection=True,
             use_apply_modifiers=False,
             use_triangulate=False,
    
             use_normals=False,
    
             use_compress=False,
    
    Campbell Barton's avatar
    Campbell Barton committed
             use_h3d=False,
    
             global_matrix=None,
             ):
    
    
        if use_compress:
            if not filepath.lower().endswith('.x3dz'):
                filepath = '.'.join(filepath.split('.')[:-1]) + '.x3dz'
        else:
            if not filepath.lower().endswith('.x3d'):
                filepath = '.'.join(filepath.split('.')[:-1]) + '.x3d'
    
        if bpy.ops.object.mode_set.poll():
            bpy.ops.object.mode_set(mode='OBJECT')
    
    
        file = None
        if filepath.lower().endswith('.x3dz'):
            try:
                import gzip
                file = gzip.open(filepath, "w")
            except:
                print("failed to import compression modules, exporting uncompressed")
                filepath = filepath[:-1]  # remove trailing z
    
        if file is None:
            file = open(filepath, "w")
    
    
        if global_matrix is None:
            global_matrix = mathutils.Matrix()
    
    
        export(file,
               global_matrix,
               context.scene,
               use_apply_modifiers=use_apply_modifiers,
               use_selection=use_selection,
    
               use_triangulate=use_triangulate,
               use_normals=use_normals,
    
    Campbell Barton's avatar
    Campbell Barton committed
               use_h3d=use_h3d,