@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
40 lines • 1.99 kB
JavaScript
import { AnimationUtils } from "../engine/engine_animation.js";
import { addComponent } from "../engine/engine_components.js";
import { ContextEvent, ContextRegistry } from "../engine/engine_context_registry.js";
import { Animation } from "./Animation.js";
import { Animator } from "./Animator.js";
import { GameObject } from "./Component.js";
import { PlayableDirector } from "./timeline/PlayableDirector.js";
ContextRegistry.registerCallback(ContextEvent.ContextCreated, args => {
const autoplay = args.context.domElement.getAttribute("autoplay");
if (autoplay !== undefined && (autoplay === "" || autoplay === "true" || autoplay === "1")) {
if (args.files) {
for (const file of args.files) {
const hasAnimation = GameObject.foreachComponent(file.file.scene, comp => {
if (comp.enabled === false)
return undefined;
if (comp instanceof Animation && comp.playAutomatically || comp instanceof Animator || comp instanceof PlayableDirector && comp.playOnAwake === true) {
return true;
}
else if (comp instanceof Animation) {
comp.playAutomatically = true;
return true;
}
else if (comp instanceof PlayableDirector) {
comp.playOnAwake = true;
return true;
}
return undefined;
}, true);
if (hasAnimation !== true) {
AnimationUtils.assignAnimationsFromFile(file.file, {
createAnimationComponent: (obj, _clip) => {
return addComponent(obj, Animation);
},
});
}
}
}
}
});
//# sourceMappingURL=AnimationUtilsAutoplay.js.map