Code archives/3D Graphics - Mesh/ColorMesh and ColorSurface

This code has been declared by its author to be Public Domain code.

Download source code

ColorMesh and ColorSurface by GIB3D2010
This only works if you use EntityFX

For coloring
EntityFX Mesh,2

For changing alpha
EntityFX Mesh,32

For both
EntityFX Mesh,2+32

2: use vertex colors instead of brush color
32: force alpha-blending
Function ColorMesh(mesh,red#,green#,blue#,alpha#=1)
	Local Surface,Surfaces,Vertices
	
	Surfaces = CountSurfaces(mesh)
	
	For s = 1 To Surfaces
		Surface = GetSurface(mesh,s)
		ColorSurface(Surface,red,green,blue,alpha)
	Next
End Function

Function ColorSurface(surface,red#,green#,blue#,alpha#=1)
	Local Surfaces,Vertices
	
	Vertices = CountVertices(surface)
	
	For v = 0 To Vertices - 1
		VertexColor surface,v,red,green,blue,alpha
	Next
End Function

Comments

RemiD2014
Your function ColorSurface() should be called something like ColorSurfaceWithVertexColor() because you can also color a surface with a brush or with a texture...


Stevie G2014
Better to automatically set the fx flags in the function.


Code Archives Forum