Forked from enzyme69/jgbpy_randomColorFacesForQuadMesh.py
Created
March 25, 2013 22:56
-
-
Save zeffii/5241626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
NOTE: The Script only works on surface with Quads Faces ONLY | |
''' | |
import bpy | |
from random import * | |
# Get selected objects | |
selected_objects = bpy.context.selected_objects | |
# Create a single Material that respect Vertex Color | |
mat = bpy.data.materials.new('VertexMat') | |
mat.use_vertex_color_paint = True | |
mat.use_vertex_color_light = True | |
for object in selected_objects: | |
# Get Mesh Data instead of Objects | |
mesh = object.data | |
object.data.materials.append(mat) | |
print('-'*5, ' START ','-'*5 ) | |
# Create new 'Col' Vertex Color Layer | |
mesh.vertex_colors.new() | |
# Vertex colour data | |
vertexColour = mesh.vertex_colors[0].data | |
faces = mesh.polygons | |
# Create random vertex colours | |
vColour = [(random(),random(),random()) for i in mesh.vertices] | |
#print(len(vColour)) | |
#print(vColour) | |
#print(len(vertexColour))g | |
#vertexColour[2].color = 1,1,1 | |
#vertexColour[6].color = 1,1,1 | |
#vertexColour[7].color = 1,1,1 | |
#vertexColour[3].color = 1,1,1 | |
# asign colours to verts | |
for i in range(len(faces)): | |
v = vertexColour[i] | |
f = faces[i].vertices | |
print(f[0]) | |
print(f[1]) | |
print(f[2]) | |
print(f[3]) | |
print(vColour[i]) | |
vertexColour[i*4 + 0].color = vColour[i] | |
vertexColour[i*4 + 1].color = vColour[i] | |
vertexColour[i*4 + 2].color = vColour[i] | |
vertexColour[i*4 + 3].color = vColour[i] | |
print('-'*5, ' END ','-'*5 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment