1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| # Créé par fdu, le 16/01/2019 en Python 3.4
# VERSION FINALE
#----------------------------------------------------------------------------------------------------------------
# Programme Python pour le logiciel 'Blender'
# Le BUT : Diminuer la taille de tous les fichiers d'un dossier et transférer ces nouveaux fichiers dans un autre dossier.
# Gain en terme de taille : 25-30% de gain par rapport à ceux de départ
#----------------------------------------------------------------------------------------------------------------
import bpy
from mathutils import Vector, Matrix, Quaternion, Euler, Color
from os import *
import os # Bibliothèque indispensable pr la gestion de fichiers ou de dossiers: Lister, créer, etc
input_dir = "C:\\Users\\fdu\\Documents\\MesDocumentsPersos\\Programmation\\Python\\vrml-De-Base\\"
output_dir = "C:\\Users\\fdu\\Documents\\MesDocumentsPersos\\Programmation\\Python\\vrmlAllegeCouleur2\\"
for wrl_file in listdir(input_dir):
if wrl_file.endswith(".wrl"):
# Savoir dans quel context on est
#print(bpy.context.mode)
filepath = path.join(input_dir, wrl_file)
print("Le fichier est : ", filepath)
bpy.ops.import_scene.x3d(filepath=filepath, filter_glob="*.wrl")
object_all = bpy.context.scene.objects
for ob in object_all:
ob.select = ob.name.startswith("Viewpoint") # Viewpoint : CAMERAS
bpy.ops.object.delete(use_global=False)
object_all = bpy.context.scene.objects
for ob in object_all:
ob.select = ob.name.startswith("Shape_IndexedFaceSet") # Shape_IndexedFaceSet -> Nom de chaque pièce composant le wrl / Pr les petits fichiers, remplacer par "Viewpoint"
bpy.context.scene.objects.active = bpy.data.objects["Shape_IndexedFaceSet"] # Pr les petits fichiers, remplacer par "Viewpoint"
bpy.ops.object.join()
# Une fois que le fichier est join, C A D, en une seule pièce , on applique la couleur
# RAJOUT pour test COULEUR
bpy.ops.object.select_all(action='INVERT')
#bpy.ops.object.mode_set(mode='EDIT')
#bpy.context.space_data.context = 'MATERIAL' #--> Pb avec cette ligne
bpy.ops.material.new()
bpy.context.object.active_material.diffuse_color=(0.0540246, 1, 0.0371847) # Couleur verte flash --> Cette ligne ne fonctionne pas pour appliquer la couleur
# FIN RAJOUT
bpy.ops.object.mode_set (mode = 'EDIT')
bpy.ops.mesh.remove_doubles(use_unselected=False, threshold=9.999999747378752e-05) # Supprime les doublons
filepath2 = os.path.join(output_dir, wrl_file)
bpy.ops.export_scene.vrml2(filepath=filepath2)
# Repasser en mode Object
bpy.ops.object.mode_set (mode = 'OBJECT')
# Supprimer toute la scene pour le prochain tour de boucle
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete(use_global=False)
for item in bpy.data.meshes:
bpy.data.meshes.remove(item)
print("\n" + "======> Le dernier fichier de la liste sélectionnée : " + wrl_file + " a ete bien copié" + "\n") |
Partager