|
@@ -85,6 +85,7 @@
|
|
curHouseObj: null,
|
|
curHouseObj: null,
|
|
controlStarPosition : { x:0, y:0, z:0}, //控制器初始位置
|
|
controlStarPosition : { x:0, y:0, z:0}, //控制器初始位置
|
|
cameraStarPosition : { x:0, y:30, z:0} ,//摄像头初始位置
|
|
cameraStarPosition : { x:0, y:30, z:0} ,//摄像头初始位置
|
|
|
|
+ allSpaceCenter:null,//所有空间的中心点-水平面
|
|
// cameraLastPosition: null, //摄像头上一次移动到的位置
|
|
// cameraLastPosition: null, //摄像头上一次移动到的位置
|
|
// controlLastPosition: null, //观察点上一次移动到的位置
|
|
// controlLastPosition: null, //观察点上一次移动到的位置
|
|
canvasHeight:200, //canvas视图的高度-计算得出
|
|
canvasHeight:200, //canvas视图的高度-计算得出
|
|
@@ -126,7 +127,7 @@
|
|
overChange:false, //是否形变中
|
|
overChange:false, //是否形变中
|
|
isIOS:false, //是否ios手机。默认不是
|
|
isIOS:false, //是否ios手机。默认不是
|
|
currentChangeSpaceId:null, //当前变化的空间id
|
|
currentChangeSpaceId:null, //当前变化的空间id
|
|
- styleType:1,
|
|
|
|
|
|
+ styleType:2,
|
|
sumArea:0, //总面积
|
|
sumArea:0, //总面积
|
|
changeArea:0, //当次变化的面积
|
|
changeArea:0, //当次变化的面积
|
|
fixedArea:0, //初始面积值
|
|
fixedArea:0, //初始面积值
|
|
@@ -202,8 +203,7 @@
|
|
screenHeight = Math.min(window.innerHeight,window.screen.height)
|
|
screenHeight = Math.min(window.innerHeight,window.screen.height)
|
|
}
|
|
}
|
|
let unit = screenWidth / 750;//单位rpm 对应 px 的值
|
|
let unit = screenWidth / 750;//单位rpm 对应 px 的值
|
|
- that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
|
|
|
|
-
|
|
|
|
|
|
+ that.canvasHeight = screenHeight - (600 * unit) + (20 * unit);
|
|
const container = this.$refs.webgl;
|
|
const container = this.$refs.webgl;
|
|
const canvas3d = this.canvas = this.$refs.glcanvas;
|
|
const canvas3d = this.canvas = this.$refs.glcanvas;
|
|
|
|
|
|
@@ -232,10 +232,12 @@
|
|
this.tweenCameraAnmaChange = tweenCameraAnmaChange;
|
|
this.tweenCameraAnmaChange = tweenCameraAnmaChange;
|
|
this.gradientResize = gradientResize;
|
|
this.gradientResize = gradientResize;
|
|
this.moveMeshCenterHandle = moveMeshCenterHandle;
|
|
this.moveMeshCenterHandle = moveMeshCenterHandle;
|
|
|
|
+ this.movePositionHandle = movePositionHandle;
|
|
this.starRender = starRender;//对外暴露启动渲染的方法
|
|
this.starRender = starRender;//对外暴露启动渲染的方法
|
|
this.stopRender = stopRender;//对外暴露停止渲染的方法
|
|
this.stopRender = stopRender;//对外暴露停止渲染的方法
|
|
this.cameraInit = cameraInit;
|
|
this.cameraInit = cameraInit;
|
|
this.resetControl = resetControl;
|
|
this.resetControl = resetControl;
|
|
|
|
+ this.setControlTarget = setControlTarget;
|
|
if(this.curHouseObj){
|
|
if(this.curHouseObj){
|
|
this.houseInit()
|
|
this.houseInit()
|
|
}
|
|
}
|
|
@@ -318,6 +320,7 @@
|
|
controls.maxPolarAngle = Math.PI / 2; // 默认Math.PI,即可以向下旋转到的视角。
|
|
controls.maxPolarAngle = Math.PI / 2; // 默认Math.PI,即可以向下旋转到的视角。
|
|
controls.target.set(that.controlStarPosition.x, that.controlStarPosition.y, that.controlStarPosition.z);
|
|
controls.target.set(that.controlStarPosition.x, that.controlStarPosition.y, that.controlStarPosition.z);
|
|
controls.enableZoom = true;//启用摄像机的缩放
|
|
controls.enableZoom = true;//启用摄像机的缩放
|
|
|
|
+ controls.enablePan = false;//启用或禁用摄像机平移,默认为true
|
|
|
|
|
|
// 监听相机移动事件-限制只能在当前空间范围内移动
|
|
// 监听相机移动事件-限制只能在当前空间范围内移动
|
|
// controls.addEventListener('change', () => {
|
|
// controls.addEventListener('change', () => {
|
|
@@ -342,6 +345,12 @@
|
|
//初始状态
|
|
//初始状态
|
|
function resetControl(){
|
|
function resetControl(){
|
|
controls.reset();
|
|
controls.reset();
|
|
|
|
+ }
|
|
|
|
+ //设置控制器的焦点
|
|
|
|
+ function setControlTarget(target){
|
|
|
|
+ if(target.isVector3){
|
|
|
|
+ controls.target = target;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
function onWindowResize() {
|
|
function onWindowResize() {
|
|
camera.aspect = screenWidth / that.canvasHeight;
|
|
camera.aspect = screenWidth / that.canvasHeight;
|
|
@@ -446,7 +455,31 @@
|
|
// updateLables();
|
|
// updateLables();
|
|
},1001);//动画结束后回复原始状态
|
|
},1001);//动画结束后回复原始状态
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ //把摄像机移动到目标点位
|
|
|
|
+ function movePositionHandle(position = null, height=null){
|
|
|
|
+ let cameraNewPosition ={};
|
|
|
|
+ let targetNewPosition ={};
|
|
|
|
+ let oldUp = {};
|
|
|
|
+ let newUp = {};
|
|
|
|
+ let cy = height ? height : camera.position.y;
|
|
|
|
+ let _juli = cy * Math.tan(Math.PI / 8);
|
|
|
|
+ cameraNewPosition = {
|
|
|
|
+ x:position.x,
|
|
|
|
+ y:cy,
|
|
|
|
+ z:position.z + _juli,//增加偏差,防止极点翻转问题?不知道为啥会有用
|
|
|
|
+ }
|
|
|
|
+ //新的观察点的位置-取模型的中心点坐标,加上高度,由于模型都是贴地的,所以高度设置为0
|
|
|
|
+ targetNewPosition = {
|
|
|
|
+ x:position.x,
|
|
|
|
+ y:position.y,
|
|
|
|
+ z:position.z
|
|
|
|
+ }
|
|
|
|
+ oldUp = camera.up;//俯视状态
|
|
|
|
+ newUp = camera.up;
|
|
|
|
+ // console.warn("**movePositionHandle***",position,JSON.stringify(camera.position),JSON.stringify(controls.target)
|
|
|
|
+ // ,cameraNewPosition,targetNewPosition,JSON.stringify(camera.up))
|
|
|
|
+ tweenCamera(camera.position,controls.target,cameraNewPosition,targetNewPosition,oldUp,newUp,1000);
|
|
|
|
+ }
|
|
// oldP 相机原来的位置
|
|
// oldP 相机原来的位置
|
|
// oldT target原来的位置
|
|
// oldT target原来的位置
|
|
// newP 相机新的位置
|
|
// newP 相机新的位置
|
|
@@ -455,9 +488,9 @@
|
|
if(JSON.stringify(oldP) == JSON.stringify(newP) && JSON.stringify(oldT) == JSON.stringify(newT)){
|
|
if(JSON.stringify(oldP) == JSON.stringify(newP) && JSON.stringify(oldT) == JSON.stringify(newT)){
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- if (!chooseMesh) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ // if (!chooseMesh) {
|
|
|
|
+ // return false;
|
|
|
|
+ // }
|
|
tweenCameraAnma = true;
|
|
tweenCameraAnma = true;
|
|
var tween = new TWEEN.Tween({
|
|
var tween = new TWEEN.Tween({
|
|
x1: oldP.x, // 相机x
|
|
x1: oldP.x, // 相机x
|
|
@@ -512,7 +545,7 @@
|
|
// let _timeStep = 20;//单位 毫秒
|
|
// let _timeStep = 20;//单位 毫秒
|
|
// let unit = screenWidth / 750;//单位rpm 对应 px 的值
|
|
// let unit = screenWidth / 750;//单位rpm 对应 px 的值
|
|
// that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
|
|
// that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
|
|
-
|
|
|
|
|
|
+ return false;//不在执行变化
|
|
let unit = screenWidth / 750;//单位rpx 对应 px 的值
|
|
let unit = screenWidth / 750;//单位rpx 对应 px 的值
|
|
let _height = startHeight - endHeight;//高度变化-单位rpx
|
|
let _height = startHeight - endHeight;//高度变化-单位rpx
|
|
let _jisua = that.canvasHeight;
|
|
let _jisua = that.canvasHeight;
|
|
@@ -615,9 +648,27 @@
|
|
requestId = requestAnimationFrame(render, canvas3d);
|
|
requestId = requestAnimationFrame(render, canvas3d);
|
|
renderer.render(scene, camera);//单次渲染
|
|
renderer.render(scene, camera);//单次渲染
|
|
if (that.screenshotResolve) {
|
|
if (that.screenshotResolve) {
|
|
- stopRender();
|
|
|
|
- that.screenshotResolve()
|
|
|
|
- that.screenshotResolve = null;//释放Promise
|
|
|
|
|
|
+ // stopRender();
|
|
|
|
+ // that.screenshotResolve()
|
|
|
|
+ // that.screenshotResolve = null;//释放Promise
|
|
|
|
+ // 上述代码是全canvas截图,下述代码是canvas部分截图
|
|
|
|
+ let gl = renderer.getContext();
|
|
|
|
+ let pix = window.devicePixelRatio;
|
|
|
|
+ let width = parseInt(screenWidth*pix);
|
|
|
|
+ let height = parseInt((that.canvasHeight - 40)*pix);//丢弃上面高度为40px 的区域
|
|
|
|
+ let pixelData = new Uint8Array(width * height * 4);
|
|
|
|
+ if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE) {
|
|
|
|
+ // gl.readPixels(0, 0, frameBuffer.x, frameBuffer.y, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
|
|
|
|
+ gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
|
|
|
|
+ // 确保有像素,微信小程序安卓在进入子页面返回本页面后,再一次readPixels稳定无像素
|
|
|
|
+ if (pixelData.some(i => i !== 0)) {
|
|
|
|
+ stopRender();
|
|
|
|
+ console.warn("***screenshotResolve-pixelData***");
|
|
|
|
+ that.screenshotResolve({pixelData, width, height})
|
|
|
|
+ that.screenshotResolve = null;//释放Promise
|
|
|
|
+ pixelData = null;//清空内存中的数据
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -815,6 +866,9 @@
|
|
|
|
|
|
this.changeSpaceColor(data.spaceId,1);//设置选中空间的颜色
|
|
this.changeSpaceColor(data.spaceId,1);//设置选中空间的颜色
|
|
this.moveMeshCenter(space);
|
|
this.moveMeshCenter(space);
|
|
|
|
+ // setTimeout(()=>{
|
|
|
|
+ // this.setControlTarget(this.allSpaceCenter)
|
|
|
|
+ // },1100)
|
|
},
|
|
},
|
|
//具体空间面积变化-拖动产生的
|
|
//具体空间面积变化-拖动产生的
|
|
//data = {
|
|
//data = {
|
|
@@ -1681,6 +1735,9 @@
|
|
this.moveMeshCenterHandle(obj,type);
|
|
this.moveMeshCenterHandle(obj,type);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ locationHandle(){
|
|
|
|
+ this.movePositionHandle(this.allSpaceCenter,this.cameraStarPosition.y);//把摄像机移动到所有模型的中心点(水平面中心)
|
|
|
|
+ },
|
|
// 绘制地板
|
|
// 绘制地板
|
|
async loadSpace(){
|
|
async loadSpace(){
|
|
this.spaceList = [];
|
|
this.spaceList = [];
|
|
@@ -1715,6 +1772,7 @@
|
|
this.curSpaceObj = this.spaceList[0];
|
|
this.curSpaceObj = this.spaceList[0];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ this.allSpaceCenter = this.getAllSpaceCenter(this.spaceList);//获取所有空间的中心点
|
|
console.log("该户型空间数据:", this.spaceList, this.layoutIds,type);
|
|
console.log("该户型空间数据:", this.spaceList, this.layoutIds,type);
|
|
console.log("当前选中的空间:", this.curSpaceObj,this.curHouseObj);
|
|
console.log("当前选中的空间:", this.curSpaceObj,this.curHouseObj);
|
|
this.spaceListBackup = JSON.parse(JSON.stringify(this.spaceList));
|
|
this.spaceListBackup = JSON.parse(JSON.stringify(this.spaceList));
|
|
@@ -1814,13 +1872,14 @@
|
|
});
|
|
});
|
|
Promise.all(promise_list).then(()=>{
|
|
Promise.all(promise_list).then(()=>{
|
|
let endTime = new Date().getTime();
|
|
let endTime = new Date().getTime();
|
|
- console.log("模型全部加载完成,时间:",endTime - startTime);
|
|
|
|
|
|
+ console.log("模型全部加载完成,时间:",endTime - startTime,this.allSpaceCenter);
|
|
this.progress = 100;
|
|
this.progress = 100;
|
|
// this.$refs.myLoading.showLoading("加载中..." + this.progress + '%')
|
|
// this.$refs.myLoading.showLoading("加载中..." + this.progress + '%')
|
|
// 设置空间数组的墙体信息
|
|
// 设置空间数组的墙体信息
|
|
// this.setSpaceListWallInfo();
|
|
// this.setSpaceListWallInfo();
|
|
this.$nextTick(()=>{
|
|
this.$nextTick(()=>{
|
|
- this.moveMeshCenter(this.curSpaceObj);
|
|
|
|
|
|
+ this.movePositionHandle(this.allSpaceCenter);//把摄像机移动到所有模型的中心点(水平面中心)
|
|
|
|
+ // this.moveMeshCenter(this.curSpaceObj);
|
|
// this.myLoadingStatus = false;
|
|
// this.myLoadingStatus = false;
|
|
// this.$refs.myLoading.hideLoading();
|
|
// this.$refs.myLoading.hideLoading();
|
|
setTimeout(()=>{
|
|
setTimeout(()=>{
|