0

I am trying to implement drag controls on this text geometry that I am creating in the viewer. I create the text like so:

createText(params) {
const textGeometry = new TextGeometry(params.text,
      Object.assign({}, {
        font: new Font(FontJson),
        params
      }));
const geometry = new THREE.BufferGeometry;

geometry.fromGeometry(textGeometry);

const material = this.createColorMaterial(
      params.color);

const text = new THREE.Mesh(
      geometry, material);

text.scale.set(params.scale, params.scale, params.scale);

text.position.set(
      params.position.x,
      params.position.y,
      10);


this.intersectMeshes.push(text);
this.viewer.impl.scene.add(text);

this.viewer.impl.sceneUpdated(true);

return text;

}

This works great, the meshes get added to the viewer, I can see them. Fantastic! Thus far, it is good. Now, I want to be able to drag them around with my mouse after I have added them. I noticed that Three.js already has drag controls built in, so I just implemented them like so:

  enableDragging(){
let controls = new THREE.DragControls( this.viewer, this.viewer.impl.camera.perspectiveCamera, this.viewer.impl.canvas );
controls.addEventListener( 'dragstart', dragStartCallback );
let startColor;
controls.addEventListener( 'dragend', dragendCallback );
function dragStartCallback(event) {
  startColor = event.object.material.color.getHex();
  event.object.material.color.setHex(0x000000);
}

function dragendCallback(event) {
  event.object.material.color.setColor(startColor);
}

}

After a big of debugging, I have seen where the problem occurs. For some reason, when I click on one of the meshes, the raycaster doesn't find any intersections. I.E. the array I get back is empty. No matter where I click on these objects.

Is my implementation wrong, or did I provision these meshes wrong to make them draggable? I have gotten the drag controls to work outside of the viewer, just not within it.

Sam Curry
  • 445
  • 2
  • 11

1 Answers1

0

This will not work, looking at the code of DragControls, the viewer implementation is too different in the way it implements the camera. You would need to either implement a custom version of DragControls or take a look at my transform tool and adapt it for custom meshes:

Moving visually your components in the viewer using the TransformTool

Felipe
  • 4,325
  • 1
  • 14
  • 19
  • Thank you! Can you tell me why the camera implementation makes it incompatible? – Sam Curry Mar 09 '18 at 14:51
  • hey Philippe, I am currently using transform extension but as soon as I add any scene using model builder the transform extension stop working, any idea what could be the issue ? – Ronak Shetiya Jun 02 '21 at 06:28
  • no idea sorry, please check with Forge support team. thanks – Felipe Jun 02 '21 at 14:02