raycasting

Raycast an object to enbable a mouse click event with Three.js

…衆ロ難τιáo~ 提交于 2020-01-03 02:29:12
问题 I'm adding objects to a scene for each entry in a database. I had a cube appearing in the scene for entry, but when I tried to add raycasting to click on objects it doesnt work, the objects dont appear and the console reads "Expression unavailable".. I got parts of the code from the three.js website for Raycasting so not sure what I'm doing wrong. Here is the JS code: var renderer, scene, container, camera; var geometry, material; var controls, group; var raycaster = new THREE.Raycaster();

Cone from direction vector

此生再无相见时 提交于 2019-12-25 08:47:53
问题 I have a normalized direction vector (from a 3d position to a light position) and I would like this vector to be rotated by some angle so I can create a "cone". Id like to simulate cone tracing by using the direction vector as the center of the cone and create an X number of samples to create more rays to sample from. What I would like to know is basically the math behind: https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Random/RandomUnitVectorinCone/index.html Which seems to do

How to find correct way to project point on triangle for drawing line on mesh?

蓝咒 提交于 2019-12-25 00:12:39
问题 I have mesh and 2 points on it - A and B . Each point lies on some triangle of mesh. The main goal is - draw correct line on mesh using 2 points. When points lies on triangles with different planes - I have problems with line drawing. What I do: CurrentTriangle = triangle on which the point A lies. While CurrentTriangle != triangle with point B: Get B projected( Bp ) to CurrentTriangle: moving B by -CurrentTriangle.normal * distance to plane. Find the exit point from the triangle - the

ThreeJS, raycaster gets strange coordinates when we log the intersection object

 ̄綄美尐妖づ 提交于 2019-12-24 07:35:53
问题 First I will expose the question, then I will show the test I made, the points where I clicked, the two sets of results, and the conclusions I got: Why exists an area where our raycaster reports that it has not intersected with the 3D model loaded? Here we see the points where I clicked: Then here we have the first result set: The first pair of coordinates, the ones logged as 'Mouse x position is: ' are the ones collected by: mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; console

Trying to get the point of intersection of a raycaster

走远了吗. 提交于 2019-12-24 07:21:53
问题 QUESTION: I load frontObject onto the scene. I get the centre of said object. Then I move beyond the object by setting a new point that reuses all the object's centre coordinates except the Z axis (the z coordinate becomes 100), so that I can trace a raycaster from the outside of the character (frontObject) towards it and get the intersection point on the back of the character so that I may place a shield on that point. Sadly, I get the following output: CODE: let box = new THREE.Box3()

Trying to get the point of intersection of a raycaster

China☆狼群 提交于 2019-12-24 07:21:02
问题 QUESTION: I load frontObject onto the scene. I get the centre of said object. Then I move beyond the object by setting a new point that reuses all the object's centre coordinates except the Z axis (the z coordinate becomes 100), so that I can trace a raycaster from the outside of the character (frontObject) towards it and get the intersection point on the back of the character so that I may place a shield on that point. Sadly, I get the following output: CODE: let box = new THREE.Box3()

Raycast2D not working as intended

萝らか妹 提交于 2019-12-23 05:14:00
问题 I am doing a mario prototype and (in this context) i am using two Raycasts, one pointing from mario up to the top of his head. That is used when mario is touching the blocks in the air. The second raycast is used down to the bottom of the feet to detect when he is stepping on a Goomba (enemy). I have included a function down below which shows that i use the same structure on both of the rays and "if" statements, but despite that, only the first one (on head) works. public void marioRaycast()

Object picking with 3 orthographic cameras and 3 viewports - three.js

时光总嘲笑我的痴心妄想 提交于 2019-12-23 04:08:29
问题 I have a WebGl/ThreeJS application, where I have 3 WebGL Renderers, 1 Scene and 1 Canvas for each renderer . The first 2 Canvases are ok, they work fine. The other canvas, is divided in 3 equal-dimension viewports and in each viewport I have added an orthographic camera in a different position. So I want to be able to detect mouse events on the objects that there in this Scene. I want to detect them in all of the viewports independently. All this, because I want to create a drag and drop

Raycast mouse clicks from Threejs model to the Fabricjs canvas used for the texture

三世轮回 提交于 2019-12-23 03:06:36
问题 I'm creating a 3D product configurator. First , I load the .gltf model and render it with Threejs. Then , I print a svg to a Fabricjs canvas and use that canvas to make a THREE.CanvasTexture and update the model with this canvas. The problem I allow people to upload text and images. Those images are added to the Fabric canvas as new objects. While the main svg is locked at the background, these uploaded images can be dragged and resized in the canvas. Screenshot canvas object Goal So my goal

Can a Three.js raycaster intersect a group?

℡╲_俬逩灬. 提交于 2019-12-22 04:28:23
问题 I want to know if my raycaster is looking at an OBJ that I've loaded. Due to the way exported from Cinema4D, I believe the OBJ is a THREE.Group with 3 children, instead of a THREE.Object. Can I just change my raycaster line of code to look for this group instead of an object? raycaster.set(controls.getObject().position, controls.getDirection(), 0, 40) var intersects = raycaster.intersectObjects(scene.children, true); if (intersects.length > 0) { //CURRENTLY INTERSECTING SOMETHING for (var i =