問題:
當我點擊多維數據集時,TransformControls附加在多維數據集上。但是當我點擊光助手時,什麼也沒有發生。當我點擊燈光助手時,我想將TransformControls附加在燈光上。你能幫助我嗎?如何偵聽onclick事件SpotLight Helper並將TransformControls附加到光源上?
這是最簡單的例子。
http://codepen.io/kranzy/pen/ALOYZw
,或者如果你需要代碼:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var transformControls = new THREE.TransformControls(camera,renderer.domElement);
scene.add(transformControls);
var objects = [];
var cube = new THREE.Mesh(geometry, material);
cube.position.x = -10;
scene.add(cube);
objects.push(cube);
var light = new THREE.SpotLight();
scene.add(light);
var help = new THREE.SpotLightHelper(light);
scene.add(help);
objects.push(help);
camera.position.z = 5;
var render = function() {
requestAnimationFrame(render);
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render(scene, camera);
};
render();
window.addEventListener('resize', onWindowResize, false);
function onWindowResize(){
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
document.addEventListener('mousedown', onDocumentMouseDown, false);
document.addEventListener('touchstart', onDocumentTouchStart, false);
function onDocumentTouchStart(event){
event.preventDefault();
event.clientX = event.touches[0].clientX;
event.clientY = event.touches[0].clientY;
onDocumentMouseDown(event);
}
function onDocumentMouseDown(event){
event.preventDefault();
mouse = new THREE.Vector2();
mouse.x = (event.clientX/window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY/window.innerHeight) * 2 + 1;
raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(objects);
if(intersects.length > 0){
SELECTED = intersects[ 0 ].object;
console.log(SELECTED);
if (SELECTED.constructor === THREE.SpotLightHelper) {
transformControls.attach(SELECTED.light);
} else {
transformControls.attach(SELECTED);
}
}
}
OK?每次評論時,如果沒有必要,我會收到通知停止評論請 – amanuel2
你不能點擊一個輕助手。它沒有網格,因此它不會與光線投射相交。我錯過了什麼嗎? –
但爲什麼@ http://threejs.org/editor我可以輕鬆地點擊輕助手?它太難了。失去了4代表,因爲downvote,現在我給你50代表。你可以嘗試更多? –