Comments (10)
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.
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.
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.
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.
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.
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.
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.
That did the trick! Both in editor, and in the build! Thank you so much!
Any way I can donate?
from unitygltf.
Happy to hear :)
from unitygltf.
@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)
- 'Texture2D' does not contain a definition for 'isDataSRGB' HOT 10
- Encounter object export errors when using package HOT 5
- Timeline for implementing KHR_interactivity? HOT 1
- ShaderGraph dependency problem for OpenUPM install HOT 5
- how to get progress (while loading) runtime.? HOT 2
- Incorrect material texture offset value on KTX2-based compressed GLB import HOT 2
- KtxTexture AssertionException HOT 5
- Textures are loading twice in memory causing doubled CPU spike and memory usage HOT 15
- Shaders don't mark any exposed properties as "Main Color" HOT 2
- Default range for imported punctual lights is too high. HOT 2
- KHR_materials_anisotropy support HOT 1
- Freeze frame during runtime loading in Android HOT 6
- Fix Suggenstion for HDRP
- Only 4 bone weights per vertex exported/imported when Unity supports up to 256 HOT 2
- Mesh with tangents has validation errors and breaking compression HOT 7
- How to load glb as byte[] or MemoryStream
- i build and run my unity project and i found only pink object. if someone know please help me. HOT 7
- Issues building for runtime loading HOT 2
- File Names are wrong HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitygltf.