- Timestamp:
- 08/03/08 21:41:57 (4 months ago)
- Files:
-
- trunk/src/demo2/main.d (modified) (2 diffs)
- trunk/src/yage/resource/model.d (modified) (8 diffs)
- trunk/src/yage/resource/ms3dloader.d (modified) (7 diffs)
- trunk/src/yage/system/device.d (modified) (1 diff)
- trunk/src/yage/system/exceptions.d (added)
- trunk/src/yage/system/interfaces.d (added)
- trunk/src/yage/system/render.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo2/main.d
r81 r83 142 142 window1.style.color = Color("black"); 143 143 144 // Beast145 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 159 144 // Music 160 145 auto music = new SoundNode(camera); … … 194 179 Timer delta = new Timer(); 195 180 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 202 183 while(1) 203 184 { 204 writefln(total);205 206 185 float dtime = delta.get(); 207 186 delta.reset(); 208 187 209 188 Input.processInput(); 210 189 camera.toTexture(); trunk/src/yage/resource/model.d
r82 r83 175 175 animation_time = time; 176 176 177 // TODO: check time constraints 177 178 179 // TODO: check time constraints 180 int i =0; 178 181 foreach(j, joint; joints) 179 182 { … … 184 187 185 188 // Find appropriate position keyframe 186 i nt i=0;189 i=0; 187 190 while ((i<joint.positions.length) && (joint.positions[i].time < time)) 188 191 i++; 189 192 190 193 // Interpolate between 2 keyframes 191 if (i>0 && i < joint.positions.length -1)194 if (i>0 && i < joint.positions.length) 192 195 { 193 196 deltatime = joint.positions[i].time - joint.positions[i-1].time; … … 202 205 m_frame.setPosition(joint.positions[0].value); 203 206 else // i==joints.positions.length 204 m_frame.setPosition(joint.positions[length -1].value);207 m_frame.setPosition(joint.positions[length].value); 205 208 206 209 // Find appropriate rotation keyframe … … 209 212 i++; 210 213 // Interpolate between 2 keyframes 211 if (i>0 && i<joint.rotations.length -1)214 if (i>0 && i<joint.rotations.length) 212 215 { 213 216 deltatime = joint.rotations[i].time - joint.rotations[i-1].time; … … 224 227 m_frame.setEuler(joint.rotations[0].value); 225 228 else // i==joints.rotations.length 226 m_frame.setEuler(joint.rotations[length -1].value);229 m_frame.setEuler(joint.rotations[length].value); 227 230 228 231 m_rel.setEuler(joint.startRotation); … … 236 239 } 237 240 241 //writefln(time, " ", i); 242 238 243 // Update vertex positions based on joints. 239 244 Vec3f[] vertices = getAttribute("gl_Vertex").vec3f; 240 245 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 } 241 253 for (int v=0; v<vertices.length; v++) 242 254 { if (joint_indices[v] != -1) … … 246 258 vertices[v] = vertices_original[v].transform(cmatx); 247 259 260 261 if (normals.length) 262 normals[v] = normals_original[v].rotate(cmatx); 248 263 // TODO: Normals 249 264 // TODO: only reassign cmatx if joint_indices[v] has changed. … … 252 267 253 268 setAttribute("gl_Vertex", vertices); 254 269 if (normals.length) 270 setAttribute("gl_Normal", normals); 255 271 } 256 272 trunk/src/yage/resource/ms3dloader.d
r82 r83 217 217 normals.length = ms3d.vertices.length; 218 218 joint_indices.length= ms3d.vertices.length; 219 219 220 220 for (int v; v<ms3d.vertices.length; v++) 221 221 { vertices[v].x = ms3d.vertices[v].vertex[0]; … … 224 224 joint_indices[v] = ms3d.vertices[v].boneId; 225 225 } 226 227 226 228 227 229 // Meshes 228 230 meshes.length = ms3d.groups.length; 229 231 for (int m; m<meshes.length; m++) 230 { meshes[m] = new Mesh(); 232 { 233 234 meshes[m] = new Mesh(); 231 235 Vec3i[] triangles = meshes[m].getTriangles(); 232 236 triangles.length = ms3d.groups[m].numtriangles; … … 306 310 { 307 311 // 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; 309 313 vertices[length-1] = vertices[ms3d.triangles[tindex].vertexIndices[0]]; 310 314 memcpy(&normals[length-1], &ms3d.triangles[tindex].vertexNormals[0], 12); 311 315 texcoords[length-1].x = ms3d.triangles[tindex].s[0]; 312 316 texcoords[length-1].y = ms3d.triangles[tindex].t[0]; 317 joint_indices[length-1] = joint_indices[ms3d.triangles[tindex].vertexIndices[1]]; 313 318 // Assign this new vertex to the triangle 314 319 triangles[t].x = vertices.length-1; … … 320 325 { 321 326 // 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; 323 328 vertices[length-1] = vertices[ms3d.triangles[tindex].vertexIndices[1]]; 324 329 memcpy(&normals[length-1], &ms3d.triangles[tindex].vertexNormals[3], 12); 325 330 texcoords[length-1].x = ms3d.triangles[tindex].s[1]; 326 331 texcoords[length-1].y = ms3d.triangles[tindex].t[1]; 332 joint_indices[length-1] = joint_indices[ms3d.triangles[tindex].vertexIndices[1]]; 327 333 // Assign this new vertex to the triangle 328 334 triangles[t].y = vertices.length-1; … … 334 340 { 335 341 // 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; 337 343 vertices[length-1] = vertices[ms3d.triangles[tindex].vertexIndices[2]]; 338 344 memcpy(&normals[length-1], &ms3d.triangles[tindex].vertexNormals[6], 12); 339 345 texcoords[length-1].x = ms3d.triangles[tindex].s[2]; 340 346 texcoords[length-1].y = ms3d.triangles[tindex].t[2]; 347 joint_indices[length-1] = joint_indices[ms3d.triangles[tindex].vertexIndices[1]]; 341 348 // Assign this new vertex to the triangle 342 349 triangles[t].z = vertices.length-1; 343 350 } 344 351 } 345 352 346 353 // Find meshes with material of -1 (no material) and assign them the default material 347 354 if (ms3d.groups[m].materialIndex==-1) … … 376 383 } 377 384 } 385 386 378 387 379 388 // Link joint parent relationships. … … 414 423 // Inverse transform each vertex and inverse rotate each normal by the joint's Matrix. 415 424 for (int i; i<vertices.length; i++) 416 { if ( joint_indices[i] != -1 )425 { if (joint_indices[i] != -1 ) 417 426 { 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); 419 429 } } 420 430 trunk/src/yage/system/device.d
r81 r83 292 292 return cast(bool)shader; 293 293 case DEVICE_VBO: //return false; // true breaks custom vertex attributes 294 return false;295 294 if (vbo==-1) 296 295 vbo = checkExtension("GL_ARB_vertex_buffer_object"); trunk/src/yage/system/render.d
r82 r83 271 271 272 272 // Draw joints 273 if ( true)273 if (_debug) 274 274 { glDisable(GL_DEPTH_TEST); 275 275 glDisable(GL_LIGHTING);
