https://hal.archives-ouvertes.fr/hal-02132380
Tip revision: 8e562fb9eaf4bb297e83ef8fcb43a92d4d52cf69 authored by Software Heritage on 11 November 2019, 16:19:57 UTC
hal: Deposit 346 in collection hal
hal: Deposit 346 in collection hal
Tip revision: 8e562fb
CreateSphereDES.py
# mis à jour le 19/10/2018
# on remet le curseur au centre à chaque itération : bpyscene.cursor_location = (0.0, 0.0, 0.0)
# et on ne fait plus de translation : mat_loc = mathutils.Matrix.Translation((0, 0, 0))
# cela permet d'avoir les vraies coordonnées de location qu'on a dans le fichier .syn (on avait avant 0,0,0)
# Maj 1/11/18 : material mat = magenta color
# Maj du 20.01.19 :
# A chaque nouvelle utilisation
# - vérifier le chemin des 2 fichiers .syn et .jva à ouvrir
# - vérifier que la texture magenta existe. Si ce n'est pas le cas, créer une sphère hors champ de vision
# et lui affecter une texture à appeler magenta
# Une fois le script exécuté, penser à sélectionner les axes avec shift-bouton gauche souris puis crtl P (parent
# pour que les boules bougent en même temps que les axes
import bpy
import bmesh
import mathutils
import math
rawfile=open('curieux.jva',"r")
tabraw=rawfile.readlines()
rawfile.close()
print(tabraw)
rawfile2=open('curieux.syn',"r",encoding='utf-8')
#rawfile2=open('c:\\tmp\\histoire.syn',"r")
tabraw2=rawfile2.readlines()
rawfile2.close()
print(tabraw2)
bpyscene = bpy.context.scene
bpyscene.cursor_location = (0.0, 0.0, 0.0)
bpyscene.update()
i=0
for word in tabraw2:
ligne=tabraw[i]
ligne=ligne.replace('\n','')
l=ligne.split(' ')
x=(float)(l[0])
y=float(l[1])
z=float(l[2])
word=word.replace('\n','')
word=str(i)+' '+word
## pour ajouter le libellé du mot à coté de la boule
#bpy.ops.object.text_add(location=(x,y,z))
#ob=bpy.context.object
#ob.data.body = word
#ob.data.size = 0.1
#ob.data.bevel_depth = 0.002
#ob.data.extrude = 0.002
# on remet le curseur au centre
bpyscene.cursor_location = (0.0, 0.0, 0.0)
# Create an empty mesh and the object.
mesh = bpy.data.meshes.new('Basic_Sphere')
basic_sphere = bpy.data.objects.new(word, mesh)
bpy.data.objects[word].location[0]=x
bpy.data.objects[word].location[1]=y
bpy.data.objects[word].location[2]=z
# Add the object into the scene.
bpyscene.objects.link(basic_sphere)
bpyscene.objects.active = basic_sphere
basic_sphere.select = True
# create a location matrix
#mat_loc = mathutils.Matrix.Translation((x, y, z))
mat_loc = mathutils.Matrix.Translation((0, 0, 0))
# Construct the bmesh cube and assign it to the blender mesh.
bm = bmesh.new()
bmesh.ops.create_uvsphere(bm, u_segments=16, v_segments=8, diameter=0.2, matrix=mat_loc)
bm.to_mesh(mesh)
bm.free()
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.shade_smooth()
ob = bpy.context.active_object
#mat = bpy.data.materials.get("boule.001")
mat = bpy.data.materials['magenta']
ob.data.materials.append(mat)
i=i+1