const SliceTools = {
|
isbim: false,
|
currentBim: {},
|
currentTiles: {},
|
pouqie: {},
|
|
clippingPlanes: {},
|
direc: {},
|
viewer: {},
|
clipTransformInverse: {},
|
isOn: false,
|
radius: {},
|
|
//裁剪面的倍数
|
clipPlatSize: 2.0,
|
|
startSlice(param) {
|
let item = param.item
|
this.pouqie = param.pouqie
|
this.viewer = param.earthCtrl.coreMap
|
if (item.sourceType === "bim") {
|
this.isbim = true;
|
this.currentBim = item;
|
} else {
|
this.isbim = false;
|
let tiles = sgworld.ProjectTree.getObject(item.id);
|
if (tiles && tiles.treeobj.type === "3DTilesets") {
|
this.currentTiles = tiles.item;
|
this.pouqie.enitity = tiles.item;
|
}
|
}
|
|
this.calcDirec()
|
|
this.isOn = false;
|
if (this.isbim === false) {
|
this.createNotBimPlant()
|
} else {
|
this.changeDirection();
|
this.createBimPlant()
|
}
|
|
this.hookHandler()
|
},
|
|
changeDirection() {
|
for (var i = 0; i < this.pouqie.planeEntities.length; i++) {
|
this.viewer.entities.remove(this.pouqie.planeEntities[i]);
|
}
|
this.pouqie.downHandler && this.pouqie.downHandler.destroy();
|
this.pouqie.upHandler && this.pouqie.upHandler.destroy();
|
this.pouqie.moveHandler && this.pouqie.moveHandler.destroy();
|
if (this.pouqie.enitity) {
|
this.pouqie.enitity.removeAll();
|
}
|
if (this.isbim) {
|
window.BIM && window.BIM.DisableClip();
|
}
|
},
|
|
calcDirec() {
|
if (this.pouqie.direction === "0") {
|
this.direc = new Cesium.Cartesian3(0.0, 0.0, 1.0);
|
} else if (this.pouqie.direction === "1") {
|
this.direc = new Cesium.Cartesian3(-1.0, 0.0, 0.0);
|
} else if (this.pouqie.direction === "2") {
|
this.direc = new Cesium.Cartesian3(0.0, -1.0, 0.0);
|
}
|
},
|
|
createNotBimPlant() {
|
if (this.pouqie.enitity) {
|
this.clippingPlanes = new Cesium.ClippingPlaneCollection({
|
planes: [new Cesium.ClippingPlane(this.direc, 0.0)],
|
edgeWidth: 1,
|
unionClippingRegions: false
|
});
|
let tileset = this.pouqie.enitity;
|
const boundingSphere = tileset.boundingSphere;
|
const radius = boundingSphere.radius;
|
if (
|
!Cesium.Matrix4.equals(
|
tileset.root.transform,
|
Cesium.Matrix4.IDENTITY
|
)
|
) {
|
const transformCenter = Cesium.Matrix4.getTranslation(
|
tileset.root.transform,
|
new Cesium.Cartesian3()
|
);
|
const transformCartographic =
|
Cesium.Cartographic.fromCartesian(transformCenter);
|
const boundingSphereCartographic =
|
Cesium.Cartographic.fromCartesian(
|
tileset.boundingSphere.center
|
);
|
const height =
|
boundingSphereCartographic.height -
|
transformCartographic.height;
|
this.clippingPlanes.modelMatrix = Cesium.Matrix4.fromTranslation(
|
new Cesium.Cartesian3(0.0, 0.0, height)
|
);
|
}
|
for (let i = 0; i < this.clippingPlanes.length; ++i) {
|
const plane = this.clippingPlanes.get(i);
|
const planeEntity = this.viewer.entities.add({
|
position: boundingSphere.center,
|
plane: {
|
dimensions: new Cesium.Cartesian2(
|
radius * 2.5,
|
radius * 2.5
|
),
|
material: Cesium.Color.BLUE.withAlpha(0.1),
|
plane: new Cesium.CallbackProperty(
|
this.createPlaneUpdateFunction(plane),
|
false
|
),
|
outline: true,
|
outlineColor: Cesium.Color.BLUE,
|
},
|
});
|
this.pouqie.planeEntities.push(planeEntity);
|
}
|
tileset.this.clippingPlanes = this.clippingPlanes;
|
this.isOn = true;
|
}
|
},
|
|
createBimPlant() {
|
let bimObj = this.currentBim;
|
let fineStage = window.BIM;
|
if (fineStage) {
|
fineStage.EnableClip(false);
|
let boundingSphere = bimObj.boundingSphere
|
const boundingSphereCartographic =
|
Cesium.Cartographic.fromCartesian(
|
boundingSphere.center
|
);
|
let lnt = Cesium.Math.toDegrees(boundingSphereCartographic.longitude)
|
let lat = Cesium.Math.toDegrees(boundingSphereCartographic.latitude)
|
var center = Cesium.Cartesian3.fromDegrees(
|
Number(lnt),
|
Number(lat),
|
boundingSphereCartographic.height
|
)
|
this.pouqie.center = center
|
this.radius = boundingSphere.radius
|
|
let p = new Cesium.ClippingPlane(this.direc, boundingSphere.radius);
|
const planeEntity = this.viewer.entities.add({
|
position: center,
|
plane: {
|
dimensions: new Cesium.Cartesian2(boundingSphere.radius * this.clipPlatSize,
|
boundingSphere.radius * this.clipPlatSize),
|
material: Cesium.Color.BLUE.withAlpha(0.2),
|
plane: new Cesium.CallbackProperty(
|
this.createPlaneUpdateFunction(p),
|
false
|
),
|
outline: true,
|
outlineColor: Cesium.Color.BLUE,
|
},
|
});
|
|
let heading = (this.pouqie.anglevalue = bimObj.pqheading || 0);
|
|
planeEntity.orientation =
|
Cesium.Transforms.headingPitchRollQuaternion(
|
center,
|
new Cesium.HeadingPitchRoll((Math.PI / 180) * heading, 0, 0)
|
);
|
|
let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
|
let rz = Cesium.Math.toRadians(360 - heading); // Cesium.Math.toRadians(bimObj.roll || 0);
|
let rotationZ = Cesium.Matrix4.fromRotationTranslation(
|
Cesium.Matrix3.fromRotationZ(rz)
|
);
|
let clipTransformInverse = new Cesium.Matrix4()
|
Cesium.Matrix4.multiply(modelMatrix, rotationZ, modelMatrix);
|
Cesium.Matrix4.inverse(modelMatrix, clipTransformInverse);
|
|
this.pouqie.clipTransformInverse = clipTransformInverse;
|
this.pouqie.clipPlan = planeEntity;
|
this.pouqie.planeEntities.push(planeEntity);
|
|
|
if (this.pouqie.direction === "0") {
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction === "1") {
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction === "2") {
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: 0,
|
});
|
}
|
this.isOn = true;
|
}
|
},
|
|
createPlaneUpdateFunction(plane) {
|
let that = this
|
return function () {
|
plane.distance = that.pouqie.targetY;
|
return plane;
|
};
|
},
|
|
hookHandler() {
|
if (this.isOn) {
|
this.pouqie.downHandler = new Cesium.ScreenSpaceEventHandler(
|
this.viewer.scene.canvas
|
);
|
this.pouqie.downHandler.setInputAction((movement) => {
|
const pickedObject = this.viewer.scene.pick(movement.position);
|
if (
|
Cesium.defined(pickedObject) &&
|
Cesium.defined(pickedObject.id) &&
|
Cesium.defined(pickedObject.id.plane)
|
) {
|
this.pouqie.selectedPlane = pickedObject.id.plane;
|
this.pouqie.selectedPlane.material =
|
Cesium.Color.BLUE.withAlpha(0.05);
|
this.pouqie.selectedPlane.outlineColor = Cesium.Color.WHITE;
|
this.viewer.scene.screenSpaceCameraController.enableInputs = false;
|
}
|
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
|
this.pouqie.upHandler = new Cesium.ScreenSpaceEventHandler(
|
this.viewer.scene.canvas
|
);
|
this.pouqie.upHandler.setInputAction(() => {
|
if (Cesium.defined(this.pouqie.selectedPlane)) {
|
this.pouqie.selectedPlane.material =
|
Cesium.Color.BLUE.withAlpha(0.2);
|
this.pouqie.selectedPlane.outlineColor = Cesium.Color.BLUE;
|
this.pouqie.selectedPlane = undefined;
|
}
|
this.viewer.scene.screenSpaceCameraController.enableInputs = true;
|
}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
this.pouqie.moveHandler = new Cesium.ScreenSpaceEventHandler(
|
this.viewer.scene.canvas
|
);
|
this.pouqie.moveHandler.setInputAction((movement) => {
|
if (Cesium.defined(this.pouqie.selectedPlane)) {
|
if (this.isbim === false) {
|
const deltaY =
|
movement.startPosition.y - movement.endPosition.y;
|
this.pouqie.targetY += deltaY;
|
} else {
|
let fineStage = window.BIM;
|
if (fineStage) {
|
if (this.pouqie.direction === "0") {
|
var deltaY =
|
movement.startPosition.y - movement.endPosition.y;
|
this.pouqie.targetY -= deltaY * 0.1;
|
fineStage.SetClipPlane(this.pouqie.clipTransformInverse, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction == "1") {
|
var deltaY = movement.startPosition.x - movement.endPosition.x
|
this.pouqie.targetY -= deltaY * 0.1;
|
fineStage.SetClipPlane(this.pouqie.clipTransformInverse, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction == "2") {
|
var deltaY =
|
movement.startPosition.x - movement.endPosition.x;
|
this.pouqie.targetY -= deltaY * 0.1;
|
fineStage.SetClipPlane(this.pouqie.clipTransformInverse, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.pouqie.targetY,
|
});
|
}
|
}
|
}
|
}
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}
|
},
|
|
angleChange(val) {
|
if (this.isbim === false) {
|
if (this.pouqie.enitity) {
|
let modelMatrix = this.pouqie.enitity.clippingPlanes.modelMatrix;
|
let rz = Cesium.Math.toRadians(270 - val);
|
let rotationZ = Cesium.Matrix4.fromRotationTranslation(
|
Cesium.Matrix3.fromRotationZ(rz)
|
);
|
Cesium.Matrix4.multiply(modelMatrix, rotationZ, modelMatrix);
|
}
|
for (let i = 0; i < this.pouqie.planeEntities.length; i++) {
|
let planeEntity = this.pouqie.planeEntities[i];
|
planeEntity.orientation =
|
Cesium.Transforms.headingPitchRollQuaternion(
|
this.pouqie.enitity.boundingSphere.center,
|
new Cesium.HeadingPitchRoll((Math.PI / 180) * val, 0, 0)
|
);
|
}
|
} else {
|
if (this.pouqie.clipPlan && this.pouqie.center) {
|
let planeEntity = this.pouqie.clipPlan;
|
let center = this.pouqie.center;
|
planeEntity.orientation =
|
Cesium.Transforms.headingPitchRollQuaternion(
|
center,
|
new Cesium.HeadingPitchRoll((Math.PI / 180) * val, 0, 0)
|
);
|
let clipTransformInverse = new Cesium.Matrix4();
|
let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
|
let rz = Cesium.Math.toRadians(360 - val);
|
let rotationZ = Cesium.Matrix4.fromRotationTranslation(
|
Cesium.Matrix3.fromRotationZ(rz)
|
);
|
Cesium.Matrix4.multiply(modelMatrix, rotationZ, modelMatrix);
|
Cesium.Matrix4.inverse(modelMatrix, clipTransformInverse);
|
this.pouqie.clipTransformInverse = clipTransformInverse;
|
let fineStage = window.BIM;
|
if (fineStage) {
|
if (this.pouqie.direction === "0") {
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction === "1") {
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction === "2") {
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: 0,
|
});
|
}
|
this.registerPouqieHandler(
|
window.sgworld.coreMap,
|
clipTransformInverse
|
);
|
}
|
}
|
}
|
},
|
|
registerPouqieHandler(viewer, clipTransformInverse) {
|
this.pouqie.downHandler && this.pouqie.downHandler.destroy();
|
this.pouqie.upHandler && this.pouqie.upHandler.destroy();
|
this.pouqie.moveHandler && this.pouqie.moveHandler.destroy();
|
this.pouqie.downHandler = new Cesium.ScreenSpaceEventHandler(
|
viewer.scene.canvas
|
);
|
this.pouqie.downHandler.setInputAction((movement) => {
|
const pickedObject = viewer.scene.pick(movement.position);
|
if (
|
Cesium.defined(pickedObject) &&
|
Cesium.defined(pickedObject.id) &&
|
Cesium.defined(pickedObject.id.plane)
|
) {
|
this.pouqie.selectedPlane = pickedObject.id.plane;
|
this.pouqie.selectedPlane.material =
|
Cesium.Color.BLUE.withAlpha(0.05);
|
this.pouqie.selectedPlane.outlineColor = Cesium.Color.WHITE;
|
viewer.scene.screenSpaceCameraController.enableInputs = false;
|
}
|
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
|
this.pouqie.upHandler = new Cesium.ScreenSpaceEventHandler(
|
viewer.scene.canvas
|
);
|
this.pouqie.upHandler.setInputAction(() => {
|
if (Cesium.defined(this.pouqie.selectedPlane)) {
|
this.pouqie.selectedPlane.material =
|
Cesium.Color.BLUE.withAlpha(0.2);
|
this.pouqie.selectedPlane.outlineColor = Cesium.Color.WHITE;
|
this.pouqie.selectedPlane = undefined;
|
}
|
viewer.scene.screenSpaceCameraController.enableInputs = true;
|
}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
this.pouqie.moveHandler = new Cesium.ScreenSpaceEventHandler(
|
viewer.scene.canvas
|
);
|
this.pouqie.moveHandler.setInputAction((movement) => {
|
if (Cesium.defined(this.pouqie.selectedPlane)) {
|
if (this.isbim === false) {
|
const deltaY = movement.startPosition.y - movement.endPosition.y;
|
this.pouqie.targetY += deltaY;
|
} else {
|
let fineStage = window.BIM;
|
if (fineStage) {
|
if (this.pouqie.direction === "0") {
|
var deltaY = movement.startPosition.y - movement.endPosition.y;
|
this.pouqie.targetY -= deltaY * 0.1;
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction == "1") {
|
var deltaY = movement.startPosition.x - movement.endPosition.x;
|
if (this.pouqie.anglevalue <= 90 || this.pouqie.anglevalue >= 270) {
|
this.pouqie.targetY -= deltaY * 0.1;
|
} else {
|
this.pouqie.targetY += deltaY * 0.1;
|
}
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: -1,
|
y: 0,
|
z: 0,
|
d: this.pouqie.targetY,
|
}, {
|
x: 0,
|
y: 0,
|
z: 1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 0,
|
z: -1,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 1,
|
y: 0,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: 1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
}, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.radius * this.clipPlatSize,
|
});
|
} else if (this.pouqie.direction == "2") {
|
var deltaY = movement.startPosition.x - movement.endPosition.x;
|
this.pouqie.targetY -= deltaY * 0.1;
|
fineStage.SetClipPlane(clipTransformInverse, {
|
x: 0,
|
y: -1,
|
z: 0,
|
d: this.pouqie.targetY,
|
});
|
}
|
}
|
}
|
}
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
},
|
}
|
export default SliceTools;
|