1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| var updateBox = function ($input) {
var rangeSizeArray = ['rangeSizeX', 'rangeSizeY', 'rangeSizeZ'] var var_type = $input.id; if (var_type==='rangeCenterX') { centerX = Number($input.value); $("#CenterX").val($input.value); }else if (var_type==='rangeCenterY') { centerY = Number($input.value); $("#CenterY").val($input.value); }else if (var_type==='rangeCenterZ') { centerZ = Number($input.value); $("#CenterZ").val($input.value); }else if (rangeSizeArray.indexOf(var_type) !== -1) { var axisX = new $3Dmol.Vector3(1,0,0); var xDegree = Number($("#RotateX").val()); var radianX = (Math.PI * xDegree) / 180;
var axisY = new $3Dmol.Vector3(0,1,0); var yDegree = Number($("#RotateY").val()); var radianY = (Math.PI * yDegree) / 180;
var axisZ = new $3Dmol.Vector3(0,0,1); var zDegree = Number($("#RotateZ").val()); var radianZ = (Math.PI * zDegree) / 180;
if (var_type==='rangeSizeX' ) { var sizeW = Number($input.value); var vecW = new $3Dmol.Vector3(sizeW,0,0); vecW.rotateAboutVector(axisX,radianX); vecW.rotateAboutVector(axisY,radianY); vecW.rotateAboutVector(axisZ,radianZ);
sizeWx = vecW.x; sizeWy = vecW.y; sizeWz = vecW.z;
sizeWx0 = sizeW; $("#SizeX").val($input.value); } else if (var_type==='rangeSizeY') { var sizeH = Number($input.value); var vecH = new $3Dmol.Vector3(0,sizeH,0); vecH.rotateAboutVector(axisX,radianX); vecH.rotateAboutVector(axisY,radianY); vecH.rotateAboutVector(axisZ,radianZ);
sizeHx = vecH.x; sizeHy = vecH.y; sizeHz = vecH.z;
sizeHy0 = sizeH; $("#SizeY").val($input.value); } else if (var_type==='rangeSizeZ') { var sizeD = Number($input.value); var vecD = new $3Dmol.Vector3(0,0,sizeD); vecD.rotateAboutVector(axisX,radianX); vecD.rotateAboutVector(axisY,radianY); vecD.rotateAboutVector(axisZ,radianZ);
sizeDx = vecD.x; sizeDy = vecD.y; sizeDz = vecD.z;
sizeDz0 = sizeD; $("#SizeZ").val($input.value); } }else{ vecW = new $3Dmol.Vector3(sizeWx0,sizeWy0,sizeWz0); vecH = new $3Dmol.Vector3(sizeHx0,sizeHy0,sizeHz0); vecD = new $3Dmol.Vector3(sizeDx0,sizeDy0,sizeDz0);
if (var_type==='rangeRotateX'){ var xDegree = Number($input.value); var yDegree = Number($("#RotateY").val()); var zDegree = Number($("#RotateZ").val()); var radianX = (Math.PI * xDegree) / 180; var radianY = (Math.PI * yDegree) / 180; var radianZ = (Math.PI * zDegree) / 180; $("#RotateX").val($input.value); }else if (var_type==='rangeRotateY') { var xDegree = Number($("#RotateX").val()); var yDegree = Number($input.value); var zDegree = Number($("#RotateZ").val()); var radianX = (Math.PI * xDegree) / 180; var radianY = (Math.PI * yDegree) / 180; var radianZ = (Math.PI * zDegree) / 180; $("#RotateY").val($input.value); }else if (var_type==='rangeRotateZ') { var xDegree = Number($("#RotateX").val()); var yDegree = Number($("#RotateY").val()); var zDegree = Number($input.value); var radianX = (Math.PI * xDegree) / 180; var radianY = (Math.PI * yDegree) / 180; var radianZ = (Math.PI * zDegree) / 180; $("#RotateZ").val($input.value); }
var axisX = new $3Dmol.Vector3(1,0,0); var axisY = new $3Dmol.Vector3(0,1,0); var axisZ = new $3Dmol.Vector3(0,0,1);
vecW.rotateAboutVector(axisX,radianX); vecW.rotateAboutVector(axisY,radianY); vecW.rotateAboutVector(axisZ,radianZ);
vecH.rotateAboutVector(axisX,radianX); vecH.rotateAboutVector(axisY,radianY); vecH.rotateAboutVector(axisZ,radianZ);
vecD.rotateAboutVector(axisX,radianX); vecD.rotateAboutVector(axisY,radianY); vecD.rotateAboutVector(axisZ,radianZ);
sizeWx = vecW.x; sizeWy = vecW.y; sizeWz = vecW.z; sizeHx = vecH.x; sizeHy = vecH.y; sizeHz = vecH.z; sizeDx = vecD.x; sizeDy = vecD.y; sizeDz = vecD.z;
}
viewer.removeAllShapes(); viewer.addBox({center:{x:centerX,y:centerY,z:centerZ}, dimensions: {'w': {'x':sizeWx, 'y':sizeWy, 'z':sizeWz}, 'h': {'x':sizeHx, 'y':sizeHy, 'z':sizeHz}, 'd': {'x':sizeDx, 'y':sizeDy, 'z':sizeDz}}, color:'yellow', opacity: 0.8 });
viewer.addLine({color:'red',start:{x:centerX0,y:centerY0,z:centerZ0},end:{x:centerX0+25,y:centerY0,z:centerZ0}}); viewer.addLine({color:'blue',start:{x:centerX0,y:centerY0,z:centerZ0},end:{x:centerX0,y:centerY0+25,z:centerZ0}}); viewer.addLine({color:'green',start:{x:centerX0,y:centerY0,z:centerZ0},end:{x:centerX0,y:centerY0,z:centerZ0+25}});
viewer.render();
}
|