function Symbol3D() { this.canvas; this.engine; this.scene; this.camera; this.light; this.groundY=-10; this.tiledGround; this.ground; this.skybox; this.lock=false; this.roomWallMeshes=[]; this.groundLength=6000; this.groundWidth=6000; this.doorBottom=60; this.windowBottom=100; this.doorHeigh=100; this.windowHeigh=50; this.doorThick=34; this.wallHeigh=150; this.wallThick=30; this.boardThick=15; this.baseSymbolThick; this.groundMaterial; this.skyboxMaterial; this.wallmaterial; this.floormaterial; this.frameMaterial; this.doorknobMaterial; this.windowframeMaterial; this.groundTexture="images/checkerboard.jpg"; //this.floorStyle={floorTexture:"images/textures/floor/floor0.jpg",floorColor:null,type:0}; this.floorStyle={floorTexture:"images/textures/floor/floor0.jpg",floorColor:null}; this.wallTexture=null; this.skyTexture="images/textures/skyboxes/sky0"; this.wallpicture_pre="images/textures/picture/"; this.meshManager={collidables:[],firstMeshes:[],arrowMeshes:[],glassBoxMeshes:[],selectFurnitureMesh:null,selectMesh:false,editProduct:false,infoSize:15,furnitureScal:0.2,selectCircle:null,rotator:null,angle:0}; this.paintPlane={id:null,value:null,beginPaint:false,currentId:null}; this.paintWall={value:null,beginPaint:false}; this.paintSet=[]; this.wallSet={submeshes:[],subMaterials:[],verticesStart:0,indexStart:0}; this.phoSet={start:false,photoFrameMesh:null,phochild:null,pts:null}; }; //添加天空 Symbol3D.prototype.addSkybox = function () { this.skybox = BABYLON.Mesh.CreateBox("skyBox", 8000, this.scene); this.setskyboxMaterial(); this.skybox.material = this.skyboxMaterial; }; Symbol3D.prototype.refreshSkybox = function () { this.setskyboxMaterial(); this.skybox.material = this.skyboxMaterial; }; //添加地面 Symbol3D.prototype.addGround = function () { // make a ground this.ground = BABYLON.Mesh.CreateBox("Ground", 1, this.scene); this.ground.scaling = new BABYLON.Vector3(this.groundLength, 10, this.groundWidth); this.ground.position.y =this.groundY/2 this.ground.checkCollisions = true; this.ground.material = this.groundMaterial; }; Symbol3D.prototype.refreshGround = function () { this.setgroundmaterial(); this.ground.material = this.groundMaterial; }; //添加地板 Symbol3D.prototype.drawFloor= function(points,id) { var shape; for(var i=0;i0;--i) { pt1=new BABYLON.Vector3(inpoints[i].x, 0, inpoints[i].y); pt2=new BABYLON.Vector3(inpoints[i-1].x, 0, inpoints[i-1].y); var toward=-1*towards[num]; var mesh=this.drawSideWall(pt1,pt2); towards.push(toward); this.meshManager.collidables[this.meshManager.collidables.length-1].toward=toward; points.push({point1:inpoints[i],point2:inpoints[i-1]}); --num; wallmeshes.push(mesh); collindex.push(mesh.planindex); } pt1=new BABYLON.Vector3(inpoints[0].x, 0, inpoints[0].y); pt2=new BABYLON.Vector3(outpoints[0].x, 0, outpoints[0].y); var mesh=this.drawSideWall(pt1,pt2); toward=calculateLine.getToward(inpoints[0],outpoints[0],outpoints[1]); towards.push(-1*toward); this.meshManager.collidables[this.meshManager.collidables.length-1].toward=-1*toward; points.push({point1:inpoints[0],point2:outpoints[0]}); wallmeshes.push(mesh); collindex.push(mesh.planindex); var _topWallmesh=BABYLON.Mesh.MergeMeshes(topWallmeshes); var topCSG = BABYLON.CSG.FromMesh(_topWallmesh); var finalTopMesh = topCSG.toMesh("wallopen",this.wallmaterial, this.scene,true); _topWallmesh.dispose(); _topWallmesh=null; this.roomWallMeshes.push(finalTopMesh); var wallmesh=BABYLON.Mesh.MergeMeshes(wallmeshes); wallmesh.subMeshes = []; this.wallSet.subMaterials=[]; for(var i=0;ithis.paintSet[i].materialId) { wall.material.subMaterials[this.paintSet[i].materialId]=this.paintSet[i].material; //break; } } wallmesh.dispose(); wallmesh=null; this.roomWallMeshes.push(wall); }; //添加墙顶 Symbol3D.prototype.drawTopWall=function(pt1,pt2,pt3,pt4) { var mesh = new BABYLON.Mesh("mesh", this.scene); //mesh.material = this.wallmaterial; var path1 = []; var path2 = []; path1.push(pt1); path1.push(pt2); path2.push(pt3); path2.push(pt4); // positions var positions = []; for (var i = 0; i < path1.length; i++) { positions.push(path1[i].x, path1[i].y, path1[i].z); positions.push(path2[i].x, path2[i].y, path2[i].z); }; // indices var indices = []; for (var i = 0; i < path1.length * 2 - 2 ; i+=2) { indices.push(i, i+1, i+2); indices.push(i+3, i+2, i+1); }; // normals var normals = []; BABYLON.VertexData.ComputeNormals(positions, indices, normals); // mesh var colors = [ 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, ]; mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors); var uvs=[[0,0],[1,0],[1,1],[0,1]]; mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs); mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false); mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false); mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false); mesh.setIndices(indices); mesh.material = this.wallmaterial; return mesh; }; //添加墙的侧面 Symbol3D.prototype.drawSideWall=function(pt1,pt2) { var mesh = new BABYLON.Mesh("mesh", this.scene); //mesh.material = this.wallmaterial; this.createwallPlane(new BABYLON.Vector2(pt1.x,pt1.z),new BABYLON.Vector2(pt2.x,pt2.z)); var path1 = []; var path2 = []; path1.push(pt1); path1.push(pt2); var pt3=new BABYLON.Vector3(pt1.x,this.wallHeigh, pt1.z); var pt4=new BABYLON.Vector3(pt2.x,this.wallHeigh, pt2.z); path2.push(pt3); path2.push(pt4); // positions var positions = []; for (var i = 0; i < path1.length; i++) { positions.push(path1[i].x, path1[i].y, path1[i].z); positions.push(path2[i].x, path2[i].y, path2[i].z); }; // indices var indices = []; for (var i = 0; i < path1.length * 2 - 2 ; i+=2) { indices.push(i, i+1, i+2); indices.push(i+3, i+2, i+1); }; // normals var normals = []; BABYLON.VertexData.ComputeNormals(positions, indices, normals); var uvs=[[0,0],[1,0],[1,1],[0,1]]; mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs); var colors = [ 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, ]; // mesh mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors); mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false); mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false); mesh.setIndices(indices); mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, uvs, false); mesh.material = this.wallmaterial; this.wallSet.submeshes.push({verticesStart:this.wallSet.verticesStart, verticesCount:mesh.getTotalVertices(), indexStart:this.wallSet.indexStart, indexCount:mesh.getTotalIndices()}); this.wallSet.verticesStart+=mesh.getTotalVertices(); this.wallSet.indexStart+=mesh.getTotalIndices(); mesh.planindex=this.meshManager.collidables.length-1; return mesh; }; //添加闭合的墙 Symbol3D.prototype.drawCloseWallSymbols=function(outpoints,inpoints,symbols,type,id) { var wallmeshes = []; var topWallmeshes=[]; var pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8; this.wallSet.submeshes=[]; this.wallSet.verticesStart=0; this.wallSet.indexStart=0; this.wallSet.subMaterials=[]; var calculateLine=layer.calculateLine; //var calculateLine=new CalculateLine(); var towards=[]; var points=[]; var collindex=[]; for(var i=0;ithis.paintSet[i].materialId) { wall.material.subMaterials[this.paintSet[i].materialId]=this.paintSet[i].material; //break; } } this.roomWallMeshes.push(wall); }; //添加画,图 Symbol3D.prototype.showPicture=function(src) { var plan = BABYLON.Mesh.CreatePlane("picture-"+src, 1, this.scene); plan.scaling.x=50; plan.scaling.y=40; plan.position=new BABYLON.Vector3(0, 0, 0); var material = new BABYLON.StandardMaterial("planmaterial", this.scene); material.diffuseTexture = new BABYLON.Texture(this.wallpicture_pre+src, this.scene); material.bumpTexture = new BABYLON.Texture("images/floor1.png", this.scene); plan.material=material; plan.rotation.x=Math.PI/2; this.meshManager.collidables.push(plan); }; //添加镜框 Symbol3D.prototype.showPhoFrame=function(src) { BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes) { newMeshes[0].scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal); newMeshes[0].computeWorldMatrix(true); newMeshes[0].refreshBoundingInfo(); newMeshes[0].position=new BABYLON.Vector3(0,-100,0); newMeshes[0].name="pho-"+src; newMeshes[0].thice=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.z-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.z); newMeshes[0].firstHeigh=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.y-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.y); if(this.phoSet.photoFrameMesh!=null) { this.phoSet.photoFrameMesh.dispose(); this.phoSet.photoFrameMesh=null; } this.phoSet.photoFrameMesh=newMeshes[0]; //this.phoSet.photoFrameMesh.showBoundingBox=true; this.phoSet.photoFrameMesh.height=newMeshes[0].firstHeigh; this.phoSet.photoFrameMesh.length=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.x-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.x); this.phoSet.photoFrameMesh.visibility=0; this.phoSet.start=true; document.getElementById("container3d").style.cursor="url('images/brush.ico'),auto"; for(var i=0;ithis.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.z) { this.phoSet.photoFrameMesh.frontindex=i; break; } } this.engine.hideLoadingUI(); }.bind(this)); }; //初始化时,会有一些三维模型 Symbol3D.prototype.showProductfirst=function(src,position,rotation) { BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes) { var mesh; if(newMeshes.length>1) { mesh=BABYLON.Mesh.MergeMeshes(newMeshes); } else { mesh=newMeshes[0]; } //mesh.scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal); //mesh.position=position; //mesh.rotation=rotation; var name=src.replace(".babylon",""); mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]); mesh.position=position; //mesh.material.specularColor=new BABYLON.Color3(0.8,0.8,0.8); //if(mesh.name=="cabinet") if(layer.parameter.cabinet.indexOf(name+",")>-1) { var glassMesh = BABYLON.Mesh.CreateBox("box", 1, this.scene); glassMesh.scaling.x=Math.abs(mesh._boundingInfo.maximum.x-mesh._boundingInfo.minimum.x)*mesh.scaling.x-5; glassMesh.scaling.y=80; glassMesh.scaling.z=Math.abs(mesh._boundingInfo.maximum.z-mesh._boundingInfo.minimum.z)*mesh.scaling.z/1.2; glassMesh.position.x=position.x; glassMesh.position.y=Math.abs(mesh._boundingInfo.maximum.y-mesh._boundingInfo.minimum.y)*mesh.scaling.y-40; glassMesh.position.z=position.z-2; glassMesh.visibility = 0.3; glassMesh.name="mirror"; this.meshManager.glassBoxMeshes.push(glassMesh); } for(var i=0;i21) { this.engine.hideLoadingUI(); initMesh=0; } this.meshManager.collidables.push(mesh); }.bind(this)); return this.meshManager.collidables[this.meshManager.collidables.length-1]; }; //加载三维模型 Symbol3D.prototype.showProduct=function(src) { this.engine.displayLoadingUI(); this.engine.loadingUIText = "正在加载家具,请稍等!"; //this.engine.loadingUIBackgroundColor = "red"; BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes) { var mesh; if(newMeshes.length>1) { mesh=BABYLON.Mesh.MergeMeshes(newMeshes); } else { mesh=newMeshes[0]; } //mesh.scaling=new BABYLON.Vector3(this.meshManager.furnitureScal,this.meshManager.furnitureScal,this.meshManager.furnitureScal); //mesh.scaling=new BABYLON.Vector3(10,10,10); var name=src.replace(".babylon",""); mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]); //mesh.position=new BABYLON.Vector3(0, 60, 0); //newMeshes[0].showBoundingBox=true; mesh.name=src; for(var i=0;iBitte haben Sie einen Moment Geduld, die benötigten Daten werden geladen... * */ }; //每个墙添加plane,防止模型与墙重合 Symbol3D.prototype.createwallPlane=function (point1,point2) { var p1=new BABYLON.Vector2(point1.x, point1.y); var p2=new BABYLON.Vector2(point2.x, point2.y); var distance= BABYLON.Vector2.Distance(p1,p2); //var plan = BABYLON.Mesh.CreatePlane("plane", distance, this.scene); var plan = BABYLON.Mesh.CreatePlane("plane", 1, this.scene); plan.scaling.x=distance; //plan.scaling.y =1; plan.scaling.y =this.wallHeigh; plan.material = this.wallmaterial; //plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,0.5, (p1.y+p2.y)/2); plan.position=new BABYLON.Vector3((p1.x+p2.x)/2,this.wallHeigh/2, (p1.y+p2.y)/2); var angle=BABYLON.Angle.BetweenTwoPoints(p1,p2); plan.rotation.y=-angle._radians; plan.visibility=0; plan.pts={point1:point1,point2:point2}; plan.planindex=this.meshManager.collidables.length; this.meshManager.collidables.push(plan); //plan.dispose(); }; Symbol3D.prototype.clearAllSymbols=function() { for(var i=0;i6) { top=radius-5; } var selectmat=new BABYLON.StandardMaterial("selectMat", this.scene); selectmat.alpha = 1.0; selectmat.diffuseColor = new BABYLON.Color3.Green(); selectmat.backFaceCulling = false; this.meshManager.selectCircle = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, this.scene); this.meshManager.selectCircle.material = selectmat; this.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,0,currentMesh._boundingInfo.boundingBox.center.z); if(currentMesh.name.indexOf("pho-")!=0&¤tMesh.name.indexOf("picture-")!=0) { this.meshManager.rotator = new BABYLON.Mesh.CreatePlane("rotator", 1, this.scene); this.meshManager.rotator.scaling.x=28; this.meshManager.rotator.scaling.y=14; this.meshManager.rotator.material = new BABYLON.StandardMaterial("buttons", this.scene); this.meshManager.rotator.material.diffuseTexture = new BABYLON.Texture("images/rotate.png", this.scene); this.meshManager.rotator.material.diffuseTexture.hasAlpha = !0; this.meshManager.rotator.material.backFaceCulling = !1; } this.meshManager.rotator.position.z = -radius; this.meshManager.rotator.position.y = 0; this.meshManager.rotator.parent = this.meshManager.selectCircle; this.meshManager.rotator.position.y = Math.PI; this.meshManager.rotator.rotation.x = Math.PI / 4; }; Symbol3D.prototype.addEvent = function () { // Events var startingPoint; var lastPosition; var current; //var angle=0; var scene =this.scene var tiledGround=this.tiledGround; var ground =this.ground; var camera =this.camera; var canvas =this.canvas; var currentMesh=null; var collidables=this.meshManager.collidables; var firstMeshes=this.meshManager.firstMeshes; //var editProduct=this.meshManager.editProduct; var infosize =this.meshManager.infoSize; var selectMesh =this.meshManager.selectMesh; var mesh1=this.meshManager.arrowMeshes[0]; var mesh2=this.meshManager.arrowMeshes[1]; var mesh3=this.meshManager.arrowMeshes[2]; var mesh4=this.meshManager.arrowMeshes[3]; //var furnitureMesh=this.meshManager.selectFurnitureMesh; var wallHeigh=this.wallHeigh; var createArrow=false; var image="images/product/info.png"; var imagearrow="images/product/arrow.png"; var imageflip="images/product/infoGroup.png"; var info=null; var infoextend=30; var selectCircleY=0; var infoheigh=3; var min,max; var top,down,left,right; var vertexPoints=[]; //var length,heigh; //line1是上下arrow的连线,line2是左右两个arrow的连线 var line1,line2; var templane=null; var interval=25; var arrowdown,arrowtop,arrowleft,arrowright; var measuremesh1=null,measuremesh2=null,measuremesh3=null,measuremesh4=null,measuremesh5=null,measuremesh6=null; var olddistance=null; var oldPlanept=null; var measurediff=null; var showpoint,showmesh; var actionmove=false; var actionRotator=false; //var picflip=1; var flipMesh=null; var calculateLine=layer.calculateLine; //var calculateLine=new CalculateLine(); //var curPicPho={target:null,colliMesh:null,distance:0}; var createSelectMat=function() { var mat=new BABYLON.StandardMaterial("selectMat", scene); mat.alpha = 1.0; mat.diffuseColor = new BABYLON.Color3.Green(); mat.backFaceCulling = false; return mat; }; var selectmat = createSelectMat(); collidables.remove = function(elem, all) { for (var i=this.length-1; i>=0; i--) { if (this[i] === elem) { this.splice(i, 1); if(!all) break; } } return this; }; var setProductInfo=function() { var position_x=document.getElementById("position-x"); var position_y=document.getElementById("position-y"); var position_z=document.getElementById("position-z"); var position=my3DEngine.meshManager.selectFurnitureMesh.position; 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"); var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z)); var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowright.x,arrowright.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z)); 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); }; var editProductInfo=function(h,position) { var width=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z)); var length=BABYLON.Vector2.Distance(new BABYLON.Vector2(arrowright.x,arrowright.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z)); var height=h; var positionX=position.x; var positionY=position.y; var positionZ=position.z; var angleY=Math.floor((my3DEngine.meshManager.angle/Math.PI)*180); var rotationy=document.getElementById("rotation-y"); if(angleY<0) { angleY=360+angleY; } 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); }; var setVertex=function(points,min,max) { var y=points[0].y; var y1=points[1].y; var m_points=[]; for(var i=0;i=0||currentMesh.name.indexOf("Window")>=0||currentMesh.name.indexOf("floor")>=0||currentMesh.name=="plane"||currentMesh.name=="skyBox"||(currentMesh.id.indexOf("wall")>=0)||(currentMesh.name=="mesh_merged")) if(currentMesh.name.indexOf("Door")>=0||currentMesh.name.indexOf("Window")>=0||currentMesh.name=="plane"||currentMesh.name=="skyBox") { return true; } else { return false; } }; var getWallPlanePosition = function () { // Use a predicate to get position on the ground var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh.name == "plane"; }); if (pickinfo.hit) { //return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex}; return {point:pickinfo.pickedPoint,index:pickinfo.pickedMesh.planindex}; } return null; }; var getGroundPosition = function () { // Use a predicate to get position on the ground var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return (mesh == tiledGround || mesh == ground ||isnotFurniture(mesh)); }); if (pickinfo.hit) { return pickinfo.pickedPoint; } return null; }; var getGroundPositionFromArrow = function () { // Use a predicate to get position on the ground var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return (mesh == tiledGround || mesh == ground ||isnotFurniture(mesh)||(mesh.id.indexOf("arrow")>-1)); }); if (pickinfo.hit) { return pickinfo.pickedPoint; } return null; }; var boundcontains=function(point,currentMesh) { currentMesh.computeWorldMatrix(true); currentMesh.refreshBoundingInfo(); if(point.x>currentMesh._boundingInfo.boundingBox.maximumWorld.x||point.y>currentMesh._boundingInfo.boundingBox.maximumWorld.z||point.x6) { top=radius-5; } if(my3DEngine.meshManager.selectCircle==null) { if(currentMesh.name.indexOf("pho-")!=0&¤tMesh.name.indexOf("picture-")!=0) { my3DEngine.meshManager.selectCircle = BABYLON.Mesh.CreateLathe('selectCircle', shape , radius,top, scene); my3DEngine.meshManager.selectCircle.material = selectmat; } } else { if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0) { my3DEngine.meshManager.selectCircle.dispose(); my3DEngine.meshManager.selectCircle=null; } } if(currentMesh.name.indexOf("pho-")!=0&¤tMesh.name.indexOf("picture-")!=0) { my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,selectCircleY,currentMesh._boundingInfo.boundingBox.center.z); if(my3DEngine.meshManager.rotator==null) { my3DEngine.meshManager.rotator=createRotator(); } my3DEngine.meshManager.rotator.position.z = -radius; my3DEngine.meshManager.rotator.position.y = selectCircleY; if(my3DEngine.meshManager.selectCircle!=null) { my3DEngine.meshManager.rotator.parent = my3DEngine.meshManager.selectCircle; } my3DEngine.meshManager.rotator.position.y = Math.PI; my3DEngine.meshManager.rotator.rotation.x = Math.PI / 4; } else { if(my3DEngine.meshManager.rotator!=null) { my3DEngine.meshManager.rotator.dispose(); my3DEngine.meshManager.rotator=null; } } if(my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion==null||typeof(my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion) == "undefined") { my3DEngine.meshManager.angle=0; } else { //var angleY=my3DEngine.meshManager.selectFurnitureMesh.rotationQuaternion.y; var angleY=my3DEngine.meshManager.selectFurnitureMesh.rotation.y; if(angleY<0) { angleY=2*Math.PI+angleY; } my3DEngine.meshManager.angle=angleY; } }; var createinfo=function() { var sprite = new BABYLON.SpriteManager("meshManager", image, 6, 128, scene); sprite.isPickable = true; // First animated player info = new BABYLON.Sprite("editFurniture", sprite); info.position= new BABYLON.Vector3(currentMesh.position.x, currentMesh._boundingInfo.boundingBox.maximumWorld.y+infoextend, currentMesh.position.z); //if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0) //{ // info.position.y=(currentMesh._boundingInfo.boundingBox.maximumWorld.y+ currentMesh._boundingInfo.boundingBox.minimumWorld.y)/2; //} info.size = infosize; infoheigh=currentMesh._boundingInfo.boundingBox.maximumWorld.y/2; // click action for player info.actionManager = new BABYLON.ActionManager(scene); info.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickUpTrigger, function () { if(!actionmove) { if(!createArrow) { currentMesh.computeWorldMatrix(true); currentMesh.refreshBoundingInfo(); var configuratorProduct=document.getElementById("configuratorWindow"); configuratorProduct.style.display="block"; /* if(currentMesh.name.indexOf("picture-")==0||currentMesh.name.indexOf("pho-")==0) { createArrows2(currentMesh,scene,imagearrow); document.getElementById("editptrot").innerText="位置"; document.getElementById("item-1").style.display="none"; document.getElementById("rotation-y").style.display="none"; document.getElementById("params-height").style.display="none"; } else { */ createArrows(currentMesh,scene,imagearrow); document.getElementById("editptrot").innerText="位置和角度"; document.getElementById("item-1").style.display=""; document.getElementById("rotation-y").style.display=""; document.getElementById("params-height").style.display=""; //} createArrow=true; info.dispose(); info=null; if(my3DEngine.meshManager.selectCircle!=null) { my3DEngine.meshManager.selectCircle.dispose(); my3DEngine.meshManager.selectCircle=null; if(my3DEngine.meshManager.rotator!=null) { my3DEngine.meshManager.rotator.dispose(); my3DEngine.meshManager.rotator=null; } } editProductInfo(Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.y- currentMesh._boundingInfo.boundingBox.minimumWorld.y),currentMesh.position); } my3DEngine.meshManager.editProduct=true; } })); info.isPickable = true; }; var selectArrow=function() { templane=BABYLON.Mesh.CreatePlane("temp", 1, scene); if(currentMesh.name=="downarrow") { templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.x*my3DEngine.meshManager.selectFurnitureMesh.scaling.x*2; templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2; templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle, BABYLON.Space.LOCAL); templane.position=arrowdown; olddistance=BABYLON.Vector3.Distance(arrowdown,arrowtop); var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z)); var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowright.x,arrowright.z)); if(distance1>distance2) { showpoint=arrowright; showmesh=mesh4; } else { showpoint=arrowleft; showmesh=mesh3; } } else if(currentMesh.name=="toparrow") { templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.x*my3DEngine.meshManager.selectFurnitureMesh.scaling.x*2; templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2; templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle, BABYLON.Space.LOCAL); templane.position=arrowtop; //templane.position=new BABYLON.Vector3(arrowtop.x,arrowtop.y,arrowtop.z); olddistance=BABYLON.Vector3.Distance(arrowdown,arrowtop); var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowleft.x,arrowleft.z)); var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowright.x,arrowright.z)); if(distance1>distance2) { showpoint=arrowright; showmesh=mesh4; } else { showpoint=arrowleft; showmesh=mesh3; } } else if(currentMesh.name=="leftarrow") { /* if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0) { templane.rotate(BABYLON.Axis.Y,Math.PI/2, BABYLON.Space.LOCAL); templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2; templane.scaling.y=10; } else { */ templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle+Math.PI/2, BABYLON.Space.LOCAL); templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.z*my3DEngine.meshManager.selectFurnitureMesh.scaling.z*2; templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2; //} templane.position=arrowleft; //templane.position=new BABYLON.Vector3(arrowleft.x,arrowleft.y,arrowleft.z); olddistance=BABYLON.Vector3.Distance(arrowleft,arrowright); var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z)); var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowdown.x,arrowdown.z)); if(distance1>distance2) { showpoint=arrowdown; showmesh=mesh1; } else { showpoint=arrowtop; showmesh=mesh2; } } else if(currentMesh.name=="rightarrow") { /* if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0) { templane.rotate(BABYLON.Axis.Y,-Math.PI/2, BABYLON.Space.LOCAL); templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2; templane.scaling.y=10; } else { */ templane.rotate(BABYLON.Axis.Y, my3DEngine.meshManager.angle+Math.PI/2, BABYLON.Space.LOCAL); templane.scaling.x=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.z*my3DEngine.meshManager.selectFurnitureMesh.scaling.z*2; templane.scaling.y=my3DEngine.meshManager.selectFurnitureMesh.getBoundingInfo().boundingBox.extendSize.y*my3DEngine.meshManager.selectFurnitureMesh.scaling.y*2; //} templane.position=arrowright; //templane.position=new BABYLON.Vector3(arrowright.x,arrowright.y,arrowright.z); olddistance=BABYLON.Vector3.Distance(arrowleft,arrowright); var distance1= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z)); var distance2= BABYLON.Vector2.Distance(new BABYLON.Vector2(camera.position.x,camera.position.z),new BABYLON.Vector2(arrowdown.x,arrowdown.z)); if(distance1>distance2) { showpoint=arrowdown; showmesh=mesh1; } else { showpoint=arrowtop; showmesh=mesh2; } } measurediff=showmesh.position.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center); var r=new BABYLON.StandardMaterial("materialplane",scene); r.diffuseColor=new BABYLON.Color3.Green(); r.backFaceCulling =false; templane.material=r; oldPlanept=new BABYLON.Vector3(templane.position.x,templane.position.y,templane.position.z); }; var removeinfo=function() { if(info!=null&&!info._isDisposed) { info.dispose(); info=null; } my3DEngine.meshManager.editProduct=false; clearArrow(); if(my3DEngine.meshManager.selectCircle!=null) { my3DEngine.meshManager.selectCircle.dispose(); my3DEngine.meshManager.selectCircle=null; if(my3DEngine.meshManager.rotator!=null) { my3DEngine.meshManager.rotator.dispose(); my3DEngine.meshManager.rotator=null; } } }; var removeSelectMesh=function() { if(my3DEngine.meshManager.selectFurnitureMesh!=null&&typeof(my3DEngine.meshManager.selectFurnitureMesh) != "undefined") { collidables.push(my3DEngine.meshManager.selectFurnitureMesh); my3DEngine.meshManager.selectFurnitureMesh=null; } if(currentMesh==null||typeof(currentMesh) == "undefined") { return; } removeinfo(); }; var finishEditMesh=function() { if(templane!=null) { if(olddistance!=null) { var dxz=templane.position.subtract(oldPlanept); var newscal,m_newdistance,m_olddistance; if(currentMesh.name=="downarrow") { m_newdistance=arrowdown.subtract(arrowtop); m_olddistance=oldPlanept.subtract(arrowtop); } else if(currentMesh.name=="toparrow") { m_newdistance=arrowtop.subtract(arrowdown); m_olddistance=oldPlanept.subtract(arrowdown); } else if(currentMesh.name=="leftarrow") { m_newdistance=arrowleft.subtract(arrowright); m_olddistance=oldPlanept.subtract(arrowright); } else if(currentMesh.name=="rightarrow") { m_newdistance=arrowright.subtract(arrowleft); m_olddistance=oldPlanept.subtract(arrowleft); } newscal=new BABYLON.Vector3(m_newdistance.x.toFixed(2)/m_olddistance.x.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.x.toFixed(2),0,m_newdistance.z.toFixed(2)/m_olddistance.z.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.z.toFixed(2)); if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow") { if(!isNaN(newscal.z)&&newscal.z!=-Number.POSITIVE_INFINITY&&newscal.z!=Number.POSITIVE_INFINITY) { /* if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")==0||my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")==0) { my3DEngine.meshManager.selectFurnitureMesh.scaling.y=m_newdistance.z.toFixed(2)/m_olddistance.z.toFixed(2)*my3DEngine.meshManager.selectFurnitureMesh.scaling.y.toFixed(2) } else { */ my3DEngine.meshManager.selectFurnitureMesh.scaling.z=newscal.z; //} } } else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow") { if(!isNaN(newscal.x)&&newscal.x!=-Number.POSITIVE_INFINITY&&newscal.x!=Number.POSITIVE_INFINITY) { my3DEngine.meshManager.selectFurnitureMesh.scaling.x=newscal.x; } } my3DEngine.meshManager.selectFurnitureMesh.computeWorldMatrix(true); my3DEngine.meshManager.selectFurnitureMesh.refreshBoundingInfo(); var dxz2; if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow") { dxz2=my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((arrowdown.x+arrowtop.x)/2,0,(arrowdown.z+arrowtop.z)/2)); my3DEngine.meshManager.selectFurnitureMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z)); arrowleft.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2)); arrowright.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2)); } else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow") { dxz2=my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center.subtract(new BABYLON.Vector3((arrowleft.x+arrowright.x)/2,0,(arrowleft.z+arrowright.z)/2)); my3DEngine.meshManager.selectFurnitureMesh.position.addInPlace(new BABYLON.Vector3(-dxz2.x,0,-dxz2.z)); arrowtop.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2)); arrowdown.addInPlace(new BABYLON.Vector3(dxz.x/2,0,dxz.z/2)); } line1=calculateLine.createLine(new BABYLON.Vector2(arrowdown.x,arrowdown.z),new BABYLON.Vector2(arrowtop.x,arrowtop.z)); line2=calculateLine.createLine(new BABYLON.Vector2(arrowleft.x,arrowleft.z),new BABYLON.Vector2(arrowright.x,arrowright.z)); } templane.dispose(); templane=null; olddistance=null; } }; var editingMesh=function(type) { var newpoint; clearMeasureMesh(); if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow") { if(type==1) { newpoint=getDiff2(current,line1); newpoint.y=currentMesh.position.y; } else //针对相框和墙贴 { newpoint=new BABYLON.Vector3(line1.x,currentMesh.position.y,current.z); } diff2=showpoint.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center); diff3=measurediff; ddif=diff3.subtract(diff2); ddif.x=ddif.x/4; ddif.y=ddif.y/4; ddif.z=ddif.z/4; startpoint=arrowtop.add(diff3); startpoint.addInPlace(ddif); endpoint=arrowdown.add(diff3); endpoint.addInPlace(ddif); var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2); fontpt.addInPlace(ddif); measuremesh6 = makeTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt); measuremesh6.rotation.x=Math.PI/2; if(showmesh.name=="rightarrow") { measuremesh6.rotation.y=-Math.PI/2+my3DEngine.meshManager.angle; } else { measuremesh6.rotation.y=Math.PI/2+my3DEngine.meshManager.angle; } } else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow") { if(type==1) { newpoint=getDiff2(current,line2); newpoint.y=currentMesh.position.y; } else { newpoint=new BABYLON.Vector3(line2.y,currentMesh.position.y,current.x); } diff2=showpoint.subtract(my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.center); diff3=measurediff; ddif=diff3.subtract(diff2); ddif.x=ddif.x/4; ddif.y=ddif.y/4; ddif.z=ddif.z/4; startpoint=arrowleft.add(diff3); startpoint.addInPlace(ddif); endpoint=arrowright.add(diff3); endpoint.addInPlace(ddif); var fontpt=new BABYLON.Vector3((startpoint.x+endpoint.x)/2,(startpoint.y+endpoint.y)/2,(startpoint.z+endpoint.z)/2); fontpt.addInPlace(ddif); measuremesh6 = makeTextPlane(BABYLON.Vector3.Distance(startpoint,endpoint).toFixed(2), "black", 50,fontpt); measuremesh6.rotation.x=Math.PI/2; if(showmesh.name=="toparrow") { measuremesh6.rotation.y=Math.PI+my3DEngine.meshManager.angle; if(measuremesh6.rotation.y>2*Math.PI) { measuremesh6.rotation.y-=2*Math.PI; } } } var startpoint1=startpoint.add(ddif); var startpoint2=startpoint.subtract(ddif); var endpoint1=endpoint.add(ddif); var endpoint2=endpoint.subtract(ddif); measuremesh1=BABYLON.Mesh.CreateLines("start",[startpoint1,startpoint2],scene); measuremesh2=BABYLON.Mesh.CreateLines("end",[endpoint1,endpoint2],scene); measuremesh3=BABYLON.Mesh.CreateLines("end",[startpoint,endpoint],scene); var pts1=drawArrow({x:startpoint.x,y:startpoint.z},{x:endpoint.x,y:endpoint.z},endpoint.y); var pts2=drawArrow({x:endpoint.x,y:endpoint.z},{x:startpoint.x,y:startpoint.z},startpoint.y); measuremesh4=BABYLON.Mesh.CreateLines("arrowend",pts1,scene); measuremesh5=BABYLON.Mesh.CreateLines("arrowstart",pts2,scene); measuremesh1.color = new BABYLON.Color3.Black(); measuremesh2.color = new BABYLON.Color3.Black(); measuremesh3.color = new BABYLON.Color3.Black(); measuremesh4.color = new BABYLON.Color3.Black(); measuremesh5.color = new BABYLON.Color3.Black(); return newpoint; }; var closeConfigProduct=function() { var configuratorProduct=document.getElementById("configuratorWindow"); configuratorProduct.style.display="none"; }; var paintWallFromSubMesh=function(subMeshId) { var addMat = new BABYLON.StandardMaterial("paint", scene); addMat.alpha = 1.0; var r=my3DEngine.paintWall.value.r; var g=my3DEngine.paintWall.value.g; var b=my3DEngine.paintWall.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=currentMesh.material.subMaterials[subMeshId/2].toward; currentMesh.material.subMaterials[subMeshId/2]=addMat; //currentMesh.applyDisplacementMap("http://3.bp.blogspot.com/-0ceB5kqwo70/TgF9neqSuKI/AAAAAAAAKCc/cdK47cIp-ZY/s1600/PUMPKIN+CARVINGS+FACE.jpg", -0.5, 0); startingPoint=null; var flag=false; for(var i=0;i=0) { if(my3DEngine.paintWall.beginPaint) { paintWallFromSubMesh(pickInfo.subMeshId); my3DEngine.paintWall.beginPaint=false; } else if(my3DEngine.phoSet.start) { my3DEngine.phoSet.start=false; document.getElementById("container3d").style.cursor="default"; var joinpoint=pickInfo.pickedPoint; var toward= currentMesh.material.subMaterials[pickInfo.subMeshId/2].toward; var indexplane=currentMesh.material.subMaterials[pickInfo.subMeshId/2].indexplane; var point1=currentMesh.material.subMaterials[pickInfo.subMeshId/2].points.point1; var point2=currentMesh.material.subMaterials[pickInfo.subMeshId/2].points.point2; var tempjoin=calculateLine.getPtIntersect3D(point1,point2,toward,my3DEngine.phoSet.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); my3DEngine.phoSet.photoFrameMesh.rotation.y=collidables[indexplane].rotation.y; my3DEngine.phoSet.photoFrameMesh.position=tempjoin1; my3DEngine.phoSet.photoFrameMesh.computeWorldMatrix(true); my3DEngine.phoSet.photoFrameMesh.refreshBoundingInfo(); if(my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.maximumWorld.y>wallHeigh||my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.minimumWorld.y<0) { my3DEngine.phoSet.photoFrameMesh.position.y=wallHeigh/2; tempjoin1.y=wallHeigh/2; tempjoin2.y=wallHeigh/2; } my3DEngine.phoSet.photoFrameMesh.planeindex=pickInfo.subMeshId/2; var diffplane=tempjoin2.subtract(tempjoin1); if(diffplane.x==0&&diffplane.y==0&&diffplane.z==0) { my3DEngine.phoSet.photoFrameMesh.visibility=1; alert("2275"); return ; } else { var add=1; while(!collidables[indexplane].intersectsMesh(my3DEngine.phoSet.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; } my3DEngine.phoSet.photoFrameMesh.position=tempjoin1; my3DEngine.phoSet.photoFrameMesh.computeWorldMatrix(true); my3DEngine.phoSet.photoFrameMesh.refreshBoundingInfo(); } my3DEngine.phoSet.photoFrameMesh.visibility=1; var fontpt=my3DEngine.phoSet.photoFrameMesh._boundingInfo.boundingBox.vectorsWorld[my3DEngine.phoSet.photoFrameMesh.frontindex]; var toward2=calculateLine.getToward(point1,point2,{x:fontpt.x,y:fontpt.z}); if(toward!=toward2) { my3DEngine.phoSet.photoFrameMesh.rotation.y+=Math.PI; } if(my3DEngine.phoSet.photoFrameMesh.rotation.y>=2*Math.PI) { my3DEngine.phoSet.photoFrameMesh.rotation.y-=2*Math.PI; } for(var i=0;i=0) { if(!my3DEngine.paintPlane.beginPaint) { removeSelectMesh(); closeConfigProduct(); return; } else { my3DEngine.paintPlane.beginPaint=false; } my3DEngine.paintPlane.currentId=currentMesh.id; my3DEngine.refreshFloor(currentMesh.wallid); return; } else if(currentMesh.name.indexOf("pho-")>=0||currentMesh.name.indexOf("picture-")>=0) { var configuratorProduct=document.getElementById("configuratorWindow"); configuratorProduct.style.display="block"; document.getElementById("editptrot").style.display="none"; document.getElementById("item-1").style.display="none"; document.getElementById("rotation-y").style.display="none"; document.getElementById("params-width").style.display="none"; var params_height=document.getElementById("params-height"); var params_length=document.getElementById("params-length"); //var height=Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.y-currentMesh._boundingInfo.boundingBox.minimumWorld.y); //var length=Math.abs(currentMesh._boundingInfo.boundingBox.maximumWorld.x-currentMesh._boundingInfo.boundingBox.minimumWorld.x); var height=currentMesh.height; var length=currentMesh.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); selectMesh=true; setTimeout(function () { camera.detachControl(canvas); }, 0); return; } selectMesh=true; if(currentMesh.name=="selectCircle"||currentMesh.name=="rotator") { actionRotator=true; setTimeout(function () { camera.detachControl(canvas); }, 0); return; } actionRotator=false; if(my3DEngine.meshManager.editProduct) { if(my3DEngine.meshManager.selectFurnitureMesh!=null&¤tMesh.name.indexOf("arrow")>-1) { selectArrow(); } else if(currentMesh.name.indexOf("arrow")<0) { clearArrow(); closeConfigProduct(); my3DEngine.meshManager.editProduct=false; if(my3DEngine.meshManager.selectFurnitureMesh.name!=currentMesh.name) { removeSelectMesh(); my3DEngine.meshManager.selectFurnitureMesh=currentMesh; } setselectMesh(); createinfo(); createArrow=false; setVertex(currentMesh._boundingInfo.boundingBox.vectorsWorld,currentMesh._boundingInfo.boundingBox.minimumWorld,currentMesh._boundingInfo.boundingBox.maximumWorld); collidables.remove(currentMesh); } else { alert("error1729"); } } else { if(typeof(my3DEngine.meshManager.selectFurnitureMesh) != "undefined"&&my3DEngine.meshManager.selectFurnitureMesh!=null) { if(my3DEngine.meshManager.selectFurnitureMesh.name!=currentMesh.name) { removeSelectMesh(); my3DEngine.meshManager.selectFurnitureMesh=currentMesh; collidables.remove(currentMesh); setselectMesh(); } else { collidables.remove(currentMesh); } lastPosition=startingPoint; } else { collidables.remove(currentMesh); my3DEngine.meshManager.selectFurnitureMesh=currentMesh; } if(typeof(currentMesh.rotationQuaternion) != "undefined"&¤tMesh.rotationQuaternion!=null) { //my3DEngine.meshManager.angle=currentMesh.rotationQuaternion.y; my3DEngine.meshManager.angle=currentMesh.rotation.y; } if(info==null) { if(my3DEngine.meshManager.selectCircle==null) { setselectMesh(); } else { my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(currentMesh._boundingInfo.boundingBox.center.x,selectCircleY,currentMesh._boundingInfo.boundingBox.center.z); } createinfo(); createArrow=false; setVertex(currentMesh._boundingInfo.boundingBox.vectorsWorld,currentMesh._boundingInfo.boundingBox.minimumWorld,currentMesh._boundingInfo.boundingBox.maximumWorld); } else { info.position= new BABYLON.Vector3(currentMesh.position.x, currentMesh._boundingInfo.boundingBox.maximumWorld.y+15, currentMesh.position.z); } } if (startingPoint) { // we need to disconnect camera from canvas setTimeout(function () { camera.detachControl(canvas); }, 0); } } else { removeSelectMesh(); closeConfigProduct(); } }.bind(this); var onPointerUp = function () { if(this.lock) { return; } if (startingPoint) { camera.attachControl(canvas, true); startingPoint = null; if(my3DEngine.meshManager.editProduct) { finishEditMesh(); clearMeasureMesh(); setProductInfo(); } actionRotator=false; selectMesh=false; return; } }; var 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; }; var clearMeasureMesh=function() { if(measuremesh1!=null) { measuremesh1.dispose(); measuremesh1=null; } if(measuremesh2!=null) { measuremesh2.dispose(); measuremesh2=null; } if(measuremesh3!=null) { measuremesh3.dispose(); measuremesh3=null; } if(measuremesh4!=null) { measuremesh4.dispose(); measuremesh4=null; } if(measuremesh5!=null) { measuremesh5.dispose(); measuremesh5=null; } if(measuremesh6!=null) { measuremesh6.dispose(); measuremesh6=null; } }; var makeTextPlane = function(text, color,size,position) { var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", 50, scene, true); dynamicTexture.hasAlpha = true; var plane = BABYLON.Mesh.CreatePlane("TextPlane", size, scene, true); plane.material = new BABYLON.StandardMaterial("TextPlaneMaterial", scene); plane.material.backFaceCulling = false; plane.material.specularColor = new BABYLON.Color3(0, 0, 0); plane.material.diffuseTexture = dynamicTexture; plane.position=position; dynamicTexture._context.font = "bold 12px Arial"; var textSize=dynamicTexture._context.measureText(text); if(size-1) { if(diff.x==0&&diff.z==0) { return; } else { var diff2,diff3; var startpoint,endpoint; var newpoint=editingMesh(1); diff = newpoint.subtract(currentMesh.position); templane.position.addInPlace(diff); if(currentMesh.name=="downarrow"||currentMesh.name=="toparrow") { mesh3.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2)); mesh4.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2)); } else if(currentMesh.name=="leftarrow"||currentMesh.name=="rightarrow") { mesh1.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2)); mesh2.position.addInPlace(new BABYLON.Vector3(diff.x/2,diff.y/2,diff.z/2)); } currentMesh.position=newpoint; my3DEngine.meshManager.selectFurnitureMesh.computeWorldMatrix(true); my3DEngine.meshManager.selectFurnitureMesh.refreshBoundingInfo(); } startingPoint = current; } evt.stopPropagation(); return; } evt.stopPropagation(); return; } if(actionRotator) { var angle1=BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(startingPoint.x,startingPoint.z),new BABYLON.Vector2(my3DEngine.meshManager.selectCircle.position.x,my3DEngine.meshManager.selectCircle.position.z)); var angle2=BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(current.x,current.z),new BABYLON.Vector2(my3DEngine.meshManager.selectCircle.position.x,my3DEngine.meshManager.selectCircle.position.z)); if(my3DEngine.meshManager.angle==null||typeof(my3DEngine.meshManager.angle)=="undefined") { my3DEngine.meshManager.angle=angle1._radians-angle2._radians; } else { my3DEngine.meshManager.angle+=angle1._radians-angle2._radians; } my3DEngine.meshManager.selectCircle.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL); my3DEngine.meshManager.selectCircle.rotation.y+=angle1._radians-angle2._radians; //if(my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("picture-")!=0&&my3DEngine.meshManager.selectFurnitureMesh.name.indexOf("pho-")!=0) //{ my3DEngine.meshManager.selectFurnitureMesh.rotate(BABYLON.Axis.Y, angle1._radians-angle2._radians, BABYLON.Space.LOCAL); my3DEngine.meshManager.selectFurnitureMesh.rotation.y+=angle1._radians-angle2._radians; my3DEngine.meshManager.angle=my3DEngine.meshManager.selectFurnitureMesh.rotation.y; //} //console.log("selectFurnitureMesh:"+my3DEngine.meshManager.selectFurnitureMesh.rotation.y+",selectCircle:"+my3DEngine.meshManager.selectCircle.rotation.y); startingPoint = current; } if (!current||!currentMesh) { evt.stopPropagation(); return; } if((currentMesh.name.indexOf("pho-")==0||currentMesh.name.indexOf("picture-")==0)) { var m_pt=getWallPlanePosition(); if(m_pt!=null) { var temp_last=null; var temp_pt =new BABYLON.Vector3(currentMesh.position.x,currentMesh.position.y,currentMesh.position.z); if(currentMesh.lastPos!=null&&typeof(currentMesh.lastPos) != "undefined") { temp_last=new BABYLON.Vector3(currentMesh.lastPos.x,currentMesh.lastPos.y,currentMesh.lastPos.z); var diff=m_pt.point.subtract(currentMesh.lastPos); currentMesh.lastPos=m_pt.point; currentMesh.position.addInPlace(diff); } else { currentMesh.lastPos=m_pt.point; } currentMesh.computeWorldMatrix(true); currentMesh.refreshBoundingInfo(); if(currentMesh._boundingInfo.boundingBox.maximumWorld.y>wallHeigh||currentMesh._boundingInfo.boundingBox.minimumWorld.y<0) { currentMesh.lastPos=temp_last; currentMesh.position=temp_pt; } else { if(m_pt.index==my3DEngine.phoSet.photoFrameMesh.planeindex) { for(var i=0;i19) { //alert(2851); break; } currentMesh.position=pos; currentMesh.computeWorldMatrix(true); currentMesh.refreshBoundingInfo(); } var fontpt=currentMesh._boundingInfo.boundingBox.vectorsWorld[currentMesh.frontindex]; var toward2=calculateLine.getToward(collidables[m_pt.index].pts.point1,collidables[m_pt.index].pts.point2,{x:fontpt.x,y:fontpt.z}); if(collidables[m_pt.index].toward!=toward2) { currentMesh.rotation.y+=Math.PI; } if(currentMesh.rotation.y>=2*Math.PI) { currentMesh.rotation.y-=2*Math.PI; } my3DEngine.phoSet.photoFrameMesh.planeindex=m_pt.index; } } } } } else { if(currentMesh.name!="selectCircle"&¤tMesh.name!="rotator") { currentMesh.position = new BABYLON.Vector3(current.x, currentMesh.position.y, current.z); } if(BABYLON.Vector2.Distance(new BABYLON.Vector2(startingPoint.x,startingPoint.z),new BABYLON.Vector2(current.x,current.z))>2) { actionmove=true; } //actionmove=true; if(info!=null) { info.position= new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x, my3DEngine.meshManager.selectFurnitureMesh._boundingInfo.boundingBox.maximumWorld.y+30, my3DEngine.meshManager.selectFurnitureMesh.position.z); } currentMesh.computeWorldMatrix(true); currentMesh.refreshBoundingInfo(); if(my3DEngine.meshManager.selectCircle!=null) { //my3DEngine.meshManager.selectCircle.position=new BABYLON.Vector3(my3DEngine.meshManager.selectFurnitureMesh.position.x,selectCircleY,my3DEngine.meshManager.selectFurnitureMesh.position.z); my3DEngine.meshManager.selectCircle.position.x=my3DEngine.meshManager.selectFurnitureMesh.position.x; my3DEngine.meshManager.selectCircle.position.z=my3DEngine.meshManager.selectFurnitureMesh.position.z; } var flag=true; var meshindex=-1; if(firstMeshes.length>0) { for(var i=0;icollidables[i]._boundingInfo.boundingBox.maximumWorld.y&¤tMesh._boundingInfo.boundingBox.maximumWorldMaxMark) { markpy=MaxMark; } mark.style.marginTop=markpy+"px"; }; canvas.addEventListener("mousedown", onPointerDown, false); canvas.addEventListener("mouseup", onPointerUp, false); canvas.addEventListener("mousemove", onPointerMove, false); canvas.addEventListener("mousewheel", onCameraWheel,false); scene.onDispose = function () { canvas.removeEventListener("mousedown", onPointerDown); canvas.removeEventListener("mouseup", onPointerUp); canvas.removeEventListener("mousemove", onPointerMove); canvas.removeEventListener("mousewheel", onCameraWheel); }; };