diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/media9/javascript')
-rw-r--r-- | Master/texmf-dist/tex/latex/media9/javascript/3Dmenu.js | 42 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/media9/javascript/asylabels.js | 91 |
2 files changed, 54 insertions, 79 deletions
diff --git a/Master/texmf-dist/tex/latex/media9/javascript/3Dmenu.js b/Master/texmf-dist/tex/latex/media9/javascript/3Dmenu.js index a987b5ed08c..20bf5a8a55a 100644 --- a/Master/texmf-dist/tex/latex/media9/javascript/3Dmenu.js +++ b/Master/texmf-dist/tex/latex/media9/javascript/3Dmenu.js @@ -4,7 +4,7 @@ // // 3Dmenu.js // -// version 20120813 +// version 20120912 // //////////////////////////////////////////////////////////////////////////////// // @@ -576,16 +576,14 @@ function get3Dview () { if(!defaultvals) res+=respart; } - //detect existing Clipping Plane (3DCrossSection) + //detect existing Clipping Plane (3D Cross Section) var clip=null; - try { - clip=scene.nodes.getByName("Clipping Plane"); - }catch(e){ - var ndcnt=scene.nodes.count; - clip=scene.createClippingPlane(); - if(ndcnt!=scene.nodes.count){ - clip.remove(); - clip=null; + for(i=0; i<scene.nodes.count; i++){ + if( + scene.nodes.getByIndex(i).name == '$$$$$$' || + scene.nodes.getByIndex(i).name == 'Clipping Plane' + ) { + clip=scene.nodes.getByIndex(i); } } if(clip){ @@ -642,21 +640,17 @@ runtime.addEventHandler(selectionEventHandler); cameraEventHandler=new CameraEventHandler(); cameraEventHandler.onEvent=function(e){ - //store current transformation matrices of all mesh nodes in the scene - var curtrans=getCurTrans(); - //detect existing clipping plane (cross section) - var ndcnt=scene.nodes.count; - var clip=scene.createClippingPlane(); - if(ndcnt!=scene.nodes.count){ - clip.remove(); - runtime.removeCustomMenuItem("csection"); - runtime.addCustomMenuItem("csection", "Cross Section", "checked", 0); - } else { - runtime.removeCustomMenuItem("csection"); - runtime.addCustomMenuItem("csection", "Cross Section", "checked", 1); + runtime.removeCustomMenuItem("csection"); + runtime.addCustomMenuItem("csection", "Cross Section", "checked", 0); + for(i=0; i<scene.nodes.count; i++){ + if( + scene.nodes.getByIndex(i).name == '$$$$$$' || + scene.nodes.getByIndex(i).name == 'Clipping Plane' + ) { + runtime.removeCustomMenuItem("csection"); + runtime.addCustomMenuItem("csection", "Cross Section", "checked", 1); + } } - //restore previous position of mesh nodes - restoreTrans(curtrans); } runtime.addEventHandler(cameraEventHandler); diff --git a/Master/texmf-dist/tex/latex/media9/javascript/asylabels.js b/Master/texmf-dist/tex/latex/media9/javascript/asylabels.js index a2455d7470c..505674a7438 100644 --- a/Master/texmf-dist/tex/latex/media9/javascript/asylabels.js +++ b/Master/texmf-dist/tex/latex/media9/javascript/asylabels.js @@ -1,19 +1,18 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2012, Alexander Grahn +// (C) 2012, Michail Vidiassov, John C. Bowman, Alexander Grahn // // asylabels.js // -// version 20120301 +// version 20120912 // //////////////////////////////////////////////////////////////////////////////// // // 3D JavaScript to be used with media9.sty (option `add3Djscript') for // Asymptote generated PRC files // -// adds billboard behaviour to text labels in Asymptote PRC files for improved -// visibility, they always face the camera while dragging the 3d object with the -// mouse. +// adds billboard behaviour to text labels in Asymptote PRC files so that +// they always face the camera under 3D rotation. // // // This work may be distributed and/or modified under the @@ -30,75 +29,57 @@ // //////////////////////////////////////////////////////////////////////////////// -//recursive function which computes the lower left BBox corner of a text -//label; it marches through all sibling mesh nodes the label is composed of; -//the returned Vector3 object will become the pivot point of the label -function nextCenter(msh){ - //compute local-to-world transf. matrix of current mesh node - var trans=new Matrix4x4(msh.transform); - var parent=msh.parent; - while(parent.transform){ - trans.multiplyInPlace(parent.transform); - parent=parent.parent; - } - - //min BBox corner of current mesh node - var min=new Vector3(); - min.set(msh.computeBoundingBox().min); - min.set(trans.transformPosition(min)); +var bbnodes=new Array(); // billboard meshes +var bbtrans=new Array(); // billboard transforms - //get min BBox corner - if(msh.nextSibling){ - var nextmin=nextCenter(msh.nextSibling); - return(min.length < nextmin.length ? min : nextmin); - }else{ - return(min); - } -} +function fulltransform(mesh) +{ + var t=new Matrix4x4(mesh.transform); + if(mesh.parent.name != "") { + var parentTransform=fulltransform(mesh.parent); + t.multiplyInPlace(parentTransform); + return t; + } else + return t; +} -//find all text labels in the scene and determine pivoting points -var zero=new Vector3(0,0,0); +// find all text labels in the scene and determine pivoting points var nodes=scene.nodes; -var center=new Array(); -var index=new Array(); -for(var i=0; i<nodes.count; i++){ +var nodescount=nodes.count; +var third=1.0/3.0; +for(var i=0; i < nodescount; i++) { var node=nodes.getByIndex(i); var name=node.name; var end=name.lastIndexOf(".")-1; - if(end > 0){ - if(name.charAt(end) == "\001"){ + if(end > 0) { + if(name.charAt(end) == "\001") { var start=name.lastIndexOf("-")+1; - if(end-start > 0) { - index.push(i); - center.push(nextCenter(node.firstChild)); + if(end > start) { node.name=name.substr(0,start-1); + var nodeMatrix=fulltransform(node.parent); + var c=nodeMatrix.translation; // position + var d=Math.pow(Math.abs(nodeMatrix.determinant),third); // scale + bbnodes.push(node); + bbtrans.push(Matrix4x4().scale(d,d,d).translate(c).multiply(nodeMatrix.inverse)); } } } } var camera=scene.cameras.getByIndex(0); +var zero=new Vector3(0,0,0); +var bbcount=bbnodes.length; -//event handler to maintain upright position of text labels +// event handler to maintain camera-facing text labels billboardHandler=new RenderEventHandler(); billboardHandler.onEvent=function(event) { - var position=camera.position; - var direction=position.subtract(camera.targetPosition); - var up=camera.up.subtract(position); - - for(var i=0; i<index.length; i++){ - var node=nodes.getByIndex(index[i]); - var R=Matrix4x4(); - R.setView(zero,direction,up); - var c=center[i]; - var T=node.transform; - T.setIdentity(); - T.translateInPlace(c.scale(-1)); - T.multiplyInPlace(R); - T.translateInPlace(c); - } + var T=new Matrix4x4(); + T.setView(zero,camera.position.subtract(camera.targetPosition), + camera.up.subtract(camera.position)); + for(var j=0; j < bbcount; j++) + bbnodes[j].transform.set(T.multiply(bbtrans[j])); runtime.refresh(); } runtime.addEventHandler(billboardHandler); |