Código:
#.Bpy. Registration información for Blender menús: Name: maplamp2mesh. Blender: 232. Group: Misc. Tip: map a colored Lamp (if Mesh is vertex coloured) todo every vertex of the Mesh. #-. # maplamptomeh. # JM soler (2004). # -. # page oficielle: # https://Jmsoler, free.fr/didacticiel/blender/tutor/. # communiquer les problemes et les erreurs sur: # https://www.zo-logique.org/3d. Blender/newsportal/thread.php?Group=3d. Blender. #-. # ce script est proposé sous licence GPL pour etre associe. # a la distribution de Blender 2.33 et suivant. #-. Import Blender. Import math. From math import *. From Blender import object,nmesh. Def multmat(m,x y, z). X1 = (x * m[0][0]) + (y * m[1][0]) + (z * m[2][0]) + m[3][0]. Y1 = (x * m[0][1]) + (y * m[1][1]) + (z * m[2][1]) + m[3][1]. Z1 = (x * m[0][2]) + (y * m[1][2]) + (z * m[2][2]) + m[3][2]. Return x1, y1, z1. Me=object. Getselected(). If len(me)>=0: If me[0].gettype ()==Mesh: Sc=blender. Scene, getcurrent(). Me=nmesh. Getraw(me[0].getdata (), name). For s in me, vértices: L=blender. Object. New(Lamp). Sc, enlace (l). #l=blender. Object. Getselected()[0]. # le dernier objet. #cre est toujours selectionne. # plus fácile pour recupere. Lampe=blender. Lamp. Get(l.data, name). #.nom, qui donnera. # acces a lobjet lui-meme. Lampe, type=2 # type spot. Lampe, Dist=20.0 # distance sur laquelle le spot projette sa lumiére. Lampe, energy=0.1 # energie, plutôt basse pour en pas saturer. Lampe, spotsize=120.0 # angle douverture du cone lumineux. Lampe, spotblend=0.7 # largeur de la frange de penombre. Lampe, mode=9 # mode ombre. X y, z=multmat(me[0].mat, co[0], co[1], co[2]). # pour resituer la position. # relle du point. L. Locx=x. L. Locy=y. L. Locz=z. Xa=s, no[0]+s, co[0]. Da=s, no[1]+s, co[1]. Wi=s, no[2]+s, co[2]. Al, be, ga=multmat(me[0].mat,xa, da,wi). S, no[0]=al-x. S, no[1]=be-y. S, no[2]=GA-z. Norm=sqrt(s, no[0]**2+s, no[1]**2+s, no[2]**2). S, no[0]=s, no[0]/Norm. S, no[1]=s, no[1]/Norm. S, no[2]=s, no[2]/Norm. #print, no[0], no[1], no[2]. If abs(s, no[1])<0.0001: S, no[1]=0.0. L. Rotx=0. Teta=-acos(s, no[2]). L. Roty=-pi+teta. If, no[1].=0: L. Rotz=-acos(s, no[0]/sin(teta))*s, no[1]/abs(s, no[1]). Else: L. Rotz=0. If, no[0]>0: L. Roty=-l. Roty. If me, hasvertexcolours()==1: For de in me, Faces: If s in d, v: #print d, col[d, v, index(s)].r/255.0. Lampe. R=d, col[d, v, index(s)].r/255.0. Lampe. G=d, col[d, v, index(s)].g/255.0. Lampe. B=d, col[d, v, index(s)].b/255.0. Break. Blender. Redraw().