123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- function ModelLoader(layer3D)
- {
- this.parameter = layer3D.layer.parameter;
- this.glassBoxMeshes = layer3D.collectMeshes.glassBoxMeshes;
- this.collidableMeshes=layer3D.collectMeshes.collidableMeshes;
-
- this.scene = layer3D.scene3D.scene;
- this.engine = layer3D.scene3D.engine;
-
- this.furnitureScal=0.2;
- this.currentPhotoMesh=null;
- };
- //添加画,图
- ModelLoader.prototype.showPicture=function(src)
- {
- var plan = BABYLON.Mesh.CreatePlane("picture-"+src, 1, this.scene);
- plan.scaling.x=50;
- plan.scaling.y=40;
- plan.floor=layer.selectFloor;
- plan.position=new BABYLON.Vector3(0, (plan.floor-1)*this.parameter.wallHeight, 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.collidableMeshes.push(plan);
- };
- //添加镜框
- ModelLoader.prototype.showPhoFrame=function(src)
- {
- BABYLON.SceneLoader.ImportMesh("", "images/3d/", src, this.scene, function (newMeshes)
- {
- newMeshes[0].scaling=new BABYLON.Vector3(this.furnitureScal,this.furnitureScal,this.furnitureScal);
-
- newMeshes[0].computeWorldMatrix(true);
- newMeshes[0].refreshBoundingInfo();
-
- newMeshes[0].position=new BABYLON.Vector3(0,this.parameter.softDecorationY,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);
- this.currentPhotoMesh=newMeshes[0];
- this.currentPhotoMesh.name="photo";
-
- this.currentPhotoMesh.height=newMeshes[0].firstHeigh;
- this.currentPhotoMesh.length=Math.abs(newMeshes[0]._boundingInfo.boundingBox.maximumWorld.x-newMeshes[0]._boundingInfo.boundingBox.minimumWorld.x);
- this.currentPhotoMesh.visibility=0;
- document.getElementById("container3d").style.cursor="url('images/brush.ico'),auto";
- for(var i=0;i<this.currentPhotoMesh._boundingInfo.boundingBox.vectorsWorld.length;++i)
- {
- if(this.currentPhotoMesh._boundingInfo.boundingBox.vectorsWorld[i].z>this.currentPhotoMesh._boundingInfo.boundingBox.minimumWorld.z)
- {
- this.currentPhotoMesh.frontindex=i;
- break;
- }
- }
- this.engine.hideLoadingUI();
- }.bind(this));
- };
- //初始化时,会有一些三维模型
- ModelLoader.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];
- }
- 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;
- 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.glassBoxMeshes.push(glassMesh);
- }
-
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if (typeof(this.collidableMeshes[i]) == "undefined") {
- this.collidableMeshes.splice(i,1);
- --i;
- continue;
- }
- if (mesh.intersectsMesh(this.collidableMeshes[i], true))
- {
- mesh.iscollision=true;
- break;
- }
- }
- ++initMesh;
- if(initMesh>21)
- {
- this.engine.hideLoadingUI();
- initMesh=0;
- }
- mesh.floor=layer.selectFloor;
- mesh.position.y+=(mesh.floor-1)*this.parameter.wallHeight;
- this.collidableMeshes.push(mesh);
- }.bind(this));
- return this.collidableMeshes[this.collidableMeshes.length-1];
- };
- //加载三维模型
- ModelLoader.prototype.showProduct=function(src)
- {
- this.engine.displayLoadingUI();
- this.engine.loadingUIText = "正在加载家具,请稍等!";
- 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];
- }
- var name=src.replace(".babylon","");
- mesh.scaling=new BABYLON.Vector3(layer.parameter.testModelData[name],layer.parameter.testModelData[name],layer.parameter.testModelData[name]);
- mesh.name=src;
-
- for(var i=0;i<this.collidableMeshes.length;++i)
- {
- if (typeof(this.collidableMeshes[i]) == "undefined") {
- this.collidableMeshes.splice(i,1);
- --i;
- continue;
- }
- if (mesh.intersectsMesh(this.collidableMeshes[i], true))
- {
- //第一次加载的模型,如果此时和别的模型发生碰撞,则表示可以碰撞,待不和别的模型发送碰撞时候,再实现不可碰撞
- mesh.iscollision=true;
- break;
- }
- }
- mesh.floor=layer.selectFloor;
- mesh.position.y=(mesh.floor-1)*this.parameter.wallHeight;
- this.collidableMeshes.push(mesh);
- this.engine.hideLoadingUI();
- }.bind(this));
- };
|