Blender (jusqu'à 2.49)
Bitmap Image's Colors 
to
mesh's vertex colors
 (version française)
    Main   Index
previoustScript Python
Script Python Next

 A very short script but a lot of  preparation

The script
The preparation
Create a vertex colored mesh with a picture
The script 
 

import Blender
# ======================
# At least one mesh must be selected 
# ======================
MESH=Blender.Object.GetSelected()[0].getData()
# ======================
# We oblige  blender to get the bitmap image's colors 
# of the texture and/or the lights positionning  1 in the 
# 3rd variable of the  update. function .
# ======================
MESH.update(0,0,1)
# ======================
# Don't forget to add a material and set the vcol paint 
# button 
# ======================
 

More details : NMesh.update function

The preparation

Create a vertex colored mesh with a picture 
télécharger/ download le/the  script
 

import Blender
from Blender import *

im=Image.Load('f:/alphatest.jpg') #   rename the file
newmat = Material.New('newmat')
newmat.mode |= Material.Modes.SHADELESS

tex = Texture.New() 
tex.setType('Image') 
tex.image = im 
newmat.setTexture(0, tex) 
mtex = newmat.getTextures()
mtex[0].texco=Texture.TexCo.ORCO

MAXV=100 # Vertices on xy axes 100x100 vertices

imagedim = im.getMaxXY()  #get xy value of the image loaded in im
n01=imagedim[0]/MAXV    # xfactor for the mesh
n02=imagedim[1]/MAXV    # yfactor for the mesh 
nx=ny=MAXV                    # 

me=NMesh.GetRaw() 
for y in range(0,ny+1,1):
 for x in range(0,nx+1,1):
   v=NMesh.Vert(x*n01,y*n02,0.0)
   me.verts.append(v) 
for x in range(0,nx):
  for y in range(0,ny):
   f=NMesh.Face()
   f.v.append(me.verts[x+y*(nx+1)])
   f.v.append(me.verts[x+1+y*(nx+1)])
   f.v.append(me.verts[x+1+(y+1)*(nx+1)])
   f.v.append(me.verts[x+(y+1)*(nx+1)])
   f.mat=0
   me.faces.append(f) 
me.materials.append(newmat) 
OB=NMesh.PutRaw(me)
me=OB.getData()
me.update(0,0,1)

Blender.Redraw()
 


 
précédentScript Python
Script Python Suivant
Vers le  Haut de page

Les questions concernant cette page  peuvent être posées sur  :
 news://news.zoo-logique.org/3D.Blender


 

 

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube