Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation #173

Open
Omega1975 opened this issue Feb 21, 2023 · 1 comment
Open

Animation #173

Omega1975 opened this issue Feb 21, 2023 · 1 comment
Labels
question Further information is requested

Comments

@Omega1975
Copy link

The program I'm writing merges several glb files, now I would like to be able to read the animation data from the original files and write them into the new file. Below the simplified code

ModelRoot model = SharpGLTF.Schema2.ModelRoot.Load(glb.FileName);

foreach (Node nd in model.LogicalNodes){
if (nd.Mesh != null){

    //duplicate mesh -> NewMesh and merged rootNode.WithLocalTransform(afm).WithMesh(NewMesh);
   .....
   //

   foreach (Animation animation in model.LogicalAnimations){
       foreach (AnimationChannel ch in animation.Channels){
          if (ch.TargetNode == nd){
              IAnimationSampler<Vector3> AS=ch.GetTranslationSampler();
              ICurveSampler<Vector3> CS = AS.CreateCurveSampler(true);

              rootNode.WithTranslationAnimation(name, CS);
          }
       }
   }
}                                           

}

the line rootNode.WithTranslationAnimation(name, CS); returns an error at runtime:
Message: "Must implement IConvertibleCurve\r\nNome parametro: sampler"
ParamName: "sampler"
Source: "SharpGLTF.Toolkit"
StackTrace: " in SharpGLTF.Schema2.Toolkit.WithTranslationAnimation(Node node, String animationName, ICurveSampler1 sampler) in D:\\Sorgenti\\SharpGLTF\\src\\SharpGLTF.Toolkit\\Schema2\\AnimationExtensions.cs:riga 56" TargetSite: {SharpGLTF.Schema2.Node WithTranslationAnimation(SharpGLTF.Schema2.Node, System.String, SharpGLTF.Animations.ICurveSampler1[System.Numerics.Vector3])}

Where am i going wrong? Which instructions should I use?

Thanks in advance for the time you will dedicate to me

@vpenades
Copy link
Owner

Without having a reproducible example, my guess is you're not using the right object for that property.

I suspect you need to use CurveBuilder

Generally speaking, ICurverSampler is an interface used to "sample values along the curve" but does not state how the curve was built in the first place.

So you need to use an object that implements both ICurveSampler and IConvertibleCurve so it can be written back to a file.

Also, there's a number of incompatible curves: you cannot mix STEP, LINEAR, or SPLINE curves,

@vpenades vpenades added the question Further information is requested label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants