1. 实例1

通过传入 id 数组将多个构件添加为被吸附对象,id 可以为构件的 componentId,也可以为外部构件的 modelKey

//获取吸附控制器对象
let adsorbControl = viewer3D.adsorbControl;

//开启吸附功能
adsorbControl.enabled = true;

//通过传入id数组将多个构件添加为被吸附对象,id可以为构件的componentId,也可以为外部构件的modelKey
adsorbControl.addTargetObjectByIds([
    {
        //该构件的ComponentId
        componentId: "M1601286135625_234936",
        //判断包围盒碰撞吸附的阈值,默认为500
        collisionThreshold: 500,
        //是否创建面高亮对象,该对象会在吸附时,高亮显示吸附面
        createHighLightMesh: true
    },
    {
        componentId: "M1601286135625_241831",
        collisionThreshold: 500,
        createHighLightMesh: true
    }
]);

//将当前对象设置为选中对象,操作方式为translate
adsorbControl.setSelectedObjectByComponentId(e.intersectInfo.selectedObjectId, BOS3D.TransformMode.translate);
//为该对象添加平移控件
viewer3D.translateComponentByKey(e.intersectInfo.selectedObjectId);

2. 实例2

将外部构件添加为当前选中对象

//获取吸附控制器对象
let adsorbControl = viewer3D.rootScene.adsorbControl;

//开启吸附功能
adsorbControl.enabled = true;

//给外部构件添加平移控件
viewer3D.translateComponentByKey(object);
//将外部构件设置为当前选中对象
adsorbControl.setSelectedObjectByCollection({
    collection: object
});

3. 实例3

直接将当前选中对象快捷吸附到指定构件的指定平面上

//将当前选中对象吸附到componentId为"M1601286135625_234936"的构件的包围盒法向量为(1, 0, 0)的平面上
adsorbControl.setAdsorbNormal("M1601286135625_234936", {
    x: 1
});

//将当前选中对象吸附到componentId为"M1601286135625_234936"的构件的包围盒法向量为(-1, 0, 0)的平面上
adsorbControl.setAdsorbNormal("M1601286135625_234936", {
    x: -1
});

//将当前选中对象吸附到componentId为"M1601286135625_234936"的构件的包围盒法向量为(0, 1, 0)的平面上
adsorbControl.setAdsorbNormal("M1601286135625_234936", {
    y: 1
});

//将当前选中对象吸附到componentId为"M1601286135625_234936"的构件的包围盒法向量为(0, -1, 0)的平面上
adsorbControl.setAdsorbNormal("M1601286135625_234936", {
    y: -1
});

//将当前选中对象吸附到componentId为"M1601286135625_234936"的构件的包围盒法向量为(0, 0, 1)的平面上
adsorbControl.setAdsorbNormal("M1601286135625_234936", {
    z: 1
});

//将当前选中对象吸附到componentId为"M1601286135625_234936"的构件的包围盒法向量为(0, 0, -1)的平面上
adsorbControl.setAdsorbNormal("M1601286135625_234936", {
    z: -1
});

4. 实例4

结束当前吸附

//结束吸附,并指定是否重置回之前的状态,这里为false,不重置
adsorbControl.endAdsorb(false);
版权所有@盈嘉互联(北京)科技有限公司 京ICP备15051988号-9 Copyright © 2021 all right reserved,powered by Gitbook该文件修订时间: 2021-12-20 09:59:48

results matching ""

    No results matching ""