AR-js-org / AR.js

Image tracking, Location Based AR, Marker tracking. All on the Web.
MIT License
5.3k stars 909 forks source link

node_modules animation-mixer not working #605

Open acarnagey opened 1 month ago

acarnagey commented 1 month ago

Do you want to request a feature or report a bug? Report a bug

What is the current behavior? When I use nextjs / webpack /node_modules the animation-mixer does not work, but it works with pure html / js If the current behavior is a bug, please provide the steps to reproduce. create a nextjs project (or any project that uses node_modules)

npm install @ar-js-org/ar.js aframe aframe-extras`
{
 ...
     "@ar-js-org/ar.js": "^3.4.5",
     "aframe": "^1.3.0",
    "aframe-extras": "^7.2.0",
}

render a client component like

import "aframe";
import "@ar-js-org/ar.js";
import "aframe-extras";

<a-scene>
<a-marker preset="hiro">
<a-entity
  position="0 0 0"
  rotation="-90 0 0"
  scale="3 3 3"
  gltf-model="/t3.glb"
  animation-mixer
    ></a-entity>
  </a-marker>
</a-scene>

The 3d model shows up but does not animate, where as w/o node_modules it works and animates

<!DOCTYPE html>
<html>
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/dev/aframe/build/aframe-ar.js"></script>
<script src="https://cdn.jsdelivr.net/gh/c-frame/aframe-extras@7.2.0/dist/aframe-extras.min.js"></script>
<body style="margin : 0px; overflow: hidden;">
  <a-scene>
    <a-marker preset="hiro">
      <a-entity position="0 0 0" rotation="-90 0 0" scale="3 3 3" gltf-model="./3d3/t3.glb" animation-mixer></a-entity>
    </a-marker>
    <a-entity camera></a-entity>
  </a-scene>
</body>
</html>

Please mention other relevant information such as the browser version, Operating System and Device Name Brave Version 1.66.110 Chromium: 125.0.6422.60 (Official Build) (64-bit) Ubuntu 24.04 LTS Desktop computer What is the expected behavior? Should animate the glb 3d asset If this is a feature request, what is motivation or use case for changing the behavior?

vincentfretin commented 1 month ago

I know nothing about nextjs so I can't help you with this specific setup. But I have a project using just webpack and a static index.html, that works fine using aframe cdn or npm dependencies. Your above configuration doesn't make any sense, are you using npm dependencies or the cdn? Please use one or the other, not both. Do you have any errors in the console?

acarnagey commented 1 month ago

Thanks for the quick response, everything works, like the 3d model displays in the camera above the marker, except for the animation when node_modules and import syntax basically.

I know nothing about nextjs so I can't help you with this specific setup. But I have a project using just webpack and a static index.html, that works fine using aframe cdn or npm dependencies.

I think this would be the same with webpack, if you could share your code where the animation works with glb and animation-mixer that would be helpful for me if it works to see if I am doing some setup incorrectly.

Your above configuration doesn't make any sense, are you using npm dependencies or the cdn? Please use one or the other, not both. Do you have any errors in the console?

I am saying if I use import and node_modules animate doesn't work, this is what I am using and would like to get working, I am just saying that my glb 3d asset and animation normally works when using a cdn , I don't see any console errors. But these are the logs I see around aframe / ar.js when the page loads

A-Frame Version: 1.5.0 (Date 2023-11-14, Commit #7856a058)
page.js:5023 THREE Version (https://github.com/supermedium/three.js): 0.158.0
page.js:5023 WebVR Polyfill Version: ^0.10.12
page.js:7471 WARNING: Multiple instances of Three.js being imported.
eval @ three.cjs:50433
...
page.js:8238 WARNING: Multiple instances of Three.js being imported.
vincentfretin commented 1 month ago

If you see the "WARNING: Multiple instances of Three.js being imported." message that's not normal with latest aframe-extras. Double check you don't include the scripts twice. I have an example of webpack config and static index.html in https://github.com/networked-aframe/naf-valid-avatars/ using a components bundle and defer ui bundle. That example uses aframe and aframe-extras with cdn in index.html. But you can put aframe and aframe-extras imports in src/components.js instead, that will work the same.

acarnagey commented 1 month ago

Thanks but this doesn't explain the reported issue, it animated for me with cdn in index.html, my issue I am reporting it is doesn't animate when I try to import aframe, aframe-extras, & @ar-js-org/ar.js as node modules.

vincentfretin commented 1 month ago

You will have a better change someone to help with your issue if you share a link where we can reproduce it. You can create a bare minimum NextJS app with one model that has an animation on https://glitch.com/~aframe for example.

Also be sure that the scripts mainly aframe-extras that includes animation-mixer component are loaded before the a-scene is created. NextJS may auto add a defer script for example that's not compatible with having a a-scene in index.html, you would need to configure the script insertion to not be defer or create a-scene dynamically when you're sure the scripts are loaded. I don't know this stack so can't help you further on it.