Changes between Version 26 and Version 27 of PythonOcc/elbow


Ignore:
Timestamp:
Dec 10, 2013, 3:23:25 AM (6 years ago)
Author:
Leon Kos
Comment:

Opeis nalaganja sestava

Legend:

Unmodified
Added
Removed
Modified
  • PythonOcc/elbow

    v26 v27  
    297297
    298298== Sestavljanje, materiali, transformacije ==
     299
     300V formatu STL ni možno nastavljati barve. Če želimo posameznim delom nastaviti barvo
     301lahko to storimo tako, da naložimo vsak kos posebej in mu nastavimo material.
     302Če sestavavljamo modele z uporabo več enakih kosov je ugodno, da naložimo le
     303osnovne dele, ki jih potem kopiramo in prestavljamo po prostoru in tako sestavimo
     304celoten sestav. Nalaganje posameznih modelov je asinhrono, kar pomeni da se hkrati
     305nalagajo in ni zagotovljen vrstni red. S takim načinom prenašanja modelov do
     306brskalnika se čas do prvega prikaza sestava skrajša. Je pa zaradi tega potrebno
     307nekoliko več programiranja transformacij in kopiranje položajev točk. Zmanjša
     308se tudi poraba pomnilnika v brskalniku, kar omogoča hitrejše obračanje sestava.
     309
     310[http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/index.html Dokumentacija objektov SJC3D]
     311nam je lahko v pomoč pri programiranju v JavaScriptu.
     312
    299313{{{
    300314#!html
     
    380394{{{
    381395#!javascript
    382 
    383 }}}
     396{{{
     397#!html
     398<script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.min.js"></script>
     399<script type="text/javascript">
     400function 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
     438        var xformMat = new JSC3D.Matrix3x4;
     439        var rotMat = new JSC3D.Matrix3x4;
     440        xformMat.identity();
     441        rotMat.identity();
     442        rotMat.rotateAboutZAxis(90);
     443        xformMat.multiply(rotMat);
     444        xformMat.translate(500, 0, 0);
     445
     446        myMesh = new JSC3D.Mesh();
     447        myMesh.vertexBuffer = new Array( meshes[i].vertexBuffer.length);
     448        myMesh.faceNormalBuffer = new Array( meshes[i].faceNormalBuffer.length);
     449        myMesh.indexBuffer = meshes[i].indexBuffer;
     450        // transform and rewrite vertex coordinates
     451        JSC3D.Math3D.transformVectors(xformMat, meshes[i].vertexBuffer, myMesh.vertexBuffer);
     452        // transform and rewrite face normals
     453        JSC3D.Math3D.transformVectors(rotMat, meshes[i].faceNormalBuffer, myMesh.faceNormalBuffer);
     454        myMesh.setMaterial(material);
     455        myMesh.init();
     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}     
     472window.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}}}