내가 선택한 개체를 얻을 수있는 다음과 같은 기능을 데와 개체를 선택할 수 없습니다, 그래서 내 기능은 여기three.js를가 Raycaster
function onMouseDown(event) {
console.log(event);
event.preventDefault();
mouse.x = (event.clientX/window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY/window.innerHeight) * 2 + 1;
// find intersections
var vector = new THREE.Vector3(mouse.x, mouse.y, 0.5);
projector.unprojectVector(vector, camera);
var pLocal = new THREE.Vector3(0, 0, -1);
var pWorld = pLocal.applyMatrix4(camera.matrixWorld);
var ray = new THREE.Raycaster(pWorld, vector.sub(pWorld).normalize());
ray.set(camera.position, vector.sub(camera.position).normalize());
var intersects = ray.intersectObjects(scene.children);
//console.log(intersects);
console.log(scene.children);
if (intersects.length > 0) {
var clickedObject = intersects[0].object;
console.log('objects '+intersects[ 0 ].object);
console.log('objects id'+intersects[ 0 ].object.id);
console.log('objects name'+intersects[ 0 ].object.name);
if (INTERSECTED != intersects[ 0 ].object) {
if (INTERSECTED) INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = intersects[ 0 ].object;
console.log('INTERSECTED '+INTERSECTED);
INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
INTERSECTED.material.emissive.setHex(0xff0000);
}
} else {
if (INTERSECTED) INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = null;
}
}
하지만 intersects
에 빈 배열을 얻고, 난 내 레벨을 시도 최고의하지만 난
var loader = new THREE.JSONLoader();
loader.load("uploads/accessories/3d/code/3dfile_"+file+".js",
function(geometry, object_material)
{
var object = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(object_material));
model = new THREE.Object3D();
model.id="Myid"+file;
model.name="Myname"+file;
model.userData ={ URL: "http://myurl.com" };
model.add(object);
model.position.set(x,y,z);
model.scale.set(obj_width,obj_height,obj_rotation);
model.opacity =2;
model.rotation.y = 600;
model.duration = 12000;
model.mirroredLoop = true;
model.castShadow = true;
model.receiveShadow = true;
console.log(model);
var smodel=model;
scene.add(smodel);
}
);
지금 내가 원하는
여기 등 장면에 객체를 추가하는이시 이전에 현장 의 연결된 모든 개체를 볼 수있는scene.children
콘솔 있다면, 여기에 어떤 해결책을 찾을 수 없습니다 추가 된 모델을에 가져옴
onMouseDown
에있는하지만 아무도 동일한 문제가 있습니까?
안녕하세요. 여전히 교차 개체를 선택할 수 없습니다. –
Jothi, 이것은 그리 어렵지 않습니다. 너 자신의 실수를 찾을 수있을거야. – WestLangley
내 편에서 어떤 문제도 찾을 수 없으므로 이런 일들에 대해 실망하고 있습니다. 교차 된 객체를 얻으려는 모든 일을하고 있지만 실패했습니다. –