123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815 |
- function Action3D(layer3D){
-
- this.scene = layer3D.scene3D.scene;
- this.ground = layer3D.scene3D.ground;
- this.camera = layer3D.scene3D.camera;
- this.canvas = layer3D.scene3D.canvas;
-
- this.layer=layer3D.layer;
- this.parameter=layer3D.layer.parameter;
- this.calculateLine=layer3D.layer.calculateLine;
- this.materials=layer3D.materials;
-
- this.layer3D=layer3D;
- //编辑模型的时候,出现的绿色的面
- //this.selectmat=null;
-
- this.vertexPoints=[];
- //选择的当前mesh
- this.currentSelectMesh=null;
- //当前操作都作用于model的mesh
- this.currentModelMesh=null;
-
- //选择模型时,显示的circle
- this.selectCircleMesh=null;
- //选择模型时,rotator
- this.selectRotatorMesh=null;
- //选择模型时,出现的sprite
- this.currentInfoMesh=null;
- this.sprite=null;
- //是否有arrow
- this.isArrow=false;
-
- //拖拽
- this.drags = {
- //拖拽的面,用来编辑模型
- planeMesh:null,
- //拖拽的面的初始位置
- planeStartPosition:null,
- //点击模型的时候,与地面的交点的位置
- modelStartPosition:null,
- //移动模型的时候,鼠标与地面的交点的位置
- moveModelPosition:null,
- //鼠标与箭头相交的位置
- arrowIntersectPosition:null
- };
-
- this.collidableMeshes=layer3D.collectMeshes.collidableMeshes;
- this.arrowMeshes=layer3D.collectMeshes.arrowMeshes;
-
- //刷墙
- this.paintSet=[];
- //锁住canvas
- this.lock=false;
-
- //判断其name的值
- //this.noModelMeshName = ["wallplane","skyBox","ground","floorPlane","wall","door","window","selectCircle","rotator"];
- this.noModelMeshName = ["wallplane","skyBox","walltop","ground","door","window"];
- this.noCareMeshName = ["wallplane","skyBox","walltop"];
-
- this.arrows={
- orgtopPosition:null,
- orgdownPosition:null,
- orgleftPosition:null,
- orgrightPosition:null,
- topMesh:null,
- downMesh:null,
- leftMesh:null,
- rightMesh:null,
- activeMesh:null,
- orgactivePosition:null,
- sideDistance:null,
- lineTopToDown:null,
- lineLeftToRight:null
- };
-
- this.measures={
- textMesh:null,
- endpointMesh1:null,
- endpointMesh2:null,
- arrowMesh1:null,
- arrowMesh2:null,
- linkMesh:null
- };
-
- this.measures.textMesh=null;
-
- this.control = {
- editProduct:false,
- addPhoto:false,
- addPicture:false,
- //是否旋转模型
- actionRotator:false
- };
- };
- //用来编辑模型的大小
- Action3D.prototype.createSelectMat=function()
- {
- var mat=new BABYLON.StandardMaterial("selectMat", this.scene);
- mat.alpha = 1.0;
- mat.diffuseColor = new BABYLON.Color3.Green();
- mat.backFaceCulling = false;
- return mat;
- };
- //从模型数组中移除某个模型
- Action3D.prototype.removeMesh = function(meshes,elem) {
- for (var i=meshes.length-1; i>=0; i--) {
- if (meshes[i] === elem) {
- meshes.splice(i, 1);
- }
- }
- return meshes;
- };
- Action3D.prototype.getAngleFromWallPlane=function(mesh)
- {
- var points = mesh._boundingInfo.boundingBox.vectorsWorld;
- var point1 = points[0];
- var point2=null;
- if(points[1].y == point1.y)
- {
- point2 = points[1];
- }
- else
- {
- point2 = points[2];
- }
-
- var line = this.layer.calculateLine.createLine(new BABYLON.Vector2(point1.x.toFixed(2),point1.z.toFixed(2)),new BABYLON.Vector2(point2.x.toFixed(2),point2.z.toFixed(2)));
- if(line.hasOwnProperty('x'))
- {
- return Math.PI/2;
- }
- else if(line.hasOwnProperty('y'))
- {
- return 0;
- }
- else
- {
- return line.a%(2*Math.PI);
- }
- };
- //移除选择的模型
- Action3D.prototype.removeSelectMesh=function()
- //Action3D.prototype.clearMesh=function(meshes,elem)
- {
- this.clearArrow();
- this.closeConfigProduct();
- this.currentSelectMesh = null;
- this.currentModelMesh = null;
- this.drags.modelStartPosition = null;
- };
- //通过鼠标移动模型或者移动arrow,将位置和模型的长宽赋值给弹出窗口
- Action3D.prototype.setProductInfo=function()
- {
- var position=null;
- if(this.currentModelMesh==null)
- {
- return;
- }
- else{
- position = this.currentModelMesh.position;
- }
-
- var position_x=document.getElementById("position-x");
- var position_y=document.getElementById("position-y");
- var position_z=document.getElementById("position-z");
- position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
- position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
- position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
-
- var params_width=document.getElementById("params-width");
- var params_length=document.getElementById("params-length");
-
- if(this.currentModelMesh.name=="photo")
- {
- params_width.childNodes[1].childNodes[0].value=Math.floor(this.currentModelMesh.height);
- params_width.childNodes[1].childNodes[0].alt=Math.floor(this.currentModelMesh.height);
- params_length.childNodes[1].childNodes[0].value=Math.floor(this.currentModelMesh.length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(this.currentModelMesh.length);
- }
- else
- {
- var width=Math.abs(this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.z-this.currentModelMesh._boundingInfo.boundingBox.minimumWorld.z);
- var length=Math.abs(this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.x-this.currentModelMesh._boundingInfo.boundingBox.minimumWorld.x);
-
- params_width.childNodes[1].childNodes[0].value=Math.floor(width);
- params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
- params_length.childNodes[1].childNodes[0].value=Math.floor(length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
- }
-
- };
- //给编辑框里赋值
- Action3D.prototype.editProductInfo=function(h,position)
- {
- var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(this.arrows.orgdownPosition.x,this.arrows.orgdownPosition.z),new BABYLON.Vector2(this.arrows.orgtopPosition.x,this.arrows.orgtopPosition.z));
- var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(this.arrows.orgrightPosition.x,this.arrows.orgrightPosition.z),new BABYLON.Vector2(this.arrows.orgleftPosition.x,this.arrows.orgleftPosition.z));
- var height=h;
-
- var positionX=position.x;
- var positionY=position.y;
- var positionZ=position.z;
- //var angleY=Math.floor((this.currentModelMesh.angle/Math.PI)*180);
- var angleY=Math.floor((this.currentSelectMesh.angle/Math.PI)*180);
-
- var rotationy=document.getElementById("rotation-y");
- if(angleY<0)
- {
- angleY=360+angleY;
- }
- else if(angleY>360)
- {
- angleY=angleY-360;
- }
- rotationy.childNodes[1].childNodes[0].value=angleY;
- rotationy.childNodes[1].childNodes[1].value=angleY;
- var position_x=document.getElementById("position-x");
- position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
-
- var position_y=document.getElementById("position-y");
- position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
-
- var position_z=document.getElementById("position-z");
- position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
-
- var params_width=document.getElementById("params-width");
- params_width.childNodes[1].childNodes[0].value=Math.floor(width);
- params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
-
- var params_length=document.getElementById("params-length");
- params_length.childNodes[1].childNodes[0].value=Math.floor(length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
-
- var params_height=document.getElementById("params-height");
- params_height.childNodes[1].childNodes[0].value=Math.floor(height);
- params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
- };
- //获取模型的boundingbox上方的四个顶点
- Action3D.prototype.setVertex=function(points,min,max)
- {
- var y=points[0].y;
- var y1=points[1].y;
- for(var i=0;i<points.length;++i)
- {
- if(y.toFixed(2)==points[i].y.toFixed(2)||Math.abs(points[i].y-y)<Math.abs(points[i].y-y1))
- {
- if(points[i].x==min.x&&points[i].z==min.z)
- {
- this.vertexPoints[0]=i;
- }
- else if(points[i].x==max.x&&points[i].z==max.z)
- {
- this.vertexPoints[2]=i;
- }
- else if(points[i].x==min.x&&points[i].z==max.z)
- {
- this.vertexPoints[1]=i;
- }
- else if(points[i].x==max.x&&points[i].z==min.z)
- {
- this.vertexPoints[3]=i;
- }
- else if(Math.abs(points[i].x-min.x)<Math.abs(points[i].x-max.x)&&Math.abs(points[i].z-min.z)<Math.abs(points[i].z-max.z))
- {
- this.vertexPoints[0]=i;
- }
- else if(Math.abs(points[i].x-max.x)<Math.abs(points[i].x-min.x)&&Math.abs(points[i].z-max.z)<Math.abs(points[i].z-min.z))
- {
- this.vertexPoints[2]=i;
- }
- else if(Math.abs(points[i].x-min.x)<Math.abs(points[i].x-max.x)&&Math.abs(points[i].z-max.z)<Math.abs(points[i].z-min.z))
- {
- this.vertexPoints[1]=i;
- }
- else if(Math.abs(points[i].x-max.x)<Math.abs(points[i].x-min.x)&&Math.abs(points[i].z-min.z)<Math.abs(points[i].z-max.z))
- {
- this.vertexPoints[3]=i;
- }
- }
- }
- };
- //选模型时显示的圈圈
- Action3D.prototype.createRotator=function()
- {
- var rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, this.scene);
- rotator.scaling.x=this.parameter.selectRotator.scalingX;
- rotator.scaling.y=this.parameter.selectRotator.scalingY;
- rotator.material=this.materials.selectRotatorMaterial;
- return rotator;
- };
- //墙除外,因为可能刷墙或者添加软饰
- Action3D.prototype.isnotModel=function (mesh)
- {
- if (mesh.name == null) {
- return false;
- }
-
- for(var i=0;i<this.noModelMeshName.length;++i)
- {
- if(this.noModelMeshName[i]==mesh.name)
- {
- return true;
- }
- }
- return false;
- };
- Action3D.prototype.isnocareMesh=function (mesh)
- {
- if (mesh.name == null) {
- return false;
- }
-
- for(var i=0;i<this.noCareMeshName.length;++i)
- {
- if(this.noCareMeshName[i]==mesh.name)
- {
- return true;
- }
- }
- return false;
- };
- //获取鼠标指向的墙
- //主要用于软饰
- Action3D.prototype.getWallPlanePosition = function () {
- // Use a predicate to get position on the ground
- var pickinfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
- return mesh.name == this.noModelMeshName[0];
- }.bind(this));
- if (pickinfo.hit) {
- //return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
- return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
- }
- return null;
- };
- //获取鼠标指向的地面
- Action3D.prototype.getGroundPosition = function () {
- // Use a predicate to get position on the ground
- var pickinfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
- //return ( mesh == ground &&this.isnotModel(mesh));
- return ( mesh.name == "ground");
- }.bind(this));
- if (pickinfo.hit) {
- return pickinfo.pickedPoint;
- }
- return null;
- };
- //获取鼠标指向的arrow
- Action3D.prototype.getGroundPositionFromArrow = function () {
- // Use a predicate to get position on the ground
- var pickinfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
- return mesh.id.indexOf("arrow")>-1;
- });
- if (pickinfo.hit) {
- return pickinfo.pickedPoint;
- }
- return null;
- };
- Action3D.prototype.getDiff2=function(current,line)
- {
- var result=null;
- var interpoint=this.calculateLine.getJoinLinePoint({x:current.x,y:current.z},line);
- result=new BABYLON.Vector3(interpoint.x,current.y,interpoint.y);
- return result;
- };
- Action3D.prototype.setselectMesh=function()
- {
- var currentModelMesh = this.currentModelMesh;
- if(this.currentModelMesh==null)
- {
- return;
- }
- var shape = [
- new BABYLON.Vector3(this.parameter.selectCircle.downRadius, 0, 0),
- new BABYLON.Vector3(this.parameter.selectCircle.topRadius, this.parameter.selectCircle.topHeight, 0)
- ];
- var top=1;
- var radius= BABYLON.Vector2.Distance(new BABYLON.Vector2(currentModelMesh._boundingInfo.boundingBox.maximumWorld.x,currentModelMesh._boundingInfo.boundingBox.maximumWorld.z),new BABYLON.Vector2(currentModelMesh._boundingInfo.boundingBox.minimumWorld.x,currentModelMesh._boundingInfo.boundingBox.minimumWorld.z))/2;
- if(radius>(this.parameter.selectRotator.differRadius+1))
- {
- top=radius-this.parameter.selectRotator.differRadius;
- }
-
- //如果加载的模型是软饰,就不要圈圈,否则就得有圈圈
- if(this.selectCircleMesh==null)
- {
- if(currentModelMesh.name!="photo"&¤tModelMesh.name.indexOf("picture-")!=0)
- {
- this.selectCircleMesh = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, this.scene);
- this.selectCircleMesh.material = this.materials.selectMaterial;
-
- var positionY = currentModelMesh.position.y+5;
-
- this.selectCircleMesh.position=new BABYLON.Vector3(currentModelMesh._boundingInfo.boundingBox.center.x,positionY,currentModelMesh._boundingInfo.boundingBox.center.z);
- if(this.selectRotatorMesh==null)
- {
- this.selectRotatorMesh=this.createRotator();
- }
- this.selectRotatorMesh.position.z = -radius;
- this.selectRotatorMesh.position.y = 5;
- if(this.selectCircleMesh!=null)
- {
- this.selectRotatorMesh.parent = this.selectCircleMesh;
- }
- this.selectRotatorMesh.rotation.y = this.parameter.selectRotator.rotationY;
- this.selectRotatorMesh.rotation.x = this.parameter.selectRotator.rotationX;
-
- this.selectRotatorMesh.computeWorldMatrix(true);
- this.selectRotatorMesh.refreshBoundingInfo();
- }
- }
- else
- {
- if(currentModelMesh.name.indexOf("picture-")==0||currentModelMesh.name=="photo")
- {
- this.selectCircleMesh.dispose();
- this.selectCircleMesh=null;
-
- if(this.selectRotatorMesh!=null)
- {
- this.selectRotatorMesh.dispose();
- this.selectRotatorMesh=null;
- }
- }
- }
- if(!currentModelMesh.rotationQuaternion)
- {
- currentModelMesh.angle=0;
- }
- else
- {
- var angleY=currentModelMesh.rotation.y;
- if(angleY<0)
- {
- angleY=2*Math.PI+angleY;
- }
- else if(angleY>2*Math.PI)
- {
- angleY=angleY-2*Math.PI;
- }
- currentModelMesh.angle=angleY;
- }
- this.createinfo();
- };
- Action3D.prototype.switchCnofigureProduct = function (type)
- {
- //显示普通模型
- if(type==1)
- {
- document.getElementById("params-width").style.display="";
- document.getElementById("editptrot").style.display="";
- document.getElementById("rotation-y").style.display="";
- document.getElementById("item-2").style.display="";
- document.getElementById("item-1").style.display="";
- }
- //显示软饰
- else
- {
- document.getElementById("params-width").style.display="none";
- document.getElementById("editptrot").style.display="none";
- document.getElementById("rotation-y").style.display="none";
- document.getElementById("item-2").style.display="none";
- document.getElementById("item-1").style.display="none";
- }
- };
- //选择模型后,出现标记
- Action3D.prototype.createinfo=function()
- {
- var currentModelMesh=this.currentModelMesh;
- if(this.currentModelMesh==null)
- {
- return;
- }
- currentModelMesh.arrowHeigh=currentModelMesh._boundingInfo.boundingBox.maximumWorld.y/2;
-
- if(this.sprite!=null)
- {
- this.removeinfo();
- }
-
- this.sprite = new BABYLON.SpriteManager("meshManager", this.parameter.selectSprite.img, this.parameter.selectSprite.capacity, this.parameter.selectSprite.cellSize, this.scene);
- this.sprite.isPickable = true;
- // First animated player
- this.currentInfoMesh = new BABYLON.Sprite("editFurniture", this.sprite);
- this.currentInfoMesh.position= new BABYLON.Vector3(currentModelMesh.position.x, currentModelMesh._boundingInfo.boundingBox.maximumWorld.y+this.parameter.selectSprite.extendY, currentModelMesh.position.z);
- this.currentInfoMesh.size = this.parameter.selectSprite.size;
- this.currentInfoMesh.isPickable = true;
-
- // click action for player
- this.currentInfoMesh.actionManager = new BABYLON.ActionManager(this.scene);
- this.currentInfoMesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickUpTrigger, function () {
- currentModelMesh.computeWorldMatrix(true);
- currentModelMesh.refreshBoundingInfo();
-
- //弹出框,显示产品的大小,位置,角度等等
- var configuratorProduct=document.getElementById("configuratorWindow");
- configuratorProduct.style.display="block";
- //创造编辑产品的箭头
- this.createArrows(currentModelMesh,this.scene,this.parameter.arrow3DImgUrl);
-
- this.switchCnofigureProduct(1);
-
- this.currentInfoMesh.dispose();
- this.currentInfoMesh=null;
-
- if(this.selectCircleMesh!=null)
- {
- this.selectCircleMesh.dispose();
- this.selectCircleMesh=null;
- if(this.selectRotatorMesh!=null)
- {
- this.selectRotatorMesh.dispose();
- this.selectRotatorMesh=null;
- }
- }
-
- this.editProductInfo(Math.abs(currentModelMesh._boundingInfo.boundingBox.maximumWorld.y- currentModelMesh._boundingInfo.boundingBox.minimumWorld.y),currentModelMesh.position);
- }.bind(this)));
- };
- //选择箭头标记
- Action3D.prototype.selectArrow=function()
- {
- this.drags.planeMesh=BABYLON.Mesh.CreatePlane("temp", 1, this.scene);
-
- if(this.currentSelectMesh.name=="downarrow")
- {
- this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.x*this.currentModelMesh.scaling.x*2;
- this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
- this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle, BABYLON.Space.LOCAL);
- this.drags.planeMesh.position=this.arrows.orgdownPosition;
- //olddistance=BABYLON.Vector3.Distance(this.arrows.orgdownPosition,this.arrows.orgtopPosition);
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgleftPosition.x,this.arrows.orgleftPosition.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgrightPosition.x,this.arrows.orgrightPosition.z));
- if(distance1>distance2)
- {
- this.arrows.orgactivePosition=this.arrows.orgrightPosition;
- this.arrows.activeMesh=this.arrows.rightMesh;
- }
- else
- {
- this.arrows.orgactivePosition=this.arrows.orgleftPosition;
- this.arrows.activeMesh=this.arrows.leftMesh;
- }
-
- }
- else if(this.currentSelectMesh.name=="toparrow")
- {
- this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.x*this.currentModelMesh.scaling.x*2;
- this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
- this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle, BABYLON.Space.LOCAL);
- this.drags.planeMesh.position=this.arrows.orgtopPosition;
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgleftPosition.x,this.arrows.orgleftPosition.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgrightPosition.x,this.arrows.orgrightPosition.z));
- if(distance1>distance2)
- {
- this.arrows.orgactivePosition=this.arrows.orgrightPosition;
- this.arrows.activeMesh=this.arrows.rightMesh;
- }
- else
- {
- this.arrows.orgactivePosition=this.arrows.orgleftPosition;
- this.arrows.activeMesh=this.arrows.leftMesh;
- }
- }
- else if(this.currentSelectMesh.name=="leftarrow")
- {
- this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle+Math.PI/2, BABYLON.Space.LOCAL);
- this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.z*this.currentModelMesh.scaling.z*2;
- this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
-
- this.drags.planeMesh.position=this.arrows.orgleftPosition;
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgtopPosition.x,this.arrows.orgtopPosition.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgdownPosition.x,this.arrows.orgdownPosition.z));
- if(distance1>distance2)
- {
- this.arrows.orgactivePosition=this.arrows.orgdownPosition;
- this.arrows.activeMesh=this.arrows.downMesh;
- }
- else
- {
- this.arrows.orgactivePosition=this.arrows.orgtopPosition;
- this.arrows.activeMesh=this.arrows.topMesh;
- }
- }
- else if(this.currentSelectMesh.name=="rightarrow")
- {
- this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle+Math.PI/2, BABYLON.Space.LOCAL);
- this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.z*this.currentModelMesh.scaling.z*2;
- this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
-
- this.drags.planeMesh.position=this.arrows.orgrightPosition;
-
- var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgtopPosition.x,this.arrows.orgtopPosition.z));
- var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(this.camera.position.x,this.camera.position.z),new BABYLON.Vector2(this.arrows.orgdownPosition.x,this.arrows.orgdownPosition.z));
- if(distance1>distance2)
- {
- this.arrows.orgactivePosition=this.arrows.orgdownPosition;
- this.arrows.activeMesh=this.arrows.downMesh;
- }
- else
- {
- this.arrows.orgactivePosition=this.arrows.orgtopPosition;
- this.arrows.activeMesh=this.arrows.topMesh;
- }
- }
- this.arrows.sideDistance=this.arrows.activeMesh.position.subtract(this.currentModelMesh._boundingInfo.boundingBox.center);
- this.drags.planeMesh.material=this.materials.selectMaterial;
- this.drags.planeStartPosition=new BABYLON.Vector3(this.drags.planeMesh.position.x,this.drags.planeMesh.position.y,this.drags.planeMesh.position.z);
- this.control.editProduct = true;
- };
- //移除选择标记及箭头
- Action3D.prototype.removeinfo=function()
- {
- if(this.currentInfoMesh!=null&&!this.currentInfoMesh._isDisposed)
- {
- this.currentInfoMesh.dispose();
- this.currentInfoMesh=null;
-
- this.sprite.dispose();
- this.sprite=null;
- }
- this.clearArrow();
-
- if(this.selectCircleMesh!=null)
- {
- this.selectCircleMesh.dispose();
- this.selectCircleMesh=null;
- if(this.selectRotatorMesh!=null)
- {
- this.selectRotatorMesh.dispose();
- this.selectRotatorMesh=null;
- }
- }
- };
- //编辑模型完成
- Action3D.prototype.finishEditMesh=function()
- {
- if(this.drags.planeMesh!=null)
- {
- var dxz=this.drags.planeMesh.position.subtract(this.drags.planeStartPosition);
- var newscal;
- //m_newdistance表示当前情况下model的长或者宽
- //m_olddistance表示过去model的长或者宽
- var m_newdistance,m_olddistance;
- if(this.currentSelectMesh.name=="downarrow")
- {
- m_newdistance=this.arrows.orgdownPosition.subtract(this.arrows.orgtopPosition);
- m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgtopPosition);
- }
- else if(this.currentSelectMesh.name=="toparrow")
- {
- m_newdistance=this.arrows.orgtopPosition.subtract(this.arrows.orgdownPosition);
- m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgdownPosition);
- }
- else if(this.currentSelectMesh.name=="leftarrow")
- {
- m_newdistance=this.arrows.orgleftPosition.subtract(this.arrows.orgrightPosition);
- m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgrightPosition);
- }
- else if(this.currentSelectMesh.name=="rightarrow")
- {
- m_newdistance=this.arrows.orgrightPosition.subtract(this.arrows.orgleftPosition);
- m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgleftPosition);
- }
- newscal=new BABYLON.Vector3(m_newdistance.x.toFixed(2)/m_olddistance.x.toFixed(2)*this.currentModelMesh.scaling.x.toFixed(2),0,m_newdistance.z.toFixed(2)/m_olddistance.z.toFixed(2)*this.currentModelMesh.scaling.z.toFixed(2));
-
- if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
- {
- if(!isNaN(newscal.z)&&newscal.z!=-Number.POSITIVE_INFINITY&&newscal.z!=Number.POSITIVE_INFINITY)
- {
- this.currentModelMesh.scaling.z=newscal.z;
- }
- }
- else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
- {
- if(!isNaN(newscal.x)&&newscal.x!=-Number.POSITIVE_INFINITY&&newscal.x!=Number.POSITIVE_INFINITY)
- {
- this.currentModelMesh.scaling.x=newscal.x;
- }
- }
- this.currentModelMesh.computeWorldMatrix(true);
- this.currentModelMesh.refreshBoundingInfo();
- var dxz2;
- if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
- {
- dxz2=this.currentModelMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((this.arrows.orgdownPosition.x+this.arrows.orgtopPosition.x)/2,0,(this.arrows.orgdownPosition.z+this.arrows.orgtopPosition.z)/2));
- this.currentModelMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
- this.arrows.orgleftPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- this.arrows.orgrightPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- }
- else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
- {
- dxz2=this.currentModelMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((this.arrows.orgleftPosition.x+this.arrows.orgrightPosition.x)/2,0,(this.arrows.orgleftPosition.z+this.arrows.orgrightPosition.z)/2));
- this.currentModelMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
- this.arrows.orgtopPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- this.arrows.orgdownPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
- }
- this.arrows.lineTopToDown=this.calculateLine.createLine(new BABYLON.Vector2(this.arrows.orgdownPosition.x,this.arrows.orgdownPosition.z),new BABYLON.Vector2(this.arrows.orgtopPosition.x,this.arrows.orgtopPosition.z));
- this.arrows.lineLeftToRight=this.calculateLine.createLine(new BABYLON.Vector2(this.arrows.orgleftPosition.x,this.arrows.orgleftPosition.z),new BABYLON.Vector2(this.arrows.orgrightPosition.x,this.arrows.orgrightPosition.z));
- this.drags.planeMesh.dispose();
- this.drags.planeMesh=null;
- }
- };
- //通过控制arrow来编辑模型
- Action3D.prototype.editingMesh=function(type)
- {
- var newpoint;
- this.clearMeasureMesh();
-
- var movdistance,diff1,diff2;
- //表示当前选择的arrow所在的线段的两个端点
- var startpoint,endpoint
-
- if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
- {
- if(type==1)
- {
- newpoint=this.getDiff2(this.drags.arrowIntersectPosition,this.arrows.lineTopToDown);
- newpoint.y=this.currentSelectMesh.position.y;
- }
- else //针对相框和墙贴
- {
- newpoint=new BABYLON.Vector3(this.arrows.lineTopToDown.x,this.currentSelectMesh.position.y,this.drags.arrowIntersectPosition.z);
- }
- diff1=this.arrows.orgactivePosition.subtract(this.currentModelMesh._boundingInfo.boundingBox.center);
- diff2=this.arrows.sideDistance;
-
- movdistance=diff2.subtract(diff1);
- movdistance.x=movdistance.x/4;
- movdistance.y=movdistance.y/4;
- movdistance.z=movdistance.z/4;
- startpoint=this.arrows.orgtopPosition.add(diff2);
- startpoint.addInPlace(movdistance);
- endpoint=this.arrows.orgdownPosition.add(diff2);
- endpoint.addInPlace(movdistance);
-
- var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
- fontpt.addInPlace(movdistance);
- if(this.measures.textMesh==null)
- {
- this.measures.textMesh = this.createTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", this.parameter.measureFontSize,fontpt);
- }
- else
- {
- this.updateTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2),this.parameter.measureFontSize,fontpt);
- }
- this.measures.textMesh.rotation.x=Math.PI/2;
- if(this.arrows.activeMesh.name=="rightarrow")
- {
- this.measures.textMesh.rotation.y=-Math.PI/2+this.currentModelMesh.angle;
- }
- else
- {
- this.measures.textMesh.rotation.y=Math.PI/2+this.currentModelMesh.angle;
- }
- }
- else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
- {
- if(type==1)
- {
- newpoint=this.getDiff2(this.drags.arrowIntersectPosition,this.arrows.lineLeftToRight);
- newpoint.y=this.currentSelectMesh.position.y;
- }
- else
- {
- newpoint=new BABYLON.Vector3(this.arrows.lineLeftToRight.y,this.currentSelectMesh.position.y,this.drags.arrowIntersectPosition.x);
- }
- diff1=this.arrows.orgactivePosition.subtract(this.currentModelMesh._boundingInfo.boundingBox.center);
- diff2=this.arrows.sideDistance;
-
- movdistance=diff2.subtract(diff1);
- movdistance.x=movdistance.x/4;
- movdistance.y=movdistance.y/4;
- movdistance.z=movdistance.z/4;
- startpoint=this.arrows.orgleftPosition.add(diff2);
- startpoint.addInPlace(movdistance);
- endpoint=this.arrows.orgrightPosition.add(diff2);
- endpoint.addInPlace(movdistance);
-
- var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
- fontpt.addInPlace(movdistance);
- //this.measures.textMesh = this.createTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt);
- if(this.measures.textMesh==null)
- {
- this.measures.textMesh = this.createTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", this.parameter.measureFontSize,fontpt);
- }
- else
- {
- this.updateTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2),this.parameter.measureFontSize,fontpt);
- }
- this.measures.textMesh.rotation.x=Math.PI/2;
- if(this.arrows.activeMesh.name=="toparrow")
- {
- this.measures.textMesh.rotation.y=Math.PI+this.currentModelMesh.angle;
- if(this.measures.textMesh.rotation.y>2*Math.PI)
- {
- this.measures.textMesh.rotation.y-=2*Math.PI;
- }
- }
- }
-
- var startpoint1=startpoint.add(movdistance);
- var startpoint2=startpoint.subtract(movdistance);
-
- var endpoint1=endpoint.add(movdistance);
- var endpoint2=endpoint.subtract(movdistance);
-
- this.showMeasureValue(startpoint,endpoint,startpoint1,endpoint1,startpoint2,endpoint2);
-
- return newpoint;
- };
- //显示测量值
- Action3D.prototype.showMeasureValue=function(startpoint,endpoint,startpoint1,endpoint1,startpoint2,endpoint2)
- {
- this.measures.endpointMesh1=BABYLON.Mesh.CreateLines("start",[startpoint1,startpoint2],this.scene);
- this.measures.endpointMesh2=BABYLON.Mesh.CreateLines("end",[endpoint1,endpoint2],this.scene);
-
- this.measures.linkMesh=BABYLON.Mesh.CreateLines("end",[startpoint,endpoint],this.scene);
-
- var pts1=this.drawArrow({x:startpoint.x,y:startpoint.z},{x:endpoint.x,y:endpoint.z},endpoint.y);
- var pts2=this.drawArrow({x:endpoint.x,y:endpoint.z},{x:startpoint.x,y:startpoint.z},startpoint.y);
-
- this.measures.arrowMesh1=BABYLON.Mesh.CreateLines("arrowend",pts1,this.scene);
- this.measures.arrowMesh2=BABYLON.Mesh.CreateLines("arrowstart",pts2,this.scene);
-
- this.measures.endpointMesh1.color = new BABYLON.Color3.Black();
- this.measures.endpointMesh2.color = new BABYLON.Color3.Black();
- this.measures.linkMesh.color = new BABYLON.Color3.Black();
- this.measures.arrowMesh1.color = new BABYLON.Color3.Black();
- this.measures.arrowMesh2.color = new BABYLON.Color3.Black();
- };
- //关闭配置窗口
- Action3D.prototype.closeConfigProduct=function()
- {
- var configuratorProduct=document.getElementById("configuratorWindow");
- configuratorProduct.style.display="none";
- this.removeinfo();
- };
- //刷墙
- Action3D.prototype.paintWallFromSubMesh=function(subMeshId)
- {
- var addMat = new BABYLON.StandardMaterial("paint", this.scene);
- addMat.alpha = 1.0;
- var r=this.layer3D.paint.value.r;
- var g=this.layer3D.paint.value.g;
- var b=this.layer3D.paint.value.b;
- addMat.diffuseColor = new BABYLON.Color3(r, g, b);
- addMat.specularColor =new BABYLON.Color3(r, g, b);
- addMat.emissiveColor = new BABYLON.Color3(r, g, b);
-
- addMat.backFaceCulling = false;
- addMat.toward=this.currentSelectMesh.material.subMaterials[subMeshId/2].toward;
- this.currentSelectMesh.material.subMaterials[subMeshId/2]=addMat;
- var flag=false;
-
- for(var i=0;i<this.paintSet.length;++i)
- {
- if(this.paintSet[i].type=="wall"&&this.paintSet[i].wallId==this.currentSelectMesh.id&&this.paintSet[i].materialId==subMeshId/2)
- {
- this.paintSet[i].material=addMat;
- flag=true;
- break;
- }
- }
- if(!flag)
- {
- this.paintSet.push({wallId:this.currentSelectMesh.id,materialId:subMeshId/2,material:addMat,type:"wall"});
- }
-
- document.getElementById("container3d").style.cursor="default";
- };
- Action3D.prototype.onPointerDown = function (evt)
- {
- if(this.lock)
- {
- return;
- }
- //如果不是鼠标左右键就返回
- if (evt.button !== 0&&evt.button !== 2) {
- return;
- }
-
- this.drags.modelStartPosition = this.getGroundPosition(evt);
-
- //点击右键
- if(evt.button == 2)
- {
- if (this.drags.modelStartPosition) { // we need to disconnect this.camera from canvas
- setTimeout(function () {
- this.camera.detachControl(this.canvas);
- }.bind(this), 0);
- }
- return;
- }
-
- // check if we are under a mesh
- var pickInfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
- return !this.isnotModel(mesh);
- }.bind(this));
-
- this.control.actionRotator=false;
-
- if (pickInfo.hit) {
-
- if(this.currentSelectMesh!=null&&this.currentSelectMesh.name!=pickInfo.pickedMesh.name&&pickInfo.pickedMesh.name!="selectCircle"&&pickInfo.pickedMesh.name!="rotator"&&pickInfo.pickedMesh.name.indexOf("arrow")<0)
- {
- this.removeSelectMesh();
- };
-
- this.currentSelectMesh= pickInfo.pickedMesh;
-
- //如果当前点击的是墙
- if(this.currentSelectMesh.name.indexOf("wall")>=0)
- {
- //刷墙
- if(this.layer3D.paint.beginPaint)
- {
- this.paintWallFromSubMesh(pickInfo.subMeshId);
- this.layer3D.paint.beginPaint=false;
- this.currentSelectMesh = null;
- return;
- }
- //添加相框
- else if(this.layer3D.modelLoader.currentPhotoMesh)
- {
- this.control.addPhoto=false;
- document.getElementById("container3d").style.cursor="default";
- var joinpoint=pickInfo.pickedPoint;
- var toward= this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].toward;
- var indexplane=this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].indexplane;
- var point1=this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].points.point1;
- var point2=this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].points.point2;
-
- var photoFrameMesh = this.layer3D.modelLoader.currentPhotoMesh;
-
- var tempjoin=this.calculateLine.getPositionIntersect3D(point1,point2,toward,photoFrameMesh.thice,joinpoint);
-
- var tempjoin1=new BABYLON.Vector3(tempjoin.point1.x,tempjoin.point1.y,tempjoin.point1.z);
- var tempjoin2=new BABYLON.Vector3(tempjoin.point2.x,tempjoin.point2.y,tempjoin.point2.z);
-
- photoFrameMesh.rotation.y=this.collidableMeshes[indexplane].rotation.y;
-
- photoFrameMesh.position=tempjoin1;
-
- photoFrameMesh.computeWorldMatrix(true);
- photoFrameMesh.refreshBoundingInfo();
- if(photoFrameMesh._boundingInfo.boundingBox.maximumWorld.y>this.parameter.wallHeight||photoFrameMesh._boundingInfo.boundingBox.minimumWorld.y<0)
- {
- photoFrameMesh.position.y=this.parameter.wallHeight/2;
- tempjoin1.y=this.parameter.wallHeight/2;
- tempjoin2.y=this.parameter.wallHeight/2;
- }
-
- photoFrameMesh.planeindex=pickInfo.subMeshId/2;
-
- var diffplane=tempjoin2.subtract(tempjoin1);
- if(diffplane.x==0&&diffplane.y==0&&diffplane.z==0)
- {
- photoFrameMesh.visibility=1;
- alert("2275");
- return ;
- }
- else
- {
- var add=1;
- while(!this.collidableMeshes[indexplane].intersectsMesh(photoFrameMesh, true))
- {
- tempjoin1.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
- ++add;
- if(add>19)
- {
- //alert(2324);
- break;
- }
- photoFrameMesh.position=tempjoin1;
- photoFrameMesh.computeWorldMatrix(true);
- photoFrameMesh.refreshBoundingInfo();
- }
- photoFrameMesh.visibility=1;
-
- var fontpt=photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[photoFrameMesh.frontindex];
- var toward2=this.calculateLine.getToward(point1,point2,{x:fontpt.x,y:fontpt.z});
- if(toward!=toward2)
- {
- photoFrameMesh.rotation.y+=Math.PI;
- }
- if(photoFrameMesh.rotation.y>=2*Math.PI)
- {
- photoFrameMesh.rotation.y-=2*Math.PI;
- }
-
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(i==indexplane)
- {
- continue;
- }
- if(this.collidableMeshes[i].intersectsMesh(photoFrameMesh, true))
- {
- photoFrameMesh.position.y=-100;
- photoFrameMesh.visibility=0;
- return;
- }
- }
-
- return;
- }
-
- }
- else
- {
- this.currentSelectMesh=null;
- this.currentModelMesh=null;
- }
- }
- //当前点击的是地板
- else if(this.currentSelectMesh.name.indexOf("floor")>=0)
- {
- //地板换贴图
- if(this.layer3D.paint.beginPaint)
- {
- this.layer3D.paint.beginPaint=false;
- this.layer3D.paint.currentId=this.currentSelectMesh.id;
- this.layer3D.decorate3D.refreshFloor(this.layer3D.paint.currentId);
- this.removeSelectMesh();
- return;
- }
- this.removeSelectMesh();
- }
- //当前点击的是相框或者图画
- else if(this.currentSelectMesh.name=="photo"||this.currentSelectMesh.name.indexOf("picture-")>=0)
- {
- var configuratorProduct=document.getElementById("configuratorWindow");
- configuratorProduct.style.display="block";
- this.switchCnofigureProduct(2);
- var params_height=document.getElementById("params-height");
- var params_length=document.getElementById("params-length");
-
- var height=this.currentSelectMesh.height;
- var length=this.currentSelectMesh.length;
-
- params_height.childNodes[1].childNodes[0].value=Math.floor(height);
- params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
- params_length.childNodes[1].childNodes[0].value=Math.floor(length);
- params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
-
- this.currentModelMesh = this.currentSelectMesh;
- setTimeout(function () {
- this.camera.detachControl(this.canvas);
- }.bind(this), 0);
- return;
- }
- //选择了编辑模型的圈圈
- else if(this.currentSelectMesh.name=="selectCircle"||this.currentSelectMesh.name=="rotator")
- {
- this.control.actionRotator=true;
- setTimeout(function () {
- this.camera.detachControl(this.canvas);
- }.bind(this), 0);
- return;
- }
- //选择了编辑模型的箭头
- else if(this.isArrow&&this.currentSelectMesh.name.indexOf("arrow")>-1)
- {
- if(!this.currentModelMesh)
- {
- alert("1083");
- }
- this.selectArrow();
- }
- //选择了模型
- else if(this.currentSelectMesh.name!="door"&&this.currentSelectMesh.name!="ground"&&this.currentSelectMesh.name!="window"&&this.currentSelectMesh.name.indexOf("arrow")<0)
- {
- this.currentModelMesh = this.currentSelectMesh;
- this.setselectMesh();
- this.setVertex(this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld,this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld,this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld);
- if (this.drags.modelStartPosition) { // we need to disconnect this.camera from canvas
- setTimeout(function () {
- this.camera.detachControl(this.canvas);
- }.bind(this), 0);
- }
- }
- else
- {
- this.removeSelectMesh();
- }
- }
- else
- {
- this.removeSelectMesh();
- }
- };
- Action3D.prototype.onPointerUp = function ()
- {
- if(this.lock)
- {
- return;
- }
- this.camera.attachControl(this.canvas, true);
-
- if (this.drags.modelStartPosition) {
- this.drags.modelStartPosition = null;
- if(this.control.editProduct)
- {
- this.finishEditMesh();
- this.clearMeasureMesh();
- }
- if(document.getElementById("configuratorWindow").style.display!="none")
- {
- this.setProductInfo();
- }
- this.control.actionRotator=false;
- return;
- }
-
- };
-
- Action3D.prototype.drawArrow= function( p0, p1,height)
- {
- var _ANGLE = 20;
- var _RADIUS = 10.0;
- var _ANGLE_CROSS = 90.0;
-
- var result=[];
-
- var nP = {};
- var angle = Math.atan2(p0.x-p1.x, p0.y-p1.y);
-
- result.push(new BABYLON.Vector3(p1.x,height,p1.y));
- //rotate by _ANGLE
- var tAngle = angle - _ANGLE * Math.PI/180.0;
- nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
- nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
-
- result.push(new BABYLON.Vector3(nP.x,height,nP.y));
- //lower part
- tAngle = angle + _ANGLE * Math.PI/180.0;
- nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
- nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
- result.push(new BABYLON.Vector3(p1.x,height,p1.y));
- result.push(new BABYLON.Vector3(nP.x,height,nP.y));
-
- return result;
- };
- Action3D.prototype.clearMeasureMesh=function()
- {
- if(this.measures.endpointMesh1!=null)
- {
- this.measures.endpointMesh1.dispose();
- this.measures.endpointMesh1=null;
- }
- if(this.measures.endpointMesh2!=null)
- {
- this.measures.endpointMesh2.dispose();
- this.measures.endpointMesh2=null;
- }
- if(this.measures.linkMesh!=null)
- {
- this.measures.linkMesh.dispose();
- this.measures.linkMesh=null;
- }
- if(this.measures.arrowMesh1!=null)
- {
- this.measures.arrowMesh1.dispose();
- this.measures.arrowMesh1=null;
- }
- if(this.measures.arrowMesh2!=null)
- {
- this.measures.arrowMesh2.dispose();
- this.measures.arrowMesh2=null;
- }
- if(this.measures.textMesh!=null)
- {
- this.measures.textMesh.dispose();
- this.measures.textMesh=null;
- }
- };
- Action3D.prototype.createTextPlane = function(text, color,size,position)
- {
-
- var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", 50, this.scene, true);
- dynamicTexture.hasAlpha = true;
-
- var plane = BABYLON.Mesh.CreatePlane("TextPlane", size, this.scene, true);
- plane.material = new BABYLON.StandardMaterial("TextPlaneMaterial", this.scene);
- plane.material.backFaceCulling = false;
- plane.material.specularColor = new BABYLON.Color3(0, 0, 0);
- plane.material.diffuseTexture = dynamicTexture;
- plane.position=position;
- dynamicTexture._context.font = "normal 12px Arial";
- var textSize=dynamicTexture._context.measureText(text);
- if(size<textSize.width)
- {
- size=Math.floor(1+textSize.width);
- }
- var x = (size - textSize.width) / 2;
- dynamicTexture.drawText(text, x, 40, "normal 12px Arial", color , "transparent", true);
-
- return plane;
- };
- Action3D.prototype.updateTextPlane = function(text,position)
- {
-
- var material = this.materials.setMeasureTextPlane();
- material.drawText(text, x, 40, "normal 12px Arial", color , "transparent", true);
- this.measures.textMesh.position = new BABYLON.Vector3(position.x,position.y,position.z);
- this.measures.textMesh.material=material;
-
- this.measures.textMesh.computeWorldMatrix(true);
- this.measures.textMesh.refreshBoundingInfo();
- /*
- var dynamicTexture=this.materials.measureTextPlaneMaterial.diffuseTexture;
- dynamicTexture.clear();
- dynamicTexture.drawText(text, x, 40, "normal 12px Arial", color , "transparent", true);
-
- */
- };
- Action3D.prototype.onPointerMove = function (evt)
- {
- if(this.lock)
- {
- return;
- }
-
- if (!this.drags.modelStartPosition) {
- return;
- }
- this.drags.moveModelPosition = this.getGroundPosition(evt);
- var diff = this.drags.moveModelPosition.subtract(this.drags.modelStartPosition);
- //通过右键移动
- if (evt.button == 2)
- {
- if(this.drags.moveModelPosition==null)
- {
- evt.stopPropagation();
- return;
- }
- this.camera.target.addInPlace(new BABYLON.Vector3(diff.x/2,0,diff.z/2));
- this.drags.modelStartPosition=new BABYLON.Vector3(this.drags.moveModelPosition.x,this.drags.moveModelPosition.y,this.drags.moveModelPosition.z) ;
- return;
- }
-
- //如果当前没有模型
- if(!this.currentSelectMesh)
- {
- evt.stopPropagation();
- return;
- }
-
- //如果处于编辑模型状态
- if(this.control.editProduct&&this.isArrow)
- {
- this.camera.detachControl(this.canvas);
- //this.drags.arrowIntersectPosition = this.getGroundPositionFromArrow(evt);
- this.drags.arrowIntersectPosition = new BABYLON.Vector3(this.drags.moveModelPosition.x,this.drags.moveModelPosition.y,this.drags.moveModelPosition.z);
- if(this.currentSelectMesh.name.indexOf("arrow")>-1)
- {
- var diff2,diff3;
- var startpoint,endpoint;
-
- var newpoint=this.editingMesh(1);
- diff = newpoint.subtract(this.currentSelectMesh.position);
- this.drags.planeMesh.position.addInPlace(diff);
- if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
- {
- this.arrows.leftMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- this.arrows.rightMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- }
- else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
- {
- this.arrows.downMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- this.arrows.topMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
- }
- this.currentSelectMesh.position=newpoint;
- this.currentSelectMesh.computeWorldMatrix(true);
- this.currentSelectMesh.refreshBoundingInfo();
- this.drags.modelStartPosition = this.drags.moveModelPosition;
- }
- evt.stopPropagation();
- return;
- }
- //通过移动模型的圈圈来旋转模型
- else if(this.control.actionRotator)
- {
- var angle1=BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(this.drags.modelStartPosition.x,this.drags.modelStartPosition.z),new BABYLON.Vector2(this.selectCircleMesh.position.x,this.selectCircleMesh.position.z));
- var angle2=BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(this.drags.moveModelPosition.x,this.drags.moveModelPosition.z),new BABYLON.Vector2(this.selectCircleMesh.position.x,this.selectCircleMesh.position.z));
- if(this.currentModelMesh.angle==null)
- {
- this.currentModelMesh.angle=angle1._radians-angle2._radians;
- }
- else
- {
- this.currentModelMesh.angle+=angle1._radians-angle2._radians;
- }
- this.selectCircleMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
-
- this.selectCircleMesh.rotation.y+=angle1._radians-angle2._radians;
- this.currentModelMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
- this.currentModelMesh.rotation.y+=angle1._radians-angle2._radians;
-
- this.currentModelMesh.angle=this.currentModelMesh.rotation.y;
- this.drags.modelStartPosition = this.drags.moveModelPosition;
- }
- //软饰
- else if((this.currentSelectMesh.name=="photo"||this.currentSelectMesh.name.indexOf("picture-")==0))
- {
- var m_pt=this.getWallPlanePosition();
- if(m_pt!=null)
- {
- var temp_last=null;
- var temp_pt =new BABYLON.Vector3(this.currentSelectMesh.position.x,this.currentSelectMesh.position.y,this.currentSelectMesh.position.z);
-
- if(this.currentSelectMesh.lastPos!=null)
- {
- temp_last=new BABYLON.Vector3(this.currentSelectMesh.lastPos.x,this.currentSelectMesh.lastPos.y,this.currentSelectMesh.lastPos.z);
- var diff2=m_pt.point.subtract(this.currentSelectMesh.lastPos);
- this.currentSelectMesh.lastPos=m_pt.point;
- this.currentSelectMesh.position.addInPlace(diff2);
- }
- else
- {
- this.currentSelectMesh.lastPos=m_pt.point;
- }
- this.currentSelectMesh.computeWorldMatrix(true);
- this.currentSelectMesh.refreshBoundingInfo();
-
- if(this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld.y>this.parameter.wallHeight||this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld.y<0)
- {
- this.currentSelectMesh.lastPos=temp_last;
- this.currentSelectMesh.position=temp_pt;
- }
- else
- {
- var photoFrameMesh = this.layer3D.modelLoader.currentPhotoMesh;
-
- if(m_pt.index==photoFrameMesh.planeindex)
- {
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(i==photoFrameMesh.planeindex)
- {
- continue;
- }
- if(this.collidableMeshes[i].intersectsMesh(this.currentSelectMesh, true))
- {
- this.currentSelectMesh.lastPos=temp_last;
- this.currentSelectMesh.position=temp_pt;
- break;
- }
- }
- }
- else
- {
- var temprotation=this.currentSelectMesh.rotation.y;
- this.currentSelectMesh.rotation.y=this.collidableMeshes[m_pt.index].rotation.y;
- if(this.collidableMeshes[photoFrameMesh.planeindex].intersectsMesh(this.currentSelectMesh, true))
- {
- this.currentSelectMesh.lastPos=temp_last;
- this.currentSelectMesh.position=temp_pt;
- this.currentSelectMesh.rotation.y=temprotation;
- }
- else
- {
- this.currentSelectMesh.computeWorldMatrix(true);
- this.currentSelectMesh.refreshBoundingInfo();
- var pos=this.currentSelectMesh.position;
- var join=this.calculateLine.getJoinLinePoint({x:pos.x,y:pos.z},this.calculateLine.createLine(this.collidableMeshes[m_pt.index].pts.point1, this.collidableMeshes[m_pt.index].pts.point2));
- join=new BABYLON.Vector3(join.x,pos.y,join.y);
- var diffplane=join.subtract(pos);
- var add=0;
- while(!this.collidableMeshes[m_pt.index].intersectsMesh(this.currentSelectMesh, true))
- {
- pos.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
- ++add;
- if(add>19)
- {
- //alert(2851);
- break;
- }
- this.currentSelectMesh.position=pos;
- this.currentSelectMesh.computeWorldMatrix(true);
- this.currentSelectMesh.refreshBoundingInfo();
- }
-
-
- var fontpt=this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.currentSelectMesh.frontindex];
- var toward2=this.calculateLine.getToward(this.collidableMeshes[m_pt.index].pts.point1,this.collidableMeshes[m_pt.index].pts.point2,{x:fontpt.x,y:fontpt.z});
- if(this.collidableMeshes[m_pt.index].toward!=toward2)
- {
- this.currentSelectMesh.rotation.y+=Math.PI;
- }
- if(this.currentSelectMesh.rotation.y>=2*Math.PI)
- {
- this.currentSelectMesh.rotation.y-=2*Math.PI;
- }
- photoFrameMesh.planeindex=m_pt.index;
- }
- }
- }
-
-
- }
- }
- //移动模型
- else
- {
- //判断选择的模型是否可以发生碰撞,true表示不能,false表示可以
- var flag=true;
- //this.currentSelectMesh.position = new BABYLON.Vector3(this.drags.moveModelPosition.x, this.drags.moveModelPosition.y, this.drags.moveModelPosition.z);
- this.currentSelectMesh.position.addInPlace(new BABYLON.Vector3(diff.x,0,diff.z));
- //移动模型上面的info标记
- if(this.currentInfoMesh!=null)
- {
- this.currentInfoMesh.position= new BABYLON.Vector3(this.currentSelectMesh.position.x, this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld.y+30, this.currentSelectMesh.position.z);
- }
- //移动模型下面的圈圈
- if(this.selectCircleMesh!=null)
- {
- this.selectCircleMesh.position.x=this.currentSelectMesh.position.x;
- this.selectCircleMesh.position.z=this.currentSelectMesh.position.z;
- }
-
- this.currentSelectMesh.computeWorldMatrix(true);
- this.currentSelectMesh.refreshBoundingInfo();
-
- //判断模型是否发生碰撞,第一次加载的模型可以和其他模型重合
- var collidableMesh=null;
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if(this.currentSelectMesh==this.collidableMeshes[i])
- {
- continue;
- }
- if (this.currentSelectMesh.intersectsMesh(this.collidableMeshes[i], true))
- {
- /*
- if(this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld.y>this.collidableMeshes[i]._boundingInfo.boundingBox.maximumWorld.y&&this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld<this.collidableMeshes[i]._boundingInfo.boundingBox.minimumWorld)
- {
- break;
- }
- */
- flag=false;
- if(this.currentSelectMesh.iscollision||this.collidableMeshes[i].iscollision)
- {
- if(this.collidableMeshes[i].name!="wallplane")
- {
- flag=true;
- }
- collidableMesh=this.collidableMeshes[i];
- }
- //else if(this.collidableMeshes[i].name=="wallplane")
- //{
- // collidableMesh=this.collidableMeshes[i];
- //}
- break;
- }
- }
-
- //当第一次加载的模型某个时刻不与任何模型重合时,就正常了。
- if(flag)
- {
- if(this.currentSelectMesh.iscollision&&!collidableMesh)
- {
- this.currentSelectMesh.iscollision=false;
- this.collidableMeshes.push(this.currentSelectMesh);
- }
- this.drags.modelStartPosition = new BABYLON.Vector3(this.currentSelectMesh.position.x, this.currentSelectMesh.position.y, this.currentSelectMesh.position.z);
- }
- else
- {
- /*
- //自动靠墙
- if(collidableMesh!=null&&collidableMesh.name=="wallplane")
- {
- var angle = this.getAngleFromWallPlane(collidableMesh);
- this.currentSelectMesh.rotation.y=angle;
- this.currentSelectMesh.angle=angle;
- }
- */
- this.currentSelectMesh.position = new BABYLON.Vector3(this.drags.modelStartPosition.x, this.drags.modelStartPosition.y, this.drags.modelStartPosition.z);
- //移动模型上面的info标记
- if(this.currentInfoMesh!=null)
- {
- this.currentInfoMesh.position= new BABYLON.Vector3(this.currentSelectMesh.position.x, this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld.y+30, this.currentSelectMesh.position.z);
- }
- //移动模型下面的圈圈
- if(this.selectCircleMesh!=null)
- {
- this.selectCircleMesh.position.x=this.currentSelectMesh.position.x;
- this.selectCircleMesh.position.z=this.currentSelectMesh.position.z;
- }
-
- this.currentSelectMesh.computeWorldMatrix(true);
- this.currentSelectMesh.refreshBoundingInfo();
- }
-
- }
-
- evt.stopPropagation();
- };
- //针对相框、壁纸
- Action3D.prototype.createArrows2=function()
- {
- min=this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld;
- max=this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld;
-
- var center=this.currentSelectMesh._boundingInfo.boundingBox.center;
-
- var points=[];
- points[0]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].z};
- points[1]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].z};
- points[2]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].z};
- points[3]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].z};
-
- var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
- var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
- var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
- var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
-
- this.arrows.orgdownPosition =new BABYLON.Vector3(down.x ,down.y,down.z);
- this.arrows.orgtopPosition =new BABYLON.Vector3(top.x ,top.y,top.z);
- this.arrows.orgleftPosition =new BABYLON.Vector3(left.x ,left.y,left.z);
- this.arrows.orgrightPosition=new BABYLON.Vector3(right.x,right.y,right.z);
-
- down=this.arrows.orgdownPosition.add(new BABYLON.Vector3(0,0,-this.parameter.arrowinterval));
- top=this.arrows.orgtopPosition.add(new BABYLON.Vector3(0,0,this.parameter.arrowinterval));
- left=this.arrows.orgleftPosition.add(new BABYLON.Vector3(-this.parameter.arrowinterval,0,0));
- right=this.arrows.orgrightPosition.add(new BABYLON.Vector3(this.parameter.arrowinterval,0,0));
- down =new BABYLON.Vector2(down.x ,down.z);
- top =new BABYLON.Vector2(top.x ,top.z);
- left =new BABYLON.Vector2(left.x ,left.z);
- right=new BABYLON.Vector2(right.x,right.z);
-
- var infoheight=this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.y/2;
-
- var arrowtexture = new BABYLON.Texture('data:my_image_name1', this.scene, true,
- true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
- null, null, this.parameter.arrow3DImgUrl, true);
-
- this.arrows.downMesh=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, this.scene, false);
- this.arrows.downMesh.material =new BABYLON.StandardMaterial('newMaterial', this.scene);
- this.arrows.downMesh.material.diffuseTexture = arrowtexture;
- this.arrows.downMesh.position= new BABYLON.Vector3(down.x, infoheight, down.y);
- this.arrows.downMesh.rotation.y=-Math.PI/2;
- this.arrows.downMesh.rotation.z=Math.PI;
- this.arrows.downMesh.name="downarrow";
-
- this.arrows.topMesh=this.arrows.downMesh.clone();
- this.arrows.topMesh.position= new BABYLON.Vector3(top.x, infoheight, top.y);
- this.arrows.topMesh.rotation.y=-3*Math.PI/2;
- this.arrows.topMesh.rotation.z=Math.PI;
- this.arrows.topMesh.name="toparrow";
-
- this.arrows.leftMesh=this.arrows.downMesh.clone();
- this.arrows.leftMesh.position= new BABYLON.Vector3(left.x, infoheight, left.y);
- this.arrows.leftMesh.rotation.y=0;
- this.arrows.leftMesh.rotation.z=Math.PI;
- this.arrows.leftMesh.name="leftarrow";
-
- this.arrows.rightMesh=this.arrows.downMesh.clone();
- this.arrows.rightMesh.position= new BABYLON.Vector3(right.x, infoheight, right.y);
- var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
- this.arrows.rightMesh.rotation.y=-Math.PI;
- this.arrows.rightMesh.rotation.z=Math.PI;
- this.arrows.rightMesh.name="rightarrow";
-
- this.arrows.lineTopToDown={x:down.x};
- this.arrows.lineLeftToRight={y:left.y};
-
- this.arrowMeshes[0]=this.arrows.downMesh;
- this.arrowMeshes[1]=this.arrows.topMesh;
- this.arrowMeshes[2]=this.arrows.leftMesh;
- this.arrowMeshes[3]=this.arrows.rightMesh;
- };
-
- Action3D.prototype.createArrows=function()
- {
- this.isArrow=true;
-
- min=this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld;
- max=this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld;
- //heigh=Math.abs(max.z-min.z);
- //length=Math.abs(max.x-min.x);
-
- var center=this.currentSelectMesh._boundingInfo.boundingBox.center;
-
- var points=[];
- points[0]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].z};
- points[1]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].z};
- points[2]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].z};
- points[3]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].z};
-
-
- var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
- var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
- var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
- var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
- this.arrows.orgdownPosition =new BABYLON.Vector3(down.x ,down.y,down.z);
- this.arrows.orgtopPosition =new BABYLON.Vector3(top.x ,top.y,top.z);
- this.arrows.orgleftPosition =new BABYLON.Vector3(left.x ,left.y,left.z);
- this.arrows.orgrightPosition=new BABYLON.Vector3(right.x,right.y,right.z);
-
-
- down =new BABYLON.Vector2(down.x ,down.z);
- top =new BABYLON.Vector2(top.x ,top.z);
- left =new BABYLON.Vector2(left.x ,left.z);
- right=new BABYLON.Vector2(right.x,right.z);
-
- var infoheight=this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.y/2;
-
- var d1=BABYLON.Vector2.Distance(down,new BABYLON.Vector2(center.x,center.z));
- var diff1=this.arrows.orgdownPosition.subtract(center);
- //down=this.arrows.orgdownPosition.addInPlace(diff1);
- down=this.arrows.orgdownPosition.add(new BABYLON.Vector3(diff1.x/d1*this.parameter.arrowinterval,0,diff1.z/d1*this.parameter.arrowinterval));
-
- var d2=BABYLON.Vector2.Distance(top,new BABYLON.Vector2(center.x,center.z));
- var diff2=this.arrows.orgtopPosition.subtract(center);
- //top=this.arrows.orgtopPosition.addInPlace(diff2);
- //top.addInPlace(diff2);
- top=this.arrows.orgtopPosition.add(new BABYLON.Vector3(diff2.x/d2*this.parameter.arrowinterval,0,diff2.z/d2*this.parameter.arrowinterval));
-
- var d3=BABYLON.Vector2.Distance(left,new BABYLON.Vector2(center.x,center.z));
- var diff3=this.arrows.orgleftPosition.subtract(center);
- //left=this.arrows.orgleftPosition.addInPlace(diff3);
- //left.addInPlace(diff3);
- left=this.arrows.orgleftPosition.add(new BABYLON.Vector3(diff3.x/d3*this.parameter.arrowinterval,0,diff3.z/d3*this.parameter.arrowinterval));
-
- var d4=BABYLON.Vector2.Distance(right,new BABYLON.Vector2(center.x,center.z));
- var diff4=this.arrows.orgrightPosition.subtract(center);
- //right=this.arrows.orgrightPosition.addInPlace(diff4);
- //right.addInPlace(diff4);
- right=this.arrows.orgrightPosition.add(new BABYLON.Vector3(diff4.x/d4*this.parameter.arrowinterval,0,diff4.z/d4*this.parameter.arrowinterval));
-
- down =new BABYLON.Vector2(down.x ,down.z);
- top =new BABYLON.Vector2(top.x ,top.z);
- left =new BABYLON.Vector2(left.x ,left.z);
- right=new BABYLON.Vector2(right.x,right.z);
-
- var arrowtexture = new BABYLON.Texture('data:my_image_name1', this.scene, true,
- true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
- null, null, this.parameter.arrow3DImgUrl, true);
-
- this.arrows.downMesh=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, this.scene, false);
- this.arrows.downMesh.material =new BABYLON.StandardMaterial('newMaterial', this.scene);
- this.arrows.downMesh.material.diffuseTexture = arrowtexture;
- this.arrows.downMesh.position= new BABYLON.Vector3(down.x, infoheight, down.y);
- var angle1=BABYLON.Angle.BetweenTwoPoints(down,top);
- this.arrows.downMesh.rotation.y=-angle1._radians;
- this.arrows.downMesh.rotation.z=Math.PI;
- this.arrows.downMesh.name="downarrow";
-
- this.arrows.topMesh=this.arrows.downMesh.clone();
- this.arrows.topMesh.position= new BABYLON.Vector3(top.x, infoheight, top.y);
- var angle2=BABYLON.Angle.BetweenTwoPoints(top,down);
- this.arrows.topMesh.rotation.y=-angle2._radians;
- this.arrows.topMesh.rotation.z=Math.PI;
- this.arrows.topMesh.name="toparrow";
-
- this.arrows.leftMesh=this.arrows.downMesh.clone();
- this.arrows.leftMesh.position= new BABYLON.Vector3(left.x, infoheight, left.y);
- var angle3=BABYLON.Angle.BetweenTwoPoints(left,right);
- this.arrows.leftMesh.rotation.y=-angle3._radians;
- this.arrows.leftMesh.rotation.z=Math.PI;
- this.arrows.leftMesh.name="leftarrow";
-
- this.arrows.rightMesh=this.arrows.downMesh.clone();
- this.arrows.rightMesh.position= new BABYLON.Vector3(right.x, infoheight, right.y);
- var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
- this.arrows.rightMesh.rotation.y=-angle4._radians;
- this.arrows.rightMesh.rotation.z=Math.PI;
- this.arrows.rightMesh.name="rightarrow";
-
- this.arrows.lineTopToDown=this.calculateLine.createLine(down,top);
- this.arrows.lineLeftToRight=this.calculateLine.createLine(left,right);
-
- this.arrowMeshes[0]=this.arrows.downMesh;
- this.arrowMeshes[1]=this.arrows.topMesh;
- this.arrowMeshes[2]=this.arrows.leftMesh;
- this.arrowMeshes[3]=this.arrows.rightMesh;
- };
-
- Action3D.prototype.clearArrow=function()
- {
- if(this.arrows.downMesh != null)
- {
- this.arrows.downMesh.dispose();
- }
- if(this.arrows.topMesh != null)
- {
- this.arrows.topMesh.dispose();
- }
- if(this.arrows.leftMesh != null)
- {
- this.arrows.leftMesh.dispose();
- }
- if(this.arrows.rightMesh != null)
- {
- this.arrows.rightMesh.dispose();
- }
- this.isArrow=false;
- };
-
- Action3D.prototype.onCameraWheel=function(e)
- {
- var type=e.type;
- var delta;
- if (type == 'DOMMouseScroll' || type == 'mousewheel') {
- delta = (e.wheelDelta) ? (e.wheelDelta / 120)*2 : -(e.detail || 0) / 3*2;
- }
-
- var mark=document.getElementById("mark");
- var markpy=parseInt(mark.style.marginTop);
- markpy-=delta;
- if(markpy<MixMark)
- {
- markpy=MixMark;
- }
- else if(markpy>MaxMark)
- {
- markpy=MaxMark;
- }
- mark.style.marginTop=markpy+"px";
- };
-
- Action3D.prototype.active = function ()
- {
- this.canvas.addEventListener("mousedown", Action3D.prototype.onPointerDown.bind(this), false);
- this.canvas.addEventListener("mouseup", Action3D.prototype.onPointerUp.bind(this), false);
- this.canvas.addEventListener("mousemove", Action3D.prototype.onPointerMove.bind(this), false);
- this.canvas.addEventListener("mousewheel", Action3D.prototype.onCameraWheel.bind(this),false);
- };
- Action3D.prototype.onDispose = function ()
- {
- this.canvas.removeEventListener("mousedown", onPointerDown);
- this.canvas.removeEventListener("mouseup", onPointerUp);
- this.canvas.removeEventListener("mousemove", onPointerMove);
- this.canvas.removeEventListener("mousewheel", onCameraWheel);
- };
|