| 299 | |
| 300 | == Sestavljanje, meteriali, transformacije == |
| 301 | {{{ |
| 302 | #!html |
| 303 | <script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.min.js"></script> |
| 304 | <script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.touch.js"></script> |
| 305 | <script type="text/javascript"> |
| 306 | function onLoad2(){ |
| 307 | var canvas = document.getElementById('cv2'); |
| 308 | var viewer = new JSC3D.Viewer(canvas); |
| 309 | //viewer.setParameter('SceneUrl', '/vaje/raw-attachment/wiki/PythonOcc/elbow/pipe.stl'); |
| 310 | viewer.setParameter('BackgroundColor1', '#FFFFFF'); |
| 311 | viewer.setParameter('BackgroundColor2', '#383840'); |
| 312 | viewer.setParameter('InitRotationX', 30); |
| 313 | viewer.setParameter('InitRotationY', 30); |
| 314 | viewer.setParameter('InitRotationZ', 30); |
| 315 | |
| 316 | viewer.init(); |
| 317 | |
| 318 | var theScene = new JSC3D.Scene; |
| 319 | var totalParts = 2; |
| 320 | var numOfLoaded = 0; |
| 321 | var onPipeLoaded = function(scene) { |
| 322 | var meshes = scene.getChildren(); |
| 323 | for (var i=0; i<meshes.length; i++) { |
| 324 | material = new JSC3D.Material(); |
| 325 | material.diffuseColor = 0x3f3f7f; |
| 326 | meshes[i].setMaterial(material); |
| 327 | theScene.addChild(meshes[i]); |
| 328 | } |
| 329 | if (++numOfLoaded == totalParts) |
| 330 | viewer.replaceScene(theScene); |
| 331 | }; |
| 332 | |
| 333 | var onElbowLoaded = function(scene) { |
| 334 | var meshes = scene.getChildren(); |
| 335 | for (var i=0; i<meshes.length; i++) { |
| 336 | material = new JSC3D.Material(); |
| 337 | material.diffuseColor = 0xcaa618; |
| 338 | material.transparency = 0; |
| 339 | meshes[i].setMaterial(material); |
| 340 | theScene.addChild(meshes[i]); |
| 341 | |
| 342 | var xformMat = new JSC3D.Matrix3x4; |
| 343 | var rotMat = new JSC3D.Matrix3x4; |
| 344 | xformMat.identity(); |
| 345 | rotMat.identity(); |
| 346 | rotMat.rotateAboutZAxis(90); |
| 347 | xformMat.multiply(rotMat); |
| 348 | xformMat.translate(500, 0, 0); |
| 349 | |
| 350 | myMesh = new JSC3D.Mesh(); |
| 351 | myMesh.vertexBuffer = new Array( meshes[i].vertexBuffer.length); |
| 352 | myMesh.faceNormalBuffer = new Array( meshes[i].faceNormalBuffer.length); |
| 353 | myMesh.indexBuffer = meshes[i].indexBuffer; |
| 354 | // transform and rewrite vertex coordinates |
| 355 | JSC3D.Math3D.transformVectors(xformMat, meshes[i].vertexBuffer, myMesh.vertexBuffer); |
| 356 | // transform and rewrite face normals |
| 357 | JSC3D.Math3D.transformVectors(rotMat, meshes[i].faceNormalBuffer, myMesh.faceNormalBuffer); |
| 358 | myMesh.setMaterial(material); |
| 359 | myMesh.init(); |
| 360 | theScene.addChild(myMesh); |
| 361 | } |
| 362 | if (++numOfLoaded == totalParts) |
| 363 | viewer.replaceScene(theScene); |
| 364 | }; |
| 365 | |
| 366 | |
| 367 | var pipe_loader = new JSC3D.StlLoader; |
| 368 | pipe_loader.onload = onPipeLoaded; |
| 369 | pipe_loader.loadFromUrl('/vaje/raw-attachment/wiki/PythonOcc/elbow/pipe.stl'); |
| 370 | var elbow_loader = new JSC3D.StlLoader; |
| 371 | elbow_loader.onload = onElbowLoaded; |
| 372 | elbow_loader.loadFromUrl('/vaje/raw-attachment/wiki/PythonOcc/elbow/elbow.stl'); |
| 373 | |
| 374 | viewer.update(); |
| 375 | } |
| 376 | window.onload = window.onresize = function() {onLoad(); onLoad2();} |
| 377 | </script> |
| 378 | <canvas id="cv2" width="600" height="400" |
| 379 | style="background:lightgrey; border: 1px solid; float:right;" ></canvas> |
| 380 | }}} |