变换控制在模型中产生间隙

Transform control produces gaps in the model

我正在引用代码 here 来移动模型。然而,我发现了 transfrom 网格和我移动的对象之间的距离,即使我使用了边界框。对象越大,变换之间的距离就越大。

我的代码

_onControlsChange(ev) {
    if (this.selectedModel) {
      const posTransform = this._controls.position;
      let tr = this.selectedModel.getPlacementTransform();
      tr.elements[12] = posTransform.x;
      tr.elements[13] = posTransform.y;
      tr.elements[14] = posTransform.z;
      this.selectedModel.setPlacementTransform(tr);

      this._viewer.impl.invalidate(true, true, true);
    }
  }

_onSelectionChange(ev) {
    const selSet = ev.selections;
    const firstSel = selSet[0];

    if (firstSel) {
      const listdbIds = firstSel.dbIdArray;
      const dbidItem = listdbIds[0];
      const typeModel = dbidItem.toString().slice(0, 3);
      if (typeModel !== "500") return;

      const model = firstSel.model;
      this.selectedModel = model;
      let dbIds = firstSel.dbIdArray;
      let firstDbId = dbIds[0];
      const instanceTree = model.getData().instanceTree;
      const fragList = model.getFragmentList();
      let bounds = new THREE.Box3();
      instanceTree.enumNodeFragments(
        firstDbId,
        (fragId) => {
          let box = new THREE.Box3();
          fragList.getWorldBounds(fragId, box);
          bounds.union(box);
        },
        true
      );

      const position = bounds.getCenter();
      this._controls.setPosition(position);
      this._controls.visible = true;
    } else {
      this._controls.visible = false;
      this.selectedModel = null;
    }
  }

我更新了 GitHub 分支中的变换工具,现在您可以将其配置为移动单个对象或整个模型。查看提交 https://github.com/petrbroz/forge-simple-viewer-nodejs/commit/a72ea8fa3782bf7458ff8e381f8ff578809462e7.

要配置工具以移动整个模型,请像这样初始化扩展:

viewer.loadExtension('TransformExtension', { mode: TransformToolMode.MODEL });