Action3D.js 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  1. function Action3D(layer3D){
  2. this.scene = layer3D.scene3D.scene;
  3. this.ground = layer3D.scene3D.ground;
  4. this.camera = layer3D.scene3D.camera;
  5. this.canvas = layer3D.scene3D.canvas;
  6. this.layer=layer3D.layer;
  7. this.parameter=layer3D.layer.parameter;
  8. this.calculateLine=layer3D.layer.calculateLine;
  9. this.materials=layer3D.materials;
  10. this.layer3D=layer3D;
  11. //编辑模型的时候,出现的绿色的面
  12. //this.selectmat=null;
  13. this.vertexPoints=[];
  14. //选择的当前mesh
  15. this.currentSelectMesh=null;
  16. //当前操作都作用于model的mesh
  17. this.currentModelMesh=null;
  18. //选择模型时,显示的circle
  19. this.selectCircleMesh=null;
  20. //选择模型时,rotator
  21. this.selectRotatorMesh=null;
  22. //选择模型时,出现的sprite
  23. this.currentInfoMesh=null;
  24. this.sprite=null;
  25. //是否有arrow
  26. this.isArrow=false;
  27. //拖拽
  28. this.drags = {
  29. //拖拽的面,用来编辑模型
  30. planeMesh:null,
  31. //拖拽的面的初始位置
  32. planeStartPosition:null,
  33. //点击模型的时候,与地面的交点的位置
  34. modelStartPosition:null,
  35. //移动模型的时候,鼠标与地面的交点的位置
  36. moveModelPosition:null,
  37. //鼠标与箭头相交的位置
  38. arrowIntersectPosition:null
  39. };
  40. this.collidableMeshes=layer3D.collectMeshes.collidableMeshes;
  41. this.arrowMeshes=layer3D.collectMeshes.arrowMeshes;
  42. //刷墙
  43. this.paintSet=[];
  44. //锁住canvas
  45. this.lock=false;
  46. //判断其name的值
  47. //this.noModelMeshName = ["wallplane","skyBox","ground","floorPlane","wall","door","window","selectCircle","rotator"];
  48. this.noModelMeshName = ["wallplane","skyBox","walltop","ground","door","window"];
  49. this.noCareMeshName = ["wallplane","skyBox","walltop"];
  50. this.arrows={
  51. orgtopPosition:null,
  52. orgdownPosition:null,
  53. orgleftPosition:null,
  54. orgrightPosition:null,
  55. topMesh:null,
  56. downMesh:null,
  57. leftMesh:null,
  58. rightMesh:null,
  59. activeMesh:null,
  60. orgactivePosition:null,
  61. sideDistance:null,
  62. lineTopToDown:null,
  63. lineLeftToRight:null
  64. };
  65. this.measures={
  66. textMesh:null,
  67. endpointMesh1:null,
  68. endpointMesh2:null,
  69. arrowMesh1:null,
  70. arrowMesh2:null,
  71. linkMesh:null
  72. };
  73. this.measures.textMesh=null;
  74. this.control = {
  75. editProduct:false,
  76. addPhoto:false,
  77. addPicture:false,
  78. //是否旋转模型
  79. actionRotator:false
  80. };
  81. };
  82. //用来编辑模型的大小
  83. Action3D.prototype.createSelectMat=function()
  84. {
  85. var mat=new BABYLON.StandardMaterial("selectMat", this.scene);
  86. mat.alpha = 1.0;
  87. mat.diffuseColor = new BABYLON.Color3.Green();
  88. mat.backFaceCulling = false;
  89. return mat;
  90. };
  91. //从模型数组中移除某个模型
  92. Action3D.prototype.removeMesh = function(meshes,elem) {
  93. for (var i=meshes.length-1; i>=0; i--) {
  94. if (meshes[i] === elem) {
  95. meshes.splice(i, 1);
  96. }
  97. }
  98. return meshes;
  99. };
  100. Action3D.prototype.getAngleFromWallPlane=function(mesh)
  101. {
  102. var points = mesh._boundingInfo.boundingBox.vectorsWorld;
  103. var point1 = points[0];
  104. var point2=null;
  105. if(points[1].y == point1.y)
  106. {
  107. point2 = points[1];
  108. }
  109. else
  110. {
  111. point2 = points[2];
  112. }
  113. 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)));
  114. if(line.hasOwnProperty('x'))
  115. {
  116. return Math.PI/2;
  117. }
  118. else if(line.hasOwnProperty('y'))
  119. {
  120. return 0;
  121. }
  122. else
  123. {
  124. return line.a%(2*Math.PI);
  125. }
  126. };
  127. //移除选择的模型
  128. Action3D.prototype.removeSelectMesh=function()
  129. //Action3D.prototype.clearMesh=function(meshes,elem)
  130. {
  131. this.clearArrow();
  132. this.closeConfigProduct();
  133. this.currentSelectMesh = null;
  134. this.currentModelMesh = null;
  135. this.drags.modelStartPosition = null;
  136. };
  137. //通过鼠标移动模型或者移动arrow,将位置和模型的长宽赋值给弹出窗口
  138. Action3D.prototype.setProductInfo=function()
  139. {
  140. var position=null;
  141. if(this.currentModelMesh==null)
  142. {
  143. return;
  144. }
  145. else{
  146. position = this.currentModelMesh.position;
  147. }
  148. var position_x=document.getElementById("position-x");
  149. var position_y=document.getElementById("position-y");
  150. var position_z=document.getElementById("position-z");
  151. position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
  152. position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
  153. position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
  154. var params_width=document.getElementById("params-width");
  155. var params_length=document.getElementById("params-length");
  156. if(this.currentModelMesh.name=="photo")
  157. {
  158. params_width.childNodes[1].childNodes[0].value=Math.floor(this.currentModelMesh.height);
  159. params_width.childNodes[1].childNodes[0].alt=Math.floor(this.currentModelMesh.height);
  160. params_length.childNodes[1].childNodes[0].value=Math.floor(this.currentModelMesh.length);
  161. params_length.childNodes[1].childNodes[0].alt=Math.floor(this.currentModelMesh.length);
  162. }
  163. else
  164. {
  165. var width=Math.abs(this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.z-this.currentModelMesh._boundingInfo.boundingBox.minimumWorld.z);
  166. var length=Math.abs(this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.x-this.currentModelMesh._boundingInfo.boundingBox.minimumWorld.x);
  167. params_width.childNodes[1].childNodes[0].value=Math.floor(width);
  168. params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
  169. params_length.childNodes[1].childNodes[0].value=Math.floor(length);
  170. params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
  171. }
  172. };
  173. //给编辑框里赋值
  174. Action3D.prototype.editProductInfo=function(h,position)
  175. {
  176. 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));
  177. 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));
  178. var height=h;
  179. var positionX=position.x;
  180. var positionY=position.y;
  181. var positionZ=position.z;
  182. //var angleY=Math.floor((this.currentModelMesh.angle/Math.PI)*180);
  183. var angleY=Math.floor((this.currentSelectMesh.angle/Math.PI)*180);
  184. var rotationy=document.getElementById("rotation-y");
  185. if(angleY<0)
  186. {
  187. angleY=360+angleY;
  188. }
  189. else if(angleY>360)
  190. {
  191. angleY=angleY-360;
  192. }
  193. rotationy.childNodes[1].childNodes[0].value=angleY;
  194. rotationy.childNodes[1].childNodes[1].value=angleY;
  195. var position_x=document.getElementById("position-x");
  196. position_x.childNodes[1].childNodes[0].value=Math.floor(position.x);
  197. var position_y=document.getElementById("position-y");
  198. position_y.childNodes[1].childNodes[0].value=Math.floor(position.y);
  199. var position_z=document.getElementById("position-z");
  200. position_z.childNodes[1].childNodes[0].value=Math.floor(position.z);
  201. var params_width=document.getElementById("params-width");
  202. params_width.childNodes[1].childNodes[0].value=Math.floor(width);
  203. params_width.childNodes[1].childNodes[0].alt=Math.floor(width);
  204. var params_length=document.getElementById("params-length");
  205. params_length.childNodes[1].childNodes[0].value=Math.floor(length);
  206. params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
  207. var params_height=document.getElementById("params-height");
  208. params_height.childNodes[1].childNodes[0].value=Math.floor(height);
  209. params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
  210. };
  211. //获取模型的boundingbox上方的四个顶点
  212. Action3D.prototype.setVertex=function(points,min,max)
  213. {
  214. var y=points[0].y;
  215. var y1=points[1].y;
  216. for(var i=0;i<points.length;++i)
  217. {
  218. if(y.toFixed(2)==points[i].y.toFixed(2)||Math.abs(points[i].y-y)<Math.abs(points[i].y-y1))
  219. {
  220. if(points[i].x==min.x&&points[i].z==min.z)
  221. {
  222. this.vertexPoints[0]=i;
  223. }
  224. else if(points[i].x==max.x&&points[i].z==max.z)
  225. {
  226. this.vertexPoints[2]=i;
  227. }
  228. else if(points[i].x==min.x&&points[i].z==max.z)
  229. {
  230. this.vertexPoints[1]=i;
  231. }
  232. else if(points[i].x==max.x&&points[i].z==min.z)
  233. {
  234. this.vertexPoints[3]=i;
  235. }
  236. 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))
  237. {
  238. this.vertexPoints[0]=i;
  239. }
  240. 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))
  241. {
  242. this.vertexPoints[2]=i;
  243. }
  244. 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))
  245. {
  246. this.vertexPoints[1]=i;
  247. }
  248. 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))
  249. {
  250. this.vertexPoints[3]=i;
  251. }
  252. }
  253. }
  254. };
  255. //选模型时显示的圈圈
  256. Action3D.prototype.createRotator=function()
  257. {
  258. var rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, this.scene);
  259. rotator.scaling.x=this.parameter.selectRotator.scalingX;
  260. rotator.scaling.y=this.parameter.selectRotator.scalingY;
  261. rotator.material=this.materials.selectRotatorMaterial;
  262. return rotator;
  263. };
  264. //墙除外,因为可能刷墙或者添加软饰
  265. Action3D.prototype.isnotModel=function (mesh)
  266. {
  267. if (mesh.name == null) {
  268. return false;
  269. }
  270. for(var i=0;i<this.noModelMeshName.length;++i)
  271. {
  272. if(this.noModelMeshName[i]==mesh.name)
  273. {
  274. return true;
  275. }
  276. }
  277. return false;
  278. };
  279. Action3D.prototype.isnocareMesh=function (mesh)
  280. {
  281. if (mesh.name == null) {
  282. return false;
  283. }
  284. for(var i=0;i<this.noCareMeshName.length;++i)
  285. {
  286. if(this.noCareMeshName[i]==mesh.name)
  287. {
  288. return true;
  289. }
  290. }
  291. return false;
  292. };
  293. //获取鼠标指向的墙
  294. //主要用于软饰
  295. Action3D.prototype.getWallPlanePosition = function () {
  296. // Use a predicate to get position on the ground
  297. var pickinfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
  298. return mesh.name == this.noModelMeshName[0];
  299. }.bind(this));
  300. if (pickinfo.hit) {
  301. //return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
  302. return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex};
  303. }
  304. return null;
  305. };
  306. //获取鼠标指向的地面
  307. Action3D.prototype.getGroundPosition = function () {
  308. // Use a predicate to get position on the ground
  309. var pickinfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
  310. //return ( mesh == ground &&this.isnotModel(mesh));
  311. return ( mesh.name == "ground");
  312. }.bind(this));
  313. if (pickinfo.hit) {
  314. return pickinfo.pickedPoint;
  315. }
  316. return null;
  317. };
  318. //获取鼠标指向的arrow
  319. Action3D.prototype.getGroundPositionFromArrow = function () {
  320. // Use a predicate to get position on the ground
  321. var pickinfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
  322. return mesh.id.indexOf("arrow")>-1;
  323. });
  324. if (pickinfo.hit) {
  325. return pickinfo.pickedPoint;
  326. }
  327. return null;
  328. };
  329. Action3D.prototype.getDiff2=function(current,line)
  330. {
  331. var result=null;
  332. var interpoint=this.calculateLine.getJoinLinePoint({x:current.x,y:current.z},line);
  333. result=new BABYLON.Vector3(interpoint.x,current.y,interpoint.y);
  334. return result;
  335. };
  336. Action3D.prototype.setselectMesh=function()
  337. {
  338. var currentModelMesh = this.currentModelMesh;
  339. if(this.currentModelMesh==null)
  340. {
  341. return;
  342. }
  343. var shape = [
  344. new BABYLON.Vector3(this.parameter.selectCircle.downRadius, 0, 0),
  345. new BABYLON.Vector3(this.parameter.selectCircle.topRadius, this.parameter.selectCircle.topHeight, 0)
  346. ];
  347. var top=1;
  348. 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;
  349. if(radius>(this.parameter.selectRotator.differRadius+1))
  350. {
  351. top=radius-this.parameter.selectRotator.differRadius;
  352. }
  353. //如果加载的模型是软饰,就不要圈圈,否则就得有圈圈
  354. if(this.selectCircleMesh==null)
  355. {
  356. if(currentModelMesh.name!="photo"&&currentModelMesh.name.indexOf("picture-")!=0)
  357. {
  358. this.selectCircleMesh = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, this.scene);
  359. this.selectCircleMesh.material = this.materials.selectMaterial;
  360. var positionY = currentModelMesh.position.y+5;
  361. this.selectCircleMesh.position=new BABYLON.Vector3(currentModelMesh._boundingInfo.boundingBox.center.x,positionY,currentModelMesh._boundingInfo.boundingBox.center.z);
  362. if(this.selectRotatorMesh==null)
  363. {
  364. this.selectRotatorMesh=this.createRotator();
  365. }
  366. this.selectRotatorMesh.position.z = -radius;
  367. this.selectRotatorMesh.position.y = 5;
  368. if(this.selectCircleMesh!=null)
  369. {
  370. this.selectRotatorMesh.parent = this.selectCircleMesh;
  371. }
  372. this.selectRotatorMesh.rotation.y = this.parameter.selectRotator.rotationY;
  373. this.selectRotatorMesh.rotation.x = this.parameter.selectRotator.rotationX;
  374. this.selectRotatorMesh.computeWorldMatrix(true);
  375. this.selectRotatorMesh.refreshBoundingInfo();
  376. }
  377. }
  378. else
  379. {
  380. if(currentModelMesh.name.indexOf("picture-")==0||currentModelMesh.name=="photo")
  381. {
  382. this.selectCircleMesh.dispose();
  383. this.selectCircleMesh=null;
  384. if(this.selectRotatorMesh!=null)
  385. {
  386. this.selectRotatorMesh.dispose();
  387. this.selectRotatorMesh=null;
  388. }
  389. }
  390. }
  391. if(!currentModelMesh.rotationQuaternion)
  392. {
  393. currentModelMesh.angle=0;
  394. }
  395. else
  396. {
  397. var angleY=currentModelMesh.rotation.y;
  398. if(angleY<0)
  399. {
  400. angleY=2*Math.PI+angleY;
  401. }
  402. else if(angleY>2*Math.PI)
  403. {
  404. angleY=angleY-2*Math.PI;
  405. }
  406. currentModelMesh.angle=angleY;
  407. }
  408. this.createinfo();
  409. };
  410. Action3D.prototype.switchCnofigureProduct = function (type)
  411. {
  412. //显示普通模型
  413. if(type==1)
  414. {
  415. document.getElementById("params-width").style.display="";
  416. document.getElementById("editptrot").style.display="";
  417. document.getElementById("rotation-y").style.display="";
  418. document.getElementById("item-2").style.display="";
  419. document.getElementById("item-1").style.display="";
  420. }
  421. //显示软饰
  422. else
  423. {
  424. document.getElementById("params-width").style.display="none";
  425. document.getElementById("editptrot").style.display="none";
  426. document.getElementById("rotation-y").style.display="none";
  427. document.getElementById("item-2").style.display="none";
  428. document.getElementById("item-1").style.display="none";
  429. }
  430. };
  431. //选择模型后,出现标记
  432. Action3D.prototype.createinfo=function()
  433. {
  434. var currentModelMesh=this.currentModelMesh;
  435. if(this.currentModelMesh==null)
  436. {
  437. return;
  438. }
  439. currentModelMesh.arrowHeigh=currentModelMesh._boundingInfo.boundingBox.maximumWorld.y/2;
  440. if(this.sprite!=null)
  441. {
  442. this.removeinfo();
  443. }
  444. this.sprite = new BABYLON.SpriteManager("meshManager", this.parameter.selectSprite.img, this.parameter.selectSprite.capacity, this.parameter.selectSprite.cellSize, this.scene);
  445. this.sprite.isPickable = true;
  446. // First animated player
  447. this.currentInfoMesh = new BABYLON.Sprite("editFurniture", this.sprite);
  448. this.currentInfoMesh.position= new BABYLON.Vector3(currentModelMesh.position.x, currentModelMesh._boundingInfo.boundingBox.maximumWorld.y+this.parameter.selectSprite.extendY, currentModelMesh.position.z);
  449. this.currentInfoMesh.size = this.parameter.selectSprite.size;
  450. this.currentInfoMesh.isPickable = true;
  451. // click action for player
  452. this.currentInfoMesh.actionManager = new BABYLON.ActionManager(this.scene);
  453. this.currentInfoMesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickUpTrigger, function () {
  454. currentModelMesh.computeWorldMatrix(true);
  455. currentModelMesh.refreshBoundingInfo();
  456. //弹出框,显示产品的大小,位置,角度等等
  457. var configuratorProduct=document.getElementById("configuratorWindow");
  458. configuratorProduct.style.display="block";
  459. //创造编辑产品的箭头
  460. this.createArrows(currentModelMesh,this.scene,this.parameter.arrow3DImgUrl);
  461. this.switchCnofigureProduct(1);
  462. this.currentInfoMesh.dispose();
  463. this.currentInfoMesh=null;
  464. if(this.selectCircleMesh!=null)
  465. {
  466. this.selectCircleMesh.dispose();
  467. this.selectCircleMesh=null;
  468. if(this.selectRotatorMesh!=null)
  469. {
  470. this.selectRotatorMesh.dispose();
  471. this.selectRotatorMesh=null;
  472. }
  473. }
  474. this.editProductInfo(Math.abs(currentModelMesh._boundingInfo.boundingBox.maximumWorld.y- currentModelMesh._boundingInfo.boundingBox.minimumWorld.y),currentModelMesh.position);
  475. }.bind(this)));
  476. };
  477. //选择箭头标记
  478. Action3D.prototype.selectArrow=function()
  479. {
  480. this.drags.planeMesh=BABYLON.Mesh.CreatePlane("temp", 1, this.scene);
  481. if(this.currentSelectMesh.name=="downarrow")
  482. {
  483. this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.x*this.currentModelMesh.scaling.x*2;
  484. this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
  485. this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle, BABYLON.Space.LOCAL);
  486. this.drags.planeMesh.position=this.arrows.orgdownPosition;
  487. //olddistance=BABYLON.Vector3.Distance(this.arrows.orgdownPosition,this.arrows.orgtopPosition);
  488. 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));
  489. 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));
  490. if(distance1>distance2)
  491. {
  492. this.arrows.orgactivePosition=this.arrows.orgrightPosition;
  493. this.arrows.activeMesh=this.arrows.rightMesh;
  494. }
  495. else
  496. {
  497. this.arrows.orgactivePosition=this.arrows.orgleftPosition;
  498. this.arrows.activeMesh=this.arrows.leftMesh;
  499. }
  500. }
  501. else if(this.currentSelectMesh.name=="toparrow")
  502. {
  503. this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.x*this.currentModelMesh.scaling.x*2;
  504. this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
  505. this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle, BABYLON.Space.LOCAL);
  506. this.drags.planeMesh.position=this.arrows.orgtopPosition;
  507. 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));
  508. 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));
  509. if(distance1>distance2)
  510. {
  511. this.arrows.orgactivePosition=this.arrows.orgrightPosition;
  512. this.arrows.activeMesh=this.arrows.rightMesh;
  513. }
  514. else
  515. {
  516. this.arrows.orgactivePosition=this.arrows.orgleftPosition;
  517. this.arrows.activeMesh=this.arrows.leftMesh;
  518. }
  519. }
  520. else if(this.currentSelectMesh.name=="leftarrow")
  521. {
  522. this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle+Math.PI/2, BABYLON.Space.LOCAL);
  523. this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.z*this.currentModelMesh.scaling.z*2;
  524. this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
  525. this.drags.planeMesh.position=this.arrows.orgleftPosition;
  526. 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));
  527. 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));
  528. if(distance1>distance2)
  529. {
  530. this.arrows.orgactivePosition=this.arrows.orgdownPosition;
  531. this.arrows.activeMesh=this.arrows.downMesh;
  532. }
  533. else
  534. {
  535. this.arrows.orgactivePosition=this.arrows.orgtopPosition;
  536. this.arrows.activeMesh=this.arrows.topMesh;
  537. }
  538. }
  539. else if(this.currentSelectMesh.name=="rightarrow")
  540. {
  541. this.drags.planeMesh.rotate(BABYLON.Axis.Y, this.currentModelMesh.angle+Math.PI/2, BABYLON.Space.LOCAL);
  542. this.drags.planeMesh.scaling.x=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.z*this.currentModelMesh.scaling.z*2;
  543. this.drags.planeMesh.scaling.y=this.currentModelMesh.getBoundingInfo().boundingBox.extendSize.y*this.currentModelMesh.scaling.y*2;
  544. this.drags.planeMesh.position=this.arrows.orgrightPosition;
  545. 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));
  546. 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));
  547. if(distance1>distance2)
  548. {
  549. this.arrows.orgactivePosition=this.arrows.orgdownPosition;
  550. this.arrows.activeMesh=this.arrows.downMesh;
  551. }
  552. else
  553. {
  554. this.arrows.orgactivePosition=this.arrows.orgtopPosition;
  555. this.arrows.activeMesh=this.arrows.topMesh;
  556. }
  557. }
  558. this.arrows.sideDistance=this.arrows.activeMesh.position.subtract(this.currentModelMesh._boundingInfo.boundingBox.center);
  559. this.drags.planeMesh.material=this.materials.selectMaterial;
  560. this.drags.planeStartPosition=new BABYLON.Vector3(this.drags.planeMesh.position.x,this.drags.planeMesh.position.y,this.drags.planeMesh.position.z);
  561. this.control.editProduct = true;
  562. };
  563. //移除选择标记及箭头
  564. Action3D.prototype.removeinfo=function()
  565. {
  566. if(this.currentInfoMesh!=null&&!this.currentInfoMesh._isDisposed)
  567. {
  568. this.currentInfoMesh.dispose();
  569. this.currentInfoMesh=null;
  570. this.sprite.dispose();
  571. this.sprite=null;
  572. }
  573. this.clearArrow();
  574. if(this.selectCircleMesh!=null)
  575. {
  576. this.selectCircleMesh.dispose();
  577. this.selectCircleMesh=null;
  578. if(this.selectRotatorMesh!=null)
  579. {
  580. this.selectRotatorMesh.dispose();
  581. this.selectRotatorMesh=null;
  582. }
  583. }
  584. };
  585. //编辑模型完成
  586. Action3D.prototype.finishEditMesh=function()
  587. {
  588. if(this.drags.planeMesh!=null)
  589. {
  590. var dxz=this.drags.planeMesh.position.subtract(this.drags.planeStartPosition);
  591. var newscal;
  592. //m_newdistance表示当前情况下model的长或者宽
  593. //m_olddistance表示过去model的长或者宽
  594. var m_newdistance,m_olddistance;
  595. if(this.currentSelectMesh.name=="downarrow")
  596. {
  597. m_newdistance=this.arrows.orgdownPosition.subtract(this.arrows.orgtopPosition);
  598. m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgtopPosition);
  599. }
  600. else if(this.currentSelectMesh.name=="toparrow")
  601. {
  602. m_newdistance=this.arrows.orgtopPosition.subtract(this.arrows.orgdownPosition);
  603. m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgdownPosition);
  604. }
  605. else if(this.currentSelectMesh.name=="leftarrow")
  606. {
  607. m_newdistance=this.arrows.orgleftPosition.subtract(this.arrows.orgrightPosition);
  608. m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgrightPosition);
  609. }
  610. else if(this.currentSelectMesh.name=="rightarrow")
  611. {
  612. m_newdistance=this.arrows.orgrightPosition.subtract(this.arrows.orgleftPosition);
  613. m_olddistance=this.drags.planeStartPosition.subtract(this.arrows.orgleftPosition);
  614. }
  615. 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));
  616. if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
  617. {
  618. if(!isNaN(newscal.z)&&newscal.z!=-Number.POSITIVE_INFINITY&&newscal.z!=Number.POSITIVE_INFINITY)
  619. {
  620. this.currentModelMesh.scaling.z=newscal.z;
  621. }
  622. }
  623. else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
  624. {
  625. if(!isNaN(newscal.x)&&newscal.x!=-Number.POSITIVE_INFINITY&&newscal.x!=Number.POSITIVE_INFINITY)
  626. {
  627. this.currentModelMesh.scaling.x=newscal.x;
  628. }
  629. }
  630. this.currentModelMesh.computeWorldMatrix(true);
  631. this.currentModelMesh.refreshBoundingInfo();
  632. var dxz2;
  633. if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
  634. {
  635. 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));
  636. this.currentModelMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
  637. this.arrows.orgleftPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  638. this.arrows.orgrightPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  639. }
  640. else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
  641. {
  642. 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));
  643. this.currentModelMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z));
  644. this.arrows.orgtopPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  645. this.arrows.orgdownPosition.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2));
  646. }
  647. 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));
  648. 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));
  649. this.drags.planeMesh.dispose();
  650. this.drags.planeMesh=null;
  651. }
  652. };
  653. //通过控制arrow来编辑模型
  654. Action3D.prototype.editingMesh=function(type)
  655. {
  656. var newpoint;
  657. this.clearMeasureMesh();
  658. var movdistance,diff1,diff2;
  659. //表示当前选择的arrow所在的线段的两个端点
  660. var startpoint,endpoint
  661. if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
  662. {
  663. if(type==1)
  664. {
  665. newpoint=this.getDiff2(this.drags.arrowIntersectPosition,this.arrows.lineTopToDown);
  666. newpoint.y=this.currentSelectMesh.position.y;
  667. }
  668. else //针对相框和墙贴
  669. {
  670. newpoint=new BABYLON.Vector3(this.arrows.lineTopToDown.x,this.currentSelectMesh.position.y,this.drags.arrowIntersectPosition.z);
  671. }
  672. diff1=this.arrows.orgactivePosition.subtract(this.currentModelMesh._boundingInfo.boundingBox.center);
  673. diff2=this.arrows.sideDistance;
  674. movdistance=diff2.subtract(diff1);
  675. movdistance.x=movdistance.x/4;
  676. movdistance.y=movdistance.y/4;
  677. movdistance.z=movdistance.z/4;
  678. startpoint=this.arrows.orgtopPosition.add(diff2);
  679. startpoint.addInPlace(movdistance);
  680. endpoint=this.arrows.orgdownPosition.add(diff2);
  681. endpoint.addInPlace(movdistance);
  682. var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
  683. fontpt.addInPlace(movdistance);
  684. if(this.measures.textMesh==null)
  685. {
  686. this.measures.textMesh = this.createTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", this.parameter.measureFontSize,fontpt);
  687. }
  688. else
  689. {
  690. this.updateTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2),this.parameter.measureFontSize,fontpt);
  691. }
  692. this.measures.textMesh.rotation.x=Math.PI/2;
  693. if(this.arrows.activeMesh.name=="rightarrow")
  694. {
  695. this.measures.textMesh.rotation.y=-Math.PI/2+this.currentModelMesh.angle;
  696. }
  697. else
  698. {
  699. this.measures.textMesh.rotation.y=Math.PI/2+this.currentModelMesh.angle;
  700. }
  701. }
  702. else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
  703. {
  704. if(type==1)
  705. {
  706. newpoint=this.getDiff2(this.drags.arrowIntersectPosition,this.arrows.lineLeftToRight);
  707. newpoint.y=this.currentSelectMesh.position.y;
  708. }
  709. else
  710. {
  711. newpoint=new BABYLON.Vector3(this.arrows.lineLeftToRight.y,this.currentSelectMesh.position.y,this.drags.arrowIntersectPosition.x);
  712. }
  713. diff1=this.arrows.orgactivePosition.subtract(this.currentModelMesh._boundingInfo.boundingBox.center);
  714. diff2=this.arrows.sideDistance;
  715. movdistance=diff2.subtract(diff1);
  716. movdistance.x=movdistance.x/4;
  717. movdistance.y=movdistance.y/4;
  718. movdistance.z=movdistance.z/4;
  719. startpoint=this.arrows.orgleftPosition.add(diff2);
  720. startpoint.addInPlace(movdistance);
  721. endpoint=this.arrows.orgrightPosition.add(diff2);
  722. endpoint.addInPlace(movdistance);
  723. var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2);
  724. fontpt.addInPlace(movdistance);
  725. //this.measures.textMesh = this.createTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt);
  726. if(this.measures.textMesh==null)
  727. {
  728. this.measures.textMesh = this.createTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", this.parameter.measureFontSize,fontpt);
  729. }
  730. else
  731. {
  732. this.updateTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2),this.parameter.measureFontSize,fontpt);
  733. }
  734. this.measures.textMesh.rotation.x=Math.PI/2;
  735. if(this.arrows.activeMesh.name=="toparrow")
  736. {
  737. this.measures.textMesh.rotation.y=Math.PI+this.currentModelMesh.angle;
  738. if(this.measures.textMesh.rotation.y>2*Math.PI)
  739. {
  740. this.measures.textMesh.rotation.y-=2*Math.PI;
  741. }
  742. }
  743. }
  744. var startpoint1=startpoint.add(movdistance);
  745. var startpoint2=startpoint.subtract(movdistance);
  746. var endpoint1=endpoint.add(movdistance);
  747. var endpoint2=endpoint.subtract(movdistance);
  748. this.showMeasureValue(startpoint,endpoint,startpoint1,endpoint1,startpoint2,endpoint2);
  749. return newpoint;
  750. };
  751. //显示测量值
  752. Action3D.prototype.showMeasureValue=function(startpoint,endpoint,startpoint1,endpoint1,startpoint2,endpoint2)
  753. {
  754. this.measures.endpointMesh1=BABYLON.Mesh.CreateLines("start",[startpoint1,startpoint2],this.scene);
  755. this.measures.endpointMesh2=BABYLON.Mesh.CreateLines("end",[endpoint1,endpoint2],this.scene);
  756. this.measures.linkMesh=BABYLON.Mesh.CreateLines("end",[startpoint,endpoint],this.scene);
  757. var pts1=this.drawArrow({x:startpoint.x,y:startpoint.z},{x:endpoint.x,y:endpoint.z},endpoint.y);
  758. var pts2=this.drawArrow({x:endpoint.x,y:endpoint.z},{x:startpoint.x,y:startpoint.z},startpoint.y);
  759. this.measures.arrowMesh1=BABYLON.Mesh.CreateLines("arrowend",pts1,this.scene);
  760. this.measures.arrowMesh2=BABYLON.Mesh.CreateLines("arrowstart",pts2,this.scene);
  761. this.measures.endpointMesh1.color = new BABYLON.Color3.Black();
  762. this.measures.endpointMesh2.color = new BABYLON.Color3.Black();
  763. this.measures.linkMesh.color = new BABYLON.Color3.Black();
  764. this.measures.arrowMesh1.color = new BABYLON.Color3.Black();
  765. this.measures.arrowMesh2.color = new BABYLON.Color3.Black();
  766. };
  767. //关闭配置窗口
  768. Action3D.prototype.closeConfigProduct=function()
  769. {
  770. var configuratorProduct=document.getElementById("configuratorWindow");
  771. configuratorProduct.style.display="none";
  772. this.removeinfo();
  773. };
  774. //刷墙
  775. Action3D.prototype.paintWallFromSubMesh=function(subMeshId)
  776. {
  777. var addMat = new BABYLON.StandardMaterial("paint", this.scene);
  778. addMat.alpha = 1.0;
  779. var r=this.layer3D.paint.value.r;
  780. var g=this.layer3D.paint.value.g;
  781. var b=this.layer3D.paint.value.b;
  782. addMat.diffuseColor = new BABYLON.Color3(r, g, b);
  783. addMat.specularColor =new BABYLON.Color3(r, g, b);
  784. addMat.emissiveColor = new BABYLON.Color3(r, g, b);
  785. addMat.backFaceCulling = false;
  786. addMat.toward=this.currentSelectMesh.material.subMaterials[subMeshId/2].toward;
  787. this.currentSelectMesh.material.subMaterials[subMeshId/2]=addMat;
  788. var flag=false;
  789. for(var i=0;i<this.paintSet.length;++i)
  790. {
  791. if(this.paintSet[i].type=="wall"&&this.paintSet[i].wallId==this.currentSelectMesh.id&&this.paintSet[i].materialId==subMeshId/2)
  792. {
  793. this.paintSet[i].material=addMat;
  794. flag=true;
  795. break;
  796. }
  797. }
  798. if(!flag)
  799. {
  800. this.paintSet.push({wallId:this.currentSelectMesh.id,materialId:subMeshId/2,material:addMat,type:"wall"});
  801. }
  802. document.getElementById("container3d").style.cursor="default";
  803. };
  804. Action3D.prototype.onPointerDown = function (evt)
  805. {
  806. if(this.lock)
  807. {
  808. return;
  809. }
  810. //如果不是鼠标左右键就返回
  811. if (evt.button !== 0&&evt.button !== 2) {
  812. return;
  813. }
  814. this.drags.modelStartPosition = this.getGroundPosition(evt);
  815. //点击右键
  816. if(evt.button == 2)
  817. {
  818. if (this.drags.modelStartPosition) { // we need to disconnect this.camera from canvas
  819. setTimeout(function () {
  820. this.camera.detachControl(this.canvas);
  821. }.bind(this), 0);
  822. }
  823. return;
  824. }
  825. // check if we are under a mesh
  826. var pickInfo = this.scene.pick(this.scene.pointerX, this.scene.pointerY, function (mesh) {
  827. return !this.isnotModel(mesh);
  828. }.bind(this));
  829. this.control.actionRotator=false;
  830. if (pickInfo.hit) {
  831. if(this.currentSelectMesh!=null&&this.currentSelectMesh.name!=pickInfo.pickedMesh.name&&pickInfo.pickedMesh.name!="selectCircle"&&pickInfo.pickedMesh.name!="rotator"&&pickInfo.pickedMesh.name.indexOf("arrow")<0)
  832. {
  833. this.removeSelectMesh();
  834. };
  835. this.currentSelectMesh= pickInfo.pickedMesh;
  836. //如果当前点击的是墙
  837. if(this.currentSelectMesh.name.indexOf("wall")>=0)
  838. {
  839. //刷墙
  840. if(this.layer3D.paint.beginPaint)
  841. {
  842. this.paintWallFromSubMesh(pickInfo.subMeshId);
  843. this.layer3D.paint.beginPaint=false;
  844. this.currentSelectMesh = null;
  845. return;
  846. }
  847. //添加相框
  848. else if(this.layer3D.modelLoader.currentPhotoMesh)
  849. {
  850. this.control.addPhoto=false;
  851. document.getElementById("container3d").style.cursor="default";
  852. var joinpoint=pickInfo.pickedPoint;
  853. var toward= this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].toward;
  854. var indexplane=this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].indexplane;
  855. var point1=this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].points.point1;
  856. var point2=this.currentSelectMesh.material.subMaterials[pickInfo.subMeshId/2].points.point2;
  857. var photoFrameMesh = this.layer3D.modelLoader.currentPhotoMesh;
  858. var tempjoin=this.calculateLine.getPositionIntersect3D(point1,point2,toward,photoFrameMesh.thice,joinpoint);
  859. var tempjoin1=new BABYLON.Vector3(tempjoin.point1.x,tempjoin.point1.y,tempjoin.point1.z);
  860. var tempjoin2=new BABYLON.Vector3(tempjoin.point2.x,tempjoin.point2.y,tempjoin.point2.z);
  861. photoFrameMesh.rotation.y=this.collidableMeshes[indexplane].rotation.y;
  862. photoFrameMesh.position=tempjoin1;
  863. photoFrameMesh.computeWorldMatrix(true);
  864. photoFrameMesh.refreshBoundingInfo();
  865. if(photoFrameMesh._boundingInfo.boundingBox.maximumWorld.y>this.parameter.wallHeight||photoFrameMesh._boundingInfo.boundingBox.minimumWorld.y<0)
  866. {
  867. photoFrameMesh.position.y=this.parameter.wallHeight/2;
  868. tempjoin1.y=this.parameter.wallHeight/2;
  869. tempjoin2.y=this.parameter.wallHeight/2;
  870. }
  871. photoFrameMesh.planeindex=pickInfo.subMeshId/2;
  872. var diffplane=tempjoin2.subtract(tempjoin1);
  873. if(diffplane.x==0&&diffplane.y==0&&diffplane.z==0)
  874. {
  875. photoFrameMesh.visibility=1;
  876. alert("2275");
  877. return ;
  878. }
  879. else
  880. {
  881. var add=1;
  882. while(!this.collidableMeshes[indexplane].intersectsMesh(photoFrameMesh, true))
  883. {
  884. tempjoin1.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
  885. ++add;
  886. if(add>19)
  887. {
  888. //alert(2324);
  889. break;
  890. }
  891. photoFrameMesh.position=tempjoin1;
  892. photoFrameMesh.computeWorldMatrix(true);
  893. photoFrameMesh.refreshBoundingInfo();
  894. }
  895. photoFrameMesh.visibility=1;
  896. var fontpt=photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[photoFrameMesh.frontindex];
  897. var toward2=this.calculateLine.getToward(point1,point2,{x:fontpt.x,y:fontpt.z});
  898. if(toward!=toward2)
  899. {
  900. photoFrameMesh.rotation.y+=Math.PI;
  901. }
  902. if(photoFrameMesh.rotation.y>=2*Math.PI)
  903. {
  904. photoFrameMesh.rotation.y-=2*Math.PI;
  905. }
  906. for(var i=0;i<this.collidableMeshes.length;++i)
  907. {
  908. if(i==indexplane)
  909. {
  910. continue;
  911. }
  912. if(this.collidableMeshes[i].intersectsMesh(photoFrameMesh, true))
  913. {
  914. photoFrameMesh.position.y=-100;
  915. photoFrameMesh.visibility=0;
  916. return;
  917. }
  918. }
  919. return;
  920. }
  921. }
  922. else
  923. {
  924. this.currentSelectMesh=null;
  925. this.currentModelMesh=null;
  926. }
  927. }
  928. //当前点击的是地板
  929. else if(this.currentSelectMesh.name.indexOf("floor")>=0)
  930. {
  931. //地板换贴图
  932. if(this.layer3D.paint.beginPaint)
  933. {
  934. this.layer3D.paint.beginPaint=false;
  935. this.layer3D.paint.currentId=this.currentSelectMesh.id;
  936. this.layer3D.decorate3D.refreshFloor(this.layer3D.paint.currentId);
  937. this.removeSelectMesh();
  938. return;
  939. }
  940. this.removeSelectMesh();
  941. }
  942. //当前点击的是相框或者图画
  943. else if(this.currentSelectMesh.name=="photo"||this.currentSelectMesh.name.indexOf("picture-")>=0)
  944. {
  945. var configuratorProduct=document.getElementById("configuratorWindow");
  946. configuratorProduct.style.display="block";
  947. this.switchCnofigureProduct(2);
  948. var params_height=document.getElementById("params-height");
  949. var params_length=document.getElementById("params-length");
  950. var height=this.currentSelectMesh.height;
  951. var length=this.currentSelectMesh.length;
  952. params_height.childNodes[1].childNodes[0].value=Math.floor(height);
  953. params_height.childNodes[1].childNodes[0].alt=Math.floor(height);
  954. params_length.childNodes[1].childNodes[0].value=Math.floor(length);
  955. params_length.childNodes[1].childNodes[0].alt=Math.floor(length);
  956. this.currentModelMesh = this.currentSelectMesh;
  957. setTimeout(function () {
  958. this.camera.detachControl(this.canvas);
  959. }.bind(this), 0);
  960. return;
  961. }
  962. //选择了编辑模型的圈圈
  963. else if(this.currentSelectMesh.name=="selectCircle"||this.currentSelectMesh.name=="rotator")
  964. {
  965. this.control.actionRotator=true;
  966. setTimeout(function () {
  967. this.camera.detachControl(this.canvas);
  968. }.bind(this), 0);
  969. return;
  970. }
  971. //选择了编辑模型的箭头
  972. else if(this.isArrow&&this.currentSelectMesh.name.indexOf("arrow")>-1)
  973. {
  974. if(!this.currentModelMesh)
  975. {
  976. alert("1083");
  977. }
  978. this.selectArrow();
  979. }
  980. //选择了模型
  981. else if(this.currentSelectMesh.name!="door"&&this.currentSelectMesh.name!="ground"&&this.currentSelectMesh.name!="window"&&this.currentSelectMesh.name.indexOf("arrow")<0)
  982. {
  983. this.currentModelMesh = this.currentSelectMesh;
  984. this.setselectMesh();
  985. this.setVertex(this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld,this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld,this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld);
  986. if (this.drags.modelStartPosition) { // we need to disconnect this.camera from canvas
  987. setTimeout(function () {
  988. this.camera.detachControl(this.canvas);
  989. }.bind(this), 0);
  990. }
  991. }
  992. else
  993. {
  994. this.removeSelectMesh();
  995. }
  996. }
  997. else
  998. {
  999. this.removeSelectMesh();
  1000. }
  1001. };
  1002. Action3D.prototype.onPointerUp = function ()
  1003. {
  1004. if(this.lock)
  1005. {
  1006. return;
  1007. }
  1008. this.camera.attachControl(this.canvas, true);
  1009. if (this.drags.modelStartPosition) {
  1010. this.drags.modelStartPosition = null;
  1011. if(this.control.editProduct)
  1012. {
  1013. this.finishEditMesh();
  1014. this.clearMeasureMesh();
  1015. }
  1016. if(document.getElementById("configuratorWindow").style.display!="none")
  1017. {
  1018. this.setProductInfo();
  1019. }
  1020. this.control.actionRotator=false;
  1021. return;
  1022. }
  1023. };
  1024. Action3D.prototype.drawArrow= function( p0, p1,height)
  1025. {
  1026. var _ANGLE = 20;
  1027. var _RADIUS = 10.0;
  1028. var _ANGLE_CROSS = 90.0;
  1029. var result=[];
  1030. var nP = {};
  1031. var angle = Math.atan2(p0.x-p1.x, p0.y-p1.y);
  1032. result.push(new BABYLON.Vector3(p1.x,height,p1.y));
  1033. //rotate by _ANGLE
  1034. var tAngle = angle - _ANGLE * Math.PI/180.0;
  1035. nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
  1036. nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
  1037. result.push(new BABYLON.Vector3(nP.x,height,nP.y));
  1038. //lower part
  1039. tAngle = angle + _ANGLE * Math.PI/180.0;
  1040. nP.x = parseFloat(p1.x) + _RADIUS * Math.sin(tAngle);
  1041. nP.y = parseFloat(p1.y) + _RADIUS * Math.cos(tAngle);
  1042. result.push(new BABYLON.Vector3(p1.x,height,p1.y));
  1043. result.push(new BABYLON.Vector3(nP.x,height,nP.y));
  1044. return result;
  1045. };
  1046. Action3D.prototype.clearMeasureMesh=function()
  1047. {
  1048. if(this.measures.endpointMesh1!=null)
  1049. {
  1050. this.measures.endpointMesh1.dispose();
  1051. this.measures.endpointMesh1=null;
  1052. }
  1053. if(this.measures.endpointMesh2!=null)
  1054. {
  1055. this.measures.endpointMesh2.dispose();
  1056. this.measures.endpointMesh2=null;
  1057. }
  1058. if(this.measures.linkMesh!=null)
  1059. {
  1060. this.measures.linkMesh.dispose();
  1061. this.measures.linkMesh=null;
  1062. }
  1063. if(this.measures.arrowMesh1!=null)
  1064. {
  1065. this.measures.arrowMesh1.dispose();
  1066. this.measures.arrowMesh1=null;
  1067. }
  1068. if(this.measures.arrowMesh2!=null)
  1069. {
  1070. this.measures.arrowMesh2.dispose();
  1071. this.measures.arrowMesh2=null;
  1072. }
  1073. if(this.measures.textMesh!=null)
  1074. {
  1075. this.measures.textMesh.dispose();
  1076. this.measures.textMesh=null;
  1077. }
  1078. };
  1079. Action3D.prototype.createTextPlane = function(text, color,size,position)
  1080. {
  1081. var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", 50, this.scene, true);
  1082. dynamicTexture.hasAlpha = true;
  1083. var plane = BABYLON.Mesh.CreatePlane("TextPlane", size, this.scene, true);
  1084. plane.material = new BABYLON.StandardMaterial("TextPlaneMaterial", this.scene);
  1085. plane.material.backFaceCulling = false;
  1086. plane.material.specularColor = new BABYLON.Color3(0, 0, 0);
  1087. plane.material.diffuseTexture = dynamicTexture;
  1088. plane.position=position;
  1089. dynamicTexture._context.font = "normal 12px Arial";
  1090. var textSize=dynamicTexture._context.measureText(text);
  1091. if(size<textSize.width)
  1092. {
  1093. size=Math.floor(1+textSize.width);
  1094. }
  1095. var x = (size - textSize.width) / 2;
  1096. dynamicTexture.drawText(text, x, 40, "normal 12px Arial", color , "transparent", true);
  1097. return plane;
  1098. };
  1099. Action3D.prototype.updateTextPlane = function(text,position)
  1100. {
  1101. var material = this.materials.setMeasureTextPlane();
  1102. material.drawText(text, x, 40, "normal 12px Arial", color , "transparent", true);
  1103. this.measures.textMesh.position = new BABYLON.Vector3(position.x,position.y,position.z);
  1104. this.measures.textMesh.material=material;
  1105. this.measures.textMesh.computeWorldMatrix(true);
  1106. this.measures.textMesh.refreshBoundingInfo();
  1107. /*
  1108. var dynamicTexture=this.materials.measureTextPlaneMaterial.diffuseTexture;
  1109. dynamicTexture.clear();
  1110. dynamicTexture.drawText(text, x, 40, "normal 12px Arial", color , "transparent", true);
  1111. */
  1112. };
  1113. Action3D.prototype.onPointerMove = function (evt)
  1114. {
  1115. if(this.lock)
  1116. {
  1117. return;
  1118. }
  1119. if (!this.drags.modelStartPosition) {
  1120. return;
  1121. }
  1122. this.drags.moveModelPosition = this.getGroundPosition(evt);
  1123. var diff = this.drags.moveModelPosition.subtract(this.drags.modelStartPosition);
  1124. //通过右键移动
  1125. if (evt.button == 2)
  1126. {
  1127. if(this.drags.moveModelPosition==null)
  1128. {
  1129. evt.stopPropagation();
  1130. return;
  1131. }
  1132. this.camera.target.addInPlace(new BABYLON.Vector3(diff.x/2,0,diff.z/2));
  1133. this.drags.modelStartPosition=new BABYLON.Vector3(this.drags.moveModelPosition.x,this.drags.moveModelPosition.y,this.drags.moveModelPosition.z) ;
  1134. return;
  1135. }
  1136. //如果当前没有模型
  1137. if(!this.currentSelectMesh)
  1138. {
  1139. evt.stopPropagation();
  1140. return;
  1141. }
  1142. //如果处于编辑模型状态
  1143. if(this.control.editProduct&&this.isArrow)
  1144. {
  1145. this.camera.detachControl(this.canvas);
  1146. //this.drags.arrowIntersectPosition = this.getGroundPositionFromArrow(evt);
  1147. this.drags.arrowIntersectPosition = new BABYLON.Vector3(this.drags.moveModelPosition.x,this.drags.moveModelPosition.y,this.drags.moveModelPosition.z);
  1148. if(this.currentSelectMesh.name.indexOf("arrow")>-1)
  1149. {
  1150. var diff2,diff3;
  1151. var startpoint,endpoint;
  1152. var newpoint=this.editingMesh(1);
  1153. diff = newpoint.subtract(this.currentSelectMesh.position);
  1154. this.drags.planeMesh.position.addInPlace(diff);
  1155. if(this.currentSelectMesh.name=="downarrow"||this.currentSelectMesh.name=="toparrow")
  1156. {
  1157. this.arrows.leftMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  1158. this.arrows.rightMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  1159. }
  1160. else if(this.currentSelectMesh.name=="leftarrow"||this.currentSelectMesh.name=="rightarrow")
  1161. {
  1162. this.arrows.downMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  1163. this.arrows.topMesh.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2));
  1164. }
  1165. this.currentSelectMesh.position=newpoint;
  1166. this.currentSelectMesh.computeWorldMatrix(true);
  1167. this.currentSelectMesh.refreshBoundingInfo();
  1168. this.drags.modelStartPosition = this.drags.moveModelPosition;
  1169. }
  1170. evt.stopPropagation();
  1171. return;
  1172. }
  1173. //通过移动模型的圈圈来旋转模型
  1174. else if(this.control.actionRotator)
  1175. {
  1176. 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));
  1177. 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));
  1178. if(this.currentModelMesh.angle==null)
  1179. {
  1180. this.currentModelMesh.angle=angle1._radians-angle2._radians;
  1181. }
  1182. else
  1183. {
  1184. this.currentModelMesh.angle+=angle1._radians-angle2._radians;
  1185. }
  1186. this.selectCircleMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
  1187. this.selectCircleMesh.rotation.y+=angle1._radians-angle2._radians;
  1188. this.currentModelMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL);
  1189. this.currentModelMesh.rotation.y+=angle1._radians-angle2._radians;
  1190. this.currentModelMesh.angle=this.currentModelMesh.rotation.y;
  1191. this.drags.modelStartPosition = this.drags.moveModelPosition;
  1192. }
  1193. //软饰
  1194. else if((this.currentSelectMesh.name=="photo"||this.currentSelectMesh.name.indexOf("picture-")==0))
  1195. {
  1196. var m_pt=this.getWallPlanePosition();
  1197. if(m_pt!=null)
  1198. {
  1199. var temp_last=null;
  1200. var temp_pt =new BABYLON.Vector3(this.currentSelectMesh.position.x,this.currentSelectMesh.position.y,this.currentSelectMesh.position.z);
  1201. if(this.currentSelectMesh.lastPos!=null)
  1202. {
  1203. temp_last=new BABYLON.Vector3(this.currentSelectMesh.lastPos.x,this.currentSelectMesh.lastPos.y,this.currentSelectMesh.lastPos.z);
  1204. var diff2=m_pt.point.subtract(this.currentSelectMesh.lastPos);
  1205. this.currentSelectMesh.lastPos=m_pt.point;
  1206. this.currentSelectMesh.position.addInPlace(diff2);
  1207. }
  1208. else
  1209. {
  1210. this.currentSelectMesh.lastPos=m_pt.point;
  1211. }
  1212. this.currentSelectMesh.computeWorldMatrix(true);
  1213. this.currentSelectMesh.refreshBoundingInfo();
  1214. if(this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld.y>this.parameter.wallHeight||this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld.y<0)
  1215. {
  1216. this.currentSelectMesh.lastPos=temp_last;
  1217. this.currentSelectMesh.position=temp_pt;
  1218. }
  1219. else
  1220. {
  1221. var photoFrameMesh = this.layer3D.modelLoader.currentPhotoMesh;
  1222. if(m_pt.index==photoFrameMesh.planeindex)
  1223. {
  1224. for(var i=0;i<this.collidableMeshes.length;++i)
  1225. {
  1226. if(i==photoFrameMesh.planeindex)
  1227. {
  1228. continue;
  1229. }
  1230. if(this.collidableMeshes[i].intersectsMesh(this.currentSelectMesh, true))
  1231. {
  1232. this.currentSelectMesh.lastPos=temp_last;
  1233. this.currentSelectMesh.position=temp_pt;
  1234. break;
  1235. }
  1236. }
  1237. }
  1238. else
  1239. {
  1240. var temprotation=this.currentSelectMesh.rotation.y;
  1241. this.currentSelectMesh.rotation.y=this.collidableMeshes[m_pt.index].rotation.y;
  1242. if(this.collidableMeshes[photoFrameMesh.planeindex].intersectsMesh(this.currentSelectMesh, true))
  1243. {
  1244. this.currentSelectMesh.lastPos=temp_last;
  1245. this.currentSelectMesh.position=temp_pt;
  1246. this.currentSelectMesh.rotation.y=temprotation;
  1247. }
  1248. else
  1249. {
  1250. this.currentSelectMesh.computeWorldMatrix(true);
  1251. this.currentSelectMesh.refreshBoundingInfo();
  1252. var pos=this.currentSelectMesh.position;
  1253. 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));
  1254. join=new BABYLON.Vector3(join.x,pos.y,join.y);
  1255. var diffplane=join.subtract(pos);
  1256. var add=0;
  1257. while(!this.collidableMeshes[m_pt.index].intersectsMesh(this.currentSelectMesh, true))
  1258. {
  1259. pos.addInPlace(new BABYLON.Vector3(diffplane.x*0.1,diffplane.y*0.1,diffplane.z*0.1));
  1260. ++add;
  1261. if(add>19)
  1262. {
  1263. //alert(2851);
  1264. break;
  1265. }
  1266. this.currentSelectMesh.position=pos;
  1267. this.currentSelectMesh.computeWorldMatrix(true);
  1268. this.currentSelectMesh.refreshBoundingInfo();
  1269. }
  1270. var fontpt=this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.currentSelectMesh.frontindex];
  1271. 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});
  1272. if(this.collidableMeshes[m_pt.index].toward!=toward2)
  1273. {
  1274. this.currentSelectMesh.rotation.y+=Math.PI;
  1275. }
  1276. if(this.currentSelectMesh.rotation.y>=2*Math.PI)
  1277. {
  1278. this.currentSelectMesh.rotation.y-=2*Math.PI;
  1279. }
  1280. photoFrameMesh.planeindex=m_pt.index;
  1281. }
  1282. }
  1283. }
  1284. }
  1285. }
  1286. //移动模型
  1287. else
  1288. {
  1289. //判断选择的模型是否可以发生碰撞,true表示不能,false表示可以
  1290. var flag=true;
  1291. //this.currentSelectMesh.position = new BABYLON.Vector3(this.drags.moveModelPosition.x, this.drags.moveModelPosition.y, this.drags.moveModelPosition.z);
  1292. this.currentSelectMesh.position.addInPlace(new BABYLON.Vector3(diff.x,0,diff.z));
  1293. //移动模型上面的info标记
  1294. if(this.currentInfoMesh!=null)
  1295. {
  1296. this.currentInfoMesh.position= new BABYLON.Vector3(this.currentSelectMesh.position.x, this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld.y+30, this.currentSelectMesh.position.z);
  1297. }
  1298. //移动模型下面的圈圈
  1299. if(this.selectCircleMesh!=null)
  1300. {
  1301. this.selectCircleMesh.position.x=this.currentSelectMesh.position.x;
  1302. this.selectCircleMesh.position.z=this.currentSelectMesh.position.z;
  1303. }
  1304. this.currentSelectMesh.computeWorldMatrix(true);
  1305. this.currentSelectMesh.refreshBoundingInfo();
  1306. //判断模型是否发生碰撞,第一次加载的模型可以和其他模型重合
  1307. var collidableMesh=null;
  1308. for(var i=0;i<this.collidableMeshes.length;++i)
  1309. {
  1310. if(this.currentSelectMesh==this.collidableMeshes[i])
  1311. {
  1312. continue;
  1313. }
  1314. if (this.currentSelectMesh.intersectsMesh(this.collidableMeshes[i], true))
  1315. {
  1316. /*
  1317. 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)
  1318. {
  1319. break;
  1320. }
  1321. */
  1322. flag=false;
  1323. if(this.currentSelectMesh.iscollision||this.collidableMeshes[i].iscollision)
  1324. {
  1325. if(this.collidableMeshes[i].name!="wallplane")
  1326. {
  1327. flag=true;
  1328. }
  1329. collidableMesh=this.collidableMeshes[i];
  1330. }
  1331. //else if(this.collidableMeshes[i].name=="wallplane")
  1332. //{
  1333. // collidableMesh=this.collidableMeshes[i];
  1334. //}
  1335. break;
  1336. }
  1337. }
  1338. //当第一次加载的模型某个时刻不与任何模型重合时,就正常了。
  1339. if(flag)
  1340. {
  1341. if(this.currentSelectMesh.iscollision&&!collidableMesh)
  1342. {
  1343. this.currentSelectMesh.iscollision=false;
  1344. this.collidableMeshes.push(this.currentSelectMesh);
  1345. }
  1346. this.drags.modelStartPosition = new BABYLON.Vector3(this.currentSelectMesh.position.x, this.currentSelectMesh.position.y, this.currentSelectMesh.position.z);
  1347. }
  1348. else
  1349. {
  1350. /*
  1351. //自动靠墙
  1352. if(collidableMesh!=null&&collidableMesh.name=="wallplane")
  1353. {
  1354. var angle = this.getAngleFromWallPlane(collidableMesh);
  1355. this.currentSelectMesh.rotation.y=angle;
  1356. this.currentSelectMesh.angle=angle;
  1357. }
  1358. */
  1359. this.currentSelectMesh.position = new BABYLON.Vector3(this.drags.modelStartPosition.x, this.drags.modelStartPosition.y, this.drags.modelStartPosition.z);
  1360. //移动模型上面的info标记
  1361. if(this.currentInfoMesh!=null)
  1362. {
  1363. this.currentInfoMesh.position= new BABYLON.Vector3(this.currentSelectMesh.position.x, this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld.y+30, this.currentSelectMesh.position.z);
  1364. }
  1365. //移动模型下面的圈圈
  1366. if(this.selectCircleMesh!=null)
  1367. {
  1368. this.selectCircleMesh.position.x=this.currentSelectMesh.position.x;
  1369. this.selectCircleMesh.position.z=this.currentSelectMesh.position.z;
  1370. }
  1371. this.currentSelectMesh.computeWorldMatrix(true);
  1372. this.currentSelectMesh.refreshBoundingInfo();
  1373. }
  1374. }
  1375. evt.stopPropagation();
  1376. };
  1377. //针对相框、壁纸
  1378. Action3D.prototype.createArrows2=function()
  1379. {
  1380. min=this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld;
  1381. max=this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld;
  1382. var center=this.currentSelectMesh._boundingInfo.boundingBox.center;
  1383. var points=[];
  1384. points[0]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].z};
  1385. points[1]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].z};
  1386. points[2]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].z};
  1387. points[3]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].z};
  1388. var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
  1389. var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
  1390. var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
  1391. var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
  1392. this.arrows.orgdownPosition =new BABYLON.Vector3(down.x ,down.y,down.z);
  1393. this.arrows.orgtopPosition =new BABYLON.Vector3(top.x ,top.y,top.z);
  1394. this.arrows.orgleftPosition =new BABYLON.Vector3(left.x ,left.y,left.z);
  1395. this.arrows.orgrightPosition=new BABYLON.Vector3(right.x,right.y,right.z);
  1396. down=this.arrows.orgdownPosition.add(new BABYLON.Vector3(0,0,-this.parameter.arrowinterval));
  1397. top=this.arrows.orgtopPosition.add(new BABYLON.Vector3(0,0,this.parameter.arrowinterval));
  1398. left=this.arrows.orgleftPosition.add(new BABYLON.Vector3(-this.parameter.arrowinterval,0,0));
  1399. right=this.arrows.orgrightPosition.add(new BABYLON.Vector3(this.parameter.arrowinterval,0,0));
  1400. down =new BABYLON.Vector2(down.x ,down.z);
  1401. top =new BABYLON.Vector2(top.x ,top.z);
  1402. left =new BABYLON.Vector2(left.x ,left.z);
  1403. right=new BABYLON.Vector2(right.x,right.z);
  1404. var infoheight=this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.y/2;
  1405. var arrowtexture = new BABYLON.Texture('data:my_image_name1', this.scene, true,
  1406. true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
  1407. null, null, this.parameter.arrow3DImgUrl, true);
  1408. this.arrows.downMesh=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, this.scene, false);
  1409. this.arrows.downMesh.material =new BABYLON.StandardMaterial('newMaterial', this.scene);
  1410. this.arrows.downMesh.material.diffuseTexture = arrowtexture;
  1411. this.arrows.downMesh.position= new BABYLON.Vector3(down.x, infoheight, down.y);
  1412. this.arrows.downMesh.rotation.y=-Math.PI/2;
  1413. this.arrows.downMesh.rotation.z=Math.PI;
  1414. this.arrows.downMesh.name="downarrow";
  1415. this.arrows.topMesh=this.arrows.downMesh.clone();
  1416. this.arrows.topMesh.position= new BABYLON.Vector3(top.x, infoheight, top.y);
  1417. this.arrows.topMesh.rotation.y=-3*Math.PI/2;
  1418. this.arrows.topMesh.rotation.z=Math.PI;
  1419. this.arrows.topMesh.name="toparrow";
  1420. this.arrows.leftMesh=this.arrows.downMesh.clone();
  1421. this.arrows.leftMesh.position= new BABYLON.Vector3(left.x, infoheight, left.y);
  1422. this.arrows.leftMesh.rotation.y=0;
  1423. this.arrows.leftMesh.rotation.z=Math.PI;
  1424. this.arrows.leftMesh.name="leftarrow";
  1425. this.arrows.rightMesh=this.arrows.downMesh.clone();
  1426. this.arrows.rightMesh.position= new BABYLON.Vector3(right.x, infoheight, right.y);
  1427. var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
  1428. this.arrows.rightMesh.rotation.y=-Math.PI;
  1429. this.arrows.rightMesh.rotation.z=Math.PI;
  1430. this.arrows.rightMesh.name="rightarrow";
  1431. this.arrows.lineTopToDown={x:down.x};
  1432. this.arrows.lineLeftToRight={y:left.y};
  1433. this.arrowMeshes[0]=this.arrows.downMesh;
  1434. this.arrowMeshes[1]=this.arrows.topMesh;
  1435. this.arrowMeshes[2]=this.arrows.leftMesh;
  1436. this.arrowMeshes[3]=this.arrows.rightMesh;
  1437. };
  1438. Action3D.prototype.createArrows=function()
  1439. {
  1440. this.isArrow=true;
  1441. min=this.currentSelectMesh._boundingInfo.boundingBox.minimumWorld;
  1442. max=this.currentSelectMesh._boundingInfo.boundingBox.maximumWorld;
  1443. //heigh=Math.abs(max.z-min.z);
  1444. //length=Math.abs(max.x-min.x);
  1445. var center=this.currentSelectMesh._boundingInfo.boundingBox.center;
  1446. var points=[];
  1447. points[0]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[0]].z};
  1448. points[1]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[1]].z};
  1449. points[2]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[2]].z};
  1450. points[3]={x:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].x,y:this.currentSelectMesh._boundingInfo.boundingBox.vectorsWorld[this.vertexPoints[3]].z};
  1451. var down =new BABYLON.Vector3((points[0].x+points[3].x)/2,center.y,(points[0].y+points[3].y)/2);
  1452. var top =new BABYLON.Vector3((points[1].x+points[2].x)/2,center.y,(points[1].y+points[2].y)/2);
  1453. var left =new BABYLON.Vector3((points[1].x+points[0].x)/2,center.y,(points[1].y+points[0].y)/2);
  1454. var right=new BABYLON.Vector3((points[2].x+points[3].x)/2,center.y,(points[2].y+points[3].y)/2);
  1455. this.arrows.orgdownPosition =new BABYLON.Vector3(down.x ,down.y,down.z);
  1456. this.arrows.orgtopPosition =new BABYLON.Vector3(top.x ,top.y,top.z);
  1457. this.arrows.orgleftPosition =new BABYLON.Vector3(left.x ,left.y,left.z);
  1458. this.arrows.orgrightPosition=new BABYLON.Vector3(right.x,right.y,right.z);
  1459. down =new BABYLON.Vector2(down.x ,down.z);
  1460. top =new BABYLON.Vector2(top.x ,top.z);
  1461. left =new BABYLON.Vector2(left.x ,left.z);
  1462. right=new BABYLON.Vector2(right.x,right.z);
  1463. var infoheight=this.currentModelMesh._boundingInfo.boundingBox.maximumWorld.y/2;
  1464. var d1=BABYLON.Vector2.Distance(down,new BABYLON.Vector2(center.x,center.z));
  1465. var diff1=this.arrows.orgdownPosition.subtract(center);
  1466. //down=this.arrows.orgdownPosition.addInPlace(diff1);
  1467. down=this.arrows.orgdownPosition.add(new BABYLON.Vector3(diff1.x/d1*this.parameter.arrowinterval,0,diff1.z/d1*this.parameter.arrowinterval));
  1468. var d2=BABYLON.Vector2.Distance(top,new BABYLON.Vector2(center.x,center.z));
  1469. var diff2=this.arrows.orgtopPosition.subtract(center);
  1470. //top=this.arrows.orgtopPosition.addInPlace(diff2);
  1471. //top.addInPlace(diff2);
  1472. top=this.arrows.orgtopPosition.add(new BABYLON.Vector3(diff2.x/d2*this.parameter.arrowinterval,0,diff2.z/d2*this.parameter.arrowinterval));
  1473. var d3=BABYLON.Vector2.Distance(left,new BABYLON.Vector2(center.x,center.z));
  1474. var diff3=this.arrows.orgleftPosition.subtract(center);
  1475. //left=this.arrows.orgleftPosition.addInPlace(diff3);
  1476. //left.addInPlace(diff3);
  1477. left=this.arrows.orgleftPosition.add(new BABYLON.Vector3(diff3.x/d3*this.parameter.arrowinterval,0,diff3.z/d3*this.parameter.arrowinterval));
  1478. var d4=BABYLON.Vector2.Distance(right,new BABYLON.Vector2(center.x,center.z));
  1479. var diff4=this.arrows.orgrightPosition.subtract(center);
  1480. //right=this.arrows.orgrightPosition.addInPlace(diff4);
  1481. //right.addInPlace(diff4);
  1482. right=this.arrows.orgrightPosition.add(new BABYLON.Vector3(diff4.x/d4*this.parameter.arrowinterval,0,diff4.z/d4*this.parameter.arrowinterval));
  1483. down =new BABYLON.Vector2(down.x ,down.z);
  1484. top =new BABYLON.Vector2(top.x ,top.z);
  1485. left =new BABYLON.Vector2(left.x ,left.z);
  1486. right=new BABYLON.Vector2(right.x,right.z);
  1487. var arrowtexture = new BABYLON.Texture('data:my_image_name1', this.scene, true,
  1488. true, BABYLON.Texture.BILINEAR_SAMPLINGMODE,
  1489. null, null, this.parameter.arrow3DImgUrl, true);
  1490. this.arrows.downMesh=BABYLON.Mesh.CreateCylinder("arrow1", 0.00001, 24, 24, 64, 12, this.scene, false);
  1491. this.arrows.downMesh.material =new BABYLON.StandardMaterial('newMaterial', this.scene);
  1492. this.arrows.downMesh.material.diffuseTexture = arrowtexture;
  1493. this.arrows.downMesh.position= new BABYLON.Vector3(down.x, infoheight, down.y);
  1494. var angle1=BABYLON.Angle.BetweenTwoPoints(down,top);
  1495. this.arrows.downMesh.rotation.y=-angle1._radians;
  1496. this.arrows.downMesh.rotation.z=Math.PI;
  1497. this.arrows.downMesh.name="downarrow";
  1498. this.arrows.topMesh=this.arrows.downMesh.clone();
  1499. this.arrows.topMesh.position= new BABYLON.Vector3(top.x, infoheight, top.y);
  1500. var angle2=BABYLON.Angle.BetweenTwoPoints(top,down);
  1501. this.arrows.topMesh.rotation.y=-angle2._radians;
  1502. this.arrows.topMesh.rotation.z=Math.PI;
  1503. this.arrows.topMesh.name="toparrow";
  1504. this.arrows.leftMesh=this.arrows.downMesh.clone();
  1505. this.arrows.leftMesh.position= new BABYLON.Vector3(left.x, infoheight, left.y);
  1506. var angle3=BABYLON.Angle.BetweenTwoPoints(left,right);
  1507. this.arrows.leftMesh.rotation.y=-angle3._radians;
  1508. this.arrows.leftMesh.rotation.z=Math.PI;
  1509. this.arrows.leftMesh.name="leftarrow";
  1510. this.arrows.rightMesh=this.arrows.downMesh.clone();
  1511. this.arrows.rightMesh.position= new BABYLON.Vector3(right.x, infoheight, right.y);
  1512. var angle4=BABYLON.Angle.BetweenTwoPoints(right,left);
  1513. this.arrows.rightMesh.rotation.y=-angle4._radians;
  1514. this.arrows.rightMesh.rotation.z=Math.PI;
  1515. this.arrows.rightMesh.name="rightarrow";
  1516. this.arrows.lineTopToDown=this.calculateLine.createLine(down,top);
  1517. this.arrows.lineLeftToRight=this.calculateLine.createLine(left,right);
  1518. this.arrowMeshes[0]=this.arrows.downMesh;
  1519. this.arrowMeshes[1]=this.arrows.topMesh;
  1520. this.arrowMeshes[2]=this.arrows.leftMesh;
  1521. this.arrowMeshes[3]=this.arrows.rightMesh;
  1522. };
  1523. Action3D.prototype.clearArrow=function()
  1524. {
  1525. if(this.arrows.downMesh != null)
  1526. {
  1527. this.arrows.downMesh.dispose();
  1528. }
  1529. if(this.arrows.topMesh != null)
  1530. {
  1531. this.arrows.topMesh.dispose();
  1532. }
  1533. if(this.arrows.leftMesh != null)
  1534. {
  1535. this.arrows.leftMesh.dispose();
  1536. }
  1537. if(this.arrows.rightMesh != null)
  1538. {
  1539. this.arrows.rightMesh.dispose();
  1540. }
  1541. this.isArrow=false;
  1542. };
  1543. Action3D.prototype.onCameraWheel=function(e)
  1544. {
  1545. var type=e.type;
  1546. var delta;
  1547. if (type == 'DOMMouseScroll' || type == 'mousewheel') {
  1548. delta = (e.wheelDelta) ? (e.wheelDelta / 120)*2 : -(e.detail || 0) / 3*2;
  1549. }
  1550. var mark=document.getElementById("mark");
  1551. var markpy=parseInt(mark.style.marginTop);
  1552. markpy-=delta;
  1553. if(markpy<MixMark)
  1554. {
  1555. markpy=MixMark;
  1556. }
  1557. else if(markpy>MaxMark)
  1558. {
  1559. markpy=MaxMark;
  1560. }
  1561. mark.style.marginTop=markpy+"px";
  1562. };
  1563. Action3D.prototype.active = function ()
  1564. {
  1565. this.canvas.addEventListener("mousedown", Action3D.prototype.onPointerDown.bind(this), false);
  1566. this.canvas.addEventListener("mouseup", Action3D.prototype.onPointerUp.bind(this), false);
  1567. this.canvas.addEventListener("mousemove", Action3D.prototype.onPointerMove.bind(this), false);
  1568. this.canvas.addEventListener("mousewheel", Action3D.prototype.onCameraWheel.bind(this),false);
  1569. };
  1570. Action3D.prototype.onDispose = function ()
  1571. {
  1572. this.canvas.removeEventListener("mousedown", onPointerDown);
  1573. this.canvas.removeEventListener("mouseup", onPointerUp);
  1574. this.canvas.removeEventListener("mousemove", onPointerMove);
  1575. this.canvas.removeEventListener("mousewheel", onCameraWheel);
  1576. };