How can I add an object at the spot where the user taps? #1864
Replies: 11 comments
-
@faizan1990 you're right to suggest that this is problem can seem deceptively simple. It's actually a pretty tricky thing to do (and even more so to do well). The short answer is that this behavior is not currently supported by
We want to define a model for rich, user-interactive composed scenes of 3D models that would work along the lines of what you are describing. But, we have a lot of other work to do first before we get there. |
Beta Was this translation helpful? Give feedback.
-
Hi @cdata, Thanks for your reply. Is there a way I can use in conjunction with ThreeJS to achieve the same? If not, is there a workaround? |
Beta Was this translation helpful? Give feedback.
-
Depending on your comfort level, there are various things you can do. The most technically wholesome thing to do would be to craft your own component based on this one, and bundle it yourself. This would require some working knowledge of the Node.js/NPM tooling ecosystem. If you want a quick / easy hack, another thing you could do is look up the const modelViewer = document.querySelector('model-viewer');
const $scene = Object.getOwnPropertySymbols(modelViewer)
.filter(symbol => symbol.description === 'scene')[0];
const scene = modelViewer[$scene];
// scene is a Three.js Scene instance that contains the loaded model With access to the scene, you should be able to do anything you would normally do with Three.js (including raycasting into the scene, adding objects etc.). DISCLAIMER: The above hack involves diving into private API that could change without notice. Also, Three.js is considered a private implementation detail; at some time in the future we might decide to use completely different renderers under some circumstances, at which time this would no longer work as expected. |
Beta Was this translation helpful? Give feedback.
-
Hi @cdata, When I am
Any idea why is it reporting version mismatch error? |
Beta Was this translation helpful? Give feedback.
-
@faizan1990 without a test case to look it, it's hard to speculate. Can you throw something up on Glitch, perhaps? |
Beta Was this translation helpful? Give feedback.
-
@cdata I am using the code in this example: https://googlewebcomponents.github.io/model-viewer/examples/augmented-reality.html. Upon running your workaround in the browser developer tools, I get the value of I am saving that JSON as a
Am I missing any step? |
Beta Was this translation helpful? Give feedback.
-
Hello, I've modified the scene slightly and doing raycasts, it seems though as if the modelviewer only re-renders once the camera orbits or user input is detected. So click and raycasts change e.g. something which is not immediately reflected, is there a way to tell modelviewer to re-render / set the scene dirty? I've found the symbol "needsRender" but I dont know how/if I can trigger that? Setting the scene dirty didnt help. |
Beta Was this translation helpful? Give feedback.
-
@marwie it should be sufficient to invoke |
Beta Was this translation helpful? Give feedback.
-
thanks for the quick reply. I've tried getting the needsRender symbol already like so (but cant seem to get it)
for example I'm setting the camera target in the threejs update loop but changes are only reflected when I start dragging in modelviewer. e.g.
(camera target is the vector3 from camera controls) |
Beta Was this translation helpful? Give feedback.
-
You can just set |
Beta Was this translation helpful? Give feedback.
-
Ok so I guess it has to do with how CameraControls are updated / passed to update the actual camera. Thanks |
Beta Was this translation helpful? Give feedback.
-
This might sound like a simple question, but unfortunately it isn't (at least not in ViroReact and other similar technologies). Is there a way using model viewer to be able to add an object (as simple as a text label) where user taps in the scene / object?
If there's an example code where this is illustrated, that would be great.
Beta Was this translation helpful? Give feedback.
All reactions