0

I am taking help of sample code of Transform tutorial for rotation and position change. I am facing couple of problems.

  1. I want to perform rotation on door and window. Currently axis of rotation pass through center. How can I change to rotate a object from axis passing through its side.

  2. For position change > when I change position lets say for a window in any direction, it moves but it is visible on wall. I want it hide when window collide with wall.

Rohit Bohara
  • 323
  • 4
  • 14

1 Answers1

1

1/ Here is a code snippet that illustrates how to rotate elements (fragments), for a more complete sample take a look at this article: Rotate Components Control for the Viewer

rotateFragments (model, fragIdsArray, axis, angle, center) {

  var quaternion = new THREE.Quaternion()

  quaternion.setFromAxisAngle(axis, angle)

  fragIdsArray.forEach((fragId, idx) => {

    var fragProxy = this.viewer.impl.getFragmentProxy(
      model, fragId)

    fragProxy.getAnimTransform()

    var position = new THREE.Vector3(
      fragProxy.position.x - center.x,
      fragProxy.position.y - center.y,
      fragProxy.position.z - center.z)

    position.applyQuaternion(quaternion)

    position.add(center)

    fragProxy.position = position

    fragProxy.quaternion.multiplyQuaternions(
      quaternion, fragProxy.quaternion)

    if (idx === 0) {

      var euler = new THREE.Euler()

      euler.setFromQuaternion(
        fragProxy.quaternion, 0)

      this.emit('rotate', {
        dbIds: this.selection.dbIdArray,
        fragIds: fragIdsArray,
        rotation: euler,
        model
      })
    }

    fragProxy.updateAnimTransform()
  })
}

2/ When you transform the geometry, you are just moving triangles around, there is no built-in logic that will hide components because they overlap, you will need to implement that yourself. You should be able to find Three.js code that computes if two meshes intersect (triangle-triangle intersection algorithm) and run that against the component you are moving and all walls that are around. Here is something that can put you on tracks: How to detect collision in three.js?

Hope that helps

Felipe
  • 4,325
  • 1
  • 14
  • 19