MeshLab是一款model display的工具軟體,它還有轉換model檔案類型的功能,要是你只有寫讀.obj檔的程式話,就可以把讀進來的model轉為.obj檔喔!
對我來說,目前最有用的功能是,可輸入和輸出格式。如下:
- import: PLY, STL, OFF, OBJ, 3DS, COLLADA, PTX, V3D, PTS, APTS, XYZ, GTS, TRI, ASC, X3D, X3DV, VRML, ALN
- export: PLY, STL, OFF, OBJ, 3DS, COLLADA, VRML, DXF, GTS, U3D, IDTF, X3D
MeshLab還有其它功能,如:
- Mesh Cleaning Filters
- Remeshing filters
- Various Colorization/Inspection filters
- Interactive Mesh Painting
- Measuring tool
- Slicing tool
- 3D Scanning tools
細節再去MeshLab官網看。
接下來我demo這款軟體目前對我來說有用的功能,同樣地~我使用cow model來實驗,這一張是no light的結果:

最簡單的light效果flat:

smooth的效果:

接下來就是shader的效果phong:

shader x-ray效果:

MeshLab這套軟體還告訴你如何寫shader,比如shader phong這個效果,它的shader是這樣寫的:
vertex shader (vertex program)
//
// Bui Tuong Phong shading model (per-pixel)
//
// by
// Massimiliano Corsini
// Visual Computing Lab (2006)
//
varying vec3 normal;
varying vec3 vpos;
void main()
{
// vertex normal
normal = normalize(gl_NormalMatrix * gl_Normal);
// vertex position
vpos = vec3(gl_ModelViewMatrix * gl_Vertex);
// vertex position
gl_Position = ftransform();
}
fragment shader (fragment program)
//
// Bui Tuong Phong shading model (per-pixel)
//
// by
// Massimiliano Corsini
// Visual Computing Lab (2006)
//
varying vec3 normal;
varying vec3 vpos;
uniform float shininess;
void main()
{
vec3 n = normalize(normal);
vec4 diffuse = vec4(0.0);
vec4 specular = vec4(0.0);
// the material properties are embedded in the shader (for now)
vec4 mat_ambient = vec4(1.0, 1.0, 1.0, 1.0);
vec4 mat_diffuse = vec4(1.0, 1.0, 1.0, 1.0);
vec4 mat_specular = vec4(1.0, 1.0, 1.0, 1.0);
// ambient term
vec4 ambient = mat_ambient * gl_LightSource[0].ambient;
// diffuse color
vec4 kd = mat_diffuse * gl_LightSource[0].diffuse;
// specular color
vec4 ks = mat_specular * gl_LightSource[0].specular;
// diffuse term
vec3 lightDir = normalize(gl_LightSource[0].position.xyz - vpos);
float NdotL = dot(n, lightDir);
if (NdotL > 0.0)
diffuse = kd * NdotL;
// specular term
vec3 rVector = normalize(2.0 * n * dot(n, lightDir) - lightDir);
vec3 viewVector = normalize(-vpos);
float RdotV = dot(rVector, viewVector);
if (RdotV > 0.0)
specular = ks * pow(RdotV, shininess);
gl_FragColor = ambient + diffuse + specular;
}
想瞭解其它有趣的shader怎麼寫,或原理如何就可從這邊著手喔!
參考:MeshLab。
隨意留個言吧:)~