剖切
接口列表
| 接口名称 | 说明 |
|---|---|
| 创建剖切 | 创建剖切 |
| 更新剖切进度 | 更新某个剖切面的进度 |
| 设置是否反向 | 设置某个剖切面是否进行反向剖切 |
| 是否显示剖切面 | 设置是否显示剖切面 |
| 是否显示盖面 | 设置是否显示盖面 |
| 添加指定剖切 | 添加指定剖切的模型 |
| 删除指定剖切 | 删除指定剖切的模型 |
| 清空指定剖切 | 清空指定剖切的模型 |
| 序列化 | 将剖切对象序列化成Json格式 |
| 反序列化 | 将Json格式 |
创建剖切
若需要剖切工具栏进行剖切功能,则可以直接使用剖切命令
boxSection('section', document.documentElement.clientWidth>480?SView.Commands.SectionMenu:SView.Commands.MobileSectionMenu);
若不需要剖切工具栏,则使用下面的接口,创建多个剖切时可以使用同一个action
let action = new SView.Actions.MultiSectionAction();
action.setScene(scene);
//设置XY方向剖切面显隐
action.setSectionVisible(SView.Actions.SectionDirectionType.SECTION_XY,true);
//设置YZ方向剖切面显隐
action.setSectionVisible(SView.Actions.SectionDirectionType.SECTION_YZ,true);
//设置ZX方向剖切面显隐
action.setSectionVisible(SView.Actions.SectionDirectionType.SECTION_ZX,true);
//设置包围盒剖切显隐
action.setSectionVisible(SView.Actions.SectionDirectionType.SECTION_BOX,false);
action.execute();
创建自定义视图,自定义视图最多创建三个,其余操作自定义剖切的接口与正常剖切一致,类型切换为自定义剖切的类型
let action = new SView.Actions.MultiSectionAction();
action.setScene(sview0.getViewer().getScene());
//第一个自定义剖切使用SView.Actions.SectionDirectionType.SECTION_CUSTOM1,后续依次是SView.Actions.SectionDirectionType.SECTION_CUSTOM2、SView.Actions.SectionDirectionType.SECTION_CUSTOM3
//设置自定义剖切方向
action.setSectionDirection(SView.Actions.SectionDirectionType.SECTION_CUSTOM1, new M3D.M3DMath.Vector3(-0.09183143610620231,-0.9944757739121634,0.05084213257207494));
//设置自定义剖切位置
action.setSectionPosition(SView.Actions.SectionDirectionType.SECTION_CUSTOM1, new M3D.M3DMath.Vector3(1647.3425839982642,1950.741735717373,-1736.2169277216883));
//设置自定义剖切显隐
action.setSectionVisible(SView.Actions.SectionDirectionType.SECTION_CUSTOM1, true);
//设置是否显示剖切面
action.setShowClipPlane(true);
//设置是否显示盖面
action.setShowCappingPlane(true);
//添加第一个自定义剖切,后续接口依次是addCustom2SectionPlane、addCustom3SectionPlane
action.addCustom1SectionPlane();
更新剖切进度
//位置为M3D.M3DMath.Vector3类型,当前方向为坐标值,其余方向传0即可
//可通过场景包围盒获取位置取值范围,
let box = scene.getBoundingBox(true);
//设置XY方向剖切位置
action.setSectionPosition(SView.Actions.SectionDirectionType.SECTION_XY,new M3D.M3DMath.Vector3(0,0,box.Center().z));
//设置YZ方向剖切位置
action.setSectionPosition(SView.Actions.SectionDirectionType.SECTION_YZ,new M3D.M3DMath.Vector3(box.Center().x,0,0));
//设置ZX方向剖切位置
action.setSectionPosition(SView.Actions.SectionDirectionType.SECTION_ZX,new M3D.M3DMath.Vector3(0,box.Center().y,0));
action.setSectionDirection(SView.Actions.SectionDirectionType.SECTION_XY,new M3D.M3DMath.Vector3(0,0,-1));
action.setSectionDirection(SView.Actions.SectionDirectionType.SECTION_YZ,new M3D.M3DMath.Vector3(-1,0,0));
action.setSectionDirection(SView.Actions.SectionDirectionType.SECTION_ZX,new M3D.M3DMath.Vector3(0,-1,0));
action.execute();
设置是否反向
//设置XY方向剖切是否反向
action.setSectionReverse(SView.Actions.SectionDirectionType.SECTION_XY,false);
//设置YZ方向剖切是否反向
action.setSectionReverse(SView.Actions.SectionDirectionType.SECTION_YZ,false);
//设置ZX方向剖切是否反向
action.setSectionReverse(SView.Actions.SectionDirectionType.SECTION_ZX,false);
//设置全部反向
action.setReverseClip(false);
action.execute();
设置显示剖切面
//设置是否显示剖切面
action.setShowClipPlane(true);
action.execute();
设置显示盖面
//设置是否显示剖切盖面
action.setShowCappingPlane(true);
action.execute();
添加指定剖切对象
//添加指定剖切模型,参数为Model对象的数组
action.addSelectedShapes([]);
action.execute();
删除指定剖切对象
//删除指定剖切模型,参数为Model对象的数组
action.removeSelectedShapes([]);
action.execute();
清空指定剖切对象
//清空指定剖切模型
action.clearSelectedShapes();
action.execute();
获取剖切面
//获取XY面剖切面
let sectionplane = action.sectionPlane_XY
//获取YZ面剖切面
let sectionplane = action.sectionPlane_YZ
//获取ZX面剖切面
let sectionplane = action.sectionPlane_ZX
//获取自定义剖切面1
let sectionplane = action.sectionPlane_Custom1
//获取自定义剖切面2
let sectionplane = action.sectionPlane_Custom2
//获取自定义剖切面3
let sectionplane = action.sectionPlane_Custom3
//获取包围盒剖切
let sectionBox = action.sectionBox;
//获取包围盒剖切面
let sectionPlanes = sectionBox.getSectionPlanes();
绑定剖切拖拽器
let sectionDraggerBindAction = new SView.Actions.SectionDraggerBindAction();
sectionDraggerBindAction.setScene(scene);
sectionDraggerBindAction.setSectionPlane(sectionplane);
sectionDraggerBindAction.execute();
let dragger = sectionDraggerBindAction.getDragger();
解绑剖切拖拽器
let draggers = scene.getDraggerManager();
draggers.unBindDragger(dragger);
序列化
//首先获取剖切对象
let sectionPlane = null;
//在H5中创建的剖切存在M3D.Shapes.ShapeType.SECTION类型中
let sectionList = shapes.getShapes(M3D.Shapes.ShapeType.SECTION);
for(let i=0;i<sectionList.length;i++){
let section = sectionList[i];
let sectionPlaneList = section.getPlaneList();
for(let j=0;j<sectionPlaneList.length;j++){
sectionPlane = sectionPlaneList[j];
let sectionPlaneJsonStr = M3D.Reader.SectionFactory.toJsonSectionPlane(sectionPlane);
break;
}
}
//从svlx中读取的剖切,存在M3D.Shapes.ShapeType.SECTION_PLANE类型中
let sectionPlaneList = shapes.getShapes(M3D.Shapes.ShapeType.SECTION_PLANE);
for(let j=0;j<sectionPlaneList.length;j++){
sectionPlane = sectionPlaneList[j];
let sectionPlaneJsonStr = M3D.Reader.SectionFactory.toJsonSectionPlane(sectionPlane);
}
反序列化
//反序列化出的剖切面会存在M3D.Shapes.ShapeType.SECTION_PLANE类型中
let jsonStr = '{"createID":19226,
"name":"",
"ShowClipPlane":true,
"ShowCappingPlane":true,
"visible":true,
"version":1.2,
"reverseClip":false,
"normalPos":[0,0,1],
"selectPos":[0,0,22.714599609374886]}';
let jsonObj = JSON.parse(jsonStr);
let plane = M3D.Reader.SectionFactory.fromJson(jsonObj,scene);
//将剖切盖面显隐设置为json中记录的状态
plane.setShowCappingPlane(plane.getOriShowCappingPlane());
//将剖切面显隐设置为json中记录的状态
plane.setShowClipPlane(plane.getOriShowClipPlane());
//将剖切面添加到Shapes中
shapes.addShape(plane);
//将剖切面显示
plane.setEnable(true);
//更新场景显示
scene.refresh();