Hi there!
We are currently working on scaling, moving, and rotating an image in our viewer using TransformControls. The viewer has a simple setup that includes an orthographic camera and OrbitControls for easy panning and zooming.
However, we’ve noticed that scaling the PlaneGeometry where the image texture is located causes the image to stretch out. We’re wondering if there’s a way to maintain the aspect ratio and prevent any stretching.
const loader = new TextureLoader();
const texture = loader.load('/grote-tekening.jpg');
const material = new MeshBasicMaterial({map: texture, color: 0xffffff, transparent: true, opacity: 0.5});
const geometry = new PlaneGeometry(8000 / 7, 4485 / 7);
const mesh = new Mesh(geometry, material);
mesh.position.set(0, 0, 0);
mesh.rotation.x = -Math.PI / 2;
ModelManager.instance.scene.add(mesh);
const control = new TransformControls(ModelManager.instance.cameraController.camera, ModelManager.instance._renderer.domElement);
control.attach(mesh);
control.axis = "XY";
control.addEventListener('dragging-changed', event => {
if (ModelManager.instance.cameraController.orbitController !== undefined)
ModelManager.instance.cameraController.orbitController.orbitControls.enabled = !event.value;
})
window.addEventListener('keydown', function (event) {
switch (event.code) {
case "KeyW":
control.setMode('translate');
break;
case "KeyE":
control.setMode('rotate');
break;
case "KeyR":
control.setMode('scale');
break;
}
});
ModelManager.instance.scene.add(control);