Changeset 83

Show
Ignore:
Timestamp:
08/03/08 21:41:57 (4 months ago)
Author:
JoeCoder
Message:

More skeletal animation features.
Ignore last revision, it's broken.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/demo2/main.d

    r81 r83  
    142142    window1.style.color = Color("black"); 
    143143     
    144     // Beast 
    145      
    146     auto beast = new ModelNode(scene); 
    147     beast.setModel("beast/beast.ms3d"); 
    148     beast.setPosition(Vec3f(0, 25, -1000)); 
    149     beast.setRotation(Vec3f(0, 1.507, 0)); 
    150      
    151      
    152     void animate(Node self) 
    153     {   ModelNode node = cast(ModelNode)self; 
    154         node.getModel().animate(node.getScene().getStartTime()); 
    155     } 
    156     beast.onUpdate(&animate); 
    157  
    158      
    159144    // Music 
    160145    auto music = new SoundNode(camera); 
     
    194179    Timer delta = new Timer(); 
    195180    Log.write("Starting rendering loop."); 
    196     //std.gc.fullCollect(); 
    197      
    198      
    199     Timer total = new Timer(); 
    200     total.setBounds(3, 5.0); 
    201      
     181    std.gc.fullCollect(); 
     182 
    202183    while(1) 
    203184    { 
    204         writefln(total); 
    205          
    206185        float dtime = delta.get(); 
    207186        delta.reset(); 
    208  
     187         
    209188        Input.processInput(); 
    210189        camera.toTexture(); 
  • trunk/src/yage/resource/model.d

    r82 r83  
    175175        animation_time = time; 
    176176         
    177         // TODO: check time constraints      
     177         
     178         
     179        // TODO: check time constraints 
     180        int i =0; 
    178181        foreach(j, joint; joints) 
    179182        { 
     
    184187             
    185188            // Find appropriate position keyframe 
    186             int i=0; 
     189            i=0; 
    187190            while ((i<joint.positions.length) && (joint.positions[i].time < time)) 
    188191                i++; 
    189192             
    190193            // Interpolate between 2 keyframes 
    191             if (i>0 && i < joint.positions.length-1
     194            if (i>0 && i < joint.positions.length
    192195            {    
    193196                deltatime = joint.positions[i].time - joint.positions[i-1].time; 
     
    202205                m_frame.setPosition(joint.positions[0].value); 
    203206            else // i==joints.positions.length 
    204                 m_frame.setPosition(joint.positions[length-1].value); 
     207                m_frame.setPosition(joint.positions[length].value); 
    205208                         
    206209            // Find appropriate rotation keyframe 
     
    209212                i++; 
    210213            // Interpolate between 2 keyframes 
    211             if (i>0 && i<joint.rotations.length-1
     214            if (i>0 && i<joint.rotations.length
    212215            {    
    213216                deltatime = joint.rotations[i].time - joint.rotations[i-1].time;                 
     
    224227                m_frame.setEuler(joint.rotations[0].value); 
    225228            else // i==joints.rotations.length 
    226                 m_frame.setEuler(joint.rotations[length-1].value); 
     229                m_frame.setEuler(joint.rotations[length].value); 
    227230             
    228231            m_rel.setEuler(joint.startRotation);  
     
    236239        } 
    237240         
     241        //writefln(time, " ", i); 
     242         
    238243        // Update vertex positions based on joints. 
    239244        Vec3f[] vertices = getAttribute("gl_Vertex").vec3f; 
    240245        Vec3f[] vertices_original = getAttribute("gl_VertexOriginal").vec3f; 
     246         
     247        Vec3f[] normals; 
     248        Vec3f[] normals_original; 
     249        if (hasAttribute("gl_Normal")) 
     250        {   normals = getAttribute("gl_Normal").vec3f; 
     251            normals_original = getAttribute("gl_NormalOriginal").vec3f;      
     252        } 
    241253        for (int v=0; v<vertices.length; v++) 
    242254        {   if (joint_indices[v] != -1) 
     
    246258                vertices[v] = vertices_original[v].transform(cmatx); 
    247259                 
     260                 
     261                if (normals.length) 
     262                    normals[v] = normals_original[v].rotate(cmatx); 
    248263                // TODO: Normals 
    249264                // TODO: only reassign cmatx if joint_indices[v] has changed. 
     
    252267                 
    253268        setAttribute("gl_Vertex", vertices); 
    254          
     269        if (normals.length) 
     270            setAttribute("gl_Normal", normals); 
    255271    }    
    256272     
  • trunk/src/yage/resource/ms3dloader.d

    r82 r83  
    217217        normals.length   = ms3d.vertices.length; 
    218218        joint_indices.length= ms3d.vertices.length; 
    219  
     219         
    220220        for (int v; v<ms3d.vertices.length; v++) 
    221221        {   vertices[v].x = ms3d.vertices[v].vertex[0]; 
     
    224224            joint_indices[v] = ms3d.vertices[v].boneId; 
    225225        } 
     226         
     227         
    226228 
    227229        // Meshes 
    228230        meshes.length = ms3d.groups.length; 
    229231        for (int m; m<meshes.length; m++) 
    230         {   meshes[m] = new Mesh(); 
     232        { 
     233             
     234            meshes[m] = new Mesh(); 
    231235            Vec3i[] triangles = meshes[m].getTriangles(); 
    232236            triangles.length = ms3d.groups[m].numtriangles; 
     
    306310                { 
    307311                    // Duplicate vertex from original and copy new texutre and normal coordinates into it. 
    308                     vertices.length = texcoords.length = normals.length = vertices.length+1; 
     312                    vertices.length = texcoords.length = normals.length = joint_indices.length = vertices.length+1; 
    309313                    vertices[length-1] = vertices[ms3d.triangles[tindex].vertexIndices[0]]; 
    310314                    memcpy(&normals[length-1], &ms3d.triangles[tindex].vertexNormals[0], 12); 
    311315                    texcoords[length-1].x = ms3d.triangles[tindex].s[0]; 
    312316                    texcoords[length-1].y = ms3d.triangles[tindex].t[0]; 
     317                    joint_indices[length-1] = joint_indices[ms3d.triangles[tindex].vertexIndices[1]]; 
    313318                    // Assign this new vertex to the triangle 
    314319                    triangles[t].x = vertices.length-1; 
     
    320325                { 
    321326                    // Duplicate vertex from original and copy new texutre and normal coordinates into it. 
    322                     vertices.length = texcoords.length = normals.length = vertices.length+1; 
     327                    vertices.length = texcoords.length = normals.length = joint_indices.length = vertices.length+1; 
    323328                    vertices[length-1] = vertices[ms3d.triangles[tindex].vertexIndices[1]]; 
    324329                    memcpy(&normals[length-1], &ms3d.triangles[tindex].vertexNormals[3], 12); 
    325330                    texcoords[length-1].x = ms3d.triangles[tindex].s[1]; 
    326331                    texcoords[length-1].y = ms3d.triangles[tindex].t[1]; 
     332                    joint_indices[length-1] = joint_indices[ms3d.triangles[tindex].vertexIndices[1]]; 
    327333                    // Assign this new vertex to the triangle 
    328334                    triangles[t].y = vertices.length-1; 
     
    334340                { 
    335341                    // Duplicate vertex from original and copy new texutre and normal coordinates into it. 
    336                     vertices.length = texcoords.length = normals.length = vertices.length+1; 
     342                    vertices.length = texcoords.length = normals.length = joint_indices.length = vertices.length+1; 
    337343                    vertices[length-1] = vertices[ms3d.triangles[tindex].vertexIndices[2]]; 
    338344                    memcpy(&normals[length-1], &ms3d.triangles[tindex].vertexNormals[6], 12); 
    339345                    texcoords[length-1].x = ms3d.triangles[tindex].s[2]; 
    340346                    texcoords[length-1].y = ms3d.triangles[tindex].t[2]; 
     347                    joint_indices[length-1] = joint_indices[ms3d.triangles[tindex].vertexIndices[1]]; 
    341348                    // Assign this new vertex to the triangle 
    342349                    triangles[t].z = vertices.length-1; 
    343350                } 
    344351            } 
    345  
     352         
    346353            // Find meshes with material of -1 (no material) and assign them the default material 
    347354            if (ms3d.groups[m].materialIndex==-1) 
     
    376383            } 
    377384        } 
     385         
     386         
    378387         
    379388        // Link joint parent relationships. 
     
    414423            // Inverse transform each vertex and inverse rotate each normal by the joint's Matrix. 
    415424            for (int i; i<vertices.length; i++) 
    416             {   if ( joint_indices[i] != -1 ) 
     425            {   if (joint_indices[i] != -1 ) 
    417426                {   Matrix matrix = joints[joint_indices[i]].transformAbs; 
    418                     vertices[i] = vertices[i].inverseTransform(matrix);          
     427                    vertices[i] = vertices[i].inverseTransform(matrix);      
     428                    normals[i] = normals[i].inverseRotate(matrix);       
    419429            }   } 
    420430             
  • trunk/src/yage/system/device.d

    r81 r83  
    292292                return cast(bool)shader; 
    293293            case DEVICE_VBO: //return false; // true breaks custom vertex attributes 
    294                 return false; 
    295294                if (vbo==-1) 
    296295                    vbo = checkExtension("GL_ARB_vertex_buffer_object"); 
  • trunk/src/yage/system/render.d

    r82 r83  
    271271         
    272272        // Draw joints 
    273         if (true
     273        if (_debug
    274274        {   glDisable(GL_DEPTH_TEST); 
    275275            glDisable(GL_LIGHTING);