Model Viewer animation on hotspot click #1888
Replies: 32 comments 10 replies
-
@Arumugamhns thank you for the thoughtful questions! Please see my answers below:
Good news: yes, this is possible. Bad news: not yet; Chrome 83 is the first browser release that will support DOM Overlay, which is what allows UI to be shown in AR mode. You can try it out today if you install Chrome Beta or Canary on an Android device. See this Tweet for an example: https://twitter.com/modelviewer/status/1250796318886252545?s=20
You will need to use some script in order to do this. For example: <model-viewer id="modelViewer" src="some-animated-model.glb" ...>
<button id="hotspotButton"
slot="hotspot-one"
data-position="..." data-normal="...">Hotspot</button>
</model-viewer>
<script>
hotspotButton.addEventListener('click', () => {
if (modelViewer.paused) {
modelViewer.play();
} else {
modelViewer.pause();
}
});
</script> |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot.. i have another question.. i need to change the model color dynamically by click the button. for example.. I have a car model in blue car on load and i have 5 button in different colors by click this i need to change model color. is it possible? |
Beta Was this translation helpful? Give feedback.
-
@Arumugamhns the basic capability to do this is supported but experimental. Please refer to this example to see how to do it: https://modelviewer.dev/examples/scene-graph.html We are rapidly working on improving this part of the feature set (our scene graph API). Soon we hope to support custom textures as well. |
Beta Was this translation helpful? Give feedback.
-
but its not working in ios.. even in obj mode |
Beta Was this translation helpful? Give feedback.
-
how https://www.8thwall.com/ they open camera inside the browser. even in low end mobile. |
Beta Was this translation helpful? Give feedback.
-
@Arumugamhns yes, Quick Look does not support any kind of scriptability via the web. For that, you will need to use Apple's Reality Composer and produce an equivalent With regards to 8th Wall, they do support AR on low-end devices on the web, but the way they do it is costly in terms of script size and relatively low-quality in terms of detection and tracking. The This is just my personal opinion, but I believe that users who experience a low-quality AR experience are less likely to seek value from AR in the future. Although for some cases it can be a fun gimmick, in many practical cases (such as placing furniture to see if it fits in your room) a low-quality AR experience can be very frustrating for users and could even lead to a lost conversion for the company that offers it. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot sir.. finally only one question.. how to switch between two models. i have vehicle model it have 5 colors. by clicking buttons i need to change the color. |
Beta Was this translation helpful? Give feedback.
-
@Arumugamhns please see my comment above #1160 (comment) We have limited facilities for this right now, but the scene graph API does allow you to switch base color factor. Otherwise, the best option is to swap between 5 different models. |
Beta Was this translation helpful? Give feedback.
-
any example is available for swapping models? |
Beta Was this translation helpful? Give feedback.
-
Hi! Thank you for all you do with Model Viewer :) Please can you help me with your above code? Thank you!! |
Beta Was this translation helpful? Give feedback.
-
Also...is there a way to add multiple hotspots to trigger multiple animations? Cheers! |
Beta Was this translation helpful? Give feedback.
-
@Arumugamhns We now have a model-switching example. @79pxls You can find examples of switching between multiple animations here. We don't currently support non-looping animations, but that feature has been requested. For now, you'll just need to watch |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply! So just to confirm...I can call specific animations by name, then pause, then fire another animation on click, and so on? Does the Many thanks. |
Beta Was this translation helpful? Give feedback.
-
@79pxls It goes by seconds. I don't believe glTF animations have a concept of frames, except for keyframes, which are not uniformly spaced. |
Beta Was this translation helpful? Give feedback.
-
Thanks for clarifying Elalish! Is there any documentation on calling specific animation by name on click anywhere? Sorry for all the questions, coding is not my strong suit. |
Beta Was this translation helpful? Give feedback.
-
@elalish Thanks for explaining that difference in camera motion vs animation! :) And in retesting.. I CAN move the 3D around and click reset and it goes to where I want it.. but then the button doesnt work on subsequent tries... I am thinking I should not need an event listener on this?! right? I am probably doing something really simple wrong in my scripts. I appreciate your help! I love this model-viewer!! and so does our team! |
Beta Was this translation helpful? Give feedback.
-
Yeah, I'm not exactly sure where the bug is, but it's probably something simple. Your syntax isn't very familiar to me; it might be helpful to look at the fourth example here which has a script snippet. |
Beta Was this translation helpful? Give feedback.
-
@elalish Thank you!!! you are awesome... that was exactly what I needed... the right way to implement the scripts and that told me what I needed! I am so excited to keep learning more about model-viewer! Thank you again for your help :) |
Beta Was this translation helpful? Give feedback.
-
@elalish Sorry for the noob question.. Im trying to test out the model switching example for webxr with no luck.. |
Beta Was this translation helpful? Give feedback.
-
@7thFlare Have you checked the JS console? Errors and warnings there are a good place to start. It's likely something simple like JS syntax or a bad file path. I can only help if you post a link I can inspect (ideally the editing link from Glitch). |
Beta Was this translation helpful? Give feedback.
-
I also thought it was the file paths but i think I got that right.. maybe a js error as you say coz i havent done much on that front. |
Beta Was this translation helpful? Give feedback.
-
@7thFlare Yeah, looks like it's the file paths; lots of 404s and 403s in the console. Looks you haven't updated all your links to your glitch CDN assets. You're still trying to load my assets in my file structure, which doesn't match your Glitch site. |
Beta Was this translation helpful? Give feedback.
-
I have two main models.. ive linked those two in glitch.. the first one loads, but if i press another they both stop. |
Beta Was this translation helpful? Give feedback.
-
@7thFlare You need to remove all of my stuff first so that it's more clear what you're trying to do. Make sure your JS is only setting |
Beta Was this translation helpful? Give feedback.
-
cleaned it up.. but still nothing.. i feel my issue might be setting the correct base for it to switch the source from. |
Beta Was this translation helpful? Give feedback.
-
@7thFlare Yes, precisely. The base of the URL is just my own file structure. You need to remove all that and set the src to what you want it to be. |
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
@likhita-biyyala You'll want Apple's documentation for that, which shouldn't be too hard to find. What I'm less sure of is if what you want to do is possible in a .reality file. I'm not sure how much UI they support, as they certainly don't support DOM like webXR does. |
Beta Was this translation helpful? Give feedback.
-
Is there anyone that could assist me with this? Thank you very much. |
Beta Was this translation helpful? Give feedback.
-
Hello, Another thing that happens is this animation crashes when I try to open in my space. This is the example: Anyone with this issue that can help?? Thank you |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In Ar mode hotspot is not displayed..
is it possible to add UI elements in AR mode.
By click hotspot i need to play animation and stop automatically.
kindly give some idea or sample files.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions