Code Monkey home page Code Monkey logo

Comments (10)

KenneyNL avatar KenneyNL commented on June 14, 2024 1

Yeah! That's why I thought it was weird that the build doesn't create the animations while in the editor (at runtime) it does. The reason I'm not using GLTFRecorder is because (and could be a mistake on my side) I'd want multiple animations to be exported in my GLB file and I'm not sure if that's possible with just GLTFRecorder. Hence I'm kind of "coding" my own animations, which honestly is also kind of fun to mess around with.

from unitygltf.

hybridherbst avatar hybridherbst commented on June 14, 2024

Hi Kenney, glad to see you here!

Your code is almost correct but what may be a bit counterintuitive is that exporting additional animation data should happen in the AfterSceneExport callback – this way, the hierarchy and nodes where animation is applied is already captured and node IDs can be properly resolved.

Also note that typically when you want to export custom animations .ExportAnimations should be false, unless you want Animation/Animator components in your scene to also export their animation clips.

var adjustedSettings = Object.Instantiate(GLTFSettings.GetOrCreateSettings());
adjustedSettings.ExportDisabledGameObjects = true;
adjustedSettings.ExportAnimations = true;

var exportContext = new ExportContext(adjustedSettings);
var _exporter = new GLTFSceneExporter(new Transform[]{transform }, exportContext);

exportContext.AfterSceneExport += (scene, root) =>
{
    GLTFAnimation _animationA = new GLTFAnimation();
    _animationA.Name = "TestA";
    _exporter.AddAnimationData(e, "translation", _animationA, new float[]{0,2}, new object[]{(object)Vector3.one, (object)Vector3.up});
    _exporter.GetRoot().Animations.Add(_animationA);
};

      
_exporter.SaveGLB(@"D:\", "export-character");

For reference you can also look at the GLTFRecorder API – which allows you to basically record arbitrary animated hierarchies into a file. It is used for the RecorderComponent and RecorderTrack/RecorderClip but you can also use it from your own scripts.

from unitygltf.

KenneyNL avatar KenneyNL commented on June 14, 2024

Hey, well - thank you for working on this and willing to help me! Your code works perfectly, I indeed had to move it to the after scene export (and update my version of UnityGLTF as I was missing ExportContext from my version).

However, my goal was to create animations and export them on run-time in a build. Currently this code works perfectly in the Unity editor during run-time, but when making a build it doesn't export the animations anymore. I was under the impression that this method should work in a build?

from unitygltf.

hybridherbst avatar hybridherbst commented on June 14, 2024

Hm, the GLTFRecorder works fine at runtime with basically the same code (that's what it's designed for) – @pfcDorn can you check?

from unitygltf.

pfcDorn avatar pfcDorn commented on June 14, 2024

Hey Kenney!
Can you share some more informations about what exactly do you wanna animate? The code above works fine in build for me

from unitygltf.

KenneyNL avatar KenneyNL commented on June 14, 2024

There's something strange going on, while a few hours ago the code worked in the editor it doesn't work at all anymore after closing and re-opening the project. The object (GLB) gets exported correctly, but without animations.

As what I'm trying to animate; it's just a game object in the hierarchy of the object I'm exporting. After creating the animations I do root.Animations.Count and it says 2 (I'm adding 2) so that's correct. Here's the exported file;

export-character-animation.zip

from unitygltf.

pfcDorn avatar pfcDorn commented on June 14, 2024

Ahh.... the file is ok! In the current version of UnityGltf the AnimationPointers are not supported on import (There's already a working branch for import support for them, but a bit WIP still).
So in your case you should deactivate AnimationPointer Export.
Try this :)

        var ext_Animationpointer = adjustedSettings.ExportPlugins.FirstOrDefault( x => x is AnimationPointerExport);
	        if (ext_Animationpointer != null)
		        ext_Animationpointer.Enabled = false;

from unitygltf.

KenneyNL avatar KenneyNL commented on June 14, 2024

That did the trick! Both in editor, and in the build! Thank you so much!

Any way I can donate?

from unitygltf.

pfcDorn avatar pfcDorn commented on June 14, 2024

Happy to hear :)

from unitygltf.

hybridherbst avatar hybridherbst commented on June 14, 2024

@KenneyNL regarding donations, development is currently a joint effort between prefrontal cortex and Needle (I'm part of both) – with Needle leveraging UnityGLTF for all exporting, and thus ongoing heavy real-world testing.

There's a donations page here: https://engine.needle.tools/donate/

I wanted to talk to you anyways about bringing more of your content to people in an interactive way :)

from unitygltf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.