Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
aframe examples model-viewer and adding animation handler

I'm working on a project in which I want to repurpuse this example https://aframe.io/aframe/examples/showcase/model-viewer/

all I want to add is a trigger that starts the animation on click event.

I have managed to implement this to run on my server https://github.com/aframevr/aframe/tree/master/examples/showcase/model-viewer

but now struggling to code the event handler.

in model-viewer.js I can see a line that triggers animation at the start

 modelEl.setAttribute('animation-mixer', '');

I cant seem to figure out how to play it on click. I have done this implementation before in a simpler setup (https://codepen.io/wspluta/pen/rNwReNB)

    <script>
                AFRAME.registerComponent('animationhandler', {
                init: function() {
                  let playing = false;
                  this.el.addEventListener('click', () => {
                    if (!playing) {
                      this.el.setAttribute('animation-mixer', 'clip:*; loop: once; clampWhenFinished: true; duration : 6');
                      playing=true;
                    } else {
                      this.el.removeAttribute('animation-mixer');
                      playing=false;
                    }
                  });
                }
              })
    </script>
<body>
<a-scene>  
 <a-assets>    
   <a-asset id="sky" src="https://raw.githubusercontent.com/WSPluta/webxr102/main/tatooine.jpg">  </a-asset>
   <a-asset-item id="tie" src="https://raw.githubusercontent.com/WSPluta/webxr102/main/newTie.gltf"></a-asset-item>

 </a-assets> <a-entity id="tie" gltf-model="#tie" position="0 0.5 -5" scale="0.25 0.25 0.25" animationhandler></a-entity>
 <a-plane id="background" position="0 5 -15" height="9" width="16" rotation="0 0 0" opacity="0.9"></a-plane>
 <a-sky src="#sky"></a-sky>
 <a-camera>
       <a-cursor color="yellow"></a-cursor>
 </a-camera>
 </a-scene>
</body>

but I'm unable to figure out how to modify example/showcase document in order to implement it. I really want to reuse the camera movement and all the good stuff that comes from the example/showcase file.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I wanted to play an animation and used this code with react/nextjs to achieve this functionality.

const handleAnimate = useCallback(
    (e) => {
      const { keyCode } = e
      const rot = document.getElementById("camOrbit").getAttribute("rotation");

      // when w is pressed
      if (keyCode === 87) {
        document
          .getElementById("modAnim")
          .setAttribute("animation-mixer", `clip: Walk; loop: repeat`);

        document.getElementById("modAnim").setAttribute("rotation", `0 ${rot.y} 0`);
        //
        //
        //
        //
        // document.getElementById("modAnim").setAttribute("position", `${pos.x} 0 ${pos.z}`);
        document.addEventListener("keyup", (event) => {
          document
            .getElementById("modAnim")
            .setAttribute("animation-mixer", `clip: Idle; loop: repeat`);
        });
      }
},
    [setAttribute]
  );
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!