【问题标题】:How to group Buffer Geometry Object in Autodesk Forge如何在 Autodesk Forge 中对缓冲区几何对象进行分组
【发布时间】:2021-10-27 02:31:15
【问题描述】:

我想知道是否可以从场景构建器中添加一组模型组。最初我使用了一个 overlay.addMesh,但我想与我创建的自定义对象进行交互。不幸的是,该对象必须是一个分组。这是我的代码。我的查看器上没有显示任何内容。

this.sceneBuilder = await this.viewer.loadExtension(
  "Autodesk.Viewing.SceneBuilder"
);
this.modelBuilder = await this.sceneBuilder.addNewModel({
  modelNameOverride: "Beacon",
  conserveMemory: false,
});
const sphereGeometry = new THREE.BufferGeometry().fromGeometry(
  new THREE.SphereGeometry(5, 8, 8)
);
const sphereMaterial = new THREE.MeshPhongMaterial({
  color: new THREE.Color(0.647, 0.165, 0.165),
});

this.meshBeacon = new THREE.Mesh(sphereGeometry, sphereMaterial);
this.meshBeacon2 = new THREE.Mesh(sphereGeometry, sphereMaterial);
this.meshBeacon.matrix = new THREE.Matrix4().compose(
  position1,
  quaternion,
  scale
);
this.meshBeacon2.matrix = new THREE.Matrix4().compose(
  position2,
  quaternion,
  scale
);

this.group = new THREE.Group();
this.group.add(this.meshBeacon);
this.group.add(this.meshBeacon2);
console.log(this.group);
this.group.dbId = 666666;
this.modelBuilder.addMesh(this.group);

【问题讨论】:

    标签: three.js autodesk-forge autodesk-viewer buffer-geometry


    【解决方案1】:

    我们需要先创建单个几何体。全部由这段代码完成。

    let modelGeometry = new THREE.Geometry();
    const globalMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
    const head = new THREE.SphereGeometry(0.5, 32, 16);
    const body = new THREE.SphereGeometry(0.5, 32, 16);
    const textGeometry = new THREE.TextGeometry("text ID", {
      font: "monaco",
      size: 1,
      height: 0,
      curveSegments: 3,
    });
    
    textGeometry.computeBoundingBox();
    const textMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
    
    const workerId = new THREE.Mesh(textGeometry, textMaterial);
    
    const headMesh = new THREE.Mesh(head, globalMaterial);
    const bodyMesh = new THREE.Mesh(body, globalMaterial);
    headMesh.matrix.setPosition(new THREE.Vector3(0, 0, 3));
    bodyMesh.matrix.scale(new THREE.Vector3(1, 1, 4));
    // bodyMesh.matrix.scale(new THREE.Vector3(0.1, 0.1, 0.1));
    modelGeometry.merge(headMesh.geometry, headMesh.matrix);
    modelGeometry.merge(bodyMesh.geometry, bodyMesh.matrix);
    modelGeometry.merge(workerId.geometry, workerId.matrix);
    

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 2020-01-18
      • 2018-10-08
      • 2014-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多