| 313 | {{{ |
| 314 | #!html |
| 315 | <script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.min.js"></script> |
| 316 | <script type="text/javascript"> |
| 317 | function copy_mesh(mesh, scene, rotx, roty, rotz, transx, transy, transz) |
| 318 | { |
| 319 | var xformMat = new JSC3D.Matrix3x4; |
| 320 | var rotMat = new JSC3D.Matrix3x4; |
| 321 | xformMat.identity(); |
| 322 | rotMat.identity(); |
| 323 | rotMat.rotateAboutXAxis(rotx); |
| 324 | rotMat.rotateAboutYAxis(roty); |
| 325 | rotMat.rotateAboutZAxis(rotz); |
| 326 | xformMat.multiply(rotMat); |
| 327 | xformMat.translate(transx, transy, transz); |
| 328 | |
| 329 | myMesh = new JSC3D.Mesh(); |
| 330 | myMesh.vertexBuffer = new Array( mesh.vertexBuffer.length); |
| 331 | myMesh.faceNormalBuffer = new Array( mesh.faceNormalBuffer.length); |
| 332 | myMesh.indexBuffer = mesh.indexBuffer; |
| 333 | // transform and rewrite vertex coordinates |
| 334 | JSC3D.Math3D.transformVectors(xformMat, mesh.vertexBuffer, myMesh.vertexBuffer); |
| 335 | // transform and rewrite face normals |
| 336 | JSC3D.Math3D.transformVectors(rotMat, mesh.faceNormalBuffer, myMesh.faceNormalBuffer); |
| 337 | myMesh.setMaterial(mesh.material); |
| 338 | myMesh.init(); |
| 339 | scene.addChild(myMesh); |
| 340 | } |
| 341 | |
| 342 | function onLoad2(){ |
| 343 | var canvas = document.getElementById('cv2'); |
| 344 | canvas.width = 0.9*window.innerWidth; |
| 345 | canvas.height = canvas.width/1.6; |
| 346 | var viewer = new JSC3D.Viewer(canvas); |
| 347 | //viewer.setParameter('SceneUrl', '/vaje/raw-attachment/wiki/PythonOcc/elbow/pipe.stl'); |
| 348 | viewer.setParameter('BackgroundColor1', '#FFFFFF'); |
| 349 | viewer.setParameter('BackgroundColor2', '#383840'); |
| 350 | viewer.setParameter('InitRotationX', 30); |
| 351 | viewer.setParameter('InitRotationY', 30); |
| 352 | viewer.setParameter('InitRotationZ', 30); |
| 353 | viewer.init(); |
| 354 | |
| 355 | var theScene = new JSC3D.Scene; |
| 356 | var totalParts = 2; |
| 357 | var numOfLoaded = 0; |
| 358 | |
| 359 | var onPipeLoaded = function(scene) { |
| 360 | var meshes = scene.getChildren(); |
| 361 | for (var i=0; i<meshes.length; i++) { |
| 362 | material = new JSC3D.Material(); |
| 363 | material.diffuseColor = 0x3f3f7f; |
| 364 | meshes[i].setMaterial(material); |
| 365 | theScene.addChild(meshes[i]); |
| 366 | } |
| 367 | if (++numOfLoaded == totalParts) |
| 368 | viewer.replaceScene(theScene); |
| 369 | }; |
| 370 | |
| 371 | var onElbowLoaded = function(scene) { |
| 372 | var meshes = scene.getChildren(); |
| 373 | for (var i=0; i<meshes.length; i++) { |
| 374 | material = new JSC3D.Material(); |
| 375 | material.diffuseColor = 0x0ab610; |
| 376 | material.transparency = 0.4; |
| 377 | meshes[i].setMaterial(material); |
| 378 | theScene.addChild(meshes[i]); |
| 379 | |
| 380 | copy_mesh(meshes[i], theScene, 0, 0, 90, 500, 0, 0); |
| 381 | copy_mesh(meshes[i], theScene, 0, 0, 180, 500, 500, 0); |
| 382 | copy_mesh(meshes[i], theScene, 0, 0, -90, 0, 500, 0); |
| 383 | } |
| 384 | if (++numOfLoaded == totalParts) |
| 385 | viewer.replaceScene(theScene); |
| 386 | }; |
| 387 | |
| 388 | |
| 389 | var pipe_loader = new JSC3D.StlLoader; |
| 390 | pipe_loader.onload = onPipeLoaded; |
| 391 | pipe_loader.loadFromUrl('/vaje/raw-attachment/wiki/PythonOcc/elbow/pipe.stl'); |
| 392 | var elbow_loader = new JSC3D.StlLoader; |
| 393 | elbow_loader.onload = onElbowLoaded; |
| 394 | elbow_loader.loadFromUrl('/vaje/raw-attachment/wiki/PythonOcc/elbow/elbow.stl'); |
| 395 | |
| 396 | viewer.update(); |
| 397 | } |
| 398 | window.onload = window.onresize = function() {onLoad(); onLoad2();} |
| 399 | </script> |
| 400 | <canvas id="cv2" width="600" height="400" |
| 401 | style="background:lightgrey; border: 1px solid; float:center;" ></canvas> |
| 402 | }}} |
| 403 | {{{ |
| 404 | #!javascript |
396 | | {{{ |
397 | | #!html |
398 | | <script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.min.js"></script> |
399 | | <script type="text/javascript"> |
400 | | function onLoad2(){ |
401 | | var canvas = document.getElementById('cv2'); |
402 | | canvas.width = 0.9*window.innerWidth; |
403 | | canvas.height = canvas.width/1.6; |
404 | | var viewer = new JSC3D.Viewer(canvas); |
405 | | //viewer.setParameter('SceneUrl', '/vaje/raw-attachment/wiki/PythonOcc/elbow/pipe.stl'); |
406 | | viewer.setParameter('BackgroundColor1', '#FFFFFF'); |
407 | | viewer.setParameter('BackgroundColor2', '#383840'); |
408 | | viewer.setParameter('InitRotationX', 30); |
409 | | viewer.setParameter('InitRotationY', 30); |
410 | | viewer.setParameter('InitRotationZ', 30); |
411 | | viewer.init(); |
412 | | |
413 | | var theScene = new JSC3D.Scene; |
414 | | var totalParts = 2; |
415 | | var numOfLoaded = 0; |
416 | | |
417 | | var onPipeLoaded = function(scene) { |
418 | | var meshes = scene.getChildren(); |
419 | | for (var i=0; i<meshes.length; i++) { |
420 | | material = new JSC3D.Material(); |
421 | | material.diffuseColor = 0x3f3f7f; |
422 | | meshes[i].setMaterial(material); |
423 | | theScene.addChild(meshes[i]); |
424 | | } |
425 | | if (++numOfLoaded == totalParts) |
426 | | viewer.replaceScene(theScene); |
427 | | }; |
428 | | |
429 | | var onElbowLoaded = function(scene) { |
430 | | var meshes = scene.getChildren(); |
431 | | for (var i=0; i<meshes.length; i++) { |
432 | | material = new JSC3D.Material(); |
433 | | material.diffuseColor = 0x0ab610; |
434 | | material.transparency = 0.4; |
435 | | meshes[i].setMaterial(material); |
436 | | theScene.addChild(meshes[i]); |
437 | | |
| 493 | function copy_mesh(mesh, scene, rotx, roty, rotz, transx, transy, transz) |
| 494 | { |
456 | | theScene.addChild(myMesh); |
457 | | } |
458 | | if (++numOfLoaded == totalParts) |
459 | | viewer.replaceScene(theScene); |
460 | | }; |
461 | | |
462 | | |
463 | | var pipe_loader = new JSC3D.StlLoader; |
464 | | pipe_loader.onload = onPipeLoaded; |
465 | | pipe_loader.loadFromUrl('/vaje/raw-attachment/wiki/PythonOcc/elbow/pipe.stl'); |
466 | | var elbow_loader = new JSC3D.StlLoader; |
467 | | elbow_loader.onload = onElbowLoaded; |
468 | | elbow_loader.loadFromUrl('/vaje/raw-attachment/wiki/PythonOcc/elbow/elbow.stl'); |
469 | | |
470 | | viewer.update(); |
471 | | } |
472 | | window.onload = window.onresize = function() {onLoad(); onLoad2();} |
473 | | </script> |
474 | | <canvas id="cv2" width="600" height="400" |
475 | | style="background:lightgrey; border: 1px solid; float:center;" ></canvas> |
476 | | }}} |
477 | | }}} |
478 | | |
479 | | V primeru dodatnih kosov je potrebno ponastaviti transformacijo in narediti |
480 | | novo mrežo, kot je to prikazano v naslednjem delčku kode. |
| 515 | scene.addChild(myMesh); |
| 516 | } |
| 517 | }}} |
| 518 | Le to potem uporabimo v funkciji ob naložitvi kosa kot |
483 | | |
484 | | xformMat.identity(); |
485 | | rotMat.identity(); |
486 | | rotMat.rotateAboutZAxis(180); |
487 | | xformMat.multiply(rotMat); |
488 | | xformMat.translate(500, 500, 0); |
489 | | myMesh = new JSC3D.Mesh(); |
490 | | myMesh.vertexBuffer = new Array( meshes[i].vertexBuffer.length); |
491 | | myMesh.faceNormalBuffer = new Array( meshes[i].faceNormalBuffer.length); |
492 | | myMesh.indexBuffer = meshes[i].indexBuffer; |
493 | | |
494 | | // transform and rewrite vertex coordinates |
495 | | JSC3D.Math3D.transformVectors(xformMat, meshes[i].vertexBuffer, myMesh.vertexBuffer); |
496 | | // transform and rewrite face normals |
497 | | JSC3D.Math3D.transformVectors(rotMat, meshes[i].faceNormalBuffer, myMesh.faceNormalBuffer); |
498 | | myMesh.setMaterial(material); |
499 | | myMesh.init(); |
500 | | theScene.addChild(myMesh); |
501 | | }}} |
| 521 | copy_mesh(meshes[i], theScene, 0, 0, 90, 500, 0, 0); |
| 522 | copy_mesh(meshes[i], theScene, 0, 0, 180, 500, 500, 0); |
| 523 | copy_mesh(meshes[i], theScene, 0, 0, -90, 0, 500, 0); |
| 524 | }}} |