At the moment TransformControls fits my needs but they have extra stuff like arrows in distance of the object and some squares. Is there anyway of me turning these off and instead keep only the arrows? enter image description here

import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import { TransformControls } from 'three/examples/jsm/controls/TransformControls.js';

const boxGeometry = new THREE.BoxGeometry();
const theeBoxMaterial = new THREE.MeshBasicMaterial({ color: 0x00FF00 });
const theeBox = new THREE.Mesh(boxGeometry, theeBoxMaterial);
const renderer = new THREE.WebGLRenderer();
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
    45,
    window.innerWidth / window.innerHeight,
    0.1,
    1000
);

const gridHelper = new THREE.GridHelper(30);
scene.add(gridHelper);

scene.add(theeBox);

const orbitControls = new OrbitControls(camera, renderer.domElement);
const transformControls = new TransformControls(camera, renderer.domElement);
transformControls.attach(theeBox);
transformControls.setMode('translate')
scene.add(transformControls);

renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

camera.position.set(50, 30, 20);
camera.lookAt(0, 0, 0);

const rayCaster = new THREE.Raycaster();
const mousePos = new THREE.Vector2();

let isDragging = false;

transformControls.addEventListener('dragging-changed', function (event) {
    orbitControls.enabled = !event.value;
    isDragging = event.value;
});



function animateTheeBox() {
    if (!isDragging && !orbitControls.enabled) {
        rayCaster.setFromCamera(mousePos, camera);
        const intersect = rayCaster.intersectObjects([theeBox]);

        if (intersect.length === 0) {
            const moveSpeed = 0.1;
            camera.position.x += (mousePos.x - 0.5) * moveSpeed;
            camera.position.y += (mousePos.y - 0.5) * moveSpeed;
            camera.lookAt(0, 0, 0);
        }
    }

    renderer.render(scene, camera);
}

renderer.setAnimationLoop(animateTheeBox);

编辑:添加图片以供参考

enter image description here

最小再现代码.提前谢谢!

推荐答案

判断Gizmo的类(line #781),

https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/TransformControls.js

class TransformControlsGizmo extends Object3D

并try 根据这一点,禁用某些东西

this.gizmo['translate'].XY.visible = false;
this.gizmo['translate'].YZ.visible = false;
this.gizmo['translate'].XZ.visible = false;
this.gizmo['rotate'].E.visible = false;
this.gizmo['scale'].XYZ.visible = false;
this.gizmo['scale'].XY.visible = false;
this.gizmo['scale'].YZ.visible = false;
this.gizmo['scale'].XZ.visible = false;

更新 根据这个答案: Three.js Hide Center Transform Controls

const gizmo = transformControls._gizmo.gizmo;

["XYZ", "XY", "YZ", "XZ"].forEach((axis) => {
  const obj = gizmo.translate.getObjectByName(axis);
  obj.visible = false;
  obj.layers.disable(0);
}); 

Javascript相关问答推荐

JS、C++和C#给出不同的Base 64 Guid编码结果

如何判断属于多个元素的属性是否具有多个值之一

materialized - activeIndex返回-1

使用javascript将Plotly Expandable Sparkline转换为HighCharter Plot在bslib卡中

使用useEffect,axios和useParams进行react测试

有条件重定向到移动子域

映射类型定义,其中值对应于键

400 bad request error posting through node-fetch

如何在.NET Core中将chtml文件链接到Java脚本文件?

在css中放置所需 colored颜色 以填充图像的透明区域

使用带有HostBinding的Angular 信号来更新样式?

将异步回调转换为异步生成器模式

如何在FastAPI中为通过file:/URL加载的本地HTML文件启用CORS?

警告框不显示包含HTML输入字段的总和

为什么延迟在我的laravel项目中不起作用?

当我点击一个按钮后按回车键时,如何阻止它再次被点击

使用Library chart.js在一个带有两个y轴的图表中绘制两个数据集

使用python,我如何判断一个html复选框是否被隐藏,以及它是否被S选中?

将Windows XP转换为原始数据以在html前端中显示

打字脚本中的函数包装键入