SourceForge.net Logo
Home
Documentation
Tutorials
    Beginning
    Gears
    Noise
    Bumpmapping
    Point sprites
    Hello World
    Armature
    Geometryshader
    Toolscripting
    Keyframe animation
    Instancing
    Bezier Surface
    Deferred shading
    Depth peeling
    Particle System
Links
Support This Project
OpenGL
keyframe animation

1. Create a Node
2. Import a md2 model
3. Add a Texture named Colormap and load a to png or jpg converted texture
4. Create script, vertex and fragment shader
5. Configure the time to 1 minute loop

Or paste these commands into the Console:


Node = World.addNode();
Node.addTexture("Colormap");
Node.addScript();
Node.addVertexShader();
Node.addFragmentShader();
Node.importModel();
Node.Colormap.load();

The first 4 functions accepts object names as argument. The last two paths to the files.
After pasting the following codes to Script, Vertex and Fragment shader. Start the
rendering script by entering "Node.Script.run();" into the console or start it from the
Scripts context menu.

Script:

World.Cam.LoadIdenty();
World.Cam.Translate(0,0,30);

shader = gl.Shader(Vertexshader,Fragmentshader);
shader.Uniformi("Colormap",0);
secondary = shader.Loc("secondary");
secondnorm = shader.Loc("secondnorm");

gl.Enable(gl.CULL_FACE);
gl.CullFace(gl.FRONT);

function render(){
Colormap.Bind(0);

gl.Rotate(-90, 1,0,0);
shader.Bind();

i = World.getTime()*3.3;

shader.Uniform("mixval",i - Math.floor(i));

Model.UvCoords.Bind();
Model.Vertex.BindKeyFrame(i);
Model.Vertex.BindKeyFrame(i+1,secondary);
Model.Normal.BindKeyFrame(i);
Model.Normal.BindKeyFrame(i+1,secondnorm);

Model.Index.Draw();

shader.Unbind();
}


Vertexshader:

attribute vec3 secondary; //2nd keyframe position
attribute vec3 secondnorm; //2nd keyframe normal
uniform float mixval;

varying vec3 N;

void main(void){

vec3 v = mix(gl_Vertex.xyz,secondary.xyz,mixval);
N= gl_NormalMatrix * mix(gl_Normal,secondnorm,mixval);

gl_Position = gl_ModelViewProjectionMatrix * vec4(v,1.0);
gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(1,-1,0,0); // divide by 32768.0 if
the texcoords are shorts;
}


Fragment shader:

uniform sampler2D Tex0;

varying vec3 N;
void main(void){
gl_FragColor.rgb = (max(0.0,dot(N,vec3(0.707,0.0,0.707))) + 0.5) *
texture2D(Tex0, vec2(gl_TexCoord[0])) ;
}



EDIT