Raycasting in Three.js doesn't work -



Raycasting in Three.js doesn't work -

i have seen tons of question subject, whenever seek adapt situation never work.

why when click on sphere (saphi_mesh) ray.intersectobject(saphi_mesh) homecoming empty array ?

what did miss here ?

jsfiddle: http://jsfiddle.net/qzh59/

init function:

container = document.createelement("div") document.body.appendchild(container) photographic camera = new three.perspectivecamera(70, window.innerwidth / window.innerheight, 1, 1000) camera.position. z = 500 scene = new three.scene() var ambientlight = new three.ambientlight(0xbbbbbb); scene.add(ambientlight); var floor_geo = new three.planegeometry(window.innerwidth, 5, 10, 10) var floor_color = new three.meshbasicmaterial({color: 0xffff00}) var floor_mesh = new three.mesh(floor_geo, floor_color) var saphi_material = new three.meshbasicmaterial({color: 0xfff000}) var saphi_geo = new three.spheregeometry(50, 50, 50) saphi_mesh = new three.mesh(saphi_geo, saphi_material) scene.add(saphi_mesh) scene.add(floor_mesh) projector = new three.projector() renderer = new three.webglrenderer() renderer.setsize(window.innerwidth, window.innerheight) container.appendchild(renderer.domelement) renderer.domelement.addeventlistener("mousedown", onclick, false)

onclick function:

x = (event.clientx / window.innerwidth) * 2 - 1 y = (event.clienty / window.innerheight) * 2 + 1 dir = new three.vector3(x, y, -1) projector.unprojectvector(dir, camera) console.log(dir) ray = new three.raycaster(camera.position, dir.sub(camera).normalize()) console.log(ray.intersectobject(saphi_mesh))

three.js

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -